Esempio n. 1
0
        /// <summary>
        /// Attempt to load an Entity subtree into the <see cref="Entity"/> without validation.
        /// </summary>
        /// <param name="tree">The root node of an Entity subtree.</param>
        /// <returns>The <see cref="Entity"/> returns itself on success, or null if the tree was unparsable.</returns>
        public Entity LoadTree(TagNode tree)
        {
            TagNodeCompound ctree = tree as TagNodeCompound;

            if (ctree == null)
            {
                return(null);
            }

            TagNodeList pos = ctree["Pos"].ToTagList();

            _pos   = new Vector3();
            _pos.X = pos[0].ToTagDouble();
            _pos.Y = pos[1].ToTagDouble();
            _pos.Z = pos[2].ToTagDouble();

            TagNodeList motion = ctree["Motion"].ToTagList();

            _motion   = new Vector3();
            _motion.X = motion[0].ToTagDouble();
            _motion.Y = motion[1].ToTagDouble();
            _motion.Z = motion[2].ToTagDouble();

            TagNodeList rotation = ctree["Rotation"].ToTagList();

            _rotation       = new Orientation();
            _rotation.Yaw   = rotation[0].ToTagFloat();
            _rotation.Pitch = rotation[1].ToTagFloat();

            _fire     = ctree["Fire"].ToTagShort();
            _air      = ctree["Air"].ToTagShort();
            _onGround = ctree["OnGround"].ToTagByte();

            return(this);
        }
Esempio n. 2
0
        public void SetTileTick(int x, int y, int z, TileTick te)
        {
            if (te.ID != _blocks[x, y, z])
            {
                throw new ArgumentException("The TileTick type is not valid for this block.", "te");
            }

            BlockKey key = (TranslateCoordinates != null)
                ? TranslateCoordinates(x, y, z)
                : new BlockKey(x, y, z);

            TagNodeCompound oldte;

            if (_tileTickTable.TryGetValue(key, out oldte))
            {
                _tileTicks.Remove(oldte);
            }

            te.X = key.x;
            te.Y = key.y;
            te.Z = key.z;

            TagNodeCompound tree = te.BuildTree() as TagNodeCompound;

            _tileTicks.Add(tree);
            _tileTickTable[key] = tree;
        }
Esempio n. 3
0
        public void CreateTileTick(int x, int y, int z)
        {
            TileTick te = new TileTick()
            {
                ID = _blocks[x, y, z],
            };

            BlockKey key = (TranslateCoordinates != null)
                ? TranslateCoordinates(x, y, z)
                : new BlockKey(x, y, z);

            TagNodeCompound oldte;

            if (_tileTickTable.TryGetValue(key, out oldte))
            {
                _tileTicks.Remove(oldte);
            }

            te.X = key.x;
            te.Y = key.y;
            te.Z = key.z;

            TagNodeCompound tree = te.BuildTree() as TagNodeCompound;

            _tileTicks.Add(tree);
            _tileTickTable[key] = tree;
        }
Esempio n. 4
0
        private static Block[] LoadBlocks(TagNodeCompound tag, TranslationMap palette, int length, int width, Dictionary <BlockPos, TileEntity> tiles)
        {
            var bLower = tag["Blocks"].ToTagByteArray().Data;
            var bUpper = new byte[(bLower.Length >> 1) + 1];

            if (tag.ContainsKey("AddBlocks"))
            {
                bUpper = tag["AddBlocks"].ToTagByteArray().Data;
            }
            else if (tag.ContainsKey("Add"))
            {
                Console.WriteLine("Schematic contains deprecated tag \"Add\", use \"AddBlocks\" instead. Loading regardless.");
                var add = tag["Add"].ToTagByteArray().Data;
                for (var i = 0; i < bLower.Length; i++)
                {
                    if ((i & 1) == 1)
                    {
                        bUpper[i >> 1] |= (byte)(add[i] & 0x0F);
                    }
                    else
                    {
                        bUpper[i >> 1] |= (byte)((add[i] & 0x0F) << 4);
                    }
                }
            }

            var bMetadata = new byte[bLower.Length];

            if (tag.ContainsKey("Metadata"))
            {
                bMetadata = tag["Metadata"].ToTagByteArray().Data;
            }
            else if (tag.ContainsKey("Data"))
            {
                bMetadata = tag["Data"].ToTagByteArray().Data;
            }

            var blocks = new Block[bLower.Length];

            for (var i = 0; i < bLower.Length; i++)
            {
                short id;
                if ((i & 1) == 1)
                {
                    id = (short)(((bUpper[i >> 1] & 0x0F) << 8) + (bLower[i] & 0xFF));
                }
                else
                {
                    id = (short)(((bUpper[i >> 1] & 0xF0) << 4) + (bLower[i] & 0xFF));
                }

                var pos      = GetBlockPos(length, width, i);
                var metadata = bMetadata[i];
                tiles.TryGetValue(pos, out var tile);

                blocks[i] = new Block(TranslateBlockId(palette, id), metadata, tile?.Data);
            }

            return(blocks);
        }
Esempio n. 5
0
        public TileEntityMobSpawner(TileEntity te)
            : base(te)
        {
            TileEntityMobSpawner tes = te as TileEntityMobSpawner;

            if (tes != null)
            {
                _delay                 = tes._delay;
                _entityID              = tes._entityID;
                _maxDelay              = tes._maxDelay;
                _minDelay              = tes._minDelay;
                _spawnCount            = tes._spawnCount;
                _spawnRange            = tes._spawnRange;
                _maxNearbyEnemies      = tes._maxNearbyEnemies;
                _requiredPlayerRange   = tes._requiredPlayerRange;
                _maxExperience         = tes._maxExperience;
                _remainingExperience   = tes._remainingExperience;
                _experienceRegenTick   = tes._experienceRegenTick;
                _experienceRegenRate   = tes._experienceRegenRate;
                _experienceRegenAmount = tes._experienceRegenAmount;

                if (tes._spawnData != null)
                {
                    _spawnData = tes._spawnData.Copy() as TagNodeCompound;
                }
            }
        }
Esempio n. 6
0
    public static void Init()
    {
        TagNodeCompound player   = NBTHelper.GetPlayerData();
        int             gameMode = player["playerGameType"] as TagNodeInt;

        _mode = (GameMode)gameMode;
    }
Esempio n. 7
0
        /// <summary>
        /// Builds an Entity subtree from the current data.
        /// </summary>
        /// <returns>The root node of an Entity subtree representing the current data.</returns>
        public TagNode BuildTree()
        {
            TagNodeCompound tree = new TagNodeCompound();

            TagNodeList pos = new TagNodeList(TagType.TAG_DOUBLE);

            pos.Add(new TagNodeDouble(_pos.X));
            pos.Add(new TagNodeDouble(_pos.Y));
            pos.Add(new TagNodeDouble(_pos.Z));
            tree["Pos"] = pos;

            TagNodeList motion = new TagNodeList(TagType.TAG_DOUBLE);

            motion.Add(new TagNodeDouble(_motion.X));
            motion.Add(new TagNodeDouble(_motion.Y));
            motion.Add(new TagNodeDouble(_motion.Z));
            tree["Motion"] = motion;

            TagNodeList rotation = new TagNodeList(TagType.TAG_FLOAT);

            rotation.Add(new TagNodeFloat((float)_rotation.Yaw));
            rotation.Add(new TagNodeFloat((float)_rotation.Pitch));
            tree["Rotation"] = rotation;

            tree["FallDistance"] = new TagNodeFloat(_fallDistance);
            tree["Fire"]         = new TagNodeShort(_fire);
            tree["Air"]          = new TagNodeShort(_air);
            tree["OnGround"]     = new TagNodeByte(_onGround);

            return(tree);
        }
Esempio n. 8
0
        /// <summary>
        /// Removes all entities matching the given condition from the collection.
        /// </summary>
        /// <param name="match">A <see cref="Predicate{T}"/> defining the matching condition.</param>
        /// <returns>A count of the number of entities that were removed.</returns>
        public int RemoveAll(Predicate <TypedEntity> match)
        {
            int rem = _entities.RemoveAll(val =>
            {
                TagNodeCompound cval = val as TagNodeCompound;
                if (cval == null)
                {
                    return(false);
                }

                TypedEntity obj = EntityFactory.Create(cval);
                if (obj == null)
                {
                    return(false);
                }

                return(match(obj));
            });

            if (rem > 0)
            {
                _dirty = true;
            }

            return(rem);
        }
Esempio n. 9
0
        public static BlockState Load(TagNodeCompound tag)
        {
            var name  = tag["Name"].ToTagString().Data;
            var props = tag.ContainsKey("Properties") ? tag["Properties"].ToTagCompound() : null;

            return(new BlockState(name, props));
        }
        public override TypedEntity LoadTree(TagNode tree)
        {
            TagNodeCompound ctree = tree as TagNodeCompound;

            if (ctree == null || base.LoadTree(tree) == null)
            {
                return(null);
            }

            _type = (CartType)ctree["Type"].ToTagInt().Data;

            switch (_type)
            {
            case CartType.EMPTY:
                return(this);

            case CartType.CHEST:
                return(new EntityMinecartChest().LoadTreeSafe(tree));

            case CartType.FURNACE:
                return(new EntityMinecartFurnace().LoadTreeSafe(tree));

            default:
                return(this);
            }
        }
Esempio n. 11
0
        /// <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();
        }
Esempio n. 12
0
    //input is local position
    public void GetBlockData(int xInChunk, int worldY, int zInChunk, out byte blockType, out byte blockData)
    {
        blockType = 0;
        blockData = 0;
        if (worldY < 0 || worldY > 255)
        {
            return;
        }

        if (xInChunk < 0 || xInChunk > 15 || zInChunk < 0 || zInChunk > 15)
        {
            NBTHelper.GetBlockData(xInChunk + 16 * x, worldY, zInChunk + 16 * z, out blockType, out blockData);
            return;
        }

        int sectionIndex = Mathf.FloorToInt(worldY / 16f);

        if (sectionIndex >= 0 && sectionIndex < Sections.Count)
        {
            TagNodeCompound  section = Sections[sectionIndex] as TagNodeCompound;
            TagNodeByteArray blocks  = section["Blocks"] as TagNodeByteArray;
            TagNodeByteArray data    = section["Data"] as TagNodeByteArray;

            int yInSection = worldY - sectionIndex * 16;
            int blockPos   = yInSection * 16 * 16 + zInChunk * 16 + xInChunk;

            if (blockPos >= 0 && blockPos < 4096)
            {
                blockType = blocks.Data[blockPos];
                blockData = NBTHelper.GetNibble(data.Data, blockPos);
                return;
            }
        }
        return;
    }
Esempio n. 13
0
    void InitTileEntity()
    {
        if (hasInitTileEntity)
        {
            return;
        }

        foreach (Vector3Int pos in tileEntityList)
        {
            if (!tileEntityObjs.ContainsKey(pos))
            {
                int              sectionIndex = pos.y / 16;
                TagNodeCompound  Section      = Sections[sectionIndex] as TagNodeCompound;
                TagNodeByteArray Blocks       = Section["Blocks"] as TagNodeByteArray;
                TagNodeByteArray Data         = Section["Data"] as TagNodeByteArray;

                int        yInSection = pos.y % 16;
                int        blockPos   = yInSection * 16 * 16 + pos.z * 16 + pos.x;
                byte       rawType    = Blocks.Data[blockPos];
                NBTBlock   generator  = NBTGeneratorManager.GetMeshGenerator(rawType);
                byte       blockData  = NBTHelper.GetNibble(Data.Data, blockPos);
                GameObject obj        = generator.GetTileEntityGameObject(this, blockData, pos);

                tileEntityObjs[pos] = obj;
            }
        }

        hasInitTileEntity = true;
    }
Esempio n. 14
0
        /// <inheritdoc/>
        public Item LoadTree(TagNode tree)
        {
            TagNodeCompound ctree = tree as TagNodeCompound;

            if (ctree == null)
            {
                return(null);
            }

            _enchantments.Clear();

            _id     = ctree["id"].ToTagString();
            _count  = ctree["Count"].ToTagByte();
            _damage = ctree["Damage"].ToTagShort();

            if (ctree.ContainsKey("tag"))
            {
                TagNodeCompound tagtree = ctree["tag"].ToTagCompound();
                if (tagtree.ContainsKey("ench"))
                {
                    TagNodeList enchList = tagtree["ench"].ToTagList();

                    foreach (TagNode tag in enchList)
                    {
                        _enchantments.Add(new Enchantment().LoadTree(tag));
                    }
                }
            }

            _source = ctree.Copy() as TagNodeCompound;

            return(this);
        }
Esempio n. 15
0
        /// <summary>
        /// Builds a Level subtree from the current data.
        /// </summary>
        /// <returns>The root node of a Level subtree representing the current data.</returns>
        public virtual TagNode BuildTree()
        {
            TagNodeCompound data = new TagNodeCompound();

            data["Time"]       = new TagNodeLong(_time);
            data["LastPlayed"] = new TagNodeLong(_lastPlayed);

            if (_player != null)
            {
                data["Player"] = _player.BuildTree();
            }

            data["SpawnX"]     = new TagNodeInt(_spawnX);
            data["SpawnY"]     = new TagNodeInt(_spawnY);
            data["SpawnZ"]     = new TagNodeInt(_spawnZ);
            data["SizeOnDisk"] = new TagNodeLong(_sizeOnDisk);
            data["RandomSeed"] = new TagNodeLong(_randomSeed);

            if (_version != null && _version != 0)
            {
                data["version"] = new TagNodeInt(_version ?? 0);
            }

            if (_name != null)
            {
                data["LevelName"] = new TagNodeString(_name);
            }

            if (_raining != null)
            {
                data["raining"] = new TagNodeByte(_raining ?? 0);
            }
            if (_thundering != null)
            {
                data["thundering"] = new TagNodeByte(_thundering ?? 0);
            }
            if (_rainTime != null)
            {
                data["rainTime"] = new TagNodeInt(_rainTime ?? 0);
            }
            if (_thunderTime != null)
            {
                data["thunderTime"] = new TagNodeInt(_thunderTime ?? 0);
            }

            if (_gameType != null)
            {
                data["GameType"] = new TagNodeInt(_gameType ?? 0);
            }
            if (_mapFeatures != null)
            {
                data["MapFeatures"] = new TagNodeByte(_mapFeatures ?? 0);
            }

            TagNodeCompound tree = new TagNodeCompound();

            tree.Add("Data", data);

            return(tree);
        }
Esempio n. 16
0
        private void BuildNbtTree()
        {
            int elements3 = XDIM * YDIM * ZDIM;

            TagNodeByteArray blocks     = new TagNodeByteArray(new byte[elements3]);
            TagNodeByteArray data       = new TagNodeByteArray(new byte[elements3 >> 1]);
            TagNodeByteArray skyLight   = new TagNodeByteArray(new byte[elements3 >> 1]);
            TagNodeByteArray blockLight = new TagNodeByteArray(new byte[elements3 >> 1]);
            TagNodeByteArray addBlocks  = new TagNodeByteArray(new byte[elements3 >> 1]);

            _blocks     = new YZXByteArray(XDIM, YDIM, ZDIM, blocks);
            _data       = new YZXNibbleArray(XDIM, YDIM, ZDIM, data);
            _skyLight   = new YZXNibbleArray(XDIM, YDIM, ZDIM, skyLight);
            _blockLight = new YZXNibbleArray(XDIM, YDIM, ZDIM, blockLight);
            _addBlocks  = new YZXNibbleArray(XDIM, YDIM, ZDIM, addBlocks);

            TagNodeCompound tree = new TagNodeCompound();

            tree.Add("Y", new TagNodeByte(_y));
            tree.Add("Blocks", blocks);
            tree.Add("Data", data);
            tree.Add("SkyLight", skyLight);
            tree.Add("BlockLight", blockLight);
            tree.Add("AddBlocks", addBlocks);

            _tree = tree;
        }
Esempio n. 17
0
        /// <inheritdoc/>
        public TagNode BuildTree()
        {
            TagNodeCompound tree = new TagNodeCompound();

            tree["id"]     = new TagNodeString(_id);
            tree["Count"]  = new TagNodeByte(_count);
            tree["Damage"] = new TagNodeShort(_damage);

            if (_enchantments.Count > 0)
            {
                TagNodeList enchList = new TagNodeList(TagType.TAG_COMPOUND);
                foreach (Enchantment e in _enchantments)
                {
                    enchList.Add(e.BuildTree());
                }

                TagNodeCompound tagtree = new TagNodeCompound();
                tagtree["ench"] = enchList;

                if (_source != null && _source.ContainsKey("tag"))
                {
                    tagtree.MergeFrom(_source["tag"].ToTagCompound());
                }

                tree["tag"] = tagtree;
            }

            if (_source != null)
            {
                tree.MergeFrom(_source);
            }

            return(tree);
        }
Esempio n. 18
0
        /// <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;

            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("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();
            }

            return(this);
        }
Esempio n. 19
0
        public AnvilSection LoadTree(TagNode tree)
        {
            TagNodeCompound ctree = tree as TagNodeCompound;

            if (ctree == null)
            {
                return(null);
            }

            _y = ctree["Y"] as TagNodeByte;

            _blocks     = new YZXByteArray(XDIM, YDIM, ZDIM, ctree["Blocks"] as TagNodeByteArray);
            _data       = new YZXNibbleArray(XDIM, YDIM, ZDIM, ctree["Data"] as TagNodeByteArray);
            _skyLight   = new YZXNibbleArray(XDIM, YDIM, ZDIM, ctree["SkyLight"] as TagNodeByteArray);
            _blockLight = new YZXNibbleArray(XDIM, YDIM, ZDIM, ctree["BlockLight"] as TagNodeByteArray);

            if (!ctree.ContainsKey("AddBlocks"))
            {
                ctree["AddBlocks"] = new TagNodeByteArray(new byte[2048]);
            }
            _addBlocks = new YZXNibbleArray(XDIM, YDIM, ZDIM, ctree["AddBlocks"] as TagNodeByteArray);

            _tree = ctree;

            return(this);
        }
Esempio n. 20
0
 public Entity(double x, double y, double z, TagNodeCompound data)
 {
     X    = x;
     Y    = y;
     Z    = z;
     Data = data;
 }
Esempio n. 21
0
        /// <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;

            _raining     = p._raining;
            _thundering  = p._thundering;
            _rainTime    = p._rainTime;
            _thunderTime = p._thunderTime;

            _gameType    = p._gameType;
            _mapFeatures = p._mapFeatures;
            _hardcore    = p._hardcore;

            if (p._player != null)
            {
                _player = p._player.Copy();
            }

            if (p._source != null)
            {
                _source = p._source.Copy() as TagNodeCompound;
            }
        }
Esempio n. 22
0
    public static NBTChunk LoadChunk(int chunkX, int chunkZ)
    {
        UnityEngine.Profiling.Profiler.BeginSample("ChunkChecker.Update");

        key.Set(chunkX, chunkZ);
        if (!chunkDict.ContainsKey(key))
        {
            TagNodeCompound Chunk = GetChunkNode(chunkX, chunkZ);
            if (Chunk != null)
            {
                TagNodeCompound Level = Chunk["Level"] as TagNodeCompound;

                TagNodeList Sections = Level["Sections"] as TagNodeList;
                NBTChunk    chunk    = ChunkPool.GetChunk();
                chunk.SetData(chunkX, chunkZ, Sections);
                chunkDict.Add(key, chunk);
            }
        }

        UnityEngine.Profiling.Profiler.EndSample();

        if (chunkDict.ContainsKey(key))
        {
            return(chunkDict[key]);
        }
        return(null);
    }
Esempio n. 23
0
        /// <summary>
        /// Removes all entities matching the given id (type) from the collection.
        /// </summary>
        /// <param name="id">The id (type) of entities that should be removed.</param>
        /// <returns>A count of the number of entities that were removed.</returns>
        public int RemoveAll(string id)
        {
            int rem = _entities.RemoveAll(val =>
            {
                TagNodeCompound cval = val as TagNodeCompound;
                if (cval == null)
                {
                    return(false);
                }

                TagNode sval;
                if (!cval.TryGetValue("id", out sval))
                {
                    return(false);
                }

                return(sval.ToTagString().Data == id);
            });

            if (rem > 0)
            {
                _dirty = true;
            }

            return(rem);
        }
Esempio n. 24
0
    static void SaveData()
    {
        // save to chest
        Instance.Items.Clear();
        Instance.Items.ChangeValueType(TagType.TAG_COMPOUND);

        int count = 0;

        for (int i = 46; i <= 72; i++)
        {
            InventoryItem item = InventorySystem.items[i];
            if (item.id != null)
            {
                TagNodeCompound serializeItem = new TagNodeCompound();
                serializeItem.Add("Count", (TagNodeByte)item.count);
                serializeItem.Add("Damage", (TagNodeShort)item.damage);
                serializeItem.Add("id", (TagNodeString)item.id);
                serializeItem.Add("Slot", (TagNodeByte)(i - 46));
                Instance.Items.Insert(count, serializeItem);

                InventorySystem.items[i].id     = null;
                InventorySystem.items[i].damage = 0;
                InventorySystem.items[i].count  = 0;
            }
        }
    }
Esempio n. 25
0
        /// <summary>
        /// Constructs a new generic <see cref="Entity"/> by copying fields from another <see cref="Entity"/> object.
        /// </summary>
        /// <param name="e">An <see cref="Entity"/> to copy fields from.</param>
        protected Entity(Entity e)
        {
            _pos   = new Vector3();
            _pos.X = e._pos.X;
            _pos.Y = e._pos.Y;
            _pos.Z = e._pos.Z;

            _motion   = new Vector3();
            _motion.X = e._motion.X;
            _motion.Y = e._motion.Y;
            _motion.Z = e._motion.Z;

            _rotation       = new Orientation();
            _rotation.Pitch = e._rotation.Pitch;
            _rotation.Yaw   = e._rotation.Yaw;

            _fallDistance = e._fallDistance;
            _fire         = e._fire;
            _air          = e._air;
            _onGround     = e._onGround;

            if (e._source != null)
            {
                _source = e._source.Copy() as TagNodeCompound;
            }
        }
Esempio n. 26
0
        public override TypedEntity LoadTree(TagNode tree)
        {
            TagNodeCompound ctree = tree as TagNodeCompound;

            if (ctree == null || base.LoadTree(tree) == null)
            {
                return(null);
            }

            _attackTime = ctree["AttackTime"].ToTagShort();
            _deathTime  = ctree["DeathTime"].ToTagShort();
            _health     = ctree["Health"].ToTagShort();
            _hurtTime   = ctree["HurtTime"].ToTagShort();

            if (ctree.ContainsKey("ActiveEffects"))
            {
                TagNodeCompound ae = ctree["ActiveEffects"].ToTagCompound();

                _activeEffects           = new ActiveEffects();
                _activeEffects.Id        = ae["Id"].ToTagByte();
                _activeEffects.Amplifier = ae["Amplifier"].ToTagByte();
                _activeEffects.Duration  = ae["Duration"].ToTagInt();
            }

            return(this);
        }
Esempio n. 27
0
        /// <summary>
        /// Builds a Player subtree from the current data.
        /// </summary>
        /// <returns>The root node of a Player subtree representing the current data.</returns>
        public virtual new TagNode BuildTree()
        {
            TagNodeCompound tree = base.BuildTree() as TagNodeCompound;

            tree["AttackTime"] = new TagNodeShort(_attackTime);
            tree["DeathTime"]  = new TagNodeShort(_deathTime);
            tree["Health"]     = new TagNodeShort(_health);
            tree["HurtTime"]   = new TagNodeShort(_hurtTime);

            tree["Dimension"]  = new TagNodeInt(_dimension);
            tree["Sleeping"]   = new TagNodeByte(_sleeping);
            tree["SleepTimer"] = new TagNodeShort(_sleepTimer);

            if (_spawnX != null && _spawnY != null && _spawnZ != null)
            {
                tree["SpawnX"] = new TagNodeInt(_spawnX ?? 0);
                tree["SpawnY"] = new TagNodeInt(_spawnY ?? 0);
                tree["SpawnZ"] = new TagNodeInt(_spawnZ ?? 0);
            }

            if (_world != null)
            {
                tree["World"] = new TagNodeString(_world);
            }

            tree["Inventory"] = _inventory.BuildTree();

            return(tree);
        }
Esempio n. 28
0
        public void SetTileEntity(int x, int y, int z, TileEntity te)
        {
            BlockInfoEx info = BlockInfo.BlockTable[_blocks[x, y, z]] as BlockInfoEx;

            if (info == null)
            {
                throw new InvalidOperationException("The given block is of a type that does not support TileEntities.");
            }

            if (te.GetType() != TileEntityFactory.Lookup(info.TileEntityName))
            {
                throw new ArgumentException("The TileEntity type is not valid for this block.", "te");
            }

            BlockKey key = (TranslateCoordinates != null)
                ? TranslateCoordinates(x, y, z)
                : new BlockKey(x, y, z);

            TagNodeCompound oldte;

            if (_tileEntityTable.TryGetValue(key, out oldte))
            {
                _tileEntities.Remove(oldte);
            }

            te.X = key.x;
            te.Y = key.y;
            te.Z = key.z;

            TagNodeCompound tree = te.BuildTree() as TagNodeCompound;

            _tileEntities.Add(tree);
            _tileEntityTable[key] = tree;
        }
Esempio n. 29
0
        public TagNode BuildTree()
        {
            TagNodeCompound level     = _tree.Root["Level"] as TagNodeCompound;
            TagNodeCompound levelCopy = new TagNodeCompound();

            foreach (KeyValuePair <string, TagNode> node in level)
            {
                levelCopy.Add(node.Key, node.Value);
            }

            TagNodeList sections = new TagNodeList(TagType.TAG_COMPOUND);

            for (int i = 0; i < _sections.Length; i++)
            {
                if (ShouldIncludeSection(_sections[i]))
                {
                    sections.Add(_sections[i].BuildTree());
                }
            }

            levelCopy["Sections"] = sections;

            if (_tileTicks.Count == 0)
            {
                levelCopy.Remove("TileTicks");
            }

            return(levelCopy);
        }
Esempio n. 30
0
        public override bool Process (DataNode dataNode, ConsoleOptions options)
        {
            if (options.Values.Count == 0)
                return false;

            string jsonPath = options.Values[0];
            using (FileStream stream = File.OpenWrite(jsonPath)) {
                using (StreamWriter writer = new StreamWriter(stream)) {
                    if (dataNode is TagDataNode) {
                        TagDataNode tagNode = dataNode as TagDataNode;
                        WriteNbtTag(writer, tagNode.Tag);
                    }
                    else if (dataNode is NbtFileDataNode) {
                        dataNode.Expand();
                        TagNodeCompound root = new TagNodeCompound();

                        foreach (DataNode child in dataNode.Nodes) {
                            TagDataNode childTagNode = child as TagDataNode;
                            if (childTagNode == null)
                                continue;

                            if (childTagNode.Tag != null)
                                root.Add(childTagNode.NodeName, childTagNode.Tag);
                        }

                        WriteNbtTag(writer, root);
                    }
                }
            }

            return true;
        }
Esempio n. 31
0
        public Item(TagNodeCompound item)
        {
            if (!item.ContainsKey("tag"))
            {
                return;
            }
            TagNodeCompound tag = item["tag"].ToTagCompound();

            if (!tag.ContainsKey("display"))
            {
                return;
            }
            TagNodeCompound display = tag["display"].ToTagCompound();

            if (display.Keys.Contains("Name"))
            {
                Name = display["Name"].ToTagString().Data;
            }
            if (display.Keys.Contains("Lore"))
            {
                TagNodeList l = display["Lore"].ToTagList();
                for (int k = 0; k < l.Count; k++)
                {
                    Lore += l[k].ToTagString().Data.Replace("Line" + (k + 1) + ":", "") + "\n";
                }
                if (Lore.Length > 0)
                {
                    Lore = Lore.Substring(0, Lore.Length - 1);
                }
            }
        }
        /// <summary>
        /// Creates a new instance of a nonspecific <see cref="TypedEntity"/> object by NBT node.
        /// </summary>
        /// <param name="tree">A <see cref="TagNodeCompound"/> representing a single Entity, containing an 'id' field.</param>
        /// <returns>A new instance of a <see cref="TypedEntity"/> object, or null if the entity is not typed.</returns>
        public static TypedEntity CreateGeneric (TagNodeCompound tree)
        {
            TagNode type;
            if (!tree.TryGetValue("id", out type)) {
                return null;
            }

            TypedEntity te = new TypedEntity(type.ToTagString().Data);

            return te.LoadTreeSafe(tree);
        }
Esempio n. 33
0
        /// <summary>
        /// Create a new instance of a concrete <see cref="TileEntity"/> type by NBT node.
        /// </summary>
        /// <param name="tree">A <see cref="TagNodeCompound"/> representing a single Tile Entity, containing an 'id' field of the Tile Entity's registered name.</param>
        /// <returns>A new instance of a concrete <see cref="TileEntity"/> type, or null if no type was registered with the given name.</returns>
        public static TileEntity Create(TagNodeCompound tree)
        {
            string type = tree["id"].ToTagString();

            Type t;
            if (!_registry.TryGetValue(type, out t)) {
                return null;
            }

            TileEntity te = Activator.CreateInstance(t) as TileEntity;

            return te.LoadTreeSafe(tree);
        }
Esempio n. 34
0
        public static byte[] SerializeNode (TagNode node)
        {
            TagNodeCompound root = new TagNodeCompound();
            root.Add("root", node);
            NbtTree tree = new NbtTree(root);

            using (MemoryStream ms = new MemoryStream()) {
                tree.WriteTo(ms);
                byte[] data = new byte[ms.Length];
                Array.Copy(ms.GetBuffer(), data, ms.Length);

                return data;
            }
        }
        /// <summary>
        /// Create a new instance of a concrete <see cref="TypedEntity"/> type by NBT node.
        /// </summary>
        /// <param name="tree">A <see cref="TagNodeCompound"/> representing a single Entity, containing an 'id' field of the Entity's registered name.</param>
        /// <returns>A new instance of a concrete <see cref="TypedEntity"/> type, or null if no type was registered with the given name.</returns>
        public static TypedEntity Create (TagNodeCompound tree)
        {
            TagNode type;
            if (!tree.TryGetValue("id", out type)) {
                return null;
            }

            Type t;
            if (!_registry.TryGetValue(type.ToTagString(), out t)) {
                return null;
            }

            TypedEntity te = Activator.CreateInstance(t) as TypedEntity;

            return te.LoadTreeSafe(tree);
        }
Esempio n. 36
0
        private static void SerializeCompound (TagNodeCompound tag, StringBuilder str, int level)
        {
            if (tag.Count == 0) {
                str.Append("{ }");
                return;
            }

            str.AppendLine();
            AddLine(str, "{", level);

            IEnumerator<KeyValuePair<string, TagNode>> en = tag.GetEnumerator();
            bool first = true;
            while (en.MoveNext()) {
                if (!first) {
                    str.Append(",");
                    str.AppendLine();
                }

                KeyValuePair<string, TagNode> item = en.Current;
                Add(str, "\"" + item.Key + "\": ", level + 1);

                if (item.Value.GetTagType() == TagType.TAG_COMPOUND) {
                    SerializeCompound(item.Value as TagNodeCompound, str, level + 1);
                }
                else if (item.Value.GetTagType() == TagType.TAG_LIST) {
                    SerializeList(item.Value as TagNodeList, str, level + 1);
                }
                else if (item.Value.GetTagType() == TagType.TAG_BYTE_ARRAY) {
                    SerializeByteArray(item.Value as TagNodeByteArray, str, level);
                }
                else if (item.Value.GetTagType() == TagType.TAG_INT_ARRAY) {
                    SerializeIntArray(item.Value as TagNodeIntArray, str, level + 1);
                }
                else {
                    SerializeScaler(item.Value, str);
                }

                first = false;
            }

            str.AppendLine();
            Add(str, "}", level);
        }
Esempio n. 37
0
        public TileEntityMobSpawner(TileEntity te)
            : base(te)
        {
            TileEntityMobSpawner tes = te as TileEntityMobSpawner;
            if (tes != null) {
                _delay = tes._delay;
                _entityID = tes._entityID;
                _maxDelay = tes._maxDelay;
                _minDelay = tes._minDelay;
                _spawnCount = tes._spawnCount;
                _spawnRange = tes._spawnRange;
                _maxNearbyEnemies = tes._maxNearbyEnemies;
                _requiredPlayerRange = tes._requiredPlayerRange;
                _maxExperience = tes._maxExperience;
                _remainingExperience = tes._remainingExperience;
                _experienceRegenTick = tes._experienceRegenTick;
                _experienceRegenRate = tes._experienceRegenRate;
                _experienceRegenAmount = tes._experienceRegenAmount;

                if (tes._spawnData != null)
                    _spawnData = tes._spawnData.Copy() as TagNodeCompound;
            }
        }
Esempio n. 38
0
        /// <summary>
        /// Exports the <see cref="Schematic"/> object to a schematic file.
        /// </summary>
        /// <param name="path">The path to write out the schematic file to.</param>
        public void Export(string path)
        {
            int xdim = _blockset.XDim;
            int ydim = _blockset.YDim;
            int zdim = _blockset.ZDim;

            byte[] blockData = new byte[xdim * ydim * zdim];
            byte[] dataData = new byte[xdim * ydim * zdim];

            YZXByteArray schemaBlocks = new YZXByteArray(_blockset.XDim, _blockset.YDim, _blockset.ZDim, blockData);
            YZXByteArray schemaData = new YZXByteArray(_blockset.XDim, _blockset.YDim, _blockset.ZDim, dataData);

            TagNodeList entities = new TagNodeList(TagType.TAG_COMPOUND);
            TagNodeList tileEntities = new TagNodeList(TagType.TAG_COMPOUND);

            for (int x = 0; x < xdim; x++) {
                for (int z = 0; z < zdim; z++) {
                    for (int y = 0; y < ydim; y++) {
                        AlphaBlock block = _blockset.GetBlock(x, y, z);
                        schemaBlocks[x, y, z] = (byte)block.ID;
                        schemaData[x, y, z] = (byte)block.Data;

                        TileEntity te = block.GetTileEntity();
                        if (te != null) {
                            te.X = x;
                            te.Y = y;
                            te.Z = z;

                            tileEntities.Add(te.BuildTree());
                        }
                    }
                }
            }

            foreach (TypedEntity e in _entityset) {
                entities.Add(e.BuildTree());
            }

            TagNodeCompound schematic = new TagNodeCompound();
            schematic["Width"] = new TagNodeShort((short)xdim);
            schematic["Length"] = new TagNodeShort((short)zdim);
            schematic["Height"] = new TagNodeShort((short)ydim);

            schematic["Entities"] = entities;
            schematic["TileEntities"] = tileEntities;

            schematic["Materials"] = new TagNodeString("Alpha");

            schematic["Blocks"] = new TagNodeByteArray(blockData);
            schematic["Data"] = new TagNodeByteArray(dataData);

            NBTFile schematicFile = new NBTFile(path);

            Stream nbtStream = schematicFile.GetDataOutputStream();
            if (nbtStream == null) {
                return;
            }

            NbtTree tree = new NbtTree(schematic, "Schematic");
            tree.WriteTo(nbtStream);

            nbtStream.Close();
        }
Esempio n. 39
0
 public static TagNodeList GetEnchantmentNBT(List<Enchantment> enchantments)
 {
     TagNodeCompound compound;
     TagNodeList list = new TagNodeList(TagType.TAG_COMPOUND);
     foreach (Enchantment ench in enchantments.ToArray())
     {
         compound = new TagNodeCompound();
         compound.Add("id", new TagNodeShort(ench.id));
         compound.Add("lvl", new TagNodeShort(ench.level));
         list.Add(compound);
     }
     return list;
 }
Esempio n. 40
0
 public TagNodeCompound GetNBTData()
 {
     TagNodeCompound comp = new TagNodeCompound();
     comp.Add("ID", new TagNodeShort(id));
     comp.Add("Count", new TagNodeByte(count));
     comp.Add("Meta", new TagNodeShort(meta));
     comp.Add("Ench", GetEnchantmentNBT());
     return comp;
 }
Esempio n. 41
0
 public void LoadNBTData(TagNodeCompound comp)
 {
     try {
         id = comp["ID"].ToTagShort();
         count = comp["Count"].ToTagByte();
         meta = comp["Meta"].ToTagShort();
         LoadEnchantmentNBT(comp["Ench"].ToTagList());
     }
     catch { Logger.Log("NBT data is invalid."); }
 }
Esempio n. 42
0
 public TagCompoundDataNode(TagNodeCompound tag)
     : base(tag)
 {
     _container = new CompoundTagContainer(tag);
 }
Esempio n. 43
0
        public override TagNode BuildTree()
        {
            TagNodeCompound tree = base.BuildTree() as TagNodeCompound;
            tree["AttackTime"] = new TagNodeShort(_attackTime);
            tree["DeathTime"] = new TagNodeShort(_deathTime);
            tree["Health"] = new TagNodeShort(_health);
            tree["HurtTime"] = new TagNodeShort(_hurtTime);

            if (_activeEffects != null) {
                TagNodeCompound ae = new TagNodeCompound();
                ae["Id"] = new TagNodeByte((byte)_activeEffects.Id);
                ae["Amplifier"] = new TagNodeByte((byte)_activeEffects.Amplifier);
                ae["Duration"] = new TagNodeInt(_activeEffects.Duration);

                tree["ActiveEffects"] = ae;
            }

            return tree;
        }
        internal static void AddTagToNode(TreeNode node, int descriptionIndex, TagType type)
        {
            TagNode tag = GetTagNode(node);
            if (tag == null)
                return;

            if (tag.GetTagType() != TagType.TAG_COMPOUND &&
                tag.GetTagType() != TagType.TAG_LIST)
                return;

            if (tag.GetTagType() == TagType.TAG_LIST &&
                tag.ToTagList().ValueType != type &&
                tag.ToTagList().Count > 0)
                return;

            TagNode newNode = null;
            switch (type)
            {
                case TagType.TAG_BYTE:
                    newNode = new TagNodeByte();
                    break;
                case TagType.TAG_SHORT:
                    newNode = new TagNodeShort();
                    break;
                case TagType.TAG_INT:
                    newNode = new TagNodeInt();
                    break;
                case TagType.TAG_LONG:
                    newNode = new TagNodeLong();
                    break;
                case TagType.TAG_FLOAT:
                    newNode = new TagNodeFloat();
                    break;
                case TagType.TAG_DOUBLE:
                    newNode = new TagNodeDouble();
                    break;
                case TagType.TAG_BYTE_ARRAY:
                    newNode = new TagNodeByteArray();
                    break;
                case TagType.TAG_STRING:
                    newNode = new TagNodeString();
                    break;
                case TagType.TAG_LIST:
                    newNode = new TagNodeList(TagType.TAG_BYTE);
                    break;
                case TagType.TAG_COMPOUND:
                    newNode = new TagNodeCompound();
                    break;
                case TagType.TAG_INT_ARRAY:
                    newNode = new TagNodeIntArray();
                    break;
            }

            if (tag is TagNodeCompound)
            {
                TagNodeCompound ctag = tag as TagNodeCompound;

                EditValue form = new EditValue("");
                foreach (string key in ctag.Keys)
                {
                    form.InvalidNames.Add(key);
                }

                if (form.ShowDialog() != DialogResult.OK)
                    return;

                ctag.Add(form.NodeName, newNode);

                TreeNode tnode = NodeFromTag(newNode, descriptionIndex, form.NodeName);
                node.Nodes.Add(tnode);

                tnode.TreeView.SelectedNode = tnode;
                tnode.Expand();
            }
            else if (tag is TagNodeList)
            {
                var ltag = tag as TagNodeList;
                if (ltag.ValueType != type)
                    ltag.ChangeValueType(type);

                ltag.Add(newNode);

                TreeNode tnode = NodeFromTag(newNode, descriptionIndex);
                node.Nodes.Add(tnode);
                tnode.TreeView.SelectedNode = tnode;

                tnode.Expand();
            }

            node.Text = GetNodeText(node);

            TreeNode baseNode = BaseNode(node);
            if (baseNode != null)
            {
                (baseNode.Tag as DataNode).Modified = true;
            }
        }
Esempio n. 45
0
        public static byte[] GetEnchantmentNBTData(List<Enchantment> enchantments)
        {
            if (enchantments.Count < 1) return new byte[0];

            NbtTree nbt = new NbtTree();
            TagNodeList list = new TagNodeList(TagType.TAG_COMPOUND);

            TagNodeCompound compound;
            foreach (Enchantment ench in enchantments.ToArray())
            {
                compound = new TagNodeCompound();
                compound.Add("id", new TagNodeShort(ench.id));
                compound.Add("lvl", new TagNodeShort(ench.level));
                list.Add(compound);
            }

            nbt.Root.Add("ench", list);

            using (MemoryStream ms = new MemoryStream())
            {
                nbt.WriteTo(ms);
                return ms.ToArray().Compress(Ionic.Zlib.CompressionLevel.BestCompression, CompressionType.GZip);
            }
        }
Esempio n. 46
0
        public void Save(World w)
        {
            try
            {
                string path = CreatePath(w, x, z, true);
                string file = CreatePath(w, x, z);
                if (!Directory.Exists(path)) Directory.CreateDirectory(path);

                NbtTree nbt = new NbtTree();
                nbt.Root.Add("Generated", new TagNodeByte((byte)(generated ? 1 : 0)));
                nbt.Root.Add("Populated", new TagNodeByte((byte)(populated ? 1 : 0)));
                nbt.Root.Add("Blocks", new TagNodeByteArray(blocks));
                nbt.Root.Add("Meta", new TagNodeByteArray(meta));
                nbt.Root.Add("BlockLight", new TagNodeByteArray(Light));
                nbt.Root.Add("SkyLight", new TagNodeByteArray(SkyL));
                nbt.Root.Add("HeightMap", new TagNodeByteArray(heightMap));
                nbt.Root.Add("HeightMapPrec", new TagNodeByteArray(precipitationHeightMap.ToByteArray()));
                TagNodeList nbtList = new TagNodeList(TagType.TAG_COMPOUND);
                TagNodeCompound nbtCompound;
                lock (extra)
                    foreach (KeyValuePair<int, ushort> kvp in extra)
                    {
                        nbtCompound = new TagNodeCompound();
                        nbtCompound.Add("Pos", new TagNodeInt(kvp.Key));
                        nbtCompound.Add("Value", new TagNodeShort((short)kvp.Value));
                        nbtList.Add(nbtCompound);
                    }
                nbt.Root.Add("Extra", nbtList);
                nbtList = new TagNodeList(TagType.TAG_COMPOUND);
                List<Physics.Check> physChecks = w.physics.GetChunkChecks(x, z);
                foreach (Physics.Check check in physChecks)
                {
                    nbtCompound = new TagNodeCompound();
                    nbtCompound.Add("Pos", new TagNodeList(TagType.TAG_INT) { new TagNodeInt(check.x), new TagNodeInt(check.y), new TagNodeInt(check.z) });
                    nbtCompound.Add("Meta", new TagNodeByte(check.meta));
                    nbtCompound.Add("Time", new TagNodeShort(check.time));
                    nbtList.Add(nbtCompound);
                }
                nbt.Root.Add("Physics", nbtList);
                nbtList = new TagNodeList(TagType.TAG_COMPOUND);
                List<Entity> entities = Entities; TagNodeCompound nbtCompound2;
                foreach (Entity e in entities)
                {
                    if (e.isPlayer) continue;
                    nbtCompound = new TagNodeCompound();
                    nbtCompound.Add("Motion", new TagNodeList(TagType.TAG_DOUBLE) { new TagNodeDouble(e.velocity[0]), new TagNodeDouble(e.velocity[1]), new TagNodeDouble(e.velocity[2]) });
                    nbtCompound.Add("Pos", new TagNodeList(TagType.TAG_DOUBLE) { new TagNodeDouble(e.pos.x), new TagNodeDouble(e.pos.y), new TagNodeDouble(e.pos.z) });
                    nbtCompound.Add("Rotation", new TagNodeList(TagType.TAG_FLOAT) { new TagNodeFloat(e.rot[0]), new TagNodeFloat(e.rot[1]) });
                    nbtCompound.Add("Type", new TagNodeByte((byte)e.Type));
                    nbtCompound.Add("Age", new TagNodeInt(e.age));
                    nbtCompound.Add("OnGround", new TagNodeByte(e.onground));
                    nbtCompound.Add("Health", new TagNodeShort(e.Health));
                    nbtCompound2 = new TagNodeCompound();
                    switch (e.Type)
                    {
                        case EntityType.AI:
                            nbtCompound2.Add("Type", new TagNodeByte(e.ai.type));
                            break;
                        case EntityType.Object:
                            nbtCompound2.Add("Type", new TagNodeByte(e.obj.type));
                            break;
                        case EntityType.Item:
                            nbtCompound2.Add("ID", new TagNodeShort(e.I.id));
                            nbtCompound2.Add("Count", new TagNodeByte(e.I.count));
                            nbtCompound2.Add("Meta", new TagNodeShort(e.I.meta));
                            break;
                    }
                    nbtCompound.Add("Data", nbtCompound2);
                    nbtList.Add(nbtCompound);
                }
                nbt.Root.Add("Entities", nbtList);
                nbtList = new TagNodeList(TagType.TAG_COMPOUND);
                foreach (Container c in GetContainers(w))
                {
                    nbtCompound = new TagNodeCompound();
                    nbtCompound.Add("Type", new TagNodeByte((byte)c.Type));
                    nbtCompound.Add("Pos", new TagNodeList(TagType.TAG_INT) { new TagNodeInt((int)c.Pos.x), new TagNodeInt((int)c.Pos.y), new TagNodeInt((int)c.Pos.z) });
                    nbtCompound.Add("Items", c.GetNBTData());
                    nbtList.Add(nbtCompound);
                    //Console.WriteLine("SAVED CONTAINER @ " + (int)c.Pos.x + "," + (int)c.Pos.y + "," + (int)c.Pos.z + " @ " + x + "," + z);
                }
                nbt.Root.Add("Containers", nbtList);

                try
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        nbt.WriteTo(ms);
                        byte[] bytes = ms.ToArray().Compress(CompressionLevel.BestCompression, CompressionType.GZip);
                        using (FileStream fs = new FileStream(file, FileMode.Create, FileAccess.Write))
                            fs.Write(bytes, 0, bytes.Length);
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogToFile("Error saving chunk at " + x + "," + z + "!");
                    Logger.LogErrorToFile(ex);
                }

                this._dirty = false;
                //Console.WriteLine("SAVED " + x + " " + z);
            }
            catch (Exception ex) { Logger.LogError(ex); }
        }
Esempio n. 47
0
 public CompoundTagContainer(TagNodeCompound tag)
 {
     _tag = tag;
 }
Esempio n. 48
0
        public override TileEntity LoadTree(TagNode tree)
        {
            TagNodeCompound ctree = tree as TagNodeCompound;
            if (ctree == null || base.LoadTree(tree) == null) {
                return null;
            }

            _delay = ctree["Delay"].ToTagShort();
            _entityID = ctree["EntityId"].ToTagString();

            if (ctree.ContainsKey("MaxSpawnDelay"))
                _maxDelay = ctree["MaxSpawnDelay"].ToTagShort();
            if (ctree.ContainsKey("MinSpawnDelay"))
                _minDelay = ctree["MinSpawnDelay"].ToTagShort();
            if (ctree.ContainsKey("SpawnCount"))
                _spawnCount = ctree["SpawnCount"].ToTagShort();
            if (ctree.ContainsKey("SpawnRange"))
                _spawnRange = ctree["SpawnRange"].ToTagShort();
            if (ctree.ContainsKey("MaxNearbyEnemies"))
                _maxNearbyEnemies = ctree["MaxNearbyEnemies"].ToTagShort();
            if (ctree.ContainsKey("RequiredPlayerRange"))
                _requiredPlayerRange = ctree["RequiredPlayerRange"].ToTagShort();
            if (ctree.ContainsKey("MaxExperience"))
                _maxExperience = ctree["MaxExperience"].ToTagInt();
            if (ctree.ContainsKey("RemainingExperience"))
                _remainingExperience = ctree["RemainingExperience"].ToTagInt();
            if (ctree.ContainsKey("ExperienceRegenTick"))
                _experienceRegenTick = ctree["ExperienceRegenTick"].ToTagInt();
            if (ctree.ContainsKey("ExperienceRegenRate"))
                _experienceRegenRate = ctree["ExperienceRegenRate"].ToTagInt();
            if (ctree.ContainsKey("ExperienceRegenAmount"))
                _experienceRegenRate = ctree["ExperienceRegenAmount"].ToTagInt();

            if (ctree.ContainsKey("SpawnData"))
                _spawnData = ctree["SpawnData"].ToTagCompound();

            return this;
        }