/**
         * Set the block at the given coords.
         * Also updates neighbor chunks if an edge block is changed.
         */
        public void SetBlock(int x, int y, int z, int id)
        {
            Chunk chunk = GetChunk(x, y, z);

            if (chunk != null)
            {
                chunk.SetBlock(x - chunk.pos.x, y - chunk.pos.y, z - chunk.pos.z, id);

                if (chunk.empty && !IsChunkEmpty(chunk))
                {
                    chunk.empty = false;
                    if (MakePhysical(chunk))
                    {
                        chunk.update = true;
                    }
                }
                else
                {
                    chunk.SetBlock(x - chunk.pos.x, y - chunk.pos.y, z - chunk.pos.z, id);
                    chunk.update = true;
                }

                UpdateIfEqual(x - chunk.pos.x, 0, new WorldPos(x - 1, y, z));
                UpdateIfEqual(x - chunk.pos.x, Chunk.chunkSize - 1, new WorldPos(x + 1, y, z));
                UpdateIfEqual(y - chunk.pos.y, 0, new WorldPos(x, y - 1, z));
                UpdateIfEqual(y - chunk.pos.y, Chunk.chunkSize - 1, new WorldPos(x, y + 1, z));
                UpdateIfEqual(z - chunk.pos.z, 0, new WorldPos(x, y, z - 1));
                UpdateIfEqual(z - chunk.pos.z, Chunk.chunkSize - 1, new WorldPos(x, y, z + 1));
            }
        }
Exemplo n.º 2
0
 void SetBlock(Chunk chunk, int blockId, WorldPos pos, bool replaceBlocks = false)
 {
     if (Chunk.InRange(pos.x) && Chunk.InRange(pos.y) && Chunk.InRange(pos.z))
     {
     if (replaceBlocks || chunk.GetBlock(pos.x, pos.y, pos.z) == 0)
     {
         chunk.SetBlock(pos.x, pos.y, pos.z, blockId);
     }
     }
 }