Exemple #1
0
 public bool IsAdjacentTo(CachedChunk chunk)
 {
     if (chunk == null)
     {
         return(false);
     }
     return(this.IsAdjacentTo(chunk.MiniMapLocation));
 }
Exemple #2
0
        public void DeallocationTest()
        {
            CachedChunk chunk = new CachedChunk(TestArchive.Chunks[0], cache);

            chunk.Allocate();

            chunk.Deallocate();

            Assert.IsNull(chunk.Files[0].CompressedData);
        }
Exemple #3
0
        public void AllocationTest()
        {
            CachedChunk chunk = new CachedChunk(TestArchive.Chunks[0], cache);

            chunk.Allocate();

            Assert.IsNotNull(chunk.Files[0].CompressedData);

            //Assert.AreEqual((int)chunk.BaseChunk.UncompressedLength, (int)chunk.Data.Length);

            //chunk.Deallocate();
        }
        public override void HandleMcpeClientCacheMissResponse(McpeClientCacheMissResponse message)
        {
            foreach (KeyValuePair <ulong, byte[]> kv in message.blobs)
            {
                ulong  hash = kv.Key;
                byte[] data = kv.Value;

                Client.BlobCache.TryAdd(hash, data);

                var chunks = _futureChunks.Where(c => c.Key.SubChunks.Contains(hash) || c.Key.Biome == hash);
                foreach (KeyValuePair <CachedChunk, object> kvp in chunks)
                {
                    CachedChunk chunk = kvp.Key;

                    if (chunk.Biome == hash)
                    {
                        chunk.Chunk.biomeId = data;
                        chunk.Biome         = 0;
                    }
                    else
                    {
                        for (int i = 0; i < chunk.SubChunks.Length; i++)
                        {
                            ulong subChunkHash = chunk.SubChunks[i];
                            if (subChunkHash == hash)
                            {
                                // parse data
                                chunk.Chunk[i]     = ClientUtils.DecodeChunkColumn(1, data, BlockPalette, _internalStates)[0];
                                chunk.SubChunks[i] = 0;
                            }
                        }
                    }
                    if (chunk.Biome == 0 && chunk.SubChunks.All(c => c == 0))
                    {
                        _futureChunks.TryRemove(chunk, out _);

                        var coordinates = new ChunkCoordinates(chunk.Chunk.X, chunk.Chunk.Z);
                        foreach (KeyValuePair <BlockCoordinates, NbtCompound> bePair in _futureBlockEntities.Where(be => (ChunkCoordinates)be.Key == coordinates))
                        {
                            chunk.Chunk.BlockEntities.Add(bePair);
                            _futureBlockEntities.TryRemove(bePair.Key, out _);
                        }

                        chunk.Chunk.RecalcHeight();
                        Client.Chunks[coordinates] = chunk.Chunk;
                    }
                }
            }
        }
Exemple #5
0
        public void FileDataTest()
        {
            CachedChunk chunk = new CachedChunk(TestArchive.Chunks[0], cache);
            CachedFile  file  = chunk.Files[0];

            using (MemoryStream mem = new MemoryStream())
                using (Stream decomp = file.GetStream())
                {
                    decomp.CopyTo(mem);

                    byte[] LoadedData = mem.ToArray();

                    Assert.IsTrue(PPeX.Utility.CompareBytes(LoadedData, TestData), "File data is not consistent.");
                }
        }
        public override void HandleMcpeLevelChunk(McpeLevelChunk message)
        {
            if (message.cacheEnabled)
            {
                var chunk = new CachedChunk
                {
                    X = message.chunkX,
                    Z = message.chunkZ,
                };
                chunk.Chunk.X = chunk.X;
                chunk.Chunk.Z = chunk.Z;

                var hits   = new List <ulong>();
                var misses = new List <ulong>();

                ulong biomeHash = message.blobHashes.Last();
                if (Client.BlobCache.TryGetValue(biomeHash, out byte[] biomes))
        private VoxelChunk CreateChunk(int hash, int chunkX, int chunkY, int chunkZ)
        {
            Vector3 position = new Vector3(chunkX * CHUNK_SIZE + CHUNK_HALF_SIZE, chunkY * CHUNK_SIZE + CHUNK_HALF_SIZE, chunkZ * CHUNK_SIZE + CHUNK_HALF_SIZE);

            if (!mCachedChunks.TryGetValue(hash, out CachedChunk cachedChunk))
            {
                cachedChunk         = new CachedChunk();
                mCachedChunks[hash] = cachedChunk;
            }

            VoxelChunk chunk = new VoxelChunk();

            chunk.Voxels   = new Voxel[CHUNK_SIZE * CHUNK_SIZE * CHUNK_SIZE];
            chunk.Position = position;

            WorldTerrainData.TerrainGeneratorSettings.PaintChunk(chunk);
            cachedChunk.Chunk = chunk;
            return(chunk);
        }