From c572546353ca21ed5c78fcc170057ed9c34575f3 Mon Sep 17 00:00:00 2001 From: Adubbz Date: Sun, 29 Mar 2015 10:29:01 +1100 Subject: [PATCH] Fixed redwood tree growth --- .../blocks/ColorizedLeavesRenderer.java | 4 +- .../features/trees/WorldGenRedwoodTree2.java | 287 ++++++++---------- 2 files changed, 124 insertions(+), 167 deletions(-) diff --git a/src/main/java/biomesoplenty/client/render/blocks/ColorizedLeavesRenderer.java b/src/main/java/biomesoplenty/client/render/blocks/ColorizedLeavesRenderer.java index 440982a2b..12a3fac43 100644 --- a/src/main/java/biomesoplenty/client/render/blocks/ColorizedLeavesRenderer.java +++ b/src/main/java/biomesoplenty/client/render/blocks/ColorizedLeavesRenderer.java @@ -39,7 +39,7 @@ public class ColorizedLeavesRenderer implements ISimpleBlockRenderingHandler int metadata = world.getBlockMetadata(x, y, z); - if (metadata % 4 == 3 && renderer.hasOverrideBlockTexture()) + if (block == BOPCBlocks.colorizedLeaves2 && metadata % 4 == 3 && renderer.hasOverrideBlockTexture()) { renderer.setOverrideBlockTexture(renderer.overrideBlockTexture); renderer.renderStandardBlock(block, x, y, z); @@ -49,7 +49,7 @@ public class ColorizedLeavesRenderer implements ISimpleBlockRenderingHandler { renderer.renderStandardBlock(block, x, y, z); - if (metadata % 4 == 3) + if (block == BOPCBlocks.colorizedLeaves2 && metadata % 4 == 3) { renderer.setOverrideBlockTexture(leavesBlock.floweringIcon); renderer.renderStandardBlock(Blocks.stone, x, y, z); diff --git a/src/main/java/biomesoplenty/common/world/features/trees/WorldGenRedwoodTree2.java b/src/main/java/biomesoplenty/common/world/features/trees/WorldGenRedwoodTree2.java index 6d659aaed..367790d40 100644 --- a/src/main/java/biomesoplenty/common/world/features/trees/WorldGenRedwoodTree2.java +++ b/src/main/java/biomesoplenty/common/world/features/trees/WorldGenRedwoodTree2.java @@ -39,195 +39,152 @@ public class WorldGenRedwoodTree2 extends WorldGenAbstractTree @Override public boolean generate(World world, Random random, int x, int y, int z) { - int l = random.nextInt(this.randomTreeHeight) + this.minTreeHeight; - boolean flag = true; + int treeHeight = random.nextInt(this.randomTreeHeight) + this.minTreeHeight; - if (y >= 1 && y + l + 1 <= 256) + if (y >= 1 && y + treeHeight + 1 <= 256) { - byte b0; - int k1; - Block block; + byte width; + int k1; + Block block; - for (int i1 = y; i1 <= y + 1 + l; ++i1) - { - b0 = 5; + boolean isSoil = true; + boolean hasSpace = true; - if (i1 == y) - { - b0 = 5; - } + for (int ix = -2; ix <= 2; ix++) + { + for (int iz = -2; iz <= 2; iz++) + { + Block block2 = world.getBlock(x + ix, y - 1, z + iz); - if (i1 >= y + 1 + l - 2) - { - b0 = 6; - } + if (!block2.canSustainPlant(world, x + ix, y - 1, z + iz, ForgeDirection.UP, (BlockSapling)Blocks.sapling)) + { + isSoil = false; + break; + } + } + } - for (int j1 = x - b0; j1 <= x + b0 && flag; ++j1) - { - for (k1 = z - b0; k1 <= z + b0 && flag; ++k1) - { - if (i1 >= 0 && i1 < 256) - { - block = world.getBlock(j1, i1, k1); + for (int ix = -2; ix <= 2; ix++) + { + for (int iy = 0; iy <= treeHeight; iy++) + { + for (int iz = -2; iz <= 2; iz++) + { + Block block2 = world.getBlock(x + ix, y + iy, z + iz); - if (!this.isReplaceable(world, j1, i1, k1)) - { - flag = false; - } - } - else - { - flag = false; - } - } - } - } + if (!block2.isAir(world, x + ix, y + iy, z + iz)) + { + hasSpace = false; + break; + } + } + } + } - if (!flag) - { - return false; - } - else - { - boolean isSoil = true; - boolean hasSpace = true; - - for (int ix = -2; ix <= 2; ix++) - { - for (int iz = -2; iz <= 2; iz++) - { - Block block2 = world.getBlock(x + ix, y - 1, z + iz); - - if (!block2.canSustainPlant(world, x + ix, y - 1, z + iz, ForgeDirection.UP, (BlockSapling)Blocks.sapling)) - { - isSoil = false; - break; - } - } - } - - for (int ix = -2; ix <= 2; ix++) - { - for (int iy = 0; iy <= l; iy++) - { - for (int iz = -2; iz <= 2; iz++) - { - Block block2 = world.getBlock(x + ix, y + iy, z + iz); + if (isSoil && hasSpace && y < 256 - treeHeight - 1) + { + for (int ix = -2; ix <= 2; ix++) + { + for (int iz = -2; iz <= 2; iz++) + { + if (((ix != -2 && ix != 2) || (iz == 0)) && ((iz != -2 && iz != 2) || (ix == 0))) + { + Block block2 = world.getBlock(x + ix, y - 1, z + iz); - if (!block2.isAir(world, x + ix, y + iy, z + iz)) - { - hasSpace = false; - break; - } - } - } - } - - if (isSoil && hasSpace && y < 256 - l - 1) - { - for (int ix = -2; ix <= 2; ix++) - { - for (int iz = -2; iz <= 2; iz++) - { - if (((ix != -2 && ix != 2) || (iz == 0)) && ((iz != -2 && iz != 2) || (ix == 0))) - { - Block block2 = world.getBlock(x + ix, y - 1, z + iz); + block2.onPlantGrow(world, x + ix, y - 1, z + iz, x + ix, y - 1, z + iz); + } + } + } - block2.onPlantGrow(world, x + ix, y - 1, z + iz, x + ix, y - 1, z + iz); - } - } - } - - b0 = 9; - byte b1 = 0; - int l1; - int i2; - int j2; - int i3; + width = 9; + byte b1 = 0; + int l1; + int i2; + int j2; + int i3; - for (k1 = y - b0 + l; k1 <= y + l; ++k1) - { - i3 = k1 - (y + l); - l1 = b1 + 1 - i3 / 6; + for (k1 = y - width + treeHeight; k1 <= y + treeHeight; ++k1) + { + i3 = k1 - (y + treeHeight); + l1 = b1 + 1 - i3 / 6; - for (i2 = x - l1; i2 <= x + l1; ++i2) - { - j2 = i2 - x; + for (i2 = x - l1; i2 <= x + l1; ++i2) + { + j2 = i2 - x; - for (int k2 = z - l1; k2 <= z + l1; ++k2) - { - int l2 = k2 - z; + for (int k2 = z - l1; k2 <= z + l1; ++k2) + { + int l2 = k2 - z; - if (Math.abs(j2) != l1 || Math.abs(l2) != l1 || random.nextInt(2) != 0 && i3 != 0) - { - Block block1 = world.getBlock(i2, k1, k2); + if (Math.abs(j2) != l1 || Math.abs(l2) != l1 || random.nextInt(2) != 0 && i3 != 0) + { + Block block1 = world.getBlock(i2, k1, k2); - if (block1.isAir(world, i2, k1, k2) || block1.isLeaves(world, i2, k1, k2)) - { - //TODO: setBlockAndMetadata() - //this.setBlockAndNotifyAdequately(world, i2, k1, k2, this.leaves, this.leavesMeta); - this.setBlockAndNotifyAdequately(world, i2, k1 + 6, k2, this.leaves, this.leavesMeta); - this.setBlockAndNotifyAdequately(world, i2, k1 + 12, k2, this.leaves, this.leavesMeta); - } - } - } - } - } + if (block1.isAir(world, i2, k1, k2) || block1.isLeaves(world, i2, k1, k2)) + { + //TODO: setBlockAndMetadata() + //this.setBlockAndNotifyAdequately(world, i2, k1, k2, this.leaves, this.leavesMeta); + this.setBlockAndNotifyAdequately(world, i2, k1 + 6, k2, this.leaves, this.leavesMeta); + this.setBlockAndNotifyAdequately(world, i2, k1 + 12, k2, this.leaves, this.leavesMeta); + } + } + } + } + } - for (k1 = 0; k1 < l; ++k1) - { - block = world.getBlock(x, y + k1, z); + for (k1 = 0; k1 < treeHeight; ++k1) + { + block = world.getBlock(x, y + k1, z); - if (block.isAir(world, x, y + k1, z) || block.isLeaves(world, x, y + k1, z)) - { - //1 - this.setBlockAndNotifyAdequately(world, x, y + (l), z, this.wood, this.woodMeta); - this.setBlockAndNotifyAdequately(world, x, y + (l + 1), z, this.wood, this.woodMeta); - this.setBlockAndNotifyAdequately(world, x, y + (l + 2), z, this.wood, this.woodMeta); - this.setBlockAndNotifyAdequately(world, x, y + (l + 3), z, this.wood, this.woodMeta); - this.setBlockAndNotifyAdequately(world, x, y + (l + 4), z, this.wood, this.woodMeta); - this.setBlockAndNotifyAdequately(world, x, y + (l + 5), z, this.wood, this.woodMeta); - this.setBlockAndNotifyAdequately(world, x, y + k1, z, this.wood, this.woodMeta); + if (block.isAir(world, x, y + k1, z) || block.isLeaves(world, x, y + k1, z)) + { + //1 + this.setBlockAndNotifyAdequately(world, x, y + (treeHeight), z, this.wood, this.woodMeta); + this.setBlockAndNotifyAdequately(world, x, y + (treeHeight + 1), z, this.wood, this.woodMeta); + this.setBlockAndNotifyAdequately(world, x, y + (treeHeight + 2), z, this.wood, this.woodMeta); + this.setBlockAndNotifyAdequately(world, x, y + (treeHeight + 3), z, this.wood, this.woodMeta); + this.setBlockAndNotifyAdequately(world, x, y + (treeHeight + 4), z, this.wood, this.woodMeta); + this.setBlockAndNotifyAdequately(world, x, y + (treeHeight + 5), z, this.wood, this.woodMeta); + this.setBlockAndNotifyAdequately(world, x, y + k1, z, this.wood, this.woodMeta); - //2 - this.setBlockAndNotifyAdequately(world, x - 1, y + MathHelper.floor_double(k1 * 0.75), z, this.wood, this.woodMeta); - this.setBlockAndNotifyAdequately(world, x + 1, y + MathHelper.floor_double(k1 * 0.75), z, this.wood, this.woodMeta); - this.setBlockAndNotifyAdequately(world, x, y + MathHelper.floor_double(k1 * 0.75), z - 1, this.wood, this.woodMeta); - this.setBlockAndNotifyAdequately(world, x, y + MathHelper.floor_double(k1 * 0.75), z + 1, this.wood, this.woodMeta); + //2 + this.setBlockAndNotifyAdequately(world, x - 1, y + MathHelper.floor_double(k1 * 0.75), z, this.wood, this.woodMeta); + this.setBlockAndNotifyAdequately(world, x + 1, y + MathHelper.floor_double(k1 * 0.75), z, this.wood, this.woodMeta); + this.setBlockAndNotifyAdequately(world, x, y + MathHelper.floor_double(k1 * 0.75), z - 1, this.wood, this.woodMeta); + this.setBlockAndNotifyAdequately(world, x, y + MathHelper.floor_double(k1 * 0.75), z + 1, this.wood, this.woodMeta); - //3 - this.setBlockAndNotifyAdequately(world, x - 1, y + (k1 / 2), z - 1, this.wood, this.woodMeta); - this.setBlockAndNotifyAdequately(world, x + 1, y + (k1 / 2), z - 1, this.wood, this.woodMeta); - this.setBlockAndNotifyAdequately(world, x - 1, y + (k1 / 2), z + 1, this.wood, this.woodMeta); - this.setBlockAndNotifyAdequately(world, x + 1, y + (k1 / 2), z + 1, this.wood, this.woodMeta); + //3 + this.setBlockAndNotifyAdequately(world, x - 1, y + (k1 / 2), z - 1, this.wood, this.woodMeta); + this.setBlockAndNotifyAdequately(world, x + 1, y + (k1 / 2), z - 1, this.wood, this.woodMeta); + this.setBlockAndNotifyAdequately(world, x - 1, y + (k1 / 2), z + 1, this.wood, this.woodMeta); + this.setBlockAndNotifyAdequately(world, x + 1, y + (k1 / 2), z + 1, this.wood, this.woodMeta); - //4 - this.setBlockAndNotifyAdequately(world, x - 2, y + (k1 / 4), z, this.wood, this.woodMeta); - this.setBlockAndNotifyAdequately(world, x + 2, y + (k1 / 4), z, this.wood, this.woodMeta); - this.setBlockAndNotifyAdequately(world, x, y + (k1 / 4), z - 2, this.wood, this.woodMeta); - this.setBlockAndNotifyAdequately(world, x, y + (k1 / 4), z + 2, this.wood, this.woodMeta); - } - } - - for (int i = 0; i < 90; ++i) - { - int randX = x - random.nextInt(8) + random.nextInt(8); - int randY = y + random.nextInt(64); - int randZ = z - random.nextInt(8) + random.nextInt(8); - new WorldGenBOPShrub(BOPCBlocks.logs3, BOPCBlocks.colorizedLeaves1, 0, 3, BOPCBlocks.logs3).generate(world, random, randX, randY, randZ); - } + //4 + this.setBlockAndNotifyAdequately(world, x - 2, y + (k1 / 4), z, this.wood, this.woodMeta); + this.setBlockAndNotifyAdequately(world, x + 2, y + (k1 / 4), z, this.wood, this.woodMeta); + this.setBlockAndNotifyAdequately(world, x, y + (k1 / 4), z - 2, this.wood, this.woodMeta); + this.setBlockAndNotifyAdequately(world, x, y + (k1 / 4), z + 2, this.wood, this.woodMeta); + } + } - return true; - } - else - { - return false; - } - } + for (int i = 0; i < 90; ++i) + { + int randX = x - random.nextInt(8) + random.nextInt(8); + int randY = y + random.nextInt(64); + int randZ = z - random.nextInt(8) + random.nextInt(8); + new WorldGenBOPShrub(BOPCBlocks.logs3, BOPCBlocks.colorizedLeaves1, 0, 3, BOPCBlocks.logs3).generate(world, random, randX, randY, randZ); + } + + return true; + } + else + { + return false; + } } else { - return false; + return false; } } } \ No newline at end of file