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