Exemplo n.º 1
0
        protected override void OnPostSetBlocks(ChunkBlocks blocks)
        {
            if (parentContext != null)
            {
                parentContext.ChildActionFinished();
            }

            Helpers.GetChunkIndex3DFrom1D(index, out int x, out int y, out int z);
            blocks.Chunk.HandleNeighbors(blockData, new Vector3Int(x, y, z));
        }
Exemplo n.º 2
0
        public void ProcessSetBlock(BlockData blockData, int index, bool setBlockModified)
        {
            // Nothing for us to do if there was no change
            BlockData oldBlockData = this[index];

            if (oldBlockData.Type == blockData.Type)
            {
                return;
            }

            Helpers.GetChunkIndex3DFrom1D(index, out int x, out int y, out int z, pow);
            Vector3Int pos = new Vector3Int(x, y, z);

            // Handle block specific events
            Block oldBlock = blockTypes[oldBlockData.Type];
            Block newBlock = blockTypes[blockData.Type];

            oldBlock.OnDestroy(Chunk, ref pos);
            newBlock.OnCreate(Chunk, ref pos);

            // Update chunk status
            if (blockData.Type == BlockProvider.AIR_TYPE)
            {
                --nonEmptyBlocks;
            }
            else if (oldBlockData.Type == BlockProvider.AIR_TYPE)
            {
                ++nonEmptyBlocks;
            }

            // Update block info
            this[index] = blockData;

            // Notify about modification
            if (setBlockModified)
            {
                Vector3Int globalPos = pos + Chunk.Pos;
                BlockModified(new BlockPos(pos.x, pos.y, pos.z), ref globalPos, blockData);
            }
        }