Ejemplo n.º 1
0
        /// <summary>
        /// Gets an internal Chunk reference from cache or queries the container for it.
        /// </summary>
        /// <returns>The ChunkRef's underlying Chunk.</returns>
        private IChunk GetChunk()
        {
            if (_chunk == null)
            {
                _chunk = _container.GetChunk(_cx, _cz);

                if (_chunk != null)
                {
                    _blocks   = _chunk.Blocks;
                    _biomes   = _chunk.Biomes;
                    _entities = _chunk.Entities;

                    // Set callback functions in the underlying block collection
                    _blocks.ResolveNeighbor      += ResolveNeighborHandler;
                    _blocks.TranslateCoordinates += TranslateCoordinatesHandler;
                }
            }
            return(_chunk);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets an internal Chunk reference from cache or queries the container for it.
        /// </summary>
        /// <returns>The ChunkRef's underlying Chunk.</returns>
        private IChunk GetChunk()
        {
            if (_chunk == null) {
                _chunk = _container.GetChunk(_cx, _cz);

                if (_chunk != null)
                {
                    _blocks = _chunk.Blocks;
                    _biomes = _chunk.Biomes;
                    _entities = _chunk.Entities;

                    // Set callback functions in the underlying block collection
                    _blocks.ResolveNeighbor += ResolveNeighborHandler;
                    _blocks.TranslateCoordinates += TranslateCoordinatesHandler;
                }
            }
            return _chunk;
        }
Ejemplo n.º 3
0
        public AnvilChunk LoadTree(TagNode tree)
        {
            TagNodeCompound ctree = tree as TagNodeCompound;

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

            _tree = new NbtTree(ctree);

            TagNodeCompound level = _tree.Root["Level"] as TagNodeCompound;

            TagNodeList sections = level["Sections"] as TagNodeList;

            foreach (TagNodeCompound section in sections)
            {
                AnvilSection anvilSection = new AnvilSection(section);
                if (anvilSection.Y < 0 || anvilSection.Y >= _sections.Length)
                {
                    continue;
                }
                _sections[anvilSection.Y] = anvilSection;
            }

            FusedDataArray3[] blocksBA     = new FusedDataArray3[_sections.Length];
            YZXNibbleArray[]  dataBA       = new YZXNibbleArray[_sections.Length];
            YZXNibbleArray[]  skyLightBA   = new YZXNibbleArray[_sections.Length];
            YZXNibbleArray[]  blockLightBA = new YZXNibbleArray[_sections.Length];

            for (int i = 0; i < _sections.Length; i++)
            {
                if (_sections[i] == null)
                {
                    _sections[i] = new AnvilSection(i);
                }

                blocksBA[i]     = new FusedDataArray3(_sections[i].AddBlocks, _sections[i].Blocks);
                dataBA[i]       = _sections[i].Data;
                skyLightBA[i]   = _sections[i].SkyLight;
                blockLightBA[i] = _sections[i].BlockLight;
            }

            _blocks     = new CompositeDataArray3(blocksBA);
            _data       = new CompositeDataArray3(dataBA);
            _skyLight   = new CompositeDataArray3(skyLightBA);
            _blockLight = new CompositeDataArray3(blockLightBA);

            _heightMap = new ZXIntArray(XDIM, ZDIM, level["HeightMap"] as TagNodeIntArray);

            if (level.ContainsKey("Biomes"))
            {
                _biomes = new ZXByteArray(XDIM, ZDIM, level["Biomes"] as TagNodeByteArray);
            }
            else
            {
                level["Biomes"] = new TagNodeByteArray(new byte[256]);
                _biomes         = new ZXByteArray(XDIM, ZDIM, level["Biomes"] as TagNodeByteArray);
                for (int x = 0; x < XDIM; x++)
                {
                    for (int z = 0; z < ZDIM; z++)
                    {
                        _biomes[x, z] = BiomeType.Default;
                    }
                }
            }

            _entities     = level["Entities"] as TagNodeList;
            _tileEntities = level["TileEntities"] as TagNodeList;

            if (level.ContainsKey("TileTicks"))
            {
                _tileTicks = level["TileTicks"] as TagNodeList;
            }
            else
            {
                _tileTicks = new TagNodeList(TagType.TAG_COMPOUND);
            }

            // List-type patch up
            if (_entities.Count == 0)
            {
                level["Entities"] = new TagNodeList(TagType.TAG_COMPOUND);
                _entities         = level["Entities"] as TagNodeList;
            }

            if (_tileEntities.Count == 0)
            {
                level["TileEntities"] = new TagNodeList(TagType.TAG_COMPOUND);
                _tileEntities         = level["TileEntities"] as TagNodeList;
            }

            if (_tileTicks.Count == 0)
            {
                level["TileTicks"] = new TagNodeList(TagType.TAG_COMPOUND);
                _tileTicks         = level["TileTicks"] as TagNodeList;
            }

            _cx = level["xPos"].ToTagInt();
            _cz = level["zPos"].ToTagInt();

            _blockManager  = new AlphaBlockCollection(_blocks, _data, _blockLight, _skyLight, _heightMap, _tileEntities, _tileTicks);
            _entityManager = new EntityCollection(_entities);
            _biomeManager  = new AnvilBiomeCollection(_biomes);

            return(this);
        }