Skip to content

Commit

Permalink
Tweak tree placement
Browse files Browse the repository at this point in the history
Since Natura is not using the DecorateBiomeEvent for whatever reason, Natura's trees are generated after the biomes are finished decorating.
This commit deals with the placement of trees, effectively only allowing to replace air in most cases, reducing conjoined trees by a lot.
This should be reworked as a whole eventually.
  • Loading branch information
ACGaming committed May 19, 2024
1 parent 31ae0c2 commit a03aa9d
Show file tree
Hide file tree
Showing 14 changed files with 257 additions and 417 deletions.
35 changes: 27 additions & 8 deletions src/main/java/com/progwml6/natura/common/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,26 @@ public static boolean syncConfig()
redwoodSpawnRarity = configFile.get(WORLDGEN, "Redwood Tree Spawn Rarity", redwoodSpawnRarity).getInt(redwoodSpawnRarity);

mapleRarity = configFile.get(WORLDGEN, "Maple Tree Spawn Rarity", mapleRarity).getInt(mapleRarity);
mapleSpawnRange = configFile.get(WORLDGEN, "Maple Tree Spawn Range", mapleSpawnRange).getInt(mapleSpawnRange);

silverbellRarity = configFile.get(WORLDGEN, "Silverbell Tree Spawn Rarity", silverbellRarity).getInt(silverbellRarity);
silverbellSpawnRange = configFile.get(WORLDGEN, "Silverbell Tree Spawn Range", silverbellSpawnRange).getInt(silverbellSpawnRange);

amaranthRarity = configFile.get(WORLDGEN, "Amaranth Tree Spawn Rarity", amaranthRarity).getInt(amaranthRarity);
amaranthSpawnRange = configFile.get(WORLDGEN, "Amaranth Tree Spawn Range", amaranthSpawnRange).getInt(amaranthSpawnRange);

tigerRarity = configFile.get(WORLDGEN, "Tigerwood Tree Spawn Rarity", tigerRarity).getInt(tigerRarity);
tigerSpawnRange = configFile.get(WORLDGEN, "Tigerwood Tree Spawn Range", tigerSpawnRange).getInt(tigerSpawnRange);

willowRarity = configFile.get(WORLDGEN, "Willow Tree Spawn Rarity", willowRarity).getInt(willowRarity);
willowSpawnRange = configFile.get(WORLDGEN, "Willow Tree Spawn Range", willowSpawnRange).getInt(willowSpawnRange);

eucalyptusSpawnRarity = configFile.get(WORLDGEN, "Eucalyptus Tree Spawn Rarity", eucalyptusSpawnRarity).getInt(eucalyptusSpawnRarity);
eucalyptusSpawnRange = configFile.get(WORLDGEN, "Eucalyptus Tree Spawn Range", eucalyptusSpawnRange).getInt(eucalyptusSpawnRange);

hopseedSpawnRarity = configFile.get(WORLDGEN, "Hopseed Tree Spawn Rarity", hopseedSpawnRarity).getInt(hopseedSpawnRarity);
hopseedSpawnRange = configFile.get(WORLDGEN, "Hopseed Tree Spawn Range", hopseedSpawnRange).getInt(hopseedSpawnRange);

sakuraSpawnRarity = configFile.get(WORLDGEN, "Sakura Tree Spawn Rarity", sakuraSpawnRarity).getInt(sakuraSpawnRarity);
sakuraSpawnRange = configFile.get(WORLDGEN, "Sakura Tree Spawn Range", sakuraSpawnRange).getInt(sakuraSpawnRange);

Expand All @@ -192,6 +203,7 @@ public static boolean syncConfig()
// Trees End

saguaroSpawnRarity = configFile.get(WORLDGEN, "Saguaro Cactus Spawn Rarity", saguaroSpawnRarity).getInt(saguaroSpawnRarity);
saguaroSpawnRange = configFile.get(WORLDGEN, "Saguaro Cactus Spawn Range", saguaroSpawnRange).getInt(saguaroSpawnRange);

// Berries Start
raspberrySpawnRarity = configFile.get(WORLDGEN, "Raspberry Spawn Rarity", raspberrySpawnRarity).getInt(raspberrySpawnRarity);
Expand Down Expand Up @@ -323,7 +335,7 @@ public static boolean syncConfig()
public static boolean canRespawnInNether = true;

// Trees Start
public static boolean generateRedwood = false;
public static boolean generateRedwood = true;
public static boolean generateMaple = true;
public static boolean generateSilverbell = true;
public static boolean generateAmaranth = true;
Expand All @@ -340,19 +352,25 @@ public static boolean syncConfig()
public static boolean generateGhostwood = true;

public static int redwoodSpawnRarity = 150;
public static int redwoodSpawnRange = 16;
public static int mapleRarity = 10;
public static int silverbellRarity = 70;
public static int amaranthRarity = 1;
public static int tigerRarity = 30;
public static int mapleSpawnRange = 48;
public static int silverbellRarity = 10;
public static int silverbellSpawnRange = 48;
public static int amaranthRarity = 10;
public static int amaranthSpawnRange = 48;
public static int tigerRarity = 10;
public static int tigerSpawnRange = 48;
public static int willowRarity = 10;
public static int willowSpawnRange = 16;
public static int eucalyptusSpawnRarity = 30;
public static int eucalyptusSpawnRange = 32;
public static int hopseedSpawnRarity = 10;
public static int hopseedSpawnRange = 20;
public static int sakuraSpawnRarity = 50;
public static int hopseedSpawnRange = 32;
public static int sakuraSpawnRarity = 30;
public static int sakuraSpawnRange = 32;
public static int appleSpawnRarity = 40;
public static int appleSpawnRange = 32;
public static int appleSpawnRarity = 20;
public static int appleSpawnRange = 48;

public static int bloodwoodSpawnRarity = 14;
public static int darkwoodSpawnRarity = 10;
Expand Down Expand Up @@ -413,6 +431,7 @@ public static boolean syncConfig()
public static boolean generateGlowshroomtree = true;

public static int saguaroSpawnRarity = 5;
public static int saguaroSpawnRange = 16;

public static int thornSpawnRarity = 40;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
package com.progwml6.natura.world.worldgen;

import java.util.Random;

import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.IChunkGenerator;
import net.minecraftforge.common.BiomeDictionary;
import net.minecraftforge.common.BiomeDictionary.Type;
import net.minecraftforge.fml.common.IWorldGenerator;

import com.progwml6.natura.common.config.Config;
import com.progwml6.natura.overworld.NaturaOverworld;
import com.progwml6.natura.overworld.block.leaves.BlockAppleLeaves;
Expand All @@ -21,7 +10,22 @@
import com.progwml6.natura.overworld.block.logs.BlockOverworldLog2;
import com.progwml6.natura.overworld.block.logs.BlockRedwoodLog;
import com.progwml6.natura.world.worldgen.saguaro.SaguaroGenerator;
import com.progwml6.natura.world.worldgen.trees.overworld.*;
import com.progwml6.natura.world.worldgen.trees.overworld.AppleTreeGenerator;
import com.progwml6.natura.world.worldgen.trees.overworld.EucalyptusTreeGenerator;
import com.progwml6.natura.world.worldgen.trees.overworld.HopseedTreeGenerator;
import com.progwml6.natura.world.worldgen.trees.overworld.OverworldTreeGenerator;
import com.progwml6.natura.world.worldgen.trees.overworld.RedwoodTreeGenerator;
import com.progwml6.natura.world.worldgen.trees.overworld.SakuraTreeGenerator;
import com.progwml6.natura.world.worldgen.trees.overworld.WillowTreeGenerator;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.IChunkGenerator;
import net.minecraftforge.common.BiomeDictionary;
import net.minecraftforge.common.BiomeDictionary.Type;
import net.minecraftforge.fml.common.IWorldGenerator;

public class OverworldTreesGenerator implements IWorldGenerator
{
Expand Down Expand Up @@ -87,6 +91,7 @@ public void retroGen(Random random, int chunkX, int chunkZ, World world)
world.getChunk(chunkX, chunkZ).markDirty();
}

// TODO: Rework tree generation to use DecorateBiomeEvent.Decorate.EventType.TREE, might have to scrap retro-gen
public void generateOverworld(Random random, int chunkX, int chunkZ, World world, boolean retroGen)
{
int xSpawn;
Expand All @@ -108,21 +113,18 @@ public void generateOverworld(Random random, int chunkX, int chunkZ, World world
{
if (Config.generateSakura && random.nextInt(Config.sakuraSpawnRarity) == 0)
{
for (int iter = 0; iter < 3; iter++)
{
xSpawn = xPos + random.nextInt(16);
ySpawn = random.nextInt(Config.sakuraSpawnRange) + Config.seaLevel;
zSpawn = zPos + random.nextInt(16);
position = new BlockPos(xSpawn, ySpawn, zSpawn);
xSpawn = xPos + random.nextInt(16);
ySpawn = Config.sakuraSpawnRange + Config.seaLevel;
zSpawn = zPos + random.nextInt(16);
position = new BlockPos(xSpawn, ySpawn, zSpawn);

this.sakuraTreeGen.generateTree(random, world, position);
}
this.sakuraTreeGen.generateTree(random, world, position);
}

if (Config.generateEucalyptus && random.nextInt(Config.eucalyptusSpawnRarity) == 0)
{
xSpawn = xPos + random.nextInt(16);
ySpawn = random.nextInt(Config.eucalyptusSpawnRange) + Config.seaLevel;
ySpawn = Config.eucalyptusSpawnRange + Config.seaLevel;
zSpawn = zPos + random.nextInt(16);
position = new BlockPos(xSpawn, ySpawn, zSpawn);

Expand All @@ -132,7 +134,7 @@ public void generateOverworld(Random random, int chunkX, int chunkZ, World world
if (Config.generateMaple && random.nextInt(Config.mapleRarity) == 0)
{
xSpawn = xPos + random.nextInt(16);
ySpawn = Config.seaLevel + 48;
ySpawn = Config.mapleSpawnRange + Config.seaLevel;
zSpawn = zPos + random.nextInt(16);
position = new BlockPos(xSpawn, ySpawn, zSpawn);

Expand All @@ -142,7 +144,7 @@ public void generateOverworld(Random random, int chunkX, int chunkZ, World world
if (Config.generateSilverbell && random.nextInt(Config.silverbellRarity) == 0)
{
xSpawn = xPos + random.nextInt(16);
ySpawn = Config.seaLevel + 48;
ySpawn = Config.silverbellSpawnRange + Config.seaLevel;
zSpawn = zPos + random.nextInt(16);
position = new BlockPos(xSpawn, ySpawn, zSpawn);

Expand All @@ -152,7 +154,7 @@ public void generateOverworld(Random random, int chunkX, int chunkZ, World world
if (Config.generateTiger && random.nextInt(Config.tigerRarity) == 0)
{
xSpawn = xPos + random.nextInt(16);
ySpawn = Config.seaLevel + 48;
ySpawn = Config.tigerSpawnRange + Config.seaLevel;
zSpawn = zPos + random.nextInt(16);
position = new BlockPos(xSpawn, ySpawn, zSpawn);

Expand All @@ -162,7 +164,7 @@ public void generateOverworld(Random random, int chunkX, int chunkZ, World world
if (Config.generateApple && random.nextInt(Config.appleSpawnRarity) == 0)
{
xSpawn = xPos + random.nextInt(16);
ySpawn = random.nextInt(Config.appleSpawnRange) + Config.seaLevel;
ySpawn = Config.appleSpawnRange + Config.seaLevel;
zSpawn = zPos + random.nextInt(16);
position = new BlockPos(xSpawn, ySpawn, zSpawn);

Expand All @@ -175,7 +177,7 @@ public void generateOverworld(Random random, int chunkX, int chunkZ, World world
if (!retroGen && Config.generateRedwood && random.nextInt(Config.redwoodSpawnRarity) == 0)
{
xSpawn = xPos + random.nextInt(16);
ySpawn = Config.seaLevel + 16;
ySpawn = Config.redwoodSpawnRange + Config.seaLevel;
zSpawn = zPos + random.nextInt(16);
position = new BlockPos(xSpawn, ySpawn, zSpawn);

Expand All @@ -185,7 +187,7 @@ public void generateOverworld(Random random, int chunkX, int chunkZ, World world
if (Config.generateEucalyptus && random.nextInt(Config.eucalyptusSpawnRarity) == 0)
{
xSpawn = xPos + random.nextInt(16);
ySpawn = random.nextInt(Config.eucalyptusSpawnRange) + Config.seaLevel;
ySpawn = Config.eucalyptusSpawnRange + Config.seaLevel;
zSpawn = zPos + random.nextInt(16);
position = new BlockPos(xSpawn, ySpawn, zSpawn);

Expand All @@ -195,7 +197,7 @@ public void generateOverworld(Random random, int chunkX, int chunkZ, World world
if (Config.generateApple && random.nextInt(Config.appleSpawnRarity) == 0)
{
xSpawn = xPos + random.nextInt(16);
ySpawn = random.nextInt(Config.appleSpawnRange) + Config.seaLevel;
ySpawn = Config.appleSpawnRange + Config.seaLevel;
zSpawn = zPos + random.nextInt(16);
position = new BlockPos(xSpawn, ySpawn, zSpawn);

Expand All @@ -208,7 +210,7 @@ public void generateOverworld(Random random, int chunkX, int chunkZ, World world
if (Config.generateHopseed && random.nextInt(Config.hopseedSpawnRarity) == 0)
{
xSpawn = xPos + random.nextInt(16);
ySpawn = random.nextInt(Config.hopseedSpawnRange) + Config.seaLevel;
ySpawn = Config.hopseedSpawnRange + Config.seaLevel;
zSpawn = zPos + random.nextInt(16);
position = new BlockPos(xSpawn, ySpawn, zSpawn);

Expand All @@ -218,7 +220,7 @@ public void generateOverworld(Random random, int chunkX, int chunkZ, World world
if (Config.generateEucalyptus && random.nextInt(Config.eucalyptusSpawnRarity) == 0)
{
xSpawn = xPos + random.nextInt(16);
ySpawn = random.nextInt(Config.eucalyptusSpawnRange) + Config.seaLevel;
ySpawn = Config.eucalyptusSpawnRange + Config.seaLevel;
zSpawn = zPos + random.nextInt(16);
position = new BlockPos(xSpawn, ySpawn, zSpawn);

Expand All @@ -230,21 +232,18 @@ public void generateOverworld(Random random, int chunkX, int chunkZ, World world
{
if (Config.generateSakura && random.nextInt(Config.sakuraSpawnRarity) == 0)
{
for (int iter = 0; iter < 3; iter++)
{
xSpawn = xPos + random.nextInt(16);
ySpawn = random.nextInt(Config.sakuraSpawnRange) + Config.seaLevel;
zSpawn = zPos + random.nextInt(16);
position = new BlockPos(xSpawn, ySpawn, zSpawn);
xSpawn = xPos + random.nextInt(16);
ySpawn = Config.sakuraSpawnRange + Config.seaLevel;
zSpawn = zPos + random.nextInt(16);
position = new BlockPos(xSpawn, ySpawn, zSpawn);

this.sakuraTreeGen.generateTree(random, world, position);
}
this.sakuraTreeGen.generateTree(random, world, position);
}

if (Config.generateWillow && random.nextInt(Config.willowRarity) == 0)
{
xSpawn = xPos + random.nextInt(16);
ySpawn = Config.seaLevel + 16;
ySpawn = Config.willowSpawnRange + Config.seaLevel;
zSpawn = zPos + random.nextInt(16);
position = new BlockPos(xSpawn, ySpawn, zSpawn);

Expand All @@ -253,11 +252,24 @@ public void generateOverworld(Random random, int chunkX, int chunkZ, World world
}

if (BiomeDictionary.hasType(biome, Type.JUNGLE))
{
if (Config.generateAmaranth)
{
xSpawn = xPos + random.nextInt(16);
ySpawn = Config.amaranthSpawnRange + Config.seaLevel;
zSpawn = zPos + random.nextInt(16);
position = new BlockPos(xSpawn, ySpawn, zSpawn);

this.amaranthTreeGen.generateTree(random, world, position);
}
}

if (BiomeDictionary.hasType(biome, Type.SAVANNA))
{
if (Config.generateAmaranth && random.nextInt(Config.amaranthRarity) == 0)
{
xSpawn = xPos + random.nextInt(16);
ySpawn = Config.seaLevel + 48;
ySpawn = Config.amaranthSpawnRange + Config.seaLevel;
zSpawn = zPos + random.nextInt(16);
position = new BlockPos(xSpawn, ySpawn, zSpawn);

Expand All @@ -272,7 +284,7 @@ public void generateOverworld(Random random, int chunkX, int chunkZ, World world
for (int i = 0; i < 3; i++)
{
xSpawn = xPos + random.nextInt(16);
ySpawn = Config.seaLevel + 16;
ySpawn = Config.amaranthSpawnRange + Config.seaLevel;
zSpawn = zPos + random.nextInt(16);
position = new BlockPos(xSpawn, ySpawn, zSpawn);

Expand All @@ -286,7 +298,7 @@ public void generateOverworld(Random random, int chunkX, int chunkZ, World world
if (Config.generateSaguaro && random.nextInt(Config.saguaroSpawnRarity) == 0)
{
xSpawn = xPos + random.nextInt(16);
ySpawn = Config.seaLevel + random.nextInt(16);
ySpawn = Config.saguaroSpawnRange + Config.seaLevel;
zSpawn = zPos + random.nextInt(16);
position = new BlockPos(xSpawn, ySpawn, zSpawn);

Expand All @@ -308,5 +320,4 @@ public boolean shouldGenerateInDimension(int dimension)

return true;
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.progwml6.natura.world.worldgen.trees;

import java.util.Random;

import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package com.progwml6.natura.world.worldgen.trees.nether;

import java.util.Random;

import com.progwml6.natura.nether.NaturaNether;
import com.progwml6.natura.world.worldgen.trees.BaseTreeGenerator;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

import com.progwml6.natura.nether.NaturaNether;
import com.progwml6.natura.world.worldgen.trees.BaseTreeGenerator;

public class BloodwoodTreeGenerator extends BaseTreeGenerator
{
public final IBlockState full;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package com.progwml6.natura.world.worldgen.trees.nether;

import java.util.Random;

import com.progwml6.natura.nether.NaturaNether;
import com.progwml6.natura.world.worldgen.trees.BaseTreeGenerator;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

import com.progwml6.natura.nether.NaturaNether;
import com.progwml6.natura.world.worldgen.trees.BaseTreeGenerator;

public class DarkwoodTreeGenerator extends BaseTreeGenerator
{
public final int minTreeHeight;
Expand Down Expand Up @@ -133,7 +131,7 @@ protected IBlockState getRandomizedLeaves(Random random)
return (random.nextInt(25) == 0 ? this.fruiting : random.nextInt(15) == 0 ? this.flowering : this.leaves);
}

BlockPos findGround(World world, BlockPos pos)
protected BlockPos findGround(World world, BlockPos pos)
{
boolean foundGround = false;
int height = pos.getY();
Expand Down
Loading

0 comments on commit a03aa9d

Please sign in to comment.