001 package net.minecraft.src; 002 003 import java.util.Map; 004 005 import com.google.common.collect.Maps; 006 007 import cpw.mods.fml.common.Side; 008 import cpw.mods.fml.common.asm.SideOnly; 009 010 public class WorldInfo 011 { 012 /** Holds the seed of the currently world. */ 013 private long randomSeed; 014 private WorldType terrainType; 015 016 /** The spawn zone position X coordinate. */ 017 private int spawnX; 018 019 /** The spawn zone position Y coordinate. */ 020 private int spawnY; 021 022 /** The spawn zone position Z coordinate. */ 023 private int spawnZ; 024 025 /** The current world time in ticks, ranging from 0 to 23999. */ 026 private long worldTime; 027 028 /** The last time the player was in this world. */ 029 private long lastTimePlayed; 030 031 /** The size of entire save of current world on the disk, isn't exactly. */ 032 private long sizeOnDisk; 033 private NBTTagCompound playerTag; 034 private int dimension; 035 036 /** The name of the save defined at world creation. */ 037 private String levelName; 038 039 /** Introduced in beta 1.3, is the save version for future control. */ 040 private int saveVersion; 041 042 /** True if it's raining, false otherwise. */ 043 private boolean raining; 044 045 /** Number of ticks until next rain. */ 046 private int rainTime; 047 048 /** Is thunderbolts failing now? */ 049 private boolean thundering; 050 051 /** Number of ticks untils next thunderbolt. */ 052 private int thunderTime; 053 054 /** The Game Type. */ 055 private EnumGameType theGameType; 056 057 /** 058 * Whether the map features (e.g. strongholds) generation is enabled or disabled. 059 */ 060 private boolean mapFeaturesEnabled; 061 062 /** Hardcore mode flag */ 063 private boolean hardcore; 064 private boolean allowCommands; 065 private boolean initialized; 066 private Map<String,NBTBase> additionalProperties; 067 068 protected WorldInfo() 069 { 070 this.terrainType = WorldType.DEFAULT; 071 } 072 073 public WorldInfo(NBTTagCompound par1NBTTagCompound) 074 { 075 this.terrainType = WorldType.DEFAULT; 076 this.randomSeed = par1NBTTagCompound.getLong("RandomSeed"); 077 078 if (par1NBTTagCompound.hasKey("generatorName")) 079 { 080 String var2 = par1NBTTagCompound.getString("generatorName"); 081 this.terrainType = WorldType.parseWorldType(var2); 082 083 if (this.terrainType == null) 084 { 085 this.terrainType = WorldType.DEFAULT; 086 } 087 else if (this.terrainType.isVersioned()) 088 { 089 int var3 = 0; 090 091 if (par1NBTTagCompound.hasKey("generatorVersion")) 092 { 093 var3 = par1NBTTagCompound.getInteger("generatorVersion"); 094 } 095 096 this.terrainType = this.terrainType.getWorldTypeForGeneratorVersion(var3); 097 } 098 } 099 100 this.theGameType = EnumGameType.getByID(par1NBTTagCompound.getInteger("GameType")); 101 102 if (par1NBTTagCompound.hasKey("MapFeatures")) 103 { 104 this.mapFeaturesEnabled = par1NBTTagCompound.getBoolean("MapFeatures"); 105 } 106 else 107 { 108 this.mapFeaturesEnabled = true; 109 } 110 111 this.spawnX = par1NBTTagCompound.getInteger("SpawnX"); 112 this.spawnY = par1NBTTagCompound.getInteger("SpawnY"); 113 this.spawnZ = par1NBTTagCompound.getInteger("SpawnZ"); 114 this.worldTime = par1NBTTagCompound.getLong("Time"); 115 this.lastTimePlayed = par1NBTTagCompound.getLong("LastPlayed"); 116 this.sizeOnDisk = par1NBTTagCompound.getLong("SizeOnDisk"); 117 this.levelName = par1NBTTagCompound.getString("LevelName"); 118 this.saveVersion = par1NBTTagCompound.getInteger("version"); 119 this.rainTime = par1NBTTagCompound.getInteger("rainTime"); 120 this.raining = par1NBTTagCompound.getBoolean("raining"); 121 this.thunderTime = par1NBTTagCompound.getInteger("thunderTime"); 122 this.thundering = par1NBTTagCompound.getBoolean("thundering"); 123 this.hardcore = par1NBTTagCompound.getBoolean("hardcore"); 124 125 if (par1NBTTagCompound.hasKey("initialized")) 126 { 127 this.initialized = par1NBTTagCompound.getBoolean("initialized"); 128 } 129 else 130 { 131 this.initialized = true; 132 } 133 134 if (par1NBTTagCompound.hasKey("allowCommands")) 135 { 136 this.allowCommands = par1NBTTagCompound.getBoolean("allowCommands"); 137 } 138 else 139 { 140 this.allowCommands = this.theGameType == EnumGameType.CREATIVE; 141 } 142 143 if (par1NBTTagCompound.hasKey("Player")) 144 { 145 this.playerTag = par1NBTTagCompound.getCompoundTag("Player"); 146 this.dimension = this.playerTag.getInteger("Dimension"); 147 } 148 } 149 150 public WorldInfo(WorldSettings par1WorldSettings, String par2Str) 151 { 152 this.terrainType = WorldType.DEFAULT; 153 this.randomSeed = par1WorldSettings.getSeed(); 154 this.theGameType = par1WorldSettings.getGameType(); 155 this.mapFeaturesEnabled = par1WorldSettings.isMapFeaturesEnabled(); 156 this.levelName = par2Str; 157 this.hardcore = par1WorldSettings.getHardcoreEnabled(); 158 this.terrainType = par1WorldSettings.getTerrainType(); 159 this.allowCommands = par1WorldSettings.areCommandsAllowed(); 160 this.initialized = false; 161 } 162 163 public WorldInfo(WorldInfo par1WorldInfo) 164 { 165 this.terrainType = WorldType.DEFAULT; 166 this.randomSeed = par1WorldInfo.randomSeed; 167 this.terrainType = par1WorldInfo.terrainType; 168 this.theGameType = par1WorldInfo.theGameType; 169 this.mapFeaturesEnabled = par1WorldInfo.mapFeaturesEnabled; 170 this.spawnX = par1WorldInfo.spawnX; 171 this.spawnY = par1WorldInfo.spawnY; 172 this.spawnZ = par1WorldInfo.spawnZ; 173 this.worldTime = par1WorldInfo.worldTime; 174 this.lastTimePlayed = par1WorldInfo.lastTimePlayed; 175 this.sizeOnDisk = par1WorldInfo.sizeOnDisk; 176 this.playerTag = par1WorldInfo.playerTag; 177 this.dimension = par1WorldInfo.dimension; 178 this.levelName = par1WorldInfo.levelName; 179 this.saveVersion = par1WorldInfo.saveVersion; 180 this.rainTime = par1WorldInfo.rainTime; 181 this.raining = par1WorldInfo.raining; 182 this.thunderTime = par1WorldInfo.thunderTime; 183 this.thundering = par1WorldInfo.thundering; 184 this.hardcore = par1WorldInfo.hardcore; 185 this.allowCommands = par1WorldInfo.allowCommands; 186 this.initialized = par1WorldInfo.initialized; 187 } 188 189 /** 190 * Gets the NBTTagCompound for the worldInfo 191 */ 192 public NBTTagCompound getNBTTagCompound() 193 { 194 NBTTagCompound var1 = new NBTTagCompound(); 195 this.updateTagCompound(var1, this.playerTag); 196 return var1; 197 } 198 199 /** 200 * Creates a new NBTTagCompound for the world, with the given NBTTag as the "Player" 201 */ 202 public NBTTagCompound cloneNBTCompound(NBTTagCompound par1NBTTagCompound) 203 { 204 NBTTagCompound var2 = new NBTTagCompound(); 205 this.updateTagCompound(var2, par1NBTTagCompound); 206 return var2; 207 } 208 209 private void updateTagCompound(NBTTagCompound par1NBTTagCompound, NBTTagCompound par2NBTTagCompound) 210 { 211 par1NBTTagCompound.setLong("RandomSeed", this.randomSeed); 212 par1NBTTagCompound.setString("generatorName", this.terrainType.getWorldTypeName()); 213 par1NBTTagCompound.setInteger("generatorVersion", this.terrainType.getGeneratorVersion()); 214 par1NBTTagCompound.setInteger("GameType", this.theGameType.getID()); 215 par1NBTTagCompound.setBoolean("MapFeatures", this.mapFeaturesEnabled); 216 par1NBTTagCompound.setInteger("SpawnX", this.spawnX); 217 par1NBTTagCompound.setInteger("SpawnY", this.spawnY); 218 par1NBTTagCompound.setInteger("SpawnZ", this.spawnZ); 219 par1NBTTagCompound.setLong("Time", this.worldTime); 220 par1NBTTagCompound.setLong("SizeOnDisk", this.sizeOnDisk); 221 par1NBTTagCompound.setLong("LastPlayed", System.currentTimeMillis()); 222 par1NBTTagCompound.setString("LevelName", this.levelName); 223 par1NBTTagCompound.setInteger("version", this.saveVersion); 224 par1NBTTagCompound.setInteger("rainTime", this.rainTime); 225 par1NBTTagCompound.setBoolean("raining", this.raining); 226 par1NBTTagCompound.setInteger("thunderTime", this.thunderTime); 227 par1NBTTagCompound.setBoolean("thundering", this.thundering); 228 par1NBTTagCompound.setBoolean("hardcore", this.hardcore); 229 par1NBTTagCompound.setBoolean("allowCommands", this.allowCommands); 230 par1NBTTagCompound.setBoolean("initialized", this.initialized); 231 232 if (par2NBTTagCompound != null) 233 { 234 par1NBTTagCompound.setCompoundTag("Player", par2NBTTagCompound); 235 } 236 } 237 238 /** 239 * Returns the seed of current world. 240 */ 241 public long getSeed() 242 { 243 return this.randomSeed; 244 } 245 246 /** 247 * Returns the x spawn position 248 */ 249 public int getSpawnX() 250 { 251 return this.spawnX; 252 } 253 254 /** 255 * Return the Y axis spawning point of the player. 256 */ 257 public int getSpawnY() 258 { 259 return this.spawnY; 260 } 261 262 /** 263 * Returns the z spawn position 264 */ 265 public int getSpawnZ() 266 { 267 return this.spawnZ; 268 } 269 270 /** 271 * Get current world time 272 */ 273 public long getWorldTime() 274 { 275 return this.worldTime; 276 } 277 278 @SideOnly(Side.CLIENT) 279 public long getSizeOnDisk() 280 { 281 return this.sizeOnDisk; 282 } 283 284 /** 285 * Returns the player's NBTTagCompound to be loaded 286 */ 287 public NBTTagCompound getPlayerNBTTagCompound() 288 { 289 return this.playerTag; 290 } 291 292 public int getDimension() 293 { 294 return this.dimension; 295 } 296 297 @SideOnly(Side.CLIENT) 298 299 /** 300 * Set the x spawn position to the passed in value 301 */ 302 public void setSpawnX(int par1) 303 { 304 this.spawnX = par1; 305 } 306 307 @SideOnly(Side.CLIENT) 308 309 /** 310 * Sets the y spawn position 311 */ 312 public void setSpawnY(int par1) 313 { 314 this.spawnY = par1; 315 } 316 317 /** 318 * Set current world time 319 */ 320 public void setWorldTime(long par1) 321 { 322 this.worldTime = par1; 323 } 324 325 @SideOnly(Side.CLIENT) 326 327 /** 328 * Set the z spawn position to the passed in value 329 */ 330 public void setSpawnZ(int par1) 331 { 332 this.spawnZ = par1; 333 } 334 335 /** 336 * Sets the spawn zone position. Args: x, y, z 337 */ 338 public void setSpawnPosition(int par1, int par2, int par3) 339 { 340 this.spawnX = par1; 341 this.spawnY = par2; 342 this.spawnZ = par3; 343 } 344 345 /** 346 * Get current world name 347 */ 348 public String getWorldName() 349 { 350 return this.levelName; 351 } 352 353 public void setWorldName(String par1Str) 354 { 355 this.levelName = par1Str; 356 } 357 358 /** 359 * Returns the save version of this world 360 */ 361 public int getSaveVersion() 362 { 363 return this.saveVersion; 364 } 365 366 /** 367 * Sets the save version of the world 368 */ 369 public void setSaveVersion(int par1) 370 { 371 this.saveVersion = par1; 372 } 373 374 @SideOnly(Side.CLIENT) 375 376 /** 377 * Return the last time the player was in this world. 378 */ 379 public long getLastTimePlayed() 380 { 381 return this.lastTimePlayed; 382 } 383 384 /** 385 * Returns true if it is thundering, false otherwise. 386 */ 387 public boolean isThundering() 388 { 389 return this.thundering; 390 } 391 392 /** 393 * Sets whether it is thundering or not. 394 */ 395 public void setThundering(boolean par1) 396 { 397 this.thundering = par1; 398 } 399 400 /** 401 * Returns the number of ticks until next thunderbolt. 402 */ 403 public int getThunderTime() 404 { 405 return this.thunderTime; 406 } 407 408 /** 409 * Defines the number of ticks until next thunderbolt. 410 */ 411 public void setThunderTime(int par1) 412 { 413 this.thunderTime = par1; 414 } 415 416 /** 417 * Returns true if it is raining, false otherwise. 418 */ 419 public boolean isRaining() 420 { 421 return this.raining; 422 } 423 424 /** 425 * Sets whether it is raining or not. 426 */ 427 public void setRaining(boolean par1) 428 { 429 this.raining = par1; 430 } 431 432 /** 433 * Return the number of ticks until rain. 434 */ 435 public int getRainTime() 436 { 437 return this.rainTime; 438 } 439 440 /** 441 * Sets the number of ticks until rain. 442 */ 443 public void setRainTime(int par1) 444 { 445 this.rainTime = par1; 446 } 447 448 /** 449 * Gets the GameType. 450 */ 451 public EnumGameType getGameType() 452 { 453 return this.theGameType; 454 } 455 456 /** 457 * Get whether the map features (e.g. strongholds) generation is enabled or disabled. 458 */ 459 public boolean isMapFeaturesEnabled() 460 { 461 return this.mapFeaturesEnabled; 462 } 463 464 /** 465 * Sets the GameType. 466 */ 467 public void setGameType(EnumGameType par1EnumGameType) 468 { 469 this.theGameType = par1EnumGameType; 470 } 471 472 /** 473 * Returns true if hardcore mode is enabled, otherwise false 474 */ 475 public boolean isHardcoreModeEnabled() 476 { 477 return this.hardcore; 478 } 479 480 public WorldType getTerrainType() 481 { 482 return this.terrainType; 483 } 484 485 public void setTerrainType(WorldType par1WorldType) 486 { 487 this.terrainType = par1WorldType; 488 } 489 490 /** 491 * Returns true if commands are allowed on this World. 492 */ 493 public boolean areCommandsAllowed() 494 { 495 return this.allowCommands; 496 } 497 498 /** 499 * Returns true if the World is initialized. 500 */ 501 public boolean isInitialized() 502 { 503 return this.initialized; 504 } 505 506 /** 507 * Sets the initialization status of the World. 508 */ 509 public void setServerInitialized(boolean par1) 510 { 511 this.initialized = par1; 512 } 513 514 /** 515 * Allow access to additional mod specific world based properties 516 * Used by FML to store mod list associated with a world, and maybe an id map 517 * Used by Forge to store the dimensions available to a world 518 * @param additionalProperties 519 */ 520 public void setAdditionalProperties(Map<String,NBTBase> additionalProperties) 521 { 522 // one time set for this 523 if (this.additionalProperties == null) 524 { 525 this.additionalProperties = additionalProperties; 526 } 527 } 528 529 public NBTBase getAdditionalProperty(String additionalProperty) 530 { 531 return this.additionalProperties!=null? this.additionalProperties.get(additionalProperty) : null; 532 } 533 }