public TileEntity GetTileEntity(int x, int y, int z)
        {
            BlockKey key = (TranslateCoordinates != null)
                ? TranslateCoordinates(x, y, z)
                : new BlockKey(x, y, z);

            TagNodeCompound te;

            if (!_tileEntityTable.TryGetValue(key, out te))
            {
                return(null);
            }

            return(TileEntityFactory.Create(te));
        }
Esempio n. 2
0
        public void CreateTileEntity(int x, int y, int z)
        {
            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.");
            }

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

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

            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;
        }