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