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