Skip to content

Commit

Permalink
Clean up tree generators
Browse files Browse the repository at this point in the history
  • Loading branch information
ACGaming committed May 4, 2024
1 parent 22a7abd commit d48034e
Show file tree
Hide file tree
Showing 14 changed files with 612 additions and 977 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/progwml6/natura/common/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,11 @@ public static boolean syncConfig()
public static int amaranthRarity = 1;
public static int tigerRarity = 30;
public static int willowRarity = 10;
public static int eucalyptusSpawnRarity = 25;
public static int eucalyptusSpawnRarity = 40;
public static int eucalyptusSpawnRange = 32;
public static int hopseedSpawnRarity = 10;
public static int hopseedSpawnRange = 20;
public static int sakuraSpawnRarity = 10;
public static int sakuraSpawnRarity = 50;
public static int sakuraSpawnRange = 32;
public static int appleSpawnRarity = 40;
public static int appleSpawnRange = 32;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,19 @@

public class OverworldTreesGenerator implements IWorldGenerator
{
public static OverworldTreesGenerator INSTANCE = new OverworldTreesGenerator();
public static final OverworldTreesGenerator INSTANCE = new OverworldTreesGenerator();

//@formatter:off
OverworldTreeGenerator mapleTreeGen;
OverworldTreeGenerator silverbellTreeGen;
OverworldTreeGenerator amaranthTreeGen;
OverworldTreeGenerator tigerTreeGen;

WillowTreeGenerator willowTreeGen;
EucalyptusTreeGenerator eucalyptusTreeGen;
HopseedTreeGenerator hopseedTreeGen;
SakuraTreeGenerator sakuraTreeGen;

RedwoodTreeGenerator redwoodTreeGen;

AppleTreeGenerator appleTreeGen;

SaguaroGenerator saguaroGen;
//@formatter:on

Expand Down Expand Up @@ -93,7 +89,9 @@ public void retroGen(Random random, int chunkX, int chunkZ, World world)

public void generateOverworld(Random random, int chunkX, int chunkZ, World world, boolean retroGen)
{
int xSpawn, ySpawn, zSpawn;
int xSpawn;
int ySpawn;
int zSpawn;

int xPos = chunkX * 16 + 8;
int zPos = chunkZ * 16 + 8;
Expand All @@ -104,16 +102,11 @@ public void generateOverworld(Random random, int chunkX, int chunkZ, World world

Biome biome = world.getChunk(chunkPos).getBiome(chunkPos, world.getBiomeProvider());

if (biome == null)
{
return;
}

if (this.shouldGenerateInDimension(world.provider.getDimension()))
{
if (BiomeDictionary.hasType(biome, Type.FOREST))
{
if (Config.generateSakura && random.nextInt(Config.sakuraSpawnRarity * 5) == 0)
if (Config.generateSakura && random.nextInt(Config.sakuraSpawnRarity) == 0)
{
for (int iter = 0; iter < 3; iter++)
{
Expand Down Expand Up @@ -189,7 +182,7 @@ public void generateOverworld(Random random, int chunkX, int chunkZ, World world
this.redwoodTreeGen.generateTree(random, world, position);
}

if (Config.generateEucalyptus && random.nextInt((int) (Config.eucalyptusSpawnRarity * 1.5)) == 0)
if (Config.generateEucalyptus && random.nextInt(Config.eucalyptusSpawnRarity) == 0)
{
xSpawn = xPos + random.nextInt(16);
ySpawn = random.nextInt(Config.eucalyptusSpawnRange) + Config.seaLevel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,20 @@

import java.util.Random;

import javax.annotation.Nullable;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.MutableBlockPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.IChunkGenerator;
import net.minecraftforge.common.IPlantable;
import net.minecraftforge.fml.common.IWorldGenerator;

public class BaseTreeGenerator implements IWorldGenerator
{
@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider)
{

}

public void generateTree(Random random, World world, BlockPos pos)
{
}

@Nullable
private static BlockPos getValidPos(World world, int x, int z, Block tree)
{
// get to the ground
final BlockPos topPos = world.getHeight(new BlockPos(x, 0, z));

if (topPos.getY() == 0)
{
return null;
}

final MutableBlockPos pos = new MutableBlockPos(topPos);

IBlockState blockState = world.getBlockState(pos);

while (canReplace(blockState, world, pos))
{
pos.move(EnumFacing.DOWN);
if (pos.getY() <= 0)
{
return null;
}
blockState = world.getBlockState(pos);
}

if (tree instanceof IPlantable && blockState.getBlock().canSustainPlant(blockState, world, pos, EnumFacing.UP, (IPlantable) tree))
{
return pos.up();
}

return null;
}

public static boolean canReplace(IBlockState blockState, World world, BlockPos pos)
{
Block block = blockState.getBlock();

return block.isReplaceable(world, pos) && !blockState.getMaterial().isLiquid();
}
}
Loading

0 comments on commit d48034e

Please sign in to comment.