From d48034e69bf1f10d8324e9fd1f44883abaefe231 Mon Sep 17 00:00:00 2001 From: ACGaming <4818419+ACGaming@users.noreply.github.com> Date: Sat, 4 May 2024 12:36:55 +0200 Subject: [PATCH] Clean up tree generators --- .../progwml6/natura/common/config/Config.java | 4 +- .../worldgen/OverworldTreesGenerator.java | 19 +- .../worldgen/trees/BaseTreeGenerator.java | 48 -- .../trees/nether/BloodwoodTreeGenerator.java | 244 +++++----- .../trees/nether/DarkwoodTreeGenerator.java | 173 ++++---- .../trees/nether/FusewoodTreeGenerator.java | 164 ++++--- .../trees/nether/GhostwoodTreeGenerator.java | 274 ++++++------ .../trees/overworld/AppleTreeGenerator.java | 27 +- .../overworld/EucalyptusTreeGenerator.java | 47 +- .../trees/overworld/HopseedTreeGenerator.java | 33 +- .../overworld/OverworldTreeGenerator.java | 39 +- .../trees/overworld/RedwoodTreeGenerator.java | 420 ++++++------------ .../trees/overworld/SakuraTreeGenerator.java | 54 +-- .../trees/overworld/WillowTreeGenerator.java | 43 +- 14 files changed, 612 insertions(+), 977 deletions(-) diff --git a/src/main/java/com/progwml6/natura/common/config/Config.java b/src/main/java/com/progwml6/natura/common/config/Config.java index 9e17b0ac..4c83acb9 100644 --- a/src/main/java/com/progwml6/natura/common/config/Config.java +++ b/src/main/java/com/progwml6/natura/common/config/Config.java @@ -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; diff --git a/src/main/java/com/progwml6/natura/world/worldgen/OverworldTreesGenerator.java b/src/main/java/com/progwml6/natura/world/worldgen/OverworldTreesGenerator.java index e2770f81..1c5e0aff 100644 --- a/src/main/java/com/progwml6/natura/world/worldgen/OverworldTreesGenerator.java +++ b/src/main/java/com/progwml6/natura/world/worldgen/OverworldTreesGenerator.java @@ -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 @@ -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; @@ -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++) { @@ -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; diff --git a/src/main/java/com/progwml6/natura/world/worldgen/trees/BaseTreeGenerator.java b/src/main/java/com/progwml6/natura/world/worldgen/trees/BaseTreeGenerator.java index 2a6b5cbf..0b90adaf 100644 --- a/src/main/java/com/progwml6/natura/world/worldgen/trees/BaseTreeGenerator.java +++ b/src/main/java/com/progwml6/natura/world/worldgen/trees/BaseTreeGenerator.java @@ -2,17 +2,10 @@ 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 @@ -20,50 +13,9 @@ 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(); - } } diff --git a/src/main/java/com/progwml6/natura/world/worldgen/trees/nether/BloodwoodTreeGenerator.java b/src/main/java/com/progwml6/natura/world/worldgen/trees/nether/BloodwoodTreeGenerator.java index 4d4206a7..72d7c3a1 100644 --- a/src/main/java/com/progwml6/natura/world/worldgen/trees/nether/BloodwoodTreeGenerator.java +++ b/src/main/java/com/progwml6/natura/world/worldgen/trees/nether/BloodwoodTreeGenerator.java @@ -2,16 +2,14 @@ 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 net.minecraft.world.chunk.IChunkProvider; -import net.minecraft.world.gen.IChunkGenerator; + +import com.progwml6.natura.nether.NaturaNether; +import com.progwml6.natura.world.worldgen.trees.BaseTreeGenerator; public class BloodwoodTreeGenerator extends BaseTreeGenerator { @@ -37,36 +35,6 @@ public BloodwoodTreeGenerator(IBlockState full, IBlockState trunk1, IBlockState this.leaves = leaves; } - BlockPos findCeiling(World world, BlockPos pos) - { - int returnHeight = 0; - - int height = pos.getY(); - - do - { - BlockPos position = new BlockPos(pos.getX(), height, pos.getZ()); - - Block block = world.getBlockState(position).getBlock(); - - if ((block == Blocks.NETHERRACK || block == Blocks.SOUL_SAND || block == NaturaNether.netherTaintedSoil) && !world.getBlockState(position.down()).isFullBlock()) - { - returnHeight = height - 1; - break; - } - - height++; - } - while (height <= world.provider.getActualHeight()); - - return new BlockPos(pos.getX(), returnHeight, pos.getZ()); - } - - @Override - public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) - { - } - @Override public void generateTree(Random random, World world, BlockPos pos) { @@ -101,6 +69,85 @@ public void generateTree(Random random, World world, BlockPos pos) this.genStraightBranch(world, random, pos.add(1, 0, 1), -treeHeight, 4); } + public void generateNode(World world, BlockPos pos) + { + this.setBlockAndMetadata(world, pos, this.full); + + for (int xIter = pos.getX() - 1; xIter <= pos.getX() + 1; xIter++) + { + for (int zIter = pos.getZ() - 1; zIter <= pos.getZ() + 1; zIter++) + { + BlockPos newPos = new BlockPos(xIter, pos.getY(), zIter); + IBlockState state = world.getBlockState(newPos); + Block block = state.getBlock(); + + if (block != NaturaNether.netherLeaves && !state.isFullBlock()) + { + this.setBlockAndMetadata(world, newPos, this.leaves); + } + } + } + + for (int xIter = pos.getX() - 1; xIter <= pos.getX() + 1; xIter++) + { + for (int zIter = pos.getZ() - 2; zIter <= pos.getZ() + 2; zIter++) + { + BlockPos newPos = new BlockPos(xIter, pos.getY(), zIter); + IBlockState state = world.getBlockState(newPos); + Block block = state.getBlock(); + + if (block != NaturaNether.netherLeaves && !state.isFullBlock()) + { + this.setBlockAndMetadata(world, newPos, this.leaves); + } + } + } + + for (int xIter = pos.getX() - 2; xIter <= pos.getX() + 2; xIter++) + { + for (int zIter = pos.getZ() - 1; zIter <= pos.getZ() + 1; zIter++) + { + BlockPos newPos = new BlockPos(xIter, pos.getY() + 1, zIter); + IBlockState state = world.getBlockState(newPos); + Block block = state.getBlock(); + + if (block != NaturaNether.netherLeaves && !state.isFullBlock()) + { + this.setBlockAndMetadata(world, newPos, this.leaves); + } + } + } + } + + protected void setBlockAndMetadata(World world, BlockPos pos, IBlockState stateNew) + { + world.setBlockState(pos, stateNew, 2); + } + + BlockPos findCeiling(World world, BlockPos pos) + { + int returnHeight = 0; + + int height = pos.getY(); + + do + { + BlockPos position = new BlockPos(pos.getX(), height, pos.getZ()); + + Block block = world.getBlockState(position).getBlock(); + + if ((block == Blocks.NETHERRACK || block == Blocks.SOUL_SAND || block == NaturaNether.netherTaintedSoil) && !world.getBlockState(position.down()).isFullBlock()) + { + returnHeight = height - 1; + break; + } + + height++; + } while (height <= world.provider.getActualHeight()); + + return new BlockPos(pos.getX(), returnHeight, pos.getZ()); + } + private void genBranch(World world, Random random, BlockPos pos, int height, int direction) { int posX = pos.getX(); @@ -111,25 +158,22 @@ private void genBranch(World world, Random random, BlockPos pos, int height, int switch (direction) { - case 1: - offsetX = 1; - offsetZ = 1; - break; - - case 2: - offsetX = -1; - offsetZ = 1; - break; - - case 3: - offsetX = 1; - offsetZ = -1; - break; - - case 4: - offsetX = -1; - offsetZ = -1; - break; + case 1: + offsetX = 1; + offsetZ = 1; + break; + case 2: + offsetX = -1; + offsetZ = 1; + break; + case 3: + offsetX = 1; + offsetZ = -1; + break; + case 4: + offsetX = -1; + offsetZ = -1; + break; } int heightShift = random.nextInt(6); @@ -152,7 +196,7 @@ private void genBranch(World world, Random random, BlockPos pos, int height, int BlockPos blockpos = new BlockPos(posX, posY, posZ); - this.generateNode(world, random, blockpos); + this.generateNode(world, blockpos); heightShift = random.nextInt(6); } @@ -169,25 +213,18 @@ private void genStraightBranch(World world, Random random, BlockPos pos, int hei switch (direction) { - case 1: - xShift = 1; - zShift = 0; - break; - - case 2: - xShift = 0; - zShift = 1; - break; - - case 3: - xShift = -1; - zShift = 0; - break; - - case 4: - xShift = 0; - zShift = -1; - break; + case 1: + xShift = 1; + break; + case 2: + zShift = 1; + break; + case 3: + xShift = -1; + break; + case 4: + zShift = -1; + break; } int heightShift = random.nextInt(6); @@ -212,66 +249,9 @@ private void genStraightBranch(World world, Random random, BlockPos pos, int hei BlockPos blockpos = new BlockPos(posX, posY, posZ); - this.generateNode(world, random, blockpos); + this.generateNode(world, blockpos); heightShift = random.nextInt(6); } } - - public boolean generateNode(World world, Random random, BlockPos pos) - { - this.setBlockAndMetadata(world, pos, this.full); - - for (int xIter = pos.getX() - 1; xIter <= pos.getX() + 1; xIter++) - { - for (int zIter = pos.getZ() - 1; zIter <= pos.getZ() + 1; zIter++) - { - BlockPos newPos = new BlockPos(xIter, pos.getY(), zIter); - IBlockState state = world.getBlockState(newPos); - Block block = state.getBlock(); - - if (block != NaturaNether.netherLeaves && !state.isFullBlock()) - { - this.setBlockAndMetadata(world, newPos, this.leaves); - } - } - } - - for (int xIter = pos.getX() - 1; xIter <= pos.getX() + 1; xIter++) - { - for (int zIter = pos.getZ() - 2; zIter <= pos.getZ() + 2; zIter++) - { - BlockPos newPos = new BlockPos(xIter, pos.getY(), zIter); - IBlockState state = world.getBlockState(newPos); - Block block = state.getBlock(); - - if (block != NaturaNether.netherLeaves && !state.isFullBlock()) - { - this.setBlockAndMetadata(world, newPos, this.leaves); - } - } - } - - for (int xIter = pos.getX() - 2; xIter <= pos.getX() + 2; xIter++) - { - for (int zIter = pos.getZ() - 1; zIter <= pos.getZ() + 1; zIter++) - { - BlockPos newPos = new BlockPos(xIter, pos.getY() + 1, zIter); - IBlockState state = world.getBlockState(newPos); - Block block = state.getBlock(); - - if (block != NaturaNether.netherLeaves && !state.isFullBlock()) - { - this.setBlockAndMetadata(world, newPos, this.leaves); - } - } - } - - return true; - } - - protected void setBlockAndMetadata(World world, BlockPos pos, IBlockState stateNew) - { - world.setBlockState(pos, stateNew, 2); - } } diff --git a/src/main/java/com/progwml6/natura/world/worldgen/trees/nether/DarkwoodTreeGenerator.java b/src/main/java/com/progwml6/natura/world/worldgen/trees/nether/DarkwoodTreeGenerator.java index 5b20aedd..6af4b239 100644 --- a/src/main/java/com/progwml6/natura/world/worldgen/trees/nether/DarkwoodTreeGenerator.java +++ b/src/main/java/com/progwml6/natura/world/worldgen/trees/nether/DarkwoodTreeGenerator.java @@ -2,17 +2,15 @@ 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 net.minecraft.world.chunk.IChunkProvider; -import net.minecraft.world.gen.IChunkGenerator; + +import com.progwml6.natura.nether.NaturaNether; +import com.progwml6.natura.world.worldgen.trees.BaseTreeGenerator; public class DarkwoodTreeGenerator extends BaseTreeGenerator { @@ -43,34 +41,6 @@ public DarkwoodTreeGenerator(int treeHeight, IBlockState log, IBlockState leaves this(treeHeight, log, leaves, flowering, fruiting, true); } - BlockPos findGround(World world, BlockPos pos) - { - boolean foundGround = false; - int height = pos.getY(); - - BlockPos position = new BlockPos(pos.getX(), height, pos.getZ()); - - do - { - position = position.down(); - Block underBlock = world.getBlockState(position).getBlock(); - - if (underBlock == Blocks.NETHERRACK || underBlock == Blocks.SOUL_SAND || underBlock == NaturaNether.netherTaintedSoil || position.getY() < 0) - { - foundGround = true; - } - } - while (!foundGround); - - return position.up(); - } - - @Override - public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) - { - - } - @Override public void generateTree(Random rand, World worldIn, BlockPos position) { @@ -100,7 +70,7 @@ public void generateTree(Random rand, World worldIn, BlockPos position) IBlockState state = worldIn.getBlockState(position.down()); Block soil = state.getBlock(); - boolean isSoil = (soil != null && soil.canSustainPlant(state, worldIn, position.down(), EnumFacing.UP, NaturaNether.netherSapling) || soil == Blocks.NETHERRACK); + boolean isSoil = soil.canSustainPlant(state, worldIn, position.down(), EnumFacing.UP, NaturaNether.netherSapling) || soil == Blocks.NETHERRACK; if (isSoil && position.getY() < 256 - heightRange - 1) { @@ -112,6 +82,78 @@ public void generateTree(Random rand, World worldIn, BlockPos position) } } + protected void placeCanopy(World world, Random random, BlockPos pos, int height) + { + for (int y = pos.getY() - 3 + height; y <= pos.getY() + height; ++y) + { + int subtract = y - (pos.getY() + height); + int subtract2 = 1 - subtract / 2; + + for (int x = pos.getX() - subtract2; x <= pos.getX() + subtract2; ++x) + { + int mathX = x - pos.getX(); + + for (int z = pos.getZ() - subtract2; z <= pos.getZ() + subtract2; ++z) + { + int mathZ = z - pos.getZ(); + + if (Math.abs(mathX) != subtract2 || Math.abs(mathZ) != subtract2 || random.nextInt(2) != 0 && subtract != 0) + { + BlockPos blockpos = new BlockPos(x, y, z); + IBlockState state = world.getBlockState(blockpos); + + state.getBlock(); + if (state.getBlock().canBeReplacedByLeaves(state, world, blockpos)) + { + world.setBlockState(blockpos, this.getRandomizedLeaves(random), 2); + } + } + } + } + } + } + + protected void placeTrunk(World world, BlockPos pos, int height) + { + for (int localHeight = 0; localHeight < height; ++localHeight) + { + BlockPos blockpos = new BlockPos(pos.getX(), pos.getY() + localHeight, pos.getZ()); + IBlockState state = world.getBlockState(blockpos); + Block block = state.getBlock(); + + if (block.isAir(state, world, blockpos) || block.isLeaves(state, world, blockpos)) + { + world.setBlockState(blockpos, this.log, 2); + } + } + } + + 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) + { + boolean foundGround = false; + int height = pos.getY(); + + BlockPos position = new BlockPos(pos.getX(), height, pos.getZ()); + + do + { + position = position.down(); + Block underBlock = world.getBlockState(position).getBlock(); + + if (underBlock == Blocks.NETHERRACK || underBlock == Blocks.SOUL_SAND || underBlock == NaturaNether.netherTaintedSoil || position.getY() < 0) + { + foundGround = true; + } + } while (!foundGround); + + return position.up(); + } + private boolean checkIfCanGrow(BlockPos position, int heightRange, World worldIn) { boolean canGrowTree = true; @@ -161,67 +203,4 @@ private boolean checkIfCanGrow(BlockPos position, int heightRange, World worldIn return canGrowTree; } - - protected void placeCanopy(World world, Random random, BlockPos pos, int height) - { - for (int y = pos.getY() - 3 + height; y <= pos.getY() + height; ++y) - { - int subract = y - (pos.getY() + height); - int subract2 = 1 - subract / 2; - - for (int x = pos.getX() - subract2; x <= pos.getX() + subract2; ++x) - { - int mathX = x - pos.getX(); - - for (int z = pos.getZ() - subract2; z <= pos.getZ() + subract2; ++z) - { - int mathZ = z - pos.getZ(); - - if (Math.abs(mathX) != subract2 || Math.abs(mathZ) != subract2 || random.nextInt(2) != 0 && subract != 0) - { - BlockPos blockpos = new BlockPos(x, y, z); - IBlockState state = world.getBlockState(blockpos); - - if (state.getBlock() == null || state.getBlock().canBeReplacedByLeaves(state, world, blockpos)) - { - world.setBlockState(blockpos, this.getRandomizedLeaves(random), 2); - } - } - } - } - } - } - - protected void placeTrunk(World world, BlockPos pos, int height) - { - for (int localHeight = 0; localHeight < height; ++localHeight) - { - BlockPos blockpos = new BlockPos(pos.getX(), pos.getY() + localHeight, pos.getZ()); - IBlockState state = world.getBlockState(blockpos); - Block block = state.getBlock(); - - if (block.isAir(state, world, blockpos) || block == null || block.isLeaves(state, world, blockpos)) - { - world.setBlockState(blockpos, this.log, 2); - } - } - - /*while (height >= 0) - { - IBlockState state = world.getBlockState(pos); - Block block = state.getBlock(); - if (block.isAir(state, world, pos) || block.isReplaceable(world, pos) || block.isLeaves(state, world, pos)) - { - this.setBlockAndMetadata(world, pos, this.log); - } - - pos = pos.up(); - height--; - }*/ - } - - protected IBlockState getRandomizedLeaves(Random random) - { - return (random.nextInt(25) == 0 ? this.fruiting : random.nextInt(15) == 0 ? this.flowering : this.leaves); - } } diff --git a/src/main/java/com/progwml6/natura/world/worldgen/trees/nether/FusewoodTreeGenerator.java b/src/main/java/com/progwml6/natura/world/worldgen/trees/nether/FusewoodTreeGenerator.java index a127450d..6fb2d09e 100644 --- a/src/main/java/com/progwml6/natura/world/worldgen/trees/nether/FusewoodTreeGenerator.java +++ b/src/main/java/com/progwml6/natura/world/worldgen/trees/nether/FusewoodTreeGenerator.java @@ -2,17 +2,15 @@ import java.util.Random; -import com.progwml6.natura.nether.NaturaNether; -import com.progwml6.natura.world.worldgen.trees.BaseTreeGenerator; - 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.util.math.BlockPos.MutableBlockPos; import net.minecraft.world.World; -import net.minecraft.world.chunk.IChunkProvider; -import net.minecraft.world.gen.IChunkGenerator; + +import com.progwml6.natura.nether.NaturaNether; +import com.progwml6.natura.world.worldgen.trees.BaseTreeGenerator; public class FusewoodTreeGenerator extends BaseTreeGenerator { @@ -37,42 +35,6 @@ public FusewoodTreeGenerator(int treeHeight, IBlockState log, IBlockState leaves this(treeHeight, log, leaves, true); } - BlockPos findGround(World world, BlockPos pos) - { - int returnHeight = 0; - - int y = pos.getY() - 1; - - do - { - BlockPos position = new BlockPos(pos.getX(), y, pos.getZ()); - IBlockState state = world.getBlockState(position); - - if (state.getBlock() == Blocks.NETHERRACK || state.getBlock() == Blocks.SOUL_SAND || state.getBlock() == NaturaNether.netherTaintedSoil || position.getY() < 0) - { - returnHeight = y + 1; - break; - } - - y--; - } - while (y > 0); - - return new BlockPos(pos.getX(), returnHeight, pos.getZ()); - } - - @Override - public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) - { - - } - - public boolean isReplaceable(World world, BlockPos pos) - { - IBlockState state = world.getBlockState(pos); - return state.getBlock() != Blocks.AIR && !state.getBlock().isLeaves(state, world, pos) && state.getBlock() != Blocks.NETHERRACK && state.getBlock() != Blocks.SOUL_SAND && state.getBlock() != NaturaNether.netherTaintedSoil && !state.getBlock().isWood(world, pos); - } - @Override public void generateTree(Random rand, World worldIn, BlockPos position) { @@ -101,7 +63,8 @@ public void generateTree(Random rand, World worldIn, BlockPos position) BlockPos down = position.down(); IBlockState state = worldIn.getBlockState(down); - boolean isSoil = (state.getBlock() != null && state.getBlock().canSustainPlant(state, worldIn, down, EnumFacing.UP, NaturaNether.netherSapling) || state.getBlock() == Blocks.NETHERRACK); + state.getBlock(); + boolean isSoil = state.getBlock().canSustainPlant(state, worldIn, down, EnumFacing.UP, NaturaNether.netherSapling) || state.getBlock() == Blocks.NETHERRACK; if (isSoil && position.getY() < 256 - height - 1) { @@ -113,6 +76,79 @@ public void generateTree(Random rand, World worldIn, BlockPos position) } } + public boolean isReplaceable(World world, BlockPos pos) + { + IBlockState state = world.getBlockState(pos); + return state.getBlock() != Blocks.AIR && !state.getBlock().isLeaves(state, world, pos) && state.getBlock() != Blocks.NETHERRACK && state.getBlock() != Blocks.SOUL_SAND && state.getBlock() != NaturaNether.netherTaintedSoil && !state.getBlock().isWood(world, pos); + } + + protected void placeCanopy(World worldIn, Random rand, BlockPos position, int height) + { + for (int y = position.getY() - 3 + height; y <= position.getY() + height; ++y) + { + int subtract = y - (position.getY() + height); + int subtract2 = 1 - subtract / 2; + + for (int x = position.getX() - subtract2; x <= position.getX() + subtract2; ++x) + { + int mathX = x - position.getX(); + + for (int z = position.getZ() - subtract2; z <= position.getZ() + subtract2; ++z) + { + int mathZ = z - position.getZ(); + + if (Math.abs(mathX) != subtract2 || Math.abs(mathZ) != subtract2 || rand.nextInt(2) != 0 && subtract != 0) + { + BlockPos blockpos = new BlockPos(x, y, z); + IBlockState state2 = worldIn.getBlockState(blockpos); + + if (state2.getBlock().isAir(state2, worldIn, blockpos)) + { + worldIn.setBlockState(blockpos, this.leaves, 2); + } + } + } + } + } + } + + protected void placeTrunk(World worldIn, BlockPos position, int height) + { + for (int localHeight = 0; localHeight < height; ++localHeight) + { + BlockPos upN = position.up(localHeight); + IBlockState state2 = worldIn.getBlockState(upN); + + if (state2.getBlock().isAir(state2, worldIn, upN) || state2.getBlock().isLeaves(state2, worldIn, upN)) + { + worldIn.setBlockState(position.up(localHeight), this.log, 2); + } + } + } + + BlockPos findGround(World world, BlockPos pos) + { + int returnHeight = 0; + + int y = pos.getY() - 1; + + do + { + BlockPos position = new BlockPos(pos.getX(), y, pos.getZ()); + IBlockState state = world.getBlockState(position); + + if (state.getBlock() == Blocks.NETHERRACK || state.getBlock() == Blocks.SOUL_SAND || state.getBlock() == NaturaNether.netherTaintedSoil || position.getY() < 0) + { + returnHeight = y + 1; + break; + } + + y--; + } while (y > 0); + + return new BlockPos(pos.getX(), returnHeight, pos.getZ()); + } + boolean checkClear(World worldIn, BlockPos position, int height) { boolean flag = true; @@ -154,48 +190,4 @@ boolean checkClear(World worldIn, BlockPos position, int height) return flag; } - - protected void placeCanopy(World worldIn, Random rand, BlockPos position, int height) - { - for (int y = position.getY() - 3 + height; y <= position.getY() + height; ++y) - { - int subract = y - (position.getY() + height); - int subract2 = 1 - subract / 2; - - for (int x = position.getX() - subract2; x <= position.getX() + subract2; ++x) - { - int mathX = x - position.getX(); - - for (int z = position.getZ() - subract2; z <= position.getZ() + subract2; ++z) - { - int mathZ = z - position.getZ(); - - if (Math.abs(mathX) != subract2 || Math.abs(mathZ) != subract2 || rand.nextInt(2) != 0 && subract != 0) - { - BlockPos blockpos = new BlockPos(x, y, z); - IBlockState state2 = worldIn.getBlockState(blockpos); - - if (state2.getBlock().isAir(state2, worldIn, blockpos) || state2.getBlock().isAir(state2, worldIn, blockpos)) - { - worldIn.setBlockState(blockpos, this.leaves, 2); - } - } - } - } - } - } - - protected void placeTrunk(World worldIn, BlockPos position, int height) - { - for (int localHeight = 0; localHeight < height; ++localHeight) - { - BlockPos upN = position.up(localHeight); - IBlockState state2 = worldIn.getBlockState(upN); - - if (state2.getBlock().isAir(state2, worldIn, upN) || state2.getBlock().isLeaves(state2, worldIn, upN)) - { - worldIn.setBlockState(position.up(localHeight), this.log, 2); - } - } - } } diff --git a/src/main/java/com/progwml6/natura/world/worldgen/trees/nether/GhostwoodTreeGenerator.java b/src/main/java/com/progwml6/natura/world/worldgen/trees/nether/GhostwoodTreeGenerator.java index 152a39d3..e3b7761f 100644 --- a/src/main/java/com/progwml6/natura/world/worldgen/trees/nether/GhostwoodTreeGenerator.java +++ b/src/main/java/com/progwml6/natura/world/worldgen/trees/nether/GhostwoodTreeGenerator.java @@ -4,10 +4,6 @@ import java.util.Random; import com.google.common.collect.Lists; -import com.progwml6.natura.common.block.BlockEnumLog; -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; @@ -15,17 +11,16 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; -import net.minecraft.world.chunk.IChunkProvider; -import net.minecraft.world.gen.IChunkGenerator; + +import com.progwml6.natura.common.block.BlockEnumLog; +import com.progwml6.natura.nether.NaturaNether; +import com.progwml6.natura.world.worldgen.trees.BaseTreeGenerator; public class GhostwoodTreeGenerator extends BaseTreeGenerator { - private Random rand; - - private World world; - - private BlockPos basePos = BlockPos.ORIGIN; - + public final IBlockState log; + public final IBlockState leaves; + public final boolean seekHeight; int heightLimit; int height; @@ -42,16 +37,15 @@ public class GhostwoodTreeGenerator extends BaseTreeGenerator int heightLimitLimit = 12; - /** Sets the distance limit for how far away the generator will populate leaves from the base leaf node. */ + /** + * Sets the distance limit for how far away the generator will populate leaves from the base leaf node. + */ int leafDistanceLimit = 4; List foliageCoords; - - public final IBlockState log; - - public final IBlockState leaves; - - public final boolean seekHeight; + private Random rand; + private World world; + private BlockPos basePos = BlockPos.ORIGIN; public GhostwoodTreeGenerator(IBlockState log, IBlockState leaves, boolean seekHeight) { @@ -60,6 +54,53 @@ public GhostwoodTreeGenerator(IBlockState log, IBlockState leaves, boolean seekH this.seekHeight = seekHeight; } + public boolean isReplaceable(World world, BlockPos pos) + { + IBlockState state = world.getBlockState(pos); + return state.getBlock().isAir(state, world, pos) || state.getBlock().isLeaves(state, world, pos); + } + + @Override + public void generateTree(Random random, World worldIn, BlockPos position) + { + this.world = worldIn; + + if (this.seekHeight) + { + this.basePos = this.findGround(worldIn, position); + } + else + { + this.basePos = position; + } + + this.rand = new Random(random.nextLong()); + + if (this.heightLimit == 0) + { + this.heightLimit = 5 + this.rand.nextInt(this.heightLimitLimit); + } + + if (this.validTreeLocation()) + { + this.generateLeafNodeList(); + this.generateLeaves(); + this.generateTrunk(); + this.generateLeafNodeBases(); + } + this.world = null; //Fix vanilla Mem leak, holds latest world + } + + protected void setBlockAndMetadata(World world, BlockPos pos, IBlockState stateNew) + { + IBlockState state = world.getBlockState(pos); + Block block = state.getBlock(); + if (block.isAir(state, world, pos) || block.canPlaceBlockAt(world, pos) || world.getBlockState(pos) == this.leaves) + { + world.setBlockState(pos, stateNew, 2); + } + } + /** * Generates a list of leaf nodes for the tree, to be populated by generateLeaves. */ @@ -81,7 +122,7 @@ void generateLeafNodeList() int j = this.basePos.getY() + this.height; int k = this.heightLimit - this.leafDistanceLimit; - this.foliageCoords = Lists. newArrayList(); + this.foliageCoords = Lists.newArrayList(); this.foliageCoords.add(new GhostwoodTreeGenerator.FoliageCoordinates(this.basePos.up(k), j)); for (; k >= 0; --k) @@ -187,9 +228,9 @@ void limb(BlockPos p_175937_1_, BlockPos p_175937_2_, IBlockState state) { BlockPos blockpos = p_175937_2_.add(-p_175937_1_.getX(), -p_175937_1_.getY(), -p_175937_1_.getZ()); int i = this.getGreatestDistance(blockpos); - float f = (float) blockpos.getX() / (float) i; - float f1 = (float) blockpos.getY() / (float) i; - float f2 = (float) blockpos.getZ() / (float) i; + float f = (float) blockpos.getX() / i; + float f1 = (float) blockpos.getY() / i; + float f2 = (float) blockpos.getZ() / i; for (int j = 0; j <= i; ++j) { @@ -199,39 +240,6 @@ void limb(BlockPos p_175937_1_, BlockPos p_175937_2_, IBlockState state) } } - /** - * Returns the absolute greatest distance in the BlockPos object. - */ - private int getGreatestDistance(BlockPos posIn) - { - int i = MathHelper.abs(posIn.getX()); - int j = MathHelper.abs(posIn.getY()); - int k = MathHelper.abs(posIn.getZ()); - return k > i && k > j ? k : (j > i ? j : i); - } - - private BlockEnumLog.EnumAxis getLogAxis(BlockPos p_175938_1_, BlockPos p_175938_2_) - { - BlockEnumLog.EnumAxis enumaxis = BlockEnumLog.EnumAxis.Y; - int i = Math.abs(p_175938_2_.getX() - p_175938_1_.getX()); - int j = Math.abs(p_175938_2_.getZ() - p_175938_1_.getZ()); - int k = Math.max(i, j); - - if (k > 0) - { - if (i == k) - { - enumaxis = BlockEnumLog.EnumAxis.X; - } - else if (j == k) - { - enumaxis = BlockEnumLog.EnumAxis.Z; - } - } - - return enumaxis; - } - /** * Generates the leaf portion of the tree as specified by the leafNodes list. */ @@ -244,7 +252,7 @@ void generateLeaves() } /** - * Indicates whether or not a leaf node requires additional wood to be added to preserve integrity. + * Indicates whether a leaf node requires additional wood to be added to preserve integrity. */ boolean leafNodeNeedsBase(int p_76493_1_) { @@ -294,78 +302,23 @@ int checkBlockLine(BlockPos posOne, BlockPos posTwo) { BlockPos blockpos = posTwo.add(-posOne.getX(), -posOne.getY(), -posOne.getZ()); int i = this.getGreatestDistance(blockpos); - float f = (float) blockpos.getX() / (float) i; - float f1 = (float) blockpos.getY() / (float) i; - float f2 = (float) blockpos.getZ() / (float) i; + float f = (float) blockpos.getX() / i; + float f1 = (float) blockpos.getY() / i; + float f2 = (float) blockpos.getZ() / i; - if (i == 0) - { - return -1; - } - else + if (i != 0) { for (int j = 0; j <= i; ++j) { - BlockPos blockpos1 = posOne.add(0.5F + j * f, 0.5F + j * f1, 0.5F + j * f2); + BlockPos blockPos = posOne.add(0.5F + j * f, 0.5F + j * f1, 0.5F + j * f2); - if (!this.isReplaceable(this.world, blockpos1)) + if (!this.isReplaceable(this.world, blockPos)) { return j; } } - - return -1; - } - } - - public void setDecorationDefaults() - { - this.leafDistanceLimit = 5; - } - - /** - * Returns a boolean indicating whether or not the current location for the tree, spanning basePos to to the height - * limit, is valid. - */ - private boolean validTreeLocation() - { - BlockPos down = this.basePos.down(); - IBlockState state = this.world.getBlockState(down); - Block soil = state.getBlock(); - boolean isSoil = (soil != null && soil.canSustainPlant(state, this.world, down, EnumFacing.UP, NaturaNether.netherSapling) || soil == Blocks.NETHERRACK); - - if (!isSoil) - { - return false; - } - else - { - int i = this.checkBlockLine(this.basePos, this.basePos.up(this.heightLimit - 1)); - - if (i == -1) - { - return true; - } - else if (i < 6) - { - return false; - } - else - { - this.heightLimit = i; - return true; - } - } - } - - protected void setBlockAndMetadata(World world, BlockPos pos, IBlockState stateNew) - { - IBlockState state = world.getBlockState(pos); - Block block = state.getBlock(); - if (block.isAir(state, world, pos) || block.canPlaceBlockAt(world, pos) || world.getBlockState(pos) == this.leaves) - { - world.setBlockState(pos, stateNew, 2); } + return -1; } BlockPos findGround(World world, BlockPos pos) @@ -384,55 +337,76 @@ BlockPos findGround(World world, BlockPos pos) { foundGround = true; } - } - while (!foundGround); + } while (!foundGround); return position.up(); } - public boolean isReplaceable(World world, BlockPos pos) - { - IBlockState state = world.getBlockState(pos); - return state.getBlock().isAir(state, world, pos) || state.getBlock().isLeaves(state, world, pos); - } - - @Override - public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) + /** + * Returns the absolute greatest distance in the BlockPos object. + */ + private int getGreatestDistance(BlockPos posIn) { + int i = MathHelper.abs(posIn.getX()); + int j = MathHelper.abs(posIn.getY()); + int k = MathHelper.abs(posIn.getZ()); + return k > i && k > j ? k : (Math.max(j, i)); } - @Override - public void generateTree(Random random, World worldIn, BlockPos position) + private BlockEnumLog.EnumAxis getLogAxis(BlockPos p_175938_1_, BlockPos p_175938_2_) { - this.world = worldIn; + BlockEnumLog.EnumAxis enumaxis = BlockEnumLog.EnumAxis.Y; + int i = Math.abs(p_175938_2_.getX() - p_175938_1_.getX()); + int j = Math.abs(p_175938_2_.getZ() - p_175938_1_.getZ()); + int k = Math.max(i, j); - if (this.seekHeight) - { - this.basePos = this.findGround(worldIn, position); - } - else + if (k > 0) { - this.basePos = position; + if (i == k) + { + enumaxis = BlockEnumLog.EnumAxis.X; + } + else + { + enumaxis = BlockEnumLog.EnumAxis.Z; + } } - this.rand = new Random(random.nextLong()); + return enumaxis; + } - if (this.heightLimit == 0) - { - this.heightLimit = 5 + this.rand.nextInt(this.heightLimitLimit); - } + /** + * Returns a boolean indicating whether the current location for the tree, spanning basePos to the height + * limit, is valid. + */ + private boolean validTreeLocation() + { + BlockPos down = this.basePos.down(); + IBlockState state = this.world.getBlockState(down); + Block soil = state.getBlock(); + boolean isSoil = soil.canSustainPlant(state, this.world, down, EnumFacing.UP, NaturaNether.netherSapling) || soil == Blocks.NETHERRACK; - if (!this.validTreeLocation()) + if (!isSoil) { - this.world = null; //Fix vanilla Mem leak, holds latest world + return false; } else { - this.generateLeafNodeList(); - this.generateLeaves(); - this.generateTrunk(); - this.generateLeafNodeBases(); - this.world = null; //Fix vanilla Mem leak, holds latest world + int i = this.checkBlockLine(this.basePos, this.basePos.up(this.heightLimit - 1)); + + if (i == -1) + { + return true; + } + else if (i < 6) + { + return false; + } + else + { + this.heightLimit = i; + return true; + } } } diff --git a/src/main/java/com/progwml6/natura/world/worldgen/trees/overworld/AppleTreeGenerator.java b/src/main/java/com/progwml6/natura/world/worldgen/trees/overworld/AppleTreeGenerator.java index 8cd37fca..c9495b27 100644 --- a/src/main/java/com/progwml6/natura/world/worldgen/trees/overworld/AppleTreeGenerator.java +++ b/src/main/java/com/progwml6/natura/world/worldgen/trees/overworld/AppleTreeGenerator.java @@ -70,7 +70,7 @@ public void generateTree(Random rand, World worldIn, BlockPos position) { IBlockState state = worldIn.getBlockState(position.down()); Block soil = state.getBlock(); - boolean isSoil = (soil != null && soil.canSustainPlant(state, worldIn, position.down(), EnumFacing.UP, NaturaOverworld.appleSapling)); + boolean isSoil = soil.canSustainPlant(state, worldIn, position.down(), EnumFacing.UP, NaturaOverworld.appleSapling); if (isSoil) { @@ -90,18 +90,18 @@ protected void placeCanopy(World world, Random random, BlockPos pos, int height) { for (int y = pos.getY() - 3 + height; y <= pos.getY() + height; ++y) { - int subract = y - (pos.getY() + height); - int subract2 = 1 - subract / 2; + int subtract = y - (pos.getY() + height); + int subtract2 = 1 - subtract / 2; - 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(); - if (Math.abs(mathX) != subract2 || Math.abs(mathZ) != subract2 || random.nextInt(2) != 0 && subract != 0) + if (Math.abs(mathX) != subtract2 || Math.abs(mathZ) != subtract2 || random.nextInt(2) != 0 && subtract != 0) { BlockPos blockpos = new BlockPos(x, y, z); IBlockState state = world.getBlockState(blockpos); @@ -124,7 +124,7 @@ protected void placeTrunk(World world, BlockPos pos, int height) IBlockState state = world.getBlockState(blockpos); Block block = state.getBlock(); - if (block == null || block.isAir(state, world, blockpos) || block.isLeaves(state, world, blockpos) || block.isReplaceable(world, blockpos)) + if (block.isAir(state, world, blockpos) || block.isLeaves(state, world, blockpos) || block.isReplaceable(world, blockpos)) { world.setBlockState(blockpos, this.log, 2); } @@ -176,12 +176,9 @@ BlockPos findGround(World world, BlockPos pos) height--; } while (height > Config.flatSeaLevel); - - return new BlockPos(pos.getX(), returnHeight, pos.getZ()); } else { - do { BlockPos position = new BlockPos(pos.getX(), height, pos.getZ()); @@ -198,13 +195,13 @@ BlockPos findGround(World world, BlockPos pos) height--; } while (height > Config.seaLevel); - return new BlockPos(pos.getX(), returnHeight, pos.getZ()); } + return new BlockPos(pos.getX(), returnHeight, pos.getZ()); } private boolean checkIfCanGrow(BlockPos position, int heightRange, World worldIn) { - boolean canGrowTree = true; + boolean canGrowTree = false; BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos(position.getX(), position.getY(), position.getZ()); @@ -225,9 +222,9 @@ private boolean checkIfCanGrow(BlockPos position, int heightRange, World worldIn range = 2; } - for (int x = position.getX() - range; x <= position.getX() + range && canGrowTree; ++x) + for (int x = position.getX() - range; x <= position.getX() + range; ++x) { - for (z = position.getZ() - range; z <= position.getZ() + range && canGrowTree; ++z) + for (z = position.getZ() - range; z <= position.getZ() + range; ++z) { if (y >= 0 && y < worldIn.getActualHeight()) { @@ -236,7 +233,7 @@ private boolean checkIfCanGrow(BlockPos position, int heightRange, World worldIn IBlockState state = worldIn.getBlockState(pos); Block block = state.getBlock(); - if (block != null && block != NaturaOverworld.appleSapling || !block.isLeaves(state, worldIn, pos)) + if (block != NaturaOverworld.appleSapling || !block.isLeaves(state, worldIn, pos)) { canGrowTree = true; } diff --git a/src/main/java/com/progwml6/natura/world/worldgen/trees/overworld/EucalyptusTreeGenerator.java b/src/main/java/com/progwml6/natura/world/worldgen/trees/overworld/EucalyptusTreeGenerator.java index ac8ecbec..410f127b 100644 --- a/src/main/java/com/progwml6/natura/world/worldgen/trees/overworld/EucalyptusTreeGenerator.java +++ b/src/main/java/com/progwml6/natura/world/worldgen/trees/overworld/EucalyptusTreeGenerator.java @@ -7,8 +7,6 @@ import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -import net.minecraft.world.chunk.IChunkProvider; -import net.minecraft.world.gen.IChunkGenerator; import com.progwml6.natura.overworld.NaturaOverworld; import com.progwml6.natura.world.worldgen.trees.BaseTreeGenerator; @@ -39,11 +37,6 @@ public EucalyptusTreeGenerator(int treeHeight, int treeRange, IBlockState log, I this(treeHeight, treeRange, log, leaves, true); } - @Override - public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) - { - } - @Override public void generateTree(Random random, World world, BlockPos pos) { @@ -74,7 +67,7 @@ public void generateTree(Random random, World world, BlockPos pos) k = 3; } - BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); + BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos(); for (int l = pos.getX() - k; l <= pos.getX() + k && flag; ++l) { @@ -82,9 +75,9 @@ public void generateTree(Random random, World world, BlockPos pos) { if (j >= 0 && j < 256) { - IBlockState iblockstate = world.getBlockState(blockpos$mutableblockpos.setPos(l, j, i1)); + IBlockState iblockstate = world.getBlockState(mutableBlockPos.setPos(l, j, i1)); - if (!iblockstate.getBlock().isAir(iblockstate, world, blockpos$mutableblockpos.setPos(l, j, i1)) && !iblockstate.getBlock().isLeaves(iblockstate, world, blockpos$mutableblockpos.setPos(l, j, i1))) + if (!iblockstate.getBlock().isAir(iblockstate, world, mutableBlockPos.setPos(l, j, i1)) && !iblockstate.getBlock().isLeaves(iblockstate, world, mutableBlockPos.setPos(l, j, i1))) { flag = false; } @@ -97,14 +90,11 @@ public void generateTree(Random random, World world, BlockPos pos) } } - if (!flag) - { - } - else + if (flag) { IBlockState state = world.getBlockState(pos.down()); Block soil = state.getBlock(); - boolean isSoil = (soil != null && soil.canSustainPlant(state, world, pos.down(), EnumFacing.UP, NaturaOverworld.overworldSapling)); + boolean isSoil = soil.canSustainPlant(state, world, pos.down(), EnumFacing.UP, NaturaOverworld.overworldSapling); if (isSoil) { @@ -119,14 +109,14 @@ public void generateTree(Random random, World world, BlockPos pos) this.genStraightBranch(world, random, pos, height, 2); this.genStraightBranch(world, random, pos, height, 3); this.genStraightBranch(world, random, pos, height, 4); - this.generateNode(world, random, pos.up(height)); + this.generateNode(world, pos.up(height)); } } } } @SuppressWarnings("deprecation") - public boolean generateNode(World world, Random random, BlockPos pos) + public void generateNode(World world, BlockPos pos) { this.setBlockAndMetadata(world, pos, this.log); @@ -175,7 +165,6 @@ public boolean generateNode(World world, Random random, BlockPos pos) } } - return true; } protected void placeTrunk(World world, BlockPos pos, int height) @@ -223,11 +212,6 @@ BlockPos findGround(World world, BlockPos pos) { BlockPos position = new BlockPos(pos.getX(), y, pos.getZ()); - if (y < 32) - { - break; - } - IBlockState state = world.getBlockState(position); Block block = state.getBlock(); boolean isSoil = block.canSustainPlant(state, world, position, EnumFacing.UP, NaturaOverworld.overworldSapling); @@ -238,8 +222,7 @@ BlockPos findGround(World world, BlockPos pos) break; } y--; - } - while (y > 0); + } while (y >= 32); return new BlockPos(pos.getX(), returnHeight, pos.getZ()); } @@ -258,17 +241,14 @@ private void genBranch(World world, Random random, BlockPos pos, int height, int byte0 = 1; byte1 = 1; break; - case 2: byte0 = -1; byte1 = 1; break; - case 3: byte0 = 1; byte1 = -1; break; - case 4: byte0 = -1; byte1 = -1; @@ -304,7 +284,7 @@ private void genBranch(World world, Random random, BlockPos pos, int height, int if (bIter == 1) { - this.generateNode(world, random, blockpos); + this.generateNode(world, blockpos); } heightShift = random.nextInt(6); @@ -324,21 +304,14 @@ private void genStraightBranch(World world, Random random, BlockPos pos, int hei { case 1: xShift = 1; - zShift = 0; break; - case 2: - xShift = 0; zShift = 1; break; - case 3: xShift = -1; - zShift = 0; break; - case 4: - xShift = 0; zShift = -1; break; } @@ -374,7 +347,7 @@ private void genStraightBranch(World world, Random random, BlockPos pos, int hei if (j2 == 1) { - this.generateNode(world, random, blockpos); + this.generateNode(world, blockpos); } heightShift = random.nextInt(6); diff --git a/src/main/java/com/progwml6/natura/world/worldgen/trees/overworld/HopseedTreeGenerator.java b/src/main/java/com/progwml6/natura/world/worldgen/trees/overworld/HopseedTreeGenerator.java index 3ea59322..12bb3530 100644 --- a/src/main/java/com/progwml6/natura/world/worldgen/trees/overworld/HopseedTreeGenerator.java +++ b/src/main/java/com/progwml6/natura/world/worldgen/trees/overworld/HopseedTreeGenerator.java @@ -9,8 +9,6 @@ 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 com.progwml6.natura.overworld.NaturaOverworld; import com.progwml6.natura.world.worldgen.trees.BaseTreeGenerator; @@ -44,11 +42,6 @@ public HopseedTreeGenerator(int treeHeight, int treeRange, IBlockState log, IBlo this(treeHeight, treeRange, log, leaves, true, false); } - @Override - public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) - { - } - @Override public void generateTree(Random random, World worldIn, BlockPos position) { @@ -115,16 +108,14 @@ public void generateTree(Random random, World worldIn, BlockPos position) } } - if (!hasSpace) - { - } - else + if (hasSpace) { BlockPos downPosition = position.down(); IBlockState state = worldIn.getBlockState(downPosition); - boolean isSoil = (state.getBlock() != null && state.getBlock().canSustainPlant(state, worldIn, downPosition, EnumFacing.UP, NaturaOverworld.overworldSapling2)); + state.getBlock(); + boolean isSoil = state.getBlock().canSustainPlant(state, worldIn, downPosition, EnumFacing.UP, NaturaOverworld.overworldSapling2); if (isSoil && position.getY() < 256 - height - 1) { @@ -143,7 +134,7 @@ public void generateTree(Random random, World worldIn, BlockPos position) IBlockState newState = worldIn.getBlockState(blockpos); - if (newState.getBlock() == Blocks.AIR || newState.getBlock() == null || newState.getBlock().isLeaves(newState, worldIn, blockpos)) + if (newState.getBlock() == Blocks.AIR || newState.getBlock().isLeaves(newState, worldIn, blockpos)) { worldIn.setBlockState(blockpos, this.log, 0); } @@ -154,7 +145,7 @@ public void generateTree(Random random, World worldIn, BlockPos position) newState = worldIn.getBlockState(blockpos); - if (newState.getBlock() == Blocks.AIR || newState.getBlock() == null || newState.getBlock().isLeaves(newState, worldIn, blockpos)) + if (newState.getBlock() == Blocks.AIR || newState.getBlock().isLeaves(newState, worldIn, blockpos)) { worldIn.setBlockState(blockpos, this.log, 0); } @@ -163,7 +154,7 @@ public void generateTree(Random random, World worldIn, BlockPos position) newState = worldIn.getBlockState(blockpos); - if (newState.getBlock() == Blocks.AIR || newState.getBlock() == null || newState.getBlock().isLeaves(newState, worldIn, blockpos)) + if (newState.getBlock() == Blocks.AIR || newState.getBlock().isLeaves(newState, worldIn, blockpos)) { worldIn.setBlockState(blockpos, this.log, 0); } @@ -172,7 +163,7 @@ public void generateTree(Random random, World worldIn, BlockPos position) newState = worldIn.getBlockState(blockpos); - if (newState.getBlock() == Blocks.AIR || newState.getBlock() == null || newState.getBlock().isLeaves(newState, worldIn, blockpos)) + if (newState.getBlock() == Blocks.AIR || newState.getBlock().isLeaves(newState, worldIn, blockpos)) { worldIn.setBlockState(blockpos, this.log, 0); } @@ -194,21 +185,21 @@ protected void growLeaves(World worldIn, Random random, BlockPos positionIn, int { for (int y = positionIn.getY() - 2 + height; y <= positionIn.getY() + height; ++y) { - int subract = y - (positionIn.getY() + height); - int subract2 = 2 + 1 - subract; + int subtract = y - (positionIn.getY() + height); + int subtract2 = 2 + 1 - subtract; - for (int x = positionIn.getX() - subract2; x <= positionIn.getX() + subract2; ++x) + for (int x = positionIn.getX() - subtract2; x <= positionIn.getX() + subtract2; ++x) { int mathX = x - positionIn.getX(); - for (int z = positionIn.getZ() - subract2; z <= positionIn.getZ() + subract2; ++z) + for (int z = positionIn.getZ() - subtract2; z <= positionIn.getZ() + subtract2; ++z) { int mathZ = z - positionIn.getZ(); BlockPos blockpos = new BlockPos(x, y, z); IBlockState state = worldIn.getBlockState(blockpos); - if ((mathX >= 0 || mathZ >= 0 || mathX * mathX + mathZ * mathZ <= subract2 * subract2) && (mathX <= 0 && mathZ <= 0 || mathX * mathX + mathZ * mathZ <= (subract2 + 1) * (subract2 + 1)) && (random.nextInt(4) != 0 || mathX * mathX + mathZ * mathZ <= (subract2 - 1) * (subract2 - 1)) && (state.getBlock().isAir(state, worldIn, blockpos) || state.getBlock().isLeaves(state, worldIn, blockpos) || state.getBlock().canBeReplacedByLeaves(state, worldIn, blockpos))) + if ((mathX >= 0 || mathZ >= 0 || mathX * mathX + mathZ * mathZ <= subtract2 * subtract2) && (mathX <= 0 && mathZ <= 0 || mathX * mathX + mathZ * mathZ <= (subtract2 + 1) * (subtract2 + 1)) && (random.nextInt(4) != 0 || mathX * mathX + mathZ * mathZ <= (subtract2 - 1) * (subtract2 - 1)) && (state.getBlock().isAir(state, worldIn, blockpos) || state.getBlock().isLeaves(state, worldIn, blockpos) || state.getBlock().canBeReplacedByLeaves(state, worldIn, blockpos))) { this.setBlockAndMetadata(worldIn, blockpos, this.leaves); } diff --git a/src/main/java/com/progwml6/natura/world/worldgen/trees/overworld/OverworldTreeGenerator.java b/src/main/java/com/progwml6/natura/world/worldgen/trees/overworld/OverworldTreeGenerator.java index 20b84853..af9e802e 100644 --- a/src/main/java/com/progwml6/natura/world/worldgen/trees/overworld/OverworldTreeGenerator.java +++ b/src/main/java/com/progwml6/natura/world/worldgen/trees/overworld/OverworldTreeGenerator.java @@ -8,8 +8,6 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.WorldType; -import net.minecraft.world.chunk.IChunkProvider; -import net.minecraft.world.gen.IChunkGenerator; import com.progwml6.natura.common.config.Config; import com.progwml6.natura.overworld.NaturaOverworld; @@ -44,11 +42,6 @@ public OverworldTreeGenerator(int treeHeight, int treeRange, IBlockState log, IB this(treeHeight, treeRange, log, leaves, true, false); } - @Override - public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) - { - } - @Override public void generateTree(Random rand, World worldIn, BlockPos position) { @@ -68,7 +61,7 @@ public void generateTree(Random rand, World worldIn, BlockPos position) { IBlockState state = worldIn.getBlockState(position.down()); Block soil = state.getBlock(); - boolean isSoil = (soil != null && soil.canSustainPlant(state, worldIn, position.down(), EnumFacing.UP, NaturaOverworld.overworldSapling)); + boolean isSoil = soil.canSustainPlant(state, worldIn, position.down(), EnumFacing.UP, NaturaOverworld.overworldSapling); if (isSoil) { @@ -88,18 +81,18 @@ protected void placeCanopy(World world, Random random, BlockPos pos, int height) { for (int y = pos.getY() - 3 + height; y <= pos.getY() + height; ++y) { - int subract = y - (pos.getY() + height); - int subract2 = 1 - subract / 2; + int subtract = y - (pos.getY() + height); + int subtract2 = 1 - subtract / 2; - 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(); - if (Math.abs(mathX) != subract2 || Math.abs(mathZ) != subract2 || random.nextInt(2) != 0 && subract != 0) + if (Math.abs(mathX) != subtract2 || Math.abs(mathZ) != subtract2 || random.nextInt(2) != 0 && subtract != 0) { BlockPos blockpos = new BlockPos(x, y, z); IBlockState state = world.getBlockState(blockpos); @@ -122,7 +115,7 @@ protected void placeTrunk(World world, BlockPos pos, int height) IBlockState state = world.getBlockState(blockpos); Block block = state.getBlock(); - if (block == null || block.isAir(state, world, blockpos) || block.isLeaves(state, world, blockpos) || block.isReplaceable(world, blockpos)) + if (block.isAir(state, world, blockpos) || block.isLeaves(state, world, blockpos) || block.isReplaceable(world, blockpos)) { world.setBlockState(blockpos, this.log, 2); } @@ -151,10 +144,8 @@ BlockPos findGround(World world, BlockPos pos) } height--; - } - while (height > Config.flatSeaLevel); + } while (height > Config.flatSeaLevel); - return new BlockPos(pos.getX(), returnHeight, pos.getZ()); } else { @@ -172,16 +163,14 @@ BlockPos findGround(World world, BlockPos pos) } height--; - } - while (height > Config.seaLevel); - - return new BlockPos(pos.getX(), returnHeight, pos.getZ()); + } while (height > Config.seaLevel); } + return new BlockPos(pos.getX(), returnHeight, pos.getZ()); } private boolean checkIfCanGrow(BlockPos position, int heightRange, World worldIn) { - boolean canGrowTree = true; + boolean canGrowTree = false; BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos(position.getX(), position.getY(), position.getZ()); @@ -202,9 +191,9 @@ private boolean checkIfCanGrow(BlockPos position, int heightRange, World worldIn range = 2; } - for (int x = position.getX() - range; x <= position.getX() + range && canGrowTree; ++x) + for (int x = position.getX() - range; x <= position.getX() + range; ++x) { - for (z = position.getZ() - range; z <= position.getZ() + range && canGrowTree; ++z) + for (z = position.getZ() - range; z <= position.getZ() + range; ++z) { if (y >= 0 && y < worldIn.getActualHeight()) { @@ -213,7 +202,7 @@ private boolean checkIfCanGrow(BlockPos position, int heightRange, World worldIn IBlockState state = worldIn.getBlockState(pos); Block block = state.getBlock(); - if (block != null && block != NaturaOverworld.overworldSapling || !block.isLeaves(state, worldIn, pos)) + if (block != NaturaOverworld.overworldSapling || !block.isLeaves(state, worldIn, pos)) { canGrowTree = true; } diff --git a/src/main/java/com/progwml6/natura/world/worldgen/trees/overworld/RedwoodTreeGenerator.java b/src/main/java/com/progwml6/natura/world/worldgen/trees/overworld/RedwoodTreeGenerator.java index 6e99c076..8f0b1ae2 100644 --- a/src/main/java/com/progwml6/natura/world/worldgen/trees/overworld/RedwoodTreeGenerator.java +++ b/src/main/java/com/progwml6/natura/world/worldgen/trees/overworld/RedwoodTreeGenerator.java @@ -13,8 +13,6 @@ import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; import net.minecraft.world.WorldType; -import net.minecraft.world.chunk.IChunkProvider; -import net.minecraft.world.gen.IChunkGenerator; import com.progwml6.natura.common.config.Config; import com.progwml6.natura.overworld.NaturaOverworld; @@ -34,7 +32,6 @@ public class RedwoodTreeGenerator extends BaseTreeGenerator double branchSlope = 0.381D; double scaleWidth = 1.0D; double leafDensity = 1.0D; - int trunkSize = 1; int heightLimitLimit = 12; /** * Sets the distance limit for how far away the generator will populate leaves from the base leaf node. @@ -78,11 +75,6 @@ public boolean isValidSpawn(World world, BlockPos pos) return ground && transparent; } - @Override - public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) - { - } - @Override public void generateTree(Random random, World world, BlockPos pos) { @@ -111,61 +103,61 @@ public void generateTree(Random random, World world, BlockPos pos) { if (currentHeight < treeHeight / 10) { - this.genRing13(world, random, groundPosition.up(currentHeight)); + this.genRing13(world, groundPosition.up(currentHeight)); } else if (currentHeight < treeHeight * 2 / 10) { - this.genRing12(world, random, groundPosition.up(currentHeight)); + this.genRing12(world, groundPosition.up(currentHeight)); } else if (currentHeight < treeHeight * 3 / 10) { - this.genRing11(world, random, groundPosition.up(currentHeight)); + this.genRing11(world, groundPosition.up(currentHeight)); } else if (currentHeight < treeHeight * 4 / 10) { - this.genRing10(world, random, groundPosition.up(currentHeight)); + this.genRing10(world, groundPosition.up(currentHeight)); } else if (currentHeight < treeHeight * 5 / 10) { - this.genRing9(world, random, groundPosition.up(currentHeight)); + this.genRing9(world, groundPosition.up(currentHeight)); - this.growLowBranch(world, random, groundPosition.up(currentHeight)); + this.growLowBranch(random, groundPosition.up(currentHeight)); } else if (currentHeight < treeHeight * 6 / 10) { - this.genRing8(world, random, groundPosition.up(currentHeight)); + this.genRing8(world, groundPosition.up(currentHeight)); - this.growLowBranch(world, random, groundPosition.up(currentHeight)); + this.growLowBranch(random, groundPosition.up(currentHeight)); } else if (currentHeight < treeHeight * 7 / 10) { - this.genRing7(world, random, groundPosition.up(currentHeight)); + this.genRing7(world, groundPosition.up(currentHeight)); - this.growMiddleBranch(world, random, groundPosition.up(currentHeight)); + this.growMiddleBranch(random, groundPosition.up(currentHeight)); } else if (currentHeight < treeHeight * 8 / 10) { - this.genRing6(world, random, groundPosition.up(currentHeight)); + this.genRing6(world, groundPosition.up(currentHeight)); - this.growMiddleBranch(world, random, groundPosition.up(currentHeight)); + this.growMiddleBranch(random, groundPosition.up(currentHeight)); } else if (currentHeight < treeHeight * 9 / 10) { - this.genRing5(world, random, groundPosition.up(currentHeight)); + this.genRing5(world, groundPosition.up(currentHeight)); - this.growHighBranch(world, random, groundPosition.up(currentHeight)); + this.growHighBranch(random, groundPosition.up(currentHeight)); } else { - this.genRing3(world, random, groundPosition.up(currentHeight)); + this.genRing3(world, groundPosition.up(currentHeight)); - this.growHighBranch(world, random, groundPosition.up(currentHeight)); + this.growHighBranch(random, groundPosition.up(currentHeight)); } } - this.growBigRoots(world, random, groundPosition.down()); + this.growBigRoots(world, groundPosition.down()); - this.growTop(world, random, groundPosition.up(this.height)); + this.growTop(groundPosition.up(this.height)); } else if (treeHeight > 100) { @@ -173,49 +165,49 @@ else if (treeHeight > 100) { if (currentHeight < treeHeight / 8) { - this.genRing11(world, random, groundPosition.up(currentHeight)); + this.genRing11(world, groundPosition.up(currentHeight)); } else if (currentHeight < treeHeight * 2 / 8) { - this.genRing10(world, random, groundPosition.up(currentHeight)); + this.genRing10(world, groundPosition.up(currentHeight)); } else if (currentHeight < treeHeight * 3 / 8) { - this.genRing9(world, random, groundPosition.up(currentHeight)); + this.genRing9(world, groundPosition.up(currentHeight)); } else if (currentHeight < treeHeight * 4 / 8) { - this.genRing8(world, random, groundPosition.up(currentHeight)); + this.genRing8(world, groundPosition.up(currentHeight)); } else if (currentHeight < treeHeight * 5 / 8) { - this.genRing7(world, random, groundPosition.up(currentHeight)); + this.genRing7(world, groundPosition.up(currentHeight)); - this.growMiddleBranch(world, random, groundPosition.up(currentHeight)); + this.growMiddleBranch(random, groundPosition.up(currentHeight)); } else if (currentHeight < treeHeight * 6 / 8) { - this.genRing6(world, random, groundPosition.up(currentHeight)); + this.genRing6(world, groundPosition.up(currentHeight)); - this.growMiddleBranch(world, random, groundPosition.up(currentHeight)); + this.growMiddleBranch(random, groundPosition.up(currentHeight)); } else if (currentHeight < treeHeight * 7 / 8) { - this.genRing5(world, random, groundPosition.up(currentHeight)); + this.genRing5(world, groundPosition.up(currentHeight)); - this.growHighBranch(world, random, groundPosition.up(currentHeight)); + this.growHighBranch(random, groundPosition.up(currentHeight)); } else { - this.genRing3(world, random, groundPosition.up(currentHeight)); + this.genRing3(world, groundPosition.up(currentHeight)); - this.growHighBranch(world, random, groundPosition.up(currentHeight)); + this.growHighBranch(random, groundPosition.up(currentHeight)); } } - this.growMediumRoots(world, random, groundPosition.down()); + this.growMediumRoots(world, groundPosition.down()); - this.growTop(world, random, groundPosition.up(this.height)); + this.growTop(groundPosition.up(this.height)); } else { @@ -223,43 +215,43 @@ else if (currentHeight < treeHeight * 7 / 8) { if (currentHeight < treeHeight / 6) { - this.genRing9(world, random, groundPosition.up(currentHeight)); + this.genRing9(world, groundPosition.up(currentHeight)); } else if (currentHeight < treeHeight * 2 / 6) { - this.genRing8(world, random, groundPosition.up(currentHeight)); + this.genRing8(world, groundPosition.up(currentHeight)); } else if (currentHeight < treeHeight * 3 / 6) { - this.genRing7(world, random, groundPosition.up(currentHeight)); + this.genRing7(world, groundPosition.up(currentHeight)); } else if (currentHeight < treeHeight * 4 / 6) { - this.genRing6(world, random, groundPosition.up(currentHeight)); + this.genRing6(world, groundPosition.up(currentHeight)); - this.growMiddleBranch(world, random, groundPosition.up(currentHeight)); + this.growMiddleBranch(random, groundPosition.up(currentHeight)); } else if (currentHeight < treeHeight * 5 / 6) { - this.genRing5(world, random, groundPosition.up(currentHeight)); + this.genRing5(world, groundPosition.up(currentHeight)); - this.growHighBranch(world, random, groundPosition.up(currentHeight)); + this.growHighBranch(random, groundPosition.up(currentHeight)); } else { - this.genRing3(world, random, groundPosition.up(currentHeight)); + this.genRing3(world, groundPosition.up(currentHeight)); - this.growHighBranch(world, random, groundPosition.up(currentHeight)); + this.growHighBranch(random, groundPosition.up(currentHeight)); } } - this.growSmallRoots(world, random, groundPosition.down()); + this.growSmallRoots(world, groundPosition.down()); - this.growTop(world, random, groundPosition.up(this.height)); + this.growTop(groundPosition.up(this.height)); } } - public boolean growTop(World world, Random random, BlockPos pos) + public void growTop(BlockPos pos) { this.basePos = pos.up(4); this.generateLeafNodeList(); @@ -280,11 +272,9 @@ public boolean growTop(World world, Random random, BlockPos pos) this.generateLeafNodeList(); this.generateLeaves(); this.generateLeafNodeBases(); - - return false; } - public boolean growHighBranch(World world, Random random, BlockPos pos) + public void growHighBranch(Random random, BlockPos pos) { int xPos = pos.getX(); int yPos = pos.getY(); @@ -297,11 +287,9 @@ public boolean growHighBranch(World world, Random random, BlockPos pos) this.generateLeaves(); this.generateLeafNodeBases(); } - - return false; } - public boolean growMiddleBranch(World world, Random random, BlockPos pos) + public void growMiddleBranch(Random random, BlockPos pos) { int xPos = pos.getX(); int yPos = pos.getY(); @@ -314,11 +302,9 @@ public boolean growMiddleBranch(World world, Random random, BlockPos pos) this.generateLeaves(); this.generateLeafNodeBases(); } - - return false; } - public boolean growLowBranch(World world, Random random, BlockPos pos) + public void growLowBranch(Random random, BlockPos pos) { int xPos = pos.getX(); int yPos = pos.getY(); @@ -342,90 +328,82 @@ public boolean growLowBranch(World world, Random random, BlockPos pos) this.generateLeafNodeList(); this.generateLeaves(); this.generateLeafNodeBases(); - - return false; } - public boolean growSmallRoots(World world, Random random, BlockPos pos) + public void growSmallRoots(World world, BlockPos pos) { - this.genRing9(world, random, pos); - - this.smallRoot1(world, random, pos.down(1)); - this.smallRoot1(world, random, pos.down(2)); - this.smallRoot1(world, random, pos.down(3)); + this.genRing9(world, pos); - this.smallRoot2(world, random, pos.down(4)); - this.smallRoot2(world, random, pos.down(5)); + this.smallRoot1(world, pos.down(1)); + this.smallRoot1(world, pos.down(2)); + this.smallRoot1(world, pos.down(3)); - this.smallRoot3(world, random, pos.down(6)); - this.smallRoot3(world, random, pos.down(7)); - this.smallRoot3(world, random, pos.down(8)); - this.smallRoot3(world, random, pos.down(9)); + this.smallRoot2(world, pos.down(4)); + this.smallRoot2(world, pos.down(5)); - this.smallRoot4(world, random, pos.down(10)); - this.smallRoot4(world, random, pos.down(11)); + this.smallRoot3(world, pos.down(6)); + this.smallRoot3(world, pos.down(7)); + this.smallRoot3(world, pos.down(8)); + this.smallRoot3(world, pos.down(9)); - return true; + this.smallRoot4(world, pos.down(10)); + this.smallRoot4(world, pos.down(11)); } - public boolean growMediumRoots(World world, Random random, BlockPos pos) + public void growMediumRoots(World world, BlockPos pos) { - this.genRing11(world, random, pos); - - this.mediumRoot1(world, random, pos.down(1)); - this.mediumRoot1(world, random, pos.down(2)); - this.mediumRoot1(world, random, pos.down(3)); + this.genRing11(world, pos); - this.mediumRoot2(world, random, pos.down(4)); - this.mediumRoot2(world, random, pos.down(5)); + this.mediumRoot1(world, pos.down(1)); + this.mediumRoot1(world, pos.down(2)); + this.mediumRoot1(world, pos.down(3)); - this.mediumRoot3(world, random, pos.down(6)); - this.mediumRoot3(world, random, pos.down(7)); - this.mediumRoot3(world, random, pos.down(8)); - this.mediumRoot3(world, random, pos.down(9)); + this.mediumRoot2(world, pos.down(4)); + this.mediumRoot2(world, pos.down(5)); - this.mediumRoot4(world, random, pos.down(10)); - this.mediumRoot4(world, random, pos.down(11)); + this.mediumRoot3(world, pos.down(6)); + this.mediumRoot3(world, pos.down(7)); + this.mediumRoot3(world, pos.down(8)); + this.mediumRoot3(world, pos.down(9)); - this.mediumRoot5(world, random, pos.down(12)); - this.mediumRoot5(world, random, pos.down(13)); - this.mediumRoot5(world, random, pos.down(14)); + this.mediumRoot4(world, pos.down(10)); + this.mediumRoot4(world, pos.down(11)); - return true; + this.mediumRoot5(world, pos.down(12)); + this.mediumRoot5(world, pos.down(13)); + this.mediumRoot5(world, pos.down(14)); } - public boolean growBigRoots(World world, Random random, BlockPos pos) + public void growBigRoots(World world, BlockPos pos) { - this.genRing13(world, random, pos); + this.genRing13(world, pos); - this.bigRoot1(world, random, pos.down(1)); - this.bigRoot1(world, random, pos.down(2)); - this.bigRoot1(world, random, pos.down(3)); + this.bigRoot1(world, pos.down(1)); + this.bigRoot1(world, pos.down(2)); + this.bigRoot1(world, pos.down(3)); - this.bigRoot2(world, random, pos.down(4)); - this.bigRoot2(world, random, pos.down(5)); + this.bigRoot2(world, pos.down(4)); + this.bigRoot2(world, pos.down(5)); - this.bigRoot3(world, random, pos.down(6)); - this.bigRoot3(world, random, pos.down(7)); - this.bigRoot3(world, random, pos.down(8)); - this.bigRoot3(world, random, pos.down(9)); + this.bigRoot3(world, pos.down(6)); + this.bigRoot3(world, pos.down(7)); + this.bigRoot3(world, pos.down(8)); + this.bigRoot3(world, pos.down(9)); - this.bigRoot4(world, random, pos.down(10)); - this.bigRoot4(world, random, pos.down(11)); + this.bigRoot4(world, pos.down(10)); + this.bigRoot4(world, pos.down(11)); - this.bigRoot5(world, random, pos.down(12)); - this.bigRoot5(world, random, pos.down(13)); - this.bigRoot5(world, random, pos.down(14)); + this.bigRoot5(world, pos.down(12)); + this.bigRoot5(world, pos.down(13)); + this.bigRoot5(world, pos.down(14)); - this.bigRoot6(world, random, pos.down(15)); - this.bigRoot6(world, random, pos.down(16)); - this.bigRoot6(world, random, pos.down(17)); - this.bigRoot6(world, random, pos.down(18)); - - return true; + this.bigRoot6(world, pos.down(15)); + this.bigRoot6(world, pos.down(16)); + this.bigRoot6(world, pos.down(17)); + this.bigRoot6(world, pos.down(18)); } - public boolean smallRoot1(World world, Random random, BlockPos pos) + public void smallRoot1(World world, BlockPos pos) { if (world.getBlockState(pos).getBlock() != Blocks.BEDROCK && pos.getY() > 0) { @@ -481,11 +459,9 @@ public boolean smallRoot1(World world, Random random, BlockPos pos) this.setBlockAndMetadata(world, pos.add(4, 0, -1), this.root); this.setBlockAndMetadata(world, pos.add(4, 0, 1), this.root); } - - return true; } - public boolean smallRoot2(World world, Random random, BlockPos pos) + public void smallRoot2(World world, BlockPos pos) { if (world.getBlockState(pos).getBlock() != Blocks.BEDROCK && pos.getY() > 0) { @@ -533,11 +509,9 @@ public boolean smallRoot2(World world, Random random, BlockPos pos) this.setBlockAndMetadata(world, pos.add(4, 0, -1), this.root); this.setBlockAndMetadata(world, pos.add(4, 0, 1), this.root); } - - return true; } - public boolean smallRoot3(World world, Random random, BlockPos pos) + public void smallRoot3(World world, BlockPos pos) { if (world.getBlockState(pos).getBlock() != Blocks.BEDROCK && pos.getY() > 0) { @@ -557,11 +531,9 @@ public boolean smallRoot3(World world, Random random, BlockPos pos) this.setBlockAndMetadata(world, pos.add(2, 0, -2), this.root); this.setBlockAndMetadata(world, pos.add(2, 0, 2), this.root); } - - return true; } - public boolean smallRoot4(World world, Random random, BlockPos pos) + public void smallRoot4(World world, BlockPos pos) { if (world.getBlockState(pos).getBlock() != Blocks.BEDROCK && pos.getY() > 0) { @@ -571,11 +543,9 @@ public boolean smallRoot4(World world, Random random, BlockPos pos) this.setBlockAndMetadata(world, pos.add(1, 0, -2), this.root); this.setBlockAndMetadata(world, pos.add(1, 0, 2), this.root); } - - return true; } - public boolean mediumRoot1(World world, Random random, BlockPos pos) + public void mediumRoot1(World world, BlockPos pos) { if (world.getBlockState(pos).getBlock() != Blocks.BEDROCK && pos.getY() > 0) { @@ -657,11 +627,9 @@ public boolean mediumRoot1(World world, Random random, BlockPos pos) this.setBlockAndMetadata(world, pos.add(5, 0, -1), this.root); this.setBlockAndMetadata(world, pos.add(5, 0, 1), this.root); } - - return true; } - public boolean mediumRoot2(World world, Random random, BlockPos pos) + public void mediumRoot2(World world, BlockPos pos) { if (world.getBlockState(pos).getBlock() != Blocks.BEDROCK && pos.getY() > 0) { @@ -713,11 +681,9 @@ public boolean mediumRoot2(World world, Random random, BlockPos pos) this.setBlockAndMetadata(world, pos.add(4, 0, -1), this.root); this.setBlockAndMetadata(world, pos.add(4, 0, 1), this.root); } - - return true; } - public boolean mediumRoot3(World world, Random random, BlockPos pos) + public void mediumRoot3(World world, BlockPos pos) { if (world.getBlockState(pos).getBlock() != Blocks.BEDROCK && pos.getY() > 0) { @@ -747,11 +713,9 @@ public boolean mediumRoot3(World world, Random random, BlockPos pos) this.setBlockAndMetadata(world, pos.add(3, 0, -2), this.root); this.setBlockAndMetadata(world, pos.add(3, 0, 2), this.root); } - - return true; } - public boolean mediumRoot4(World world, Random random, BlockPos pos) + public void mediumRoot4(World world, BlockPos pos) { if (world.getBlockState(pos).getBlock() != Blocks.BEDROCK && pos.getY() > 0) { @@ -767,11 +731,9 @@ public boolean mediumRoot4(World world, Random random, BlockPos pos) this.setBlockAndMetadata(world, pos.add(2, 0, -2), this.root); this.setBlockAndMetadata(world, pos.add(2, 0, 2), this.root); } - - return true; } - public boolean mediumRoot5(World world, Random random, BlockPos pos) + public void mediumRoot5(World world, BlockPos pos) { if (world.getBlockState(pos).getBlock() != Blocks.BEDROCK && pos.getY() > 0) { @@ -780,11 +742,9 @@ public boolean mediumRoot5(World world, Random random, BlockPos pos) this.setBlockAndMetadata(world, pos.add(1, 0, -3), this.root); this.setBlockAndMetadata(world, pos.add(1, 0, 3), this.root); } - - return true; } - public boolean bigRoot1(World world, Random random, BlockPos pos) + public void bigRoot1(World world, BlockPos pos) { if (world.getBlockState(pos).getBlock() != Blocks.BEDROCK && pos.getY() > 0) { @@ -912,11 +872,9 @@ public boolean bigRoot1(World world, Random random, BlockPos pos) this.setBlockAndMetadata(world, pos.add(6, 0, 1), this.root); this.setBlockAndMetadata(world, pos.add(6, 0, 2), this.root); } - - return true; } - public boolean bigRoot2(World world, Random random, BlockPos pos) + public void bigRoot2(World world, BlockPos pos) { if (world.getBlockState(pos).getBlock() != Blocks.BEDROCK && pos.getY() > 0) { @@ -1034,13 +992,11 @@ public boolean bigRoot2(World world, Random random, BlockPos pos) this.setBlockAndMetadata(world, pos.add(5, 0, 3), this.root); this.setBlockAndMetadata(world, pos.add(5, 0, 4), this.root); } - - return true; } //TODO: CHANGE EVERYTHING BELOW. - public boolean bigRoot3(World world, Random random, BlockPos pos) + public void bigRoot3(World world, BlockPos pos) { if (world.getBlockState(pos).getBlock() != Blocks.BEDROCK && pos.getY() > 0) { @@ -1100,11 +1056,9 @@ public boolean bigRoot3(World world, Random random, BlockPos pos) this.setBlockAndMetadata(world, pos.add(4, 0, 2), this.root); this.setBlockAndMetadata(world, pos.add(4, 0, 3), this.root); } - - return true; } - public boolean bigRoot4(World world, Random random, BlockPos pos) + public void bigRoot4(World world, BlockPos pos) { if (world.getBlockState(pos).getBlock() != Blocks.BEDROCK && pos.getY() > 0) { @@ -1144,11 +1098,9 @@ public boolean bigRoot4(World world, Random random, BlockPos pos) this.setBlockAndMetadata(world, pos.add(4, 0, -3), this.root); this.setBlockAndMetadata(world, pos.add(4, 0, 3), this.root); } - - return true; } - public boolean bigRoot5(World world, Random random, BlockPos pos) + public void bigRoot5(World world, BlockPos pos) { if (world.getBlockState(pos).getBlock() != Blocks.BEDROCK && pos.getY() > 0) { @@ -1174,11 +1126,9 @@ public boolean bigRoot5(World world, Random random, BlockPos pos) this.setBlockAndMetadata(world, pos.add(3, 0, -3), this.root); this.setBlockAndMetadata(world, pos.add(3, 0, 3), this.root); } - - return true; } - public boolean bigRoot6(World world, Random random, BlockPos pos) + public void bigRoot6(World world, BlockPos pos) { if (world.getBlockState(pos).getBlock() != Blocks.BEDROCK && pos.getY() > 0) { @@ -1192,11 +1142,9 @@ public boolean bigRoot6(World world, Random random, BlockPos pos) this.setBlockAndMetadata(world, pos.add(2, 0, 3), this.root); this.setBlockAndMetadata(world, pos.add(2, 0, 4), this.root); } - - return true; } - public boolean genRing13(World world, Random random, BlockPos pos) + public void genRing13(World world, BlockPos pos) { if (world.getBlockState(pos).getBlock() != Blocks.BEDROCK && pos.getY() > 0) { @@ -1352,11 +1300,9 @@ public boolean genRing13(World world, Random random, BlockPos pos) this.setBlockAndMetadata(world, pos.add(6, 0, 1), this.bark); this.setBlockAndMetadata(world, pos.add(6, 0, 2), this.bark); } - - return true; } - public boolean genRing12(World world, Random random, BlockPos pos) + public void genRing12(World world, BlockPos pos) { if (world.getBlockState(pos).getBlock() != Blocks.BEDROCK && pos.getY() > 0) { @@ -1500,11 +1446,9 @@ public boolean genRing12(World world, Random random, BlockPos pos) this.setBlockAndMetadata(world, pos.add(6, 0, 0), this.bark); this.setBlockAndMetadata(world, pos.add(6, 0, 1), this.bark); } - - return true; } - public boolean genRing11(World world, Random random, BlockPos pos) + public void genRing11(World world, BlockPos pos) { if (world.getBlockState(pos).getBlock() != Blocks.BEDROCK && pos.getY() > 0) { @@ -1610,11 +1554,9 @@ public boolean genRing11(World world, Random random, BlockPos pos) this.setBlockAndMetadata(world, pos.add(5, 0, 0), this.bark); this.setBlockAndMetadata(world, pos.add(5, 0, 1), this.bark); } - - return true; } - public boolean genRing10(World world, Random random, BlockPos pos) + public void genRing10(World world, BlockPos pos) { if (world.getBlockState(pos).getBlock() != Blocks.BEDROCK && pos.getY() > 0) { @@ -1698,11 +1640,9 @@ public boolean genRing10(World world, Random random, BlockPos pos) this.setBlockAndMetadata(world, pos.add(4, 0, 1), this.bark); this.setBlockAndMetadata(world, pos.add(4, 0, 2), this.bark); } - - return true; } - public boolean genRing9(World world, Random random, BlockPos pos) + public void genRing9(World world, BlockPos pos) { if (world.getBlockState(pos).getBlock() != Blocks.BEDROCK && pos.getY() > 0) { @@ -1778,11 +1718,9 @@ public boolean genRing9(World world, Random random, BlockPos pos) this.setBlockAndMetadata(world, pos.add(4, 0, 0), this.bark); this.setBlockAndMetadata(world, pos.add(4, 0, 1), this.bark); } - - return true; } - public boolean genRing8(World world, Random random, BlockPos pos) + public void genRing8(World world, BlockPos pos) { if (world.getBlockState(pos).getBlock() != Blocks.BEDROCK && pos.getY() > 0) { @@ -1840,11 +1778,9 @@ public boolean genRing8(World world, Random random, BlockPos pos) this.setBlockAndMetadata(world, pos.add(3, 0, 1), this.bark); this.setBlockAndMetadata(world, pos.add(3, 0, 2), this.bark); } - - return true; } - public boolean genRing7(World world, Random random, BlockPos pos) + public void genRing7(World world, BlockPos pos) { if (world.getBlockState(pos).getBlock() != Blocks.BEDROCK && pos.getY() > 0) { @@ -1895,10 +1831,9 @@ public boolean genRing7(World world, Random random, BlockPos pos) this.setBlockAndMetadata(world, pos.add(3, 0, 1), this.bark); } - return true; } - public boolean genRing6(World world, Random random, BlockPos pos) + public void genRing6(World world, BlockPos pos) { if (world.getBlockState(pos).getBlock() != Blocks.BEDROCK && pos.getY() > 0) { @@ -1935,10 +1870,9 @@ public boolean genRing6(World world, Random random, BlockPos pos) this.setBlockAndMetadata(world, pos.add(2, 0, 2), this.bark); } - return true; } - public boolean genRing5(World world, Random random, BlockPos pos) + public void genRing5(World world, BlockPos pos) { if (world.getBlockState(pos).getBlock() != Blocks.BEDROCK && pos.getY() > 0) { @@ -1971,57 +1905,9 @@ public boolean genRing5(World world, Random random, BlockPos pos) this.setBlockAndMetadata(world, pos.add(2, 0, 1), this.bark); } - return true; } - public boolean genRing4(World world, Random random, BlockPos pos) - { - if (world.getBlockState(pos).getBlock() != Blocks.BEDROCK && pos.getY() > 0) - { - this.setBlockAndMetadata(world, pos.add(-2, 0, -1), this.bark); - this.setBlockAndMetadata(world, pos.add(-2, 0, 0), this.bark); - - this.setBlockAndMetadata(world, pos.add(-1, 0, -2), this.bark); - this.setBlockAndMetadata(world, pos.add(-1, 0, -1), this.heart); - this.setBlockAndMetadata(world, pos.add(-1, 0, 0), this.heart); - this.setBlockAndMetadata(world, pos.add(-1, 0, 1), this.bark); - - this.setBlockAndMetadata(world, pos.add(0, 0, -2), this.bark); - this.setBlockAndMetadata(world, pos.add(0, 0, -1), this.heart); - - this.setBlockAndMetadata(world, pos, this.heart); - - this.setBlockAndMetadata(world, pos.add(0, 0, 1), this.bark); - - this.setBlockAndMetadata(world, pos.add(1, 0, -1), this.bark); - this.setBlockAndMetadata(world, pos.add(1, 0, 0), this.bark); - } - - return true; - } - - public boolean genRing3s(World world, Random random, BlockPos pos) - { - if (world.getBlockState(pos).getBlock() != Blocks.BEDROCK && pos.getY() > 0) - { - this.setBlockAndMetadata(world, pos.add(-1, 0, -1), this.bark); - this.setBlockAndMetadata(world, pos.add(-1, 0, 0), this.bark); - this.setBlockAndMetadata(world, pos.add(-1, 0, 1), this.bark); - - this.setBlockAndMetadata(world, pos.add(0, 0, -1), this.bark); - - this.setBlockAndMetadata(world, pos, this.heart); - - this.setBlockAndMetadata(world, pos.add(0, 0, 1), this.bark); - - this.setBlockAndMetadata(world, pos.add(1, 0, -1), this.bark); - this.setBlockAndMetadata(world, pos.add(1, 0, 0), this.bark); - } - - return true; - } - - public boolean genRing3(World world, Random random, BlockPos pos) + public void genRing3(World world, BlockPos pos) { if (world.getBlockState(pos).getBlock() != Blocks.BEDROCK && pos.getY() > 0) { @@ -2039,33 +1925,6 @@ public boolean genRing3(World world, Random random, BlockPos pos) this.setBlockAndMetadata(world, pos.add(1, 0, 0), this.bark); this.setBlockAndMetadata(world, pos.add(1, 0, 1), this.bark); } - - return true; - } - - public boolean genRing2(World world, Random random, BlockPos pos) - { - if (world.getBlockState(pos).getBlock() != Blocks.BEDROCK && pos.getY() > 0) - { - this.setBlockAndMetadata(world, pos.add(-1, 0, -1), this.bark); - this.setBlockAndMetadata(world, pos.add(-1, 0, 0), this.bark); - - this.setBlockAndMetadata(world, pos.add(0, 0, -1), this.bark); - - this.setBlockAndMetadata(world, pos, this.bark); - } - - return true; - } - - public boolean genRing1(World world, Random random, BlockPos pos) - { - if (world.getBlockState(pos).getBlock() != Blocks.BEDROCK && pos.getY() > 0) - { - this.setBlockAndMetadata(world, pos, this.bark); - } - - return true; } protected void setBlockAndMetadata(World world, BlockPos pos, IBlockState stateNew) @@ -2077,7 +1936,7 @@ protected void setBlockAndMetadata(World world, BlockPos pos, IBlockState stateN } /** - * returns whether or not a tree can grow into a block + * returns whether a tree can grow into a block * For example, a tree will not grow into stone */ protected boolean canGrowInto(Block blockType) @@ -2213,9 +2072,9 @@ void limb(BlockPos pos1, BlockPos pos2, IBlockState state) { BlockPos blockpos = pos2.add(-pos1.getX(), -pos1.getY(), -pos1.getZ()); int i = this.getGreatestDistance(blockpos); - float f = (float) blockpos.getX() / (float) i; - float f1 = (float) blockpos.getY() / (float) i; - float f2 = (float) blockpos.getZ() / (float) i; + float f = (float) blockpos.getX() / i; + float f1 = (float) blockpos.getY() / i; + float f2 = (float) blockpos.getZ() / i; for (int j = 0; j <= i; ++j) { @@ -2236,7 +2095,7 @@ void generateLeaves() } /** - * Indicates whether or not a leaf node requires additional wood to be added to preserve integrity. + * Indicates whether a leaf node requires additional wood to be added to preserve integrity. */ boolean leafNodeNeedsBase(int p_76493_1_) { @@ -2268,28 +2127,23 @@ int checkBlockLine(BlockPos posOne, BlockPos posTwo) { BlockPos blockpos = posTwo.add(-posOne.getX(), -posOne.getY(), -posOne.getZ()); int i = this.getGreatestDistance(blockpos); - float f = (float) blockpos.getX() / (float) i; - float f1 = (float) blockpos.getY() / (float) i; - float f2 = (float) blockpos.getZ() / (float) i; + float f = (float) blockpos.getX() / i; + float f1 = (float) blockpos.getY() / i; + float f2 = (float) blockpos.getZ() / i; - if (i == 0) - { - return -1; - } - else + if (i != 0) { for (int j = 0; j <= i; ++j) { - BlockPos blockpos1 = posOne.add(0.5F + j * f, 0.5F + j * f1, 0.5F + j * f2); + BlockPos pos = posOne.add(0.5F + j * f, 0.5F + j * f1, 0.5F + j * f2); - if (!this.isReplaceable(this.world, blockpos1)) + if (!this.isReplaceable(this.world, pos)) { return j; } } - - return -1; } + return -1; } BlockPos findGround(World world, BlockPos pos) @@ -2313,8 +2167,7 @@ BlockPos findGround(World world, BlockPos pos) { foundGround = true; } - } - while (!foundGround); + } while (!foundGround); return new BlockPos(pos.getX(), height, pos.getZ()); } @@ -2337,8 +2190,7 @@ BlockPos findGround(World world, BlockPos pos) { foundGround = true; } - } - while (!foundGround); + } while (!foundGround); return new BlockPos(pos.getX(), height, pos.getZ()); } @@ -2352,7 +2204,7 @@ private int getGreatestDistance(BlockPos posIn) int i = MathHelper.abs(posIn.getX()); int j = MathHelper.abs(posIn.getY()); int k = MathHelper.abs(posIn.getZ()); - return k > i && k > j ? k : (j > i ? j : i); + return k > i && k > j ? k : (Math.max(j, i)); } //TODO: CHANGE EVERYTHING ABOVE. diff --git a/src/main/java/com/progwml6/natura/world/worldgen/trees/overworld/SakuraTreeGenerator.java b/src/main/java/com/progwml6/natura/world/worldgen/trees/overworld/SakuraTreeGenerator.java index 40da0a74..130cf6dd 100644 --- a/src/main/java/com/progwml6/natura/world/worldgen/trees/overworld/SakuraTreeGenerator.java +++ b/src/main/java/com/progwml6/natura/world/worldgen/trees/overworld/SakuraTreeGenerator.java @@ -11,8 +11,6 @@ import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; import net.minecraft.world.WorldType; -import net.minecraft.world.chunk.IChunkProvider; -import net.minecraft.world.gen.IChunkGenerator; import com.progwml6.natura.common.block.BlockEnumLog; import com.progwml6.natura.common.config.Config; @@ -50,22 +48,12 @@ public SakuraTreeGenerator(IBlockState log, IBlockState leaves, boolean findGrou this.leaves = leaves; } - public void setDecorationDefaults() - { - this.leafDistanceLimit = 5; - } - public boolean isReplaceable(World world, BlockPos pos) { net.minecraft.block.state.IBlockState state = world.getBlockState(pos); return state.getBlock().isAir(state, world, pos) || state.getBlock().isLeaves(state, world, pos); } - @Override - public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) - { - } - @Override public void generateTree(Random random, World worldIn, BlockPos position) { @@ -87,18 +75,14 @@ public void generateTree(Random random, World worldIn, BlockPos position) this.heightLimit = 5 + this.rand.nextInt(this.heightLimitLimit); } - if (!this.validTreeLocation()) - { - this.world = null; //Fix vanilla Mem leak, holds latest world - } - else + if (this.validTreeLocation()) { this.generateLeafNodeList(); this.generateLeaves(); this.generateTrunk(); this.generateLeafNodeBases(); - this.world = null; //Fix vanilla Mem leak, holds latest world } + this.world = null; //Fix vanilla Mem leak, holds latest world } protected void setBlockAndMetadata(World world, BlockPos pos, IBlockState stateNew) @@ -239,9 +223,9 @@ void limb(BlockPos p_175937_1_, BlockPos p_175937_2_, IBlockState state) { BlockPos blockpos = p_175937_2_.add(-p_175937_1_.getX(), -p_175937_1_.getY(), -p_175937_1_.getZ()); int i = this.getGreatestDistance(blockpos); - float f = (float) blockpos.getX() / (float) i; - float f1 = (float) blockpos.getY() / (float) i; - float f2 = (float) blockpos.getZ() / (float) i; + float f = (float) blockpos.getX() / i; + float f1 = (float) blockpos.getY() / i; + float f2 = (float) blockpos.getZ() / i; for (int j = 0; j <= i; ++j) { @@ -263,7 +247,7 @@ void generateLeaves() } /** - * Indicates whether or not a leaf node requires additional wood to be added to preserve integrity. + * Indicates whether a leaf node requires additional wood to be added to preserve integrity. */ boolean leafNodeNeedsBase(int p_76493_1_) { @@ -313,15 +297,11 @@ int checkBlockLine(BlockPos posOne, BlockPos posTwo) { BlockPos blockpos = posTwo.add(-posOne.getX(), -posOne.getY(), -posOne.getZ()); int i = this.getGreatestDistance(blockpos); - float f = (float) blockpos.getX() / (float) i; - float f1 = (float) blockpos.getY() / (float) i; - float f2 = (float) blockpos.getZ() / (float) i; + float f = (float) blockpos.getX() / i; + float f1 = (float) blockpos.getY() / i; + float f2 = (float) blockpos.getZ() / i; - if (i == 0) - { - return -1; - } - else + if (i != 0) { for (int j = 0; j <= i; ++j) { @@ -333,8 +313,8 @@ int checkBlockLine(BlockPos posOne, BlockPos posTwo) } } - return -1; } + return -1; } BlockPos findGround(World world, BlockPos pos) @@ -357,8 +337,7 @@ BlockPos findGround(World world, BlockPos pos) { foundGround = true; } - } - while (!foundGround); + } while (!foundGround); return new BlockPos(pos.getX(), height + 1, pos.getZ()); } @@ -380,8 +359,7 @@ BlockPos findGround(World world, BlockPos pos) { foundGround = true; } - } - while (!foundGround); + } while (!foundGround); return new BlockPos(pos.getX(), height + 1, pos.getZ()); } @@ -395,7 +373,7 @@ private int getGreatestDistance(BlockPos posIn) int i = MathHelper.abs(posIn.getX()); int j = MathHelper.abs(posIn.getY()); int k = MathHelper.abs(posIn.getZ()); - return k > i && k > j ? k : (j > i ? j : i); + return k > i && k > j ? k : (Math.max(j, i)); } private BlockEnumLog.EnumAxis getLogAxis(BlockPos p_175938_1_, BlockPos p_175938_2_) @@ -411,7 +389,7 @@ private BlockEnumLog.EnumAxis getLogAxis(BlockPos p_175938_1_, BlockPos p_175938 { enumaxis = BlockEnumLog.EnumAxis.X; } - else if (j == k) + else { enumaxis = BlockEnumLog.EnumAxis.Z; } @@ -421,7 +399,7 @@ else if (j == k) } /** - * Returns a boolean indicating whether or not the current location for the tree, spanning basePos to to the height + * Returns a boolean indicating whether the current location for the tree, spanning basePos to the height * limit, is valid. */ private boolean validTreeLocation() diff --git a/src/main/java/com/progwml6/natura/world/worldgen/trees/overworld/WillowTreeGenerator.java b/src/main/java/com/progwml6/natura/world/worldgen/trees/overworld/WillowTreeGenerator.java index 747ba9d3..7a79005c 100644 --- a/src/main/java/com/progwml6/natura/world/worldgen/trees/overworld/WillowTreeGenerator.java +++ b/src/main/java/com/progwml6/natura/world/worldgen/trees/overworld/WillowTreeGenerator.java @@ -10,8 +10,6 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.WorldType; -import net.minecraft.world.chunk.IChunkProvider; -import net.minecraft.world.gen.IChunkGenerator; import com.progwml6.natura.common.config.Config; import com.progwml6.natura.overworld.NaturaOverworld; @@ -46,11 +44,6 @@ public WillowTreeGenerator(int treeHeight, int treeRange, IBlockState log, IBloc this(treeHeight, treeRange, log, leaves, true, false); } - @Override - public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) - { - } - @Override public void generateTree(Random random, World worldIn, BlockPos position) { @@ -86,7 +79,7 @@ public void generateTree(Random random, World worldIn, BlockPos position) k = 3; } - BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); + BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos(); for (int l = position.getX() - k; l <= position.getX() + k && flag; ++l) { @@ -94,10 +87,10 @@ public void generateTree(Random random, World worldIn, BlockPos position) { if (j >= 0 && j < 128) { - IBlockState iblockstate = worldIn.getBlockState(blockpos$mutableblockpos.setPos(l, j, i1)); + IBlockState iblockstate = worldIn.getBlockState(mutableBlockPos.setPos(l, j, i1)); Block block = iblockstate.getBlock(); - if (!iblockstate.getBlock().isAir(iblockstate, worldIn, blockpos$mutableblockpos.setPos(l, j, i1)) && !iblockstate.getBlock().isLeaves(iblockstate, worldIn, blockpos$mutableblockpos.setPos(l, j, i1))) + if (!iblockstate.getBlock().isAir(iblockstate, worldIn, mutableBlockPos.setPos(l, j, i1)) && !iblockstate.getBlock().isLeaves(iblockstate, worldIn, mutableBlockPos.setPos(l, j, i1))) { if (block != Blocks.WATER && block != Blocks.FLOWING_WATER) { @@ -117,10 +110,7 @@ else if (j > position.getY()) } } - if (!flag) - { - } - else + if (flag) { BlockPos down = position.down(); IBlockState state = worldIn.getBlockState(down); @@ -173,20 +163,20 @@ else if (j > position.getY()) { int k2 = i2 - (position.getY() + height); int i3 = 2 - k2 / 2; - BlockPos.MutableBlockPos blockpos$mutableblockpos1 = new BlockPos.MutableBlockPos(); + BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos(); for (int l3 = position.getX() - i3; l3 <= position.getX() + i3; ++l3) { for (int j4 = position.getZ() - i3; j4 <= position.getZ() + i3; ++j4) { - blockpos$mutableblockpos1.setPos(l3, i2, j4); + mutableBlockPos.setPos(l3, i2, j4); - if (worldIn.getBlockState(blockpos$mutableblockpos1).getMaterial() == Material.LEAVES) + if (worldIn.getBlockState(mutableBlockPos).getMaterial() == Material.LEAVES) { - BlockPos blockpos3 = blockpos$mutableblockpos1.west(); - BlockPos blockpos4 = blockpos$mutableblockpos1.east(); - BlockPos blockpos1 = blockpos$mutableblockpos1.north(); - BlockPos blockpos2 = blockpos$mutableblockpos1.south(); + BlockPos blockpos3 = mutableBlockPos.west(); + BlockPos blockpos4 = mutableBlockPos.east(); + BlockPos blockpos1 = mutableBlockPos.north(); + BlockPos blockpos2 = mutableBlockPos.south(); if (random.nextInt(4) == 0 && this.isAir(worldIn, blockpos3)) { @@ -248,10 +238,7 @@ BlockPos findGround(World world, BlockPos pos) } height--; - } - while (height > Config.flatSeaLevel); - - return new BlockPos(pos.getX(), returnHeight, pos.getZ()); + } while (height > Config.flatSeaLevel); } else { @@ -269,11 +256,9 @@ BlockPos findGround(World world, BlockPos pos) } height--; - } - while (height > Config.seaLevel); - - return new BlockPos(pos.getX(), returnHeight, pos.getZ()); + } while (height > Config.seaLevel); } + return new BlockPos(pos.getX(), returnHeight, pos.getZ()); } private void addDownLeaves(World worldIn, BlockPos pos)