コード例 #1
0
        private void GenerateTree(IChunk c, int x, int y, int z)
        {
            // Trees should only be placed in direct sunlight
            if (!CanSeeTheSky(x, y + 1, z, c))
            {
                return;
            }

            double r2 = _FastRandom.standNormalDistrDouble();

            /*if (r2 > -2 && r2 < -1)
             * {*/
            // Standard tree

            for (int by = y + 4; by < y + 6; by++)
            {
                for (int bx = x - 2; bx <= x + 2; bx++)
                {
                    for (int bz = z - 2; bz <= z + 2; bz++)
                    {
                        c.SetSectionType(bx, by, bz, BlockData.Blocks.Leaves);
                        c.SetData(bx, by, bz, 0, false);
                    }
                }
            }

            for (int bx = x - 1; bx <= x + 1; bx++)
            {
                for (int bz = z - 1; bz <= z + 1; bz++)
                {
                    c.SetSectionType(bx, y + 6, bz, BlockData.Blocks.Leaves);
                    c.SetData(bx, y + 6, bz, 0, false);
                }
            }

            for (int by = y + 1; by < y + 6; by++)
            {
                c.SetSectionType(x, by, z, BlockData.Blocks.Log);
                c.SetData(x, by, z, 0, false);
            }
            //}
            // TODO: other tree types

            /*else if (r2 > 1 && r2 < 2)
             * {
             *  c.setBlock(x, y + 1, z, (byte)0x0);
             *  c.getParent().getObjectGenerator("firTree").generate(c.getBlockWorldPosX(x), y + 1, c.getBlockWorldPosZ(z), false);
             * }
             * else
             * {
             *  c.setBlock(x, y + 1, z, (byte)0x0);
             *  c.getParent().getObjectGenerator("tree").generate(c.getBlockWorldPosX(x), y + 1, c.getBlockWorldPosZ(z), false);
             * }*/
        }
コード例 #2
0
ファイル: CustomChunkGenerator.cs プロジェクト: TheaP/c-raft
        private void GenerateTree(IChunk c, int x, int y, int z)
        {
            // Trees should only be placed in direct sunlight
            if (!CanSeeTheSky(x, y + 1, z, c))
                return;

            double r2 = _FastRandom.standNormalDistrDouble();
            /*if (r2 > -2 && r2 < -1)
            {*/
            // Standard tree

            for (int by = y + 4; by < y + 6; by++)
                for (int bx = x - 2; bx <= x + 2; bx++)
                    for (int bz = z - 2; bz <= z + 2; bz++)
                    {
                        c.SetType(bx, by, bz, BlockData.Blocks.Leaves, false);
                        c.SetData(bx, by, bz, 0, false);
                    }

            for (int bx = x - 1; bx <= x + 1; bx++)
                for (int bz = z - 1; bz <= z + 1; bz++)
                {
                    c.SetType(bx, y + 6, bz, BlockData.Blocks.Leaves, false);
                    c.SetData(bx, y + 6, bz, 0, false);
                }

            for (int by = y + 1; by < y + 6; by++)
            {
                c.SetType(x, by, z, BlockData.Blocks.Wood, false);
                c.SetData(x, by, z, 0, false);
            }
            //}
            // TODO: other tree types
            /*else if (r2 > 1 && r2 < 2)
            {
                c.setBlock(x, y + 1, z, (byte)0x0);
                c.getParent().getObjectGenerator("firTree").generate(c.getBlockWorldPosX(x), y + 1, c.getBlockWorldPosZ(z), false);
            }
            else
            {
                c.setBlock(x, y + 1, z, (byte)0x0);
                c.getParent().getObjectGenerator("tree").generate(c.getBlockWorldPosX(x), y + 1, c.getBlockWorldPosZ(z), false);
            }*/
        }
コード例 #3
0
        private void GenerateFlora(IChunk c, int x, int z)
        {
            BIOME_TYPE biome = CalcBiomeType(x, z);

            for (int bx = 0; bx < 16; ++bx)
            {
                int worldX = bx + x * 16;
                for (int bz = 0; bz < 16; ++bz)
                {
                    int worldZ = bz + z * 16;
                    for (int by = 64; by < 128; ++by)
                    {
                        int worldY = by;
                        //int index = bx << 11 | bz << 7 | by + 1;

                        if (c.GetSectionType(bx, by, bz) == (byte)BlockData.Blocks.Grass && c.GetSectionType(bx, by + 1, bz) == (byte)BlockData.Blocks.Air)
                        {
                            double grassDens = CalcGrassDensity(worldX, worldZ);
                            if (grassDens > 0.0)
                            {
                                // Generate high grass.
                                double rand = _FastRandom.standNormalDistrDouble();
                                if (rand > -0.2 && rand < 0.2)
                                {
                                    c.SetSectionType(bx, by + 1, bz, BlockData.Blocks.TallGrass);
                                    c.SetData(bx, by + 1, bz, 1, false);
                                }


                                //Generate flowers.
                                if (_FastRandom.standNormalDistrDouble() < -2)
                                {
                                    if (_FastRandom.randomBoolean())
                                    {
                                        c.SetSectionType(bx, by + 1, bz, BlockData.Blocks.Rose);
                                    }
                                    else
                                    {
                                        c.SetSectionType(bx, by + 1, bz, BlockData.Blocks.Yellow_Flower);
                                    }
                                }
                            }

                            if (by < 110 && bx % 4 == 0 && bz % 4 == 0)
                            {
                                double forestDens = CalcForestDensity(worldX, worldZ);

                                if (forestDens > 0.005)
                                {
                                    int randX = bx + _FastRandom.randomInt() % 12 + 4;
                                    int randZ = bz + _FastRandom.randomInt() % 12 + 4;

                                    if (randX < 3)
                                    {
                                        randX = 3;
                                    }
                                    else if (randX > 12)
                                    {
                                        randX = 12;
                                    }

                                    if (randZ < 3)
                                    {
                                        randZ = 3;
                                    }
                                    else if (randZ > 15)
                                    {
                                        randZ = 12;
                                    }

                                    if (c.GetSectionType(randX, by, randZ) == (byte)BlockData.Blocks.Grass)
                                    {
                                        GenerateTree(c, randX, by, randZ);
                                    }

                                    else if (biome == BIOME_TYPE.DESERT && c.GetSectionType(randX, by, randZ) == (byte)BlockData.Blocks.Sand)
                                    {
                                        GenerateCactus(c, randX, by, randZ);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #4
0
ファイル: CustomChunkGenerator.cs プロジェクト: TheaP/c-raft
        private void GenerateFlora(IChunk c, int x, int z)
        {
            BIOME_TYPE biome = CalcBiomeType(x, z);
            for (int bx = 0; bx < 16; ++bx)
            {
                int worldX = bx + x * 16;
                for (int bz = 0; bz < 16; ++bz)
                {
                    int worldZ = bz + z * 16;
                    for (int by = 64; by < 128; ++by)
                    {
                        int worldY = by;
                        //int index = bx << 11 | bz << 7 | by + 1;

                        if (c.GetType(bx, by, bz) == BlockData.Blocks.Grass && c.GetType(bx, by + 1, bz) == (byte)BlockData.Blocks.Air)
                        {
                            double grassDens = CalcGrassDensity(worldX, worldZ);
                            if (grassDens > 0.0)
                            {
                                // Generate high grass.
                                double rand = _FastRandom.standNormalDistrDouble();
                                if (rand > -0.2 && rand < 0.2)
                                {
                                    c.SetType(bx, by + 1, bz, BlockData.Blocks.TallGrass, false);
                                    c.SetData(bx, by + 1, bz, 1, false);
                                }


                                //Generate flowers.
                                if (_FastRandom.standNormalDistrDouble() < -2)
                                {
                                    if (_FastRandom.randomBoolean())
                                        c.SetType(bx, by + 1, bz, BlockData.Blocks.Rose, false);
                                    else
                                        c.SetType(bx, by + 1, bz, BlockData.Blocks.Yellow_Flower, false);
                                }
                            }

                            if (by < 110 && bx % 4 == 0 && bz % 4 == 0)
                            {
                                double forestDens = CalcForestDensity(worldX, worldZ);

                                if (forestDens > 0.005)
                                {
                                    int randX = bx + _FastRandom.randomInt() % 12 + 4;
                                    int randZ = bz + _FastRandom.randomInt() % 12 + 4;

                                    if (randX < 3)
                                        randX = 3;
                                    else if (randX > 12)
                                        randX = 12;

                                    if (randZ < 3)
                                        randZ = 3;
                                    else if (randZ > 15)
                                        randZ = 12;

                                    if (c.GetType(randX, by, randZ) == BlockData.Blocks.Grass)
                                        GenerateTree(c, randX, by, randZ);
                                    
                                    else if (biome == BIOME_TYPE.DESERT && c.GetType(randX, by, randZ) == BlockData.Blocks.Sand)
                                        GenerateCactus(c, randX, by, randZ);
                                    
                                }
                            }
                        }
                    }
                }
            }
        }