Exemplo n.º 1
0
        public bool TryGetRegionView(
            Dimension dimension,
            int regionX,
            int regionZ,
            out ChunkView[] views,
            bool getBiomeData     = false,
            bool getHeightmapData = false,
            bool getSubchunkData  = false
            )
        {
            if (!(getBiomeData || getHeightmapData || getSubchunkData))
            {
                throw new ArgumentException("Must request at least one of biome, height, and subchunk data.");
            }

            bool foundChunk = false;

            views = new ChunkView[64 * 64];
            int chunkX           = regionX * 64;
            int chunkZ           = regionZ * 64;
            int destinationIndex = 0;

            for (int z = 0; z < 64; z++)
            {
                for (int x = 0; x < 64; x++)
                {
                    if (TryGetChunkView(dimension, chunkX + x, chunkZ + z, out ChunkView chunk, getBiomeData: getBiomeData, getHeightmap: getHeightmapData, getSubchunkData: getSubchunkData))
                    {
                        foundChunk = true;
                        views[destinationIndex] = chunk;
                    }

                    destinationIndex++;
                }
            }

            if (!foundChunk)
            {
                views = null;
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        public bool TryGetChunkView(
            Dimension dimension,
            int chunkX,
            int chunkZ,
            out ChunkView view,
            bool getBiomeData         = false,
            bool getHeightmap         = false,
            bool getSubchunkData      = false,
            bool getVersion           = false,
            bool getEntities          = false,
            bool getBlockEntities     = false,
            bool getExtraBlockData    = false,
            bool getPendingTickList   = false,
            bool getFinalizedState    = false,
            bool getBorderBlocks      = false,
            bool getHardcodedSpawners = false
            )
        {
            if (!CheckDimensionBitmapIfAvailable(dimension, chunkX, chunkZ))
            {
                view = null;
                return(false);
            }

            byte[] biomeData = null, heightmap = null;
            if (getBiomeData || getHeightmap)
            {
                byte[] data2D = db_.Query(dimension, chunkX, chunkZ, DbKeyType.Data2D);
                if (data2D != null)
                {
                    heightmap = new byte[512];
                    biomeData = new byte[256];
                    Buffer.BlockCopy(data2D, 0, heightmap, 0, NUMBER_OF_DATA_VALUES_IN_CHUNK * 2);
                    Buffer.BlockCopy(data2D, OFFSET_OF_CHUNK_BIOMES_DATA, biomeData, 0, 256);
                }
            }

            byte[][] subchunkData = null;
            if (getSubchunkData)
            {
                List <byte[]> subchunks = new List <byte[]>();
                int           maxYIndex = dimension.Value == Dimension.DIMENSION_ID_NETHER ? 8 : 16;
                for (int y = 0; y < maxYIndex; y++)
                {
                    var subchunk = db_.QuerySubchunkData(dimension, chunkX, y, chunkZ);
                    if (subchunk != null)
                    {
                        subchunks.Add(subchunk);
                    }
                    else
                    {
                        break;
                    }
                }

                if (subchunks.Count > 0)
                {
                    subchunkData = subchunks.ToArray();
                }
            }

            byte[] version = null;
            if (getVersion)
            {
                version = db_.Query(dimension, chunkX, chunkZ, DbKeyType.Version);
            }

            byte[] entities = null;
            if (getEntities)
            {
                entities = db_.Query(dimension, chunkX, chunkZ, DbKeyType.Entity);
            }

            byte[] blockEntities = null;
            if (getBlockEntities)
            {
                blockEntities = db_.Query(dimension, chunkX, chunkZ, DbKeyType.BlockEntity);
            }

            byte[] blockExtraData = null;
            if (getExtraBlockData)
            {
                blockExtraData = db_.Query(dimension, chunkX, chunkZ, DbKeyType.BlockExtraData);
            }

            byte[] pendingTicks = null;
            if (getPendingTickList)
            {
                pendingTicks = db_.Query(dimension, chunkX, chunkZ, DbKeyType.PendingTicks);
            }

            byte[] finalizedState = null;
            if (getFinalizedState)
            {
                finalizedState = db_.Query(dimension, chunkX, chunkZ, DbKeyType.FinalizedState);
            }

            byte[] borderBlocks = null;
            if (getBorderBlocks)
            {
                borderBlocks = db_.Query(dimension, chunkX, chunkZ, DbKeyType.BorderBlocks);
            }

            byte[] hcSpawners = null;
            if (getHardcodedSpawners)
            {
                hcSpawners = db_.Query(dimension, chunkX, chunkZ, DbKeyType.HardcodedSpawners);
            }

            if (biomeData == null && heightmap == null && subchunkData == null && version == null && entities == null &&
                blockEntities == null && blockExtraData == null && pendingTicks == null && finalizedState == null &&
                borderBlocks == null && hcSpawners == null)
            {
                view = null;
                return(false);
            }

            view = new ChunkView(
                dimension,
                chunkX,
                chunkZ,
                biomeData,
                heightmap,
                subchunkData,
                version,
                entities,
                blockEntities,
                blockExtraData,
                pendingTicks,
                finalizedState,
                borderBlocks,
                hcSpawners
                );
            return(true);
        }