Example #1
0
        /// <summary>
        /// Updates the chunk's global world coordinates.
        /// </summary>
        /// <param name="x">Global X-coordinate.</param>
        /// <param name="z">Global Z-coordinate.</param>
        public virtual void SetLocation(int x, int z)
        {
            int diffx = (x - _cx) * XDIM;
            int diffz = (z - _cz) * ZDIM;

            // Update chunk position

            _cx = x;
            _cz = z;

            _tree.Root["Level"].ToTagCompound()["xPos"].ToTagInt().Data = x;
            _tree.Root["Level"].ToTagCompound()["zPos"].ToTagInt().Data = z;

            // Update tile entity coordinates

            List <TileEntity> tileEntites = new List <TileEntity>();

            foreach (TagNodeCompound tag in _tileEntities)
            {
                TileEntity te = TileEntityFactory.Create(tag);
                if (te == null)
                {
                    te = TileEntity.FromTreeSafe(tag);
                }

                if (te != null)
                {
                    te.MoveBy(diffx, 0, diffz);
                    tileEntites.Add(te);
                }
            }

            _tileEntities.Clear();
            foreach (TileEntity te in tileEntites)
            {
                _tileEntities.Add(te.BuildTree());
            }

            // Update entity coordinates

            List <TypedEntity> entities = new List <TypedEntity>();

            foreach (TypedEntity entity in _entityManager)
            {
                entity.MoveBy(diffx, 0, diffz);
                entities.Add(entity);
            }

            _entities.Clear();
            foreach (TypedEntity entity in entities)
            {
                _entityManager.Add(entity);
            }
        }
Example #2
0
    public static void SaveData(TagNodeList Inventory)
    {
        Inventory.Clear();
        Inventory.ChangeValueType(TagType.TAG_COMPOUND);

        int count = 0;

        for (int i = 0; i < 36; i++)
        {
            InventoryItem item = 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);
                Inventory.Insert(count, serializeItem);
            }
        }
    }