From 69602ddf250902c98ff9f3dff130ef3174abdc98 Mon Sep 17 00:00:00 2001 From: ACGaming <4818419+ACGaming@users.noreply.github.com> Date: Sat, 4 May 2024 12:43:45 +0200 Subject: [PATCH] Clean up berry bush generators --- .../OverworldBerryBushesGenerator.java | 21 +++---- .../berry/BaseBerryBushGenerator.java | 2 - .../nether/NetherBerryBushGenerator.java | 59 +++++++++---------- .../OverworldBerryBushGenerator.java | 53 ++++++++--------- 4 files changed, 61 insertions(+), 74 deletions(-) diff --git a/src/main/java/com/progwml6/natura/world/worldgen/OverworldBerryBushesGenerator.java b/src/main/java/com/progwml6/natura/world/worldgen/OverworldBerryBushesGenerator.java index 040cc948..cd32cc5c 100644 --- a/src/main/java/com/progwml6/natura/world/worldgen/OverworldBerryBushesGenerator.java +++ b/src/main/java/com/progwml6/natura/world/worldgen/OverworldBerryBushesGenerator.java @@ -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; @@ -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; @@ -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; @@ -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; } } diff --git a/src/main/java/com/progwml6/natura/world/worldgen/berry/BaseBerryBushGenerator.java b/src/main/java/com/progwml6/natura/world/worldgen/berry/BaseBerryBushGenerator.java index d3fff863..f2693954 100644 --- a/src/main/java/com/progwml6/natura/world/worldgen/berry/BaseBerryBushGenerator.java +++ b/src/main/java/com/progwml6/natura/world/worldgen/berry/BaseBerryBushGenerator.java @@ -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) { } - } diff --git a/src/main/java/com/progwml6/natura/world/worldgen/berry/nether/NetherBerryBushGenerator.java b/src/main/java/com/progwml6/natura/world/worldgen/berry/nether/NetherBerryBushGenerator.java index cb3cb70c..fe98bfca 100644 --- a/src/main/java/com/progwml6/natura/world/worldgen/berry/nether/NetherBerryBushGenerator.java +++ b/src/main/java/com/progwml6/natura/world/worldgen/berry/nether/NetherBerryBushGenerator.java @@ -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; @@ -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; @@ -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))); } } } @@ -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))); } } } @@ -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))); } } } @@ -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))); } } } @@ -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(); @@ -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))); } } } @@ -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()) { @@ -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()); } diff --git a/src/main/java/com/progwml6/natura/world/worldgen/berry/overworld/OverworldBerryBushGenerator.java b/src/main/java/com/progwml6/natura/world/worldgen/berry/overworld/OverworldBerryBushGenerator.java index 3140cbbe..30b89062 100644 --- a/src/main/java/com/progwml6/natura/world/worldgen/berry/overworld/OverworldBerryBushGenerator.java +++ b/src/main/java/com/progwml6/natura/world/worldgen/berry/overworld/OverworldBerryBushGenerator.java @@ -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; @@ -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))); } } } @@ -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))); } } } @@ -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))); } } } @@ -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))); } } } @@ -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(); @@ -141,14 +139,14 @@ 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(); @@ -156,9 +154,9 @@ protected void generateShrub(Random random, World world, BlockPos pos) 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))); } } } @@ -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()) { @@ -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()); }