Esempio n. 1
0
        void PlantTrees()
        {
            int maxTrees = mapWidth * mapLength / TreeClusterDensity;

            for (int cluster = 0; cluster < maxTrees; cluster++)
            {
                int clusterX = random.Next(mapWidth);
                int clusterY = random.Next(mapLength);
                for (int tree = 0; tree < TreeChainsPerCluster; tree++)
                {
                    int x = clusterX;
                    int y = clusterY;
                    for (int hop = 0; hop < TreeHopsPerChain; hop++)
                    {
                        x += random.Next(TreeSpread) - random.Next(TreeSpread);
                        y += random.Next(TreeSpread) - random.Next(TreeSpread);
                        if ((x < 0) || (y < 0) || (x >= mapWidth) || (y >= mapLength))
                        {
                            continue;
                        }
                        if (random.Next(TreePlantRatio) != 0)
                        {
                            continue;
                        }
                        int z = heightmap[(x + y * mapWidth)] + 1;
                        map.GrowTree(random, x, y, z);
                    }
                }
            }
        }
Esempio n. 2
0
        void TriggerSapling(int x, int y, int z)
        {
            if (!Config.PhysicsPlants)
            {
                return;
            }
            Block blockUnder = map.GetBlock(x, y, z - 1);

            if (blockUnder != Block.Grass && blockUnder != Block.Dirt || !IsLit(x, y, z))
            {
                map.SetBlock(null, x, y, z, Block.Air);
                return;
            }
            if (Config.PhysicsTrees && random.Next(5) == 0)
            {
                map.SetBlockNoUpdate(x, y, z, Block.Air);
                if (!map.GrowTree(random, x, y, z))
                {
                    map.SetBlockNoUpdate(x, y, z, Block.Sapling);
                }
            }
        }