예제 #1
0
        void GrowTree(int treeX, int treeY, int treeZ, int height)
        {
            int baseHeight = height - 4;

            // leaves bottom layer
            for (int y = treeY + baseHeight; y < treeY + baseHeight + 2; y++)
            {
                for (int zz = -2; zz <= 2; zz++)
                {
                    for (int xx = -2; xx <= 2; xx++)
                    {
                        int x = xx + treeX, z = zz + treeZ;

                        if (Math.Abs(xx) == 2 && Math.Abs(zz) == 2)
                        {
                            if (rnd.NextFloat() >= 0.5)
                            {
                                ChunkHandler.SetBlockAdj(x, y, z, Block.Leaves);
                            }
                        }
                        else
                        {
                            ChunkHandler.SetBlockAdj(x, y, z, Block.Leaves);
                        }
                    }
                }
            }

            // leaves top layer
            int bottomY = treeY + baseHeight + 2;

            for (int y = treeY + baseHeight + 2; y < treeY + height; y++)
            {
                for (int zz = -1; zz <= 1; zz++)
                {
                    for (int xx = -1; xx <= 1; xx++)
                    {
                        int x = xx + treeX, z = zz + treeZ;

                        if (xx == 0 || zz == 0)
                        {
                            ChunkHandler.SetBlockAdj(x, y, z, Block.Leaves);
                        }
                        else if (y == bottomY && rnd.NextFloat() >= 0.5)
                        {
                            ChunkHandler.SetBlockAdj(x, y, z, Block.Leaves);
                        }
                    }
                }
            }

            // then place trunk
            for (int y = 0; y < height - 1; y++)
            {
                //blocks[index] = Block.Log;
                ChunkHandler.SetBlockAdj(treeX, (treeY + y), treeZ, Block.Log);
            }
        }
        /// <summary> Sets the block at the given world coordinates without bounds checking. </summary>
        public void SetBlockAdj(int x, int y, int z, BlockID blockId)
        {
            int i = (y * Length + z) * Width + x;

            //blocks1[i] = (BlockRaw)blockId;
            ChunkHandler.SetBlockAdj(x, y, z, (byte)blockId);
            //if (blocks1 == blocks2) return;
            //blocks2[i] = (BlockRaw)(blockId >> 8);
        }