/// <summary> /// Creates a new <see cref="Level"/> object with reasonable defaults tied to the given world. /// </summary> /// <param name="world">The world that the <see cref="Level"/> should be tied to.</param> public Level(NbtWorld world) { _world = world; // Sane defaults _time = 0; _lastPlayed = 0; _spawnX = 0; _spawnY = 64; _spawnZ = 0; _sizeOnDisk = 0; _randomSeed = new Random().Next(); //_version = 19132; _version = 19133; _name = "Untitled"; _generator = "default"; _hardcore = 0; _generatorOptions = ""; _generatorVersion = 1; _initialized = 0; _allowCommands = 0; _DayTime = 0; _gameRules = new GameRules(); GameType = GameType.SURVIVAL; UseMapFeatures = true; _source = new TagNodeCompound(); }
/// <summary> /// Creates a copy of an existing <see cref="Level"/> object. /// </summary> /// <param name="p">The <see cref="Level"/> object to copy.</param> protected Level(Level p) { _world = p._world; _time = p._time; _lastPlayed = p._lastPlayed; _spawnX = p._spawnX; _spawnY = p._spawnY; _spawnZ = p._spawnZ; _sizeOnDisk = p._sizeOnDisk; _randomSeed = p._randomSeed; _version = p._version; _name = p._name; _generator = p._generator; _raining = p._raining; _thundering = p._thundering; _rainTime = p._rainTime; _thunderTime = p._thunderTime; _gameType = p._gameType; _mapFeatures = p._mapFeatures; _hardcore = p._hardcore; _generatorVersion = p._generatorVersion; _generatorOptions = p._generatorOptions; _initialized = p._initialized; _allowCommands = p._allowCommands; _DayTime = p._DayTime; _gameRules = p._gameRules.Copy(); if (p._player != null) { _player = p._player.Copy(); } if (p._source != null) { _source = p._source.Copy() as TagNodeCompound; } }
/// <summary> /// Attempt to load a Level subtree into the <see cref="Level"/> without validation. /// </summary> /// <param name="tree">The root node of a Level subtree.</param> /// <returns>The <see cref="Level"/> returns itself on success, or null if the tree was unparsable.</returns> public virtual Level LoadTree(TagNode tree) { TagNodeCompound dtree = tree as TagNodeCompound; if (dtree == null) { return(null); } _version = null; _raining = null; _rainTime = null; _thundering = null; _thunderTime = null; _gameType = null; _mapFeatures = null; _generatorOptions = null; _generatorVersion = null; _allowCommands = null; _initialized = null; _DayTime = null; TagNodeCompound ctree = dtree["Data"].ToTagCompound(); _time = ctree["Time"].ToTagLong(); _lastPlayed = ctree["LastPlayed"].ToTagLong(); if (ctree.ContainsKey("Player")) { _player = new Player().LoadTree(ctree["Player"]); } _spawnX = ctree["SpawnX"].ToTagInt(); _spawnY = ctree["SpawnY"].ToTagInt(); _spawnZ = ctree["SpawnZ"].ToTagInt(); _sizeOnDisk = ctree["SizeOnDisk"].ToTagLong(); _randomSeed = ctree["RandomSeed"].ToTagLong(); if (ctree.ContainsKey("version")) { _version = ctree["version"].ToTagInt(); } if (ctree.ContainsKey("LevelName")) { _name = ctree["LevelName"].ToTagString(); } if (ctree.ContainsKey("generatorName")) { _generator = ctree["generatorName"].ToTagString(); } if (ctree.ContainsKey("raining")) { _raining = ctree["raining"].ToTagByte(); } if (ctree.ContainsKey("thundering")) { _thundering = ctree["thundering"].ToTagByte(); } if (ctree.ContainsKey("rainTime")) { _rainTime = ctree["rainTime"].ToTagInt(); } if (ctree.ContainsKey("thunderTime")) { _thunderTime = ctree["thunderTime"].ToTagInt(); } if (ctree.ContainsKey("GameType")) { _gameType = ctree["GameType"].ToTagInt(); } if (ctree.ContainsKey("MapFeatures")) { _mapFeatures = ctree["MapFeatures"].ToTagByte(); } if (ctree.ContainsKey("hardcore")) { _hardcore = ctree["hardcore"].ToTagByte(); } if (ctree.ContainsKey("generatorVersion")) { _generatorVersion = ctree["generatorVersion"].ToTagInt(); } if (ctree.ContainsKey("generatorOptions")) { _generatorOptions = ctree["generatorOptions"].ToTagString(); } if (ctree.ContainsKey("allowCommands")) { _allowCommands = ctree["allowCommands"].ToTagByte(); } if (ctree.ContainsKey("initialized")) { _initialized = ctree["initialized"].ToTagByte(); } if (ctree.ContainsKey("DayTime")) { _DayTime = ctree["DayTime"].ToTagLong(); } if (ctree.ContainsKey("GameRules")) { TagNodeCompound gr = ctree["GameRules"].ToTagCompound(); _gameRules = new GameRules(); _gameRules.CommandBlockOutput = gr["commandBlockOutput"].ToTagString().Data == "true"; _gameRules.DoFireTick = gr["doFireTick"].ToTagString().Data == "true"; _gameRules.DoMobLoot = gr["doMobLoot"].ToTagString().Data == "true"; _gameRules.DoMobSpawning = gr["doMobSpawning"].ToTagString().Data == "true"; _gameRules.DoTileDrops = gr["doTileDrops"].ToTagString().Data == "true"; _gameRules.KeepInventory = gr["keepInventory"].ToTagString().Data == "true"; _gameRules.MobGriefing = gr["mobGriefing"].ToTagString().Data == "true"; } _source = ctree.Copy() as TagNodeCompound; return(this); }