Beispiel #1
0
 public TreeGen(TreeGenConfig config, int seed, ForestFloorSystem ffs)
 {
     this.config      = config;
     this.forestFloor = ffs;
     lcgrandTL        = new ThreadLocal <LCGRandom>(() => new LCGRandom(seed));
 }
Beispiel #2
0
 public TreeGen(TreeGenConfig config, int seed)
 {
     this.config = config;
     lcgrandTL   = new ThreadLocal <LCGRandom>(() => new LCGRandom(seed));
 }
Beispiel #3
0
 public TreeGen(TreeGenConfig config, int seed)
 {
     this.config = config;
     rand        = new Random(seed);
 }
        internal void CreateForestFloor(IBlockAccessor blockAccessor, TreeGenConfig config, BlockPos pos, LCGRandom rnd, int treesInChunkGenerated)
        {
            int grassLevelOffset = 0;
            // More grass coverage for jungles
            ClimateCondition climate = blockAccessor.GetClimateAt(pos, EnumGetClimateMode.WorldGenValues);

            if (climate.Temperature > 24 && climate.Rainfall > 160)
            {
                grassLevelOffset = 2;
            }

            short[] outline = outlineThreadSafe.Value;
            this.api = blockAccessor;

            float forestness = climate.ForestDensity * climate.ForestDensity * 4 * (climate.Fertility + 0.25f);


            // Only replace soil with forestFloor in certain climate conditions
            if (climate.Fertility <= 0.25 || forestness <= 0.4)
            {
                return;
            }

            // Otherwise adjust the strength of the effect according to forest density and fertility (fertility is higher for tropical forests)
            for (int i = 0; i < outline.Length; i++)
            {
                outline[i] = (short)(outline[i] * forestness + 0.3f);
            }

            // Blend the canopy outline outwards from the center in a way that ensures smoothness
            for (int pass = 0; pass < 7; pass++)
            {
                bool noChange = true;

                for (int x = 0; x < 16; x++)
                {
                    for (int z = 0; z < 16; z++)
                    {
                        if (x == 0 && z == 0)
                        {
                            continue;
                        }
                        int o = Math.Min((int)outline[(16 + z) * 33 + (16 + x)], 18 * 9);
                        if (o == 0)
                        {
                            continue;
                        }

                        int n1 = (17 + z) * 33 + (16 + x);
                        int n2 = (16 + z) * 33 + (17 + x);
                        if (outline[n1] < o - 18)
                        {
                            outline[n1] = (short)(o - 18);
                            noChange    = false;
                        }
                        if (outline[n2] < o - 18)
                        {
                            outline[n2] = (short)(o - 18);
                            noChange    = false;
                        }

                        o  = Math.Min((int)outline[(16 - z) * 33 + (16 + x)], 18 * 9);
                        n1 = (15 - z) * 33 + (16 + x);
                        n2 = (16 - z) * 33 + (17 + x);
                        if (outline[n1] < o - 18)
                        {
                            outline[n1] = (short)(o - 18);
                            noChange    = false;
                        }
                        if (outline[n2] < o - 18)
                        {
                            outline[n2] = (short)(o - 18);
                            noChange    = false;
                        }
                    }

                    for (int z = 0; z < 16; z++)
                    {
                        if (x == 0 && z == 0)
                        {
                            continue;
                        }
                        int o  = Math.Min((int)outline[(16 + z) * 33 + (16 - x)], 18 * 9);
                        int n1 = (17 + z) * 33 + (16 - x);
                        int n2 = (16 + z) * 33 + (15 - x);
                        if (outline[n1] < o - 18)
                        {
                            outline[n1] = (short)(o - 18);
                            noChange    = false;
                        }
                        if (outline[n2] < o - 18)
                        {
                            outline[n2] = (short)(o - 18);
                            noChange    = false;
                        }

                        o  = Math.Min((int)outline[(16 - z) * 33 + (16 - x)], 18 * 9);
                        n1 = (15 - z) * 33 + (16 - x);
                        n2 = (16 - z) * 33 + (15 - x);
                        if (outline[n1] < o - 18)
                        {
                            outline[n1] = (short)(o - 18);
                            noChange    = false;
                        }
                        if (outline[n2] < o - 18)
                        {
                            outline[n2] = (short)(o - 18);
                            noChange    = false;
                        }
                    }
                }
                if (noChange)
                {
                    break;
                }
            }


            BlockPos currentPos = new BlockPos();

            for (int canopyIndex = 0; canopyIndex < outline.Length; canopyIndex++)
            {
                int intensity = outline[canopyIndex];
                if (intensity == 0)
                {
                    continue;
                }

                int dz = canopyIndex / 33 - 16;
                int dx = canopyIndex % 33 - 16;
                currentPos.Set(pos.X + dx, pos.Y, pos.Z + dz);
                currentPos.Y = blockAccessor.GetTerrainMapheightAt(currentPos);

                if (currentPos.Y - pos.Y < 4)  //Don't place forest floor above approximate height of the canopy of this tree
                {
                    CheckAndReplaceForestFloor(currentPos, intensity, grassLevelOffset);
                }
            }

            GenPatches(blockAccessor, pos, forestness, config.Treetype, rnd);
        }