Ejemplo n.º 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);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets a new Tile Entity record for the block.
        /// </summary>
        /// <param name="te">A Tile Entity record compatible with the block's type.</param>
        /// <exception cref="ArgumentException">Thrown when an incompatible <see cref="TileEntity"/> is added to a block.</exception>
        /// <exception cref="InvalidOperationException">Thrown when a <see cref="TileEntity"/> is added to a block that does not use tile entities.</exception>
        public void SetTileEntity(TileEntity te)
        {
            BlockInfoEx info = BlockInfo.BlockTable[_id] as BlockInfoEx;

            if (info == null)
            {
                throw new InvalidOperationException("The current block type does not accept a Tile Entity");
            }

            if (te.GetType() != TileEntityFactory.Lookup(info.TileEntityName))
            {
                throw new ArgumentException("The current block type is not compatible with the given Tile Entity", "te");
            }

            _tileEntity = te;
        }
Ejemplo n.º 3
0
        private void UpdateTileEntity(int old, int value)
        {
            BlockInfoEx info1 = BlockInfo.BlockTable[old] as BlockInfoEx;
            BlockInfoEx info2 = BlockInfo.BlockTable[value] as BlockInfoEx;

            if (info1 != info2)
            {
                if (info1 != null)
                {
                    _tileEntity = null;
                }

                if (info2 != null)
                {
                    _tileEntity = TileEntityFactory.Create(info2.TileEntityName);
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a default Tile Entity record appropriate for the block.
        /// </summary>
        public void CreateTileEntity()
        {
            BlockInfoEx info = BlockInfo.BlockTable[_id] as BlockInfoEx;

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

            TileEntity te = TileEntityFactory.Create(info.TileEntityName);

            if (te == null)
            {
                throw new UnknownTileEntityException("The TileEntity type '" + info.TileEntityName + "' has not been registered with the TileEntityFactory.");
            }

            _tileEntity = te;
        }