| 1 | package net.minecraft.world;
|
| 2 |
|
| 3 | import net.minecraft.entity.player.PlayerCapabilities;
|
| 4 | import net.minecraft.world.storage.WorldInfo;
|
| 5 |
|
| 6 | public final class WorldSettings
|
| 7 | {
|
| 8 | /** The seed for the map. */
|
| 9 | private final long seed;
|
| 10 |
|
| 11 | /** The EnumGameType. */
|
| 12 | private final WorldSettings.GameType theGameType;
|
| 13 |
|
| 14 | /**
|
| 15 | * Switch for the map features. 'true' for enabled, 'false' for disabled.
|
| 16 | */
|
| 17 | private final boolean mapFeaturesEnabled;
|
| 18 |
|
| 19 | /** True if hardcore mode is enabled */
|
| 20 | private final boolean hardcoreEnabled;
|
| 21 | private final WorldType terrainType;
|
| 22 |
|
| 23 | /** True if Commands (cheats) are allowed. */
|
| 24 | private boolean commandsAllowed;
|
| 25 |
|
| 26 | /** True if the Bonus Chest is enabled. */
|
| 27 | private boolean bonusChestEnabled;
|
| 28 | private String worldName;
|
| 29 |
|
| 30 | public WorldSettings(long seedIn, WorldSettings.GameType gameType, boolean enableMapFeatures, boolean hardcoreMode, WorldType worldTypeIn)
|
| 31 | {
|
| 32 | this.worldName = "";
|
| 33 | this.seed = seedIn;
|
| 34 | this.theGameType = gameType;
|
| 35 | this.mapFeaturesEnabled = enableMapFeatures;
|
| 36 | this.hardcoreEnabled = hardcoreMode;
|
| 37 | this.terrainType = worldTypeIn;
|
| 38 | }
|
| 39 |
|
| 40 | public WorldSettings(WorldInfo info)
|
| 41 | {
|
| 42 | this(info.getSeed(), info.getGameType(), info.isMapFeaturesEnabled(), info.isHardcoreModeEnabled(), info.getTerrainType());
|
| 43 | }
|
| 44 |
|
| 45 | /**
|
| 46 | * Enables the bonus chest.
|
| 47 | */
|
| 48 | public WorldSettings enableBonusChest()
|
| 49 | {
|
| 50 | this.bonusChestEnabled = true;
|
| 51 | return this;
|
| 52 | }
|
| 53 |
|
| 54 | /**
|
| 55 | * Enables Commands (cheats).
|
| 56 | */
|
| 57 | public WorldSettings enableCommands()
|
| 58 | {
|
| 59 | this.commandsAllowed = true;
|
| 60 | return this;
|
| 61 | }
|
| 62 |
|
| 63 | public WorldSettings setWorldName(String name)
|
| 64 | {
|
| 65 | this.worldName = name;
|
| 66 | return this;
|
| 67 | }
|
| 68 |
|
| 69 | /**
|
| 70 | * Returns true if the Bonus Chest is enabled.
|
| 71 | */
|
| 72 | public boolean isBonusChestEnabled()
|
| 73 | {
|
| 74 | return this.bonusChestEnabled;
|
| 75 | }
|
| 76 |
|
| 77 | /**
|
| 78 | * Returns the seed for the world.
|
| 79 | */
|
| 80 | public long getSeed()
|
| 81 | {
|
| 82 | return this.seed;
|
| 83 | }
|
| 84 |
|
| 85 | /**
|
| 86 | * Gets the game type.
|
| 87 | */
|
| 88 | public WorldSettings.GameType getGameType()
|
| 89 | {
|
| 90 | return this.theGameType;
|
| 91 | }
|
| 92 |
|
| 93 | /**
|
| 94 | * Returns true if hardcore mode is enabled, otherwise false
|
| 95 | */
|
| 96 | public boolean getHardcoreEnabled()
|
| 97 | {
|
| 98 | return this.hardcoreEnabled;
|
| 99 | }
|
| 100 |
|
| 101 | /**
|
| 102 | * Get whether the map features (e.g. strongholds) generation is enabled or disabled.
|
| 103 | */
|
| 104 | public boolean isMapFeaturesEnabled()
|
| 105 | {
|
| 106 | return this.mapFeaturesEnabled;
|
| 107 | }
|
| 108 |
|
| 109 | public WorldType getTerrainType()
|
| 110 | {
|
| 111 | return this.terrainType;
|
| 112 | }
|
| 113 |
|
| 114 | /**
|
| 115 | * Returns true if Commands (cheats) are allowed.
|
| 116 | */
|
| 117 | public boolean areCommandsAllowed()
|
| 118 | {
|
| 119 | return this.commandsAllowed;
|
| 120 | }
|
| 121 |
|
| 122 | /**
|
| 123 | * Gets the GameType by ID
|
| 124 | */
|
| 125 | public static WorldSettings.GameType getGameTypeById(int id)
|
| 126 | {
|
| 127 | return WorldSettings.GameType.getByID(id);
|
| 128 | }
|
| 129 |
|
| 130 | public String getWorldName()
|
| 131 | {
|
| 132 | return this.worldName;
|
| 133 | }
|
| 134 |
|
| 135 | public static enum GameType
|
| 136 | {
|
| 137 | NOT_SET(-1, ""),
|
| 138 | SURVIVAL(0, "survival"),
|
| 139 | CREATIVE(1, "creative"),
|
| 140 | ADVENTURE(2, "adventure"),
|
| 141 | SPECTATOR(3, "spectator");
|
| 142 |
|
| 143 | int id;
|
| 144 | String name;
|
| 145 |
|
| 146 | private GameType(int typeId, String nameIn)
|
| 147 | {
|
| 148 | this.id = typeId;
|
| 149 | this.name = nameIn;
|
| 150 | }
|
| 151 |
|
| 152 | public int getID()
|
| 153 | {
|
| 154 | return this.id;
|
| 155 | }
|
| 156 |
|
| 157 | public String getName()
|
| 158 | {
|
| 159 | return this.name;
|
| 160 | }
|
| 161 |
|
| 162 | public void configurePlayerCapabilities(PlayerCapabilities capabilities)
|
| 163 | {
|
| 164 | if (this == CREATIVE)
|
| 165 | {
|
| 166 | capabilities.allowFlying = true;
|
| 167 | capabilities.isCreativeMode = true;
|
| 168 | capabilities.disableDamage = true;
|
| 169 | }
|
| 170 | else if (this == SPECTATOR)
|
| 171 | {
|
| 172 | capabilities.allowFlying = true;
|
| 173 | capabilities.isCreativeMode = false;
|
| 174 | capabilities.disableDamage = true;
|
| 175 | capabilities.isFlying = true;
|
| 176 | }
|
| 177 | else
|
| 178 | {
|
| 179 | capabilities.allowFlying = false;
|
| 180 | capabilities.isCreativeMode = false;
|
| 181 | capabilities.disableDamage = false;
|
| 182 | capabilities.isFlying = false;
|
| 183 | }
|
| 184 |
|
| 185 | capabilities.allowEdit = !this.isAdventure();
|
| 186 | }
|
| 187 |
|
| 188 | public boolean isAdventure()
|
| 189 | {
|
| 190 | return this == ADVENTURE || this == SPECTATOR;
|
| 191 | }
|
| 192 |
|
| 193 | public boolean isCreative()
|
| 194 | {
|
| 195 | return this == CREATIVE;
|
| 196 | }
|
| 197 |
|
| 198 | public boolean isSurvivalOrAdventure()
|
| 199 | {
|
| 200 | return this == SURVIVAL || this == ADVENTURE;
|
| 201 | }
|
| 202 |
|
| 203 | public static WorldSettings.GameType getByID(int idIn)
|
| 204 | {
|
| 205 | for (WorldSettings.GameType worldsettings$gametype : values())
|
| 206 | {
|
| 207 | if (worldsettings$gametype.id == idIn)
|
| 208 | {
|
| 209 | return worldsettings$gametype;
|
| 210 | }
|
| 211 | }
|
| 212 |
|
| 213 | return SURVIVAL;
|
| 214 | }
|
| 215 |
|
| 216 | public static WorldSettings.GameType getByName(String gamemodeName)
|
| 217 | {
|
| 218 | for (WorldSettings.GameType worldsettings$gametype : values())
|
| 219 | {
|
| 220 | if (worldsettings$gametype.name.equals(gamemodeName))
|
| 221 | {
|
| 222 | return worldsettings$gametype;
|
| 223 | }
|
| 224 | }
|
| 225 |
|
| 226 | return SURVIVAL;
|
| 227 | }
|
| 228 | }
|
| 229 | }
|
| 230 |
|