Пример #1
0
        /// <summary>
        /// Sets the chunk at the given position to the chunk provided.
        /// </summary>
        /// <param name="position">Position in chunk coordinates</param>
        public void SetChunk(Vector3 position, Chunk chunk)
        {
            //In chunks
            int x = (int)position.X;
            int z = (int)position.Z;

            //In regions
            int regionX = x / Region.Width - ((x < 0) ? 1 : 0);
            int regionZ = z / Region.Depth - ((z < 0) ? 1 : 0);

            Vector3 region = new Vector3(regionX, 0, regionZ);
            if (!Regions.ContainsKey(region))
                Regions.Add(region, new Region(region, WorldGenerator));

            Regions[region].SetChunk(new Vector3(x - regionX * 32, 0, z - regionZ * 32), chunk);
        }
Пример #2
0
        public ChunkDataPacket(ref Chunk Chunk) : this()
        {
            this.X = (int)Chunk.AbsolutePosition.X;
            this.Z = (int)Chunk.AbsolutePosition.Z;

            byte[] blockData = new byte[0];
            byte[] metadata = new byte[0];
            byte[] blockLight = new byte[0];
            byte[] skyLight = new byte[0];
            
            ushort mask = 1, chunkY = 0;
            bool nonAir = true;
            for (int i = 15; i >= 0; i--)
            {
                Section s = Chunk.Sections [chunkY++];

                if (s.IsAir)
                    nonAir = false;
                if (nonAir)
                {
                    blockData = blockData.Concat(s.Blocks).ToArray();
                    metadata = metadata.Concat(s.Metadata.Data).ToArray();
                    blockLight = blockLight.Concat(s.BlockLight.Data).ToArray();
                    skyLight = skyLight.Concat(s.SkyLight.Data).ToArray();
                    
                    this.PrimaryBitMap |= mask;
                }
                
                mask <<= 1;
            }

            byte[] data = blockData.Concat(metadata).Concat(blockLight)
                .Concat(skyLight).Concat(Chunk.Biomes).ToArray();
            int length;
            byte[] result = new byte[data.Length];
            lock (LockObject)
            {
                zLibDeflater.SetInput(data);
                zLibDeflater.Finish();
                length = zLibDeflater.Deflate(result);
                zLibDeflater.Reset();
            }

            this.GroundUpContiguous = true;

            CompressedData = result.Take(length).ToArray();
        }
Пример #3
0
 internal void SetChunk(Vector3 position, Chunk chunk)
 {
     if (!Chunks.ContainsKey(position))
         Chunks.Add(position, chunk);
     Chunks[position] = chunk;
 }
Пример #4
0
        private Vector3 FindBlockPosition(Vector3 position, out Chunk chunk)
        {
            int x = (int)position.X;
            int y = (int)position.Y;
            int z = (int)position.Z;

            if (y < 0 || y >= Chunk.Height) throw new ArgumentOutOfRangeException("Block is out of range");

            int chunkX = x / (Chunk.Width) - ((x < 0) ? 1 : 0);
            int chunkZ = z / (Chunk.Depth) - ((z < 0) ? 1 : 0);

            chunk = GetChunk(new Vector3(chunkX, 0, chunkZ));
            return new Vector3(x - chunkX * Chunk.Width, y, z - chunkZ * Chunk.Depth);;
        }