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