Skip to content

Commit

Permalink
Clean up berry bush generators
Browse files Browse the repository at this point in the history
  • Loading branch information
ACGaming committed May 4, 2024
1 parent c062a56 commit 69602dd
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

import java.util.Random;

import com.progwml6.natura.common.config.Config;
import com.progwml6.natura.overworld.NaturaOverworld;
import com.progwml6.natura.world.worldgen.berry.overworld.OverworldBerryBushGenerator;

import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
Expand All @@ -15,9 +11,13 @@
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.world.worldgen.berry.overworld.OverworldBerryBushGenerator;

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

//@formatter:off
OverworldBerryBushGenerator raspberryBushGen;
Expand Down Expand Up @@ -49,7 +49,9 @@ public void retroGen(Random random, int chunkX, int chunkZ, World world)

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

int xPos = chunkX * 16 + 8;
int zPos = chunkZ * 16 + 8;
Expand Down Expand Up @@ -132,12 +134,7 @@ public boolean goodClimate(Biome biome, float minTemp, float maxTemp, float minR
float temp = biome.getDefaultTemperature();
float rain = biome.getRainfall();

if (minTemp <= temp && temp <= maxTemp && minRain <= rain && rain <= maxRain)
{
return true;
}

return false;
return minTemp <= temp && temp <= maxTemp && minRain <= rain && rain <= maxRain;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ public class BaseBerryBushGenerator implements IWorldGenerator
@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider)
{

}

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

import java.util.Random;

import com.progwml6.natura.common.block.BlockEnumBerryBush;
import com.progwml6.natura.world.worldgen.berry.BaseBerryBushGenerator;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
Expand All @@ -13,6 +10,9 @@
import net.minecraft.world.World;
import net.minecraftforge.common.IPlantable;

import com.progwml6.natura.common.block.BlockEnumBerryBush;
import com.progwml6.natura.world.worldgen.berry.BaseBerryBushGenerator;

public class NetherBerryBushGenerator extends BaseBerryBushGenerator
{
public final IBlockState berryBush;
Expand Down Expand Up @@ -66,7 +66,7 @@ protected void generateLargeNode(Random random, World world, BlockPos pos)
{
BlockPos blockpos = new BlockPos(iterX, iterY, iterZ);

this.setBlockAndMetadata(random, world, blockpos, this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomFullAge(random)));
this.setBlockAndMetadata(world, blockpos, this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomFullAge(random)));
}
}
}
Expand All @@ -79,7 +79,7 @@ protected void generateLargeNode(Random random, World world, BlockPos pos)
{
BlockPos blockpos = new BlockPos(iterX, iterY, iterZ);

this.setBlockAndMetadata(random, world, blockpos, this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomFullAge(random)));
this.setBlockAndMetadata(world, blockpos, this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomFullAge(random)));
}
}
}
Expand All @@ -92,7 +92,7 @@ protected void generateLargeNode(Random random, World world, BlockPos pos)
{
BlockPos blockpos = new BlockPos(iterX, iterY, iterZ);

this.setBlockAndMetadata(random, world, blockpos, this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomFullAge(random)));
this.setBlockAndMetadata(world, blockpos, this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomFullAge(random)));
}
}
}
Expand All @@ -104,12 +104,12 @@ protected void generateLargeNode(Random random, World world, BlockPos pos)
int yPos = pos.getY() + 1;
BlockPos blockpos = new BlockPos(iterX, yPos, iterZ);

this.setBlockAndMetadata(random, world, blockpos, this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomFullAge(random)));
this.setBlockAndMetadata(world, blockpos, this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomFullAge(random)));

yPos = pos.getY() - 2;
blockpos = new BlockPos(iterX, yPos, iterZ);

this.setBlockAndMetadata(random, world, blockpos, this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomFullAge(random)));
this.setBlockAndMetadata(world, blockpos, this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomFullAge(random)));
}
}
}
Expand All @@ -125,8 +125,7 @@ protected void generateShrub(Random random, World world, BlockPos pos)
break;
}
pos = pos.down();
}
while (pos.getY() > 0);
} while (pos.getY() > 0);

IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
Expand All @@ -137,23 +136,23 @@ protected void generateShrub(Random random, World world, BlockPos pos)

for (int y = pos.getY(); y <= pos.getY() + 2; ++y)
{
int subract = y - pos.getY();
int subract2 = 2 - subract;
int subtract = y - pos.getY();
int subtract2 = 2 - subtract;

for (int x = pos.getX() - subract2; x <= pos.getX() + subract2; ++x)
for (int x = pos.getX() - subtract2; x <= pos.getX() + subtract2; ++x)
{
int mathX = x - pos.getX();

for (int z = pos.getZ() - subract2; z <= pos.getZ() + subract2; ++z)
for (int z = pos.getZ() - subtract2; z <= pos.getZ() + subtract2; ++z)
{
int mathZ = z - pos.getZ();

BlockPos blockpos = new BlockPos(x, y, z);
IBlockState blockState = world.getBlockState(blockpos);

if (Math.abs(mathX) != subract2 || Math.abs(mathZ) != subract2 || random.nextInt(2) != 0 && (block == null || block.canBeReplacedByLeaves(blockState, world, blockpos)))
if (Math.abs(mathX) != subtract2 || Math.abs(mathZ) != subtract2 || random.nextInt(2) != 0 && block.canBeReplacedByLeaves(blockState, world, blockpos))
{
this.setBlockAndMetadata(random, world, blockpos, this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomFullAge(random)));
this.setBlockAndMetadata(world, blockpos, this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomFullAge(random)));
}
}
}
Expand All @@ -163,35 +162,35 @@ protected void generateShrub(Random random, World world, BlockPos pos)

protected void generateSmallNode(Random random, World world, BlockPos pos)
{
this.setBlockAndMetadata(random, world, pos, this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomFullAge(random)));
this.setBlockAndMetadata(world, pos, this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomFullAge(random)));

if (random.nextBoolean())
{
this.setBlockAndMetadata(random, world, pos.east(), this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomAge(random)));
this.setBlockAndMetadata(world, pos.east(), this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomAge(random)));
}

if (random.nextBoolean())
{
this.setBlockAndMetadata(random, world, pos.west(), this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomAge(random)));
this.setBlockAndMetadata(world, pos.west(), this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomAge(random)));
}

if (random.nextBoolean())
{
this.setBlockAndMetadata(random, world, pos.south(), this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomAge(random)));
this.setBlockAndMetadata(world, pos.south(), this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomAge(random)));
}

if (random.nextBoolean())
{
this.setBlockAndMetadata(random, world, pos.north(), this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomAge(random)));
this.setBlockAndMetadata(world, pos.north(), this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomAge(random)));
}
}

protected void generateTinyNode(Random random, World world, BlockPos pos)
{
this.setBlockAndMetadata(random, world, pos, this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomAge(random)));
this.setBlockAndMetadata(world, pos, this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomAge(random)));
}

protected void setBlockAndMetadata(Random random, World world, BlockPos pos, IBlockState stateNew)
protected void setBlockAndMetadata(World world, BlockPos pos, IBlockState stateNew)
{
if (!world.getBlockState(pos).isOpaqueCube())
{
Expand All @@ -218,21 +217,17 @@ BlockPos findGround(World world, BlockPos pos)
{
IBlockState state = world.getBlockState(position);
Block block = state.getBlock();
if (!world.isAirBlock(position))
if (!world.isAirBlock(position) && block == Blocks.NETHERRACK || block.canSustainPlant(state, world, position, EnumFacing.UP, (IPlantable) this.berryBush.getBlock()))
{
if (block == Blocks.NETHERRACK || block.canSustainPlant(state, world, position, EnumFacing.UP, (IPlantable) this.berryBush.getBlock()))
if (!world.getBlockState(position.up()).isOpaqueCube())
{
if (!world.getBlockState(position.up()).isOpaqueCube())
{
returnHeight = height + 1;
}
break;
returnHeight = height + 1;
}
break;
}
height--;
position = position.down();
}
while (height > 0);
} while (height > 0);

return new BlockPos(pos.getX(), returnHeight, pos.getZ());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@

import java.util.Random;

import com.progwml6.natura.common.block.BlockEnumBerryBush;
import com.progwml6.natura.common.config.Config;
import com.progwml6.natura.overworld.NaturaOverworld;
import com.progwml6.natura.world.worldgen.berry.BaseBerryBushGenerator;

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.common.block.BlockEnumBerryBush;
import com.progwml6.natura.common.config.Config;
import com.progwml6.natura.overworld.NaturaOverworld;
import com.progwml6.natura.world.worldgen.berry.BaseBerryBushGenerator;

public class OverworldBerryBushGenerator extends BaseBerryBushGenerator
{
public final int spawnHeight;
Expand Down Expand Up @@ -69,7 +68,7 @@ protected void generateLargeNode(Random random, World world, BlockPos pos)
{
BlockPos blockpos = new BlockPos(iterX, iterY, iterZ);

this.setBlockAndMetadata(random, world, blockpos, this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomFullAge(random)));
this.setBlockAndMetadata(world, blockpos, this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomFullAge(random)));
}
}
}
Expand All @@ -82,7 +81,7 @@ protected void generateLargeNode(Random random, World world, BlockPos pos)
{
BlockPos blockpos = new BlockPos(iterX, iterY, iterZ);

this.setBlockAndMetadata(random, world, blockpos, this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomFullAge(random)));
this.setBlockAndMetadata(world, blockpos, this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomFullAge(random)));
}
}
}
Expand All @@ -95,7 +94,7 @@ protected void generateLargeNode(Random random, World world, BlockPos pos)
{
BlockPos blockpos = new BlockPos(iterX, iterY, iterZ);

this.setBlockAndMetadata(random, world, blockpos, this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomFullAge(random)));
this.setBlockAndMetadata(world, blockpos, this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomFullAge(random)));
}
}
}
Expand All @@ -107,12 +106,12 @@ protected void generateLargeNode(Random random, World world, BlockPos pos)
int yPos = pos.getY() + 1;
BlockPos blockpos = new BlockPos(iterX, yPos, iterZ);

this.setBlockAndMetadata(random, world, blockpos, this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomFullAge(random)));
this.setBlockAndMetadata(world, blockpos, this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomFullAge(random)));

yPos = pos.getY() - 2;
blockpos = new BlockPos(iterX, yPos, iterZ);

this.setBlockAndMetadata(random, world, blockpos, this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomFullAge(random)));
this.setBlockAndMetadata(world, blockpos, this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomFullAge(random)));
}
}
}
Expand All @@ -128,8 +127,7 @@ protected void generateShrub(Random random, World world, BlockPos pos)
break;
}
pos = pos.down();
}
while (pos.getY() > 0);
} while (pos.getY() > 0);

IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
Expand All @@ -141,24 +139,24 @@ protected void generateShrub(Random random, World world, BlockPos pos)

for (int y = pos.getY(); y <= pos.getY() + 2; ++y)
{
int subract = y - pos.getY();
int subract2 = 2 - subract;
int subtract = y - pos.getY();
int subtract2 = 2 - subtract;

for (int x = pos.getX() - subract2; x <= pos.getX() + subract2; ++x)
for (int x = pos.getX() - subtract2; x <= pos.getX() + subtract2; ++x)
{
int mathX = x - pos.getX();

for (int z = pos.getZ() - subract2; z <= pos.getZ() + subract2; ++z)
for (int z = pos.getZ() - subtract2; z <= pos.getZ() + subtract2; ++z)
{
int mathZ = z - pos.getZ();

BlockPos blockpos = new BlockPos(x, y, z);
IBlockState blockState = world.getBlockState(blockpos);
Block blockFromState = state.getBlock();

if (Math.abs(mathX) != subract2 || Math.abs(mathZ) != subract2 || random.nextInt(2) != 0 && (blockFromState == null || blockFromState.canBeReplacedByLeaves(blockState, world, blockpos)))
if (Math.abs(mathX) != subtract2 || Math.abs(mathZ) != subtract2 || random.nextInt(2) != 0 && blockFromState.canBeReplacedByLeaves(blockState, world, blockpos))
{
this.setBlockAndMetadata(random, world, blockpos, this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomFullAge(random)));
this.setBlockAndMetadata(world, blockpos, this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomFullAge(random)));
}
}
}
Expand All @@ -168,35 +166,35 @@ protected void generateShrub(Random random, World world, BlockPos pos)

protected void generateSmallNode(Random random, World world, BlockPos pos)
{
this.setBlockAndMetadata(random, world, pos, this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomFullAge(random)));
this.setBlockAndMetadata(world, pos, this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomFullAge(random)));

if (random.nextBoolean())
{
this.setBlockAndMetadata(random, world, pos.east(), this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomAge(random)));
this.setBlockAndMetadata(world, pos.east(), this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomAge(random)));
}

if (random.nextBoolean())
{
this.setBlockAndMetadata(random, world, pos.west(), this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomAge(random)));
this.setBlockAndMetadata(world, pos.west(), this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomAge(random)));
}

if (random.nextBoolean())
{
this.setBlockAndMetadata(random, world, pos.south(), this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomAge(random)));
this.setBlockAndMetadata(world, pos.south(), this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomAge(random)));
}

if (random.nextBoolean())
{
this.setBlockAndMetadata(random, world, pos.north(), this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomAge(random)));
this.setBlockAndMetadata(world, pos.north(), this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomAge(random)));
}
}

protected void generateTinyNode(Random random, World world, BlockPos pos)
{
this.setBlockAndMetadata(random, world, pos, this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomAge(random)));
this.setBlockAndMetadata(world, pos, this.berryBush.withProperty(BlockEnumBerryBush.AGE, this.randomAge(random)));
}

protected void setBlockAndMetadata(Random random, World world, BlockPos pos, IBlockState stateNew)
protected void setBlockAndMetadata(World world, BlockPos pos, IBlockState stateNew)
{
if (!world.getBlockState(pos).isOpaqueCube())
{
Expand Down Expand Up @@ -242,8 +240,7 @@ BlockPos findGround(World world, BlockPos pos)
}

height--;
}
while (height > 0);
} while (height > 0);

return new BlockPos(pos.getX(), returnHeight, pos.getZ());
}
Expand Down

0 comments on commit 69602dd

Please sign in to comment.