diff --git a/src/main/java/forestry/arboriculture/LeafDecayHelper.java b/src/main/java/forestry/arboriculture/LeafDecayHelper.java deleted file mode 100644 index 5cac5916b..000000000 --- a/src/main/java/forestry/arboriculture/LeafDecayHelper.java +++ /dev/null @@ -1,102 +0,0 @@ -package forestry.arboriculture; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockLeaves; -import net.minecraft.block.state.IBlockState; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; - -import forestry.core.utils.BlockUtil; - -/** Based on vanilla leaf decay, but accepts leaves that are connected further from a trunk */ -public abstract class LeafDecayHelper { - private static final short SUSTAINS_LEAVES = 0; - private static final short NOT_SUSTAINS_LEAVES = -1; - private static final short IS_LEAVES = -2; - private static int[] leafDecayValues; - - public static void leafDecay(BlockLeaves leaves, World world, BlockPos pos) { - if (world.isRemote) { - return; - } - IBlockState state = world.getBlockState(pos); - - int leafMeta = state.getBlock().getMetaFromState(state); - - if ((leafMeta & 8) != 0 && (leafMeta & 4) == 0) { - byte radius = 4; - byte yArrayMult = 32; - int xArrayMult = yArrayMult * yArrayMult; - int arrayOffset = yArrayMult / 2; - - if (leafDecayValues == null) { - leafDecayValues = new int[yArrayMult * yArrayMult * yArrayMult]; - } - - int radius1 = radius + 1; - if (BlockUtil.checkChunksExist(world, pos.getX() - radius1, pos.getY() - radius1, pos.getZ() - radius1, pos.getX() + radius1, pos.getY() + radius1, pos.getZ() + radius1)) { - for (int xOffset = -radius; xOffset <= radius; ++xOffset) { - for (int yOffset = -radius; yOffset <= radius; ++yOffset) { - for (int zOffset = -radius; zOffset <= radius; ++zOffset) { - BlockPos blockPos = pos.add(xOffset, yOffset, zOffset); - IBlockState blockState = world.getBlockState(blockPos); - Block block = blockState.getBlock(); - if (!block.canSustainLeaves(blockState, world, blockPos)) { - if (block.isLeaves(blockState, world, blockPos)) { - leafDecayValues[(xOffset + arrayOffset) * xArrayMult + (yOffset + arrayOffset) * yArrayMult + zOffset + arrayOffset] = IS_LEAVES; - } else { - leafDecayValues[(xOffset + arrayOffset) * xArrayMult + (yOffset + arrayOffset) * yArrayMult + zOffset + arrayOffset] = NOT_SUSTAINS_LEAVES; - } - } else { - leafDecayValues[(xOffset + arrayOffset) * xArrayMult + (yOffset + arrayOffset) * yArrayMult + zOffset + arrayOffset] = SUSTAINS_LEAVES; - } - } - } - } - - for (int sustainedValue = 1; sustainedValue <= 8; ++sustainedValue) { - for (int xOffset = -radius; xOffset <= radius; ++xOffset) { - for (int yOffset = -radius; yOffset <= radius; ++yOffset) { - for (int zOffset = -radius; zOffset <= radius; ++zOffset) { - if (leafDecayValues[(xOffset + arrayOffset) * xArrayMult + (yOffset + arrayOffset) * yArrayMult + zOffset + arrayOffset] == sustainedValue - 1) { - if (leafDecayValues[(xOffset + arrayOffset - 1) * xArrayMult + (yOffset + arrayOffset) * yArrayMult + zOffset + arrayOffset] == IS_LEAVES) { - leafDecayValues[(xOffset + arrayOffset - 1) * xArrayMult + (yOffset + arrayOffset) * yArrayMult + zOffset + arrayOffset] = sustainedValue; - } - - if (leafDecayValues[(xOffset + arrayOffset + 1) * xArrayMult + (yOffset + arrayOffset) * yArrayMult + zOffset + arrayOffset] == IS_LEAVES) { - leafDecayValues[(xOffset + arrayOffset + 1) * xArrayMult + (yOffset + arrayOffset) * yArrayMult + zOffset + arrayOffset] = sustainedValue; - } - - if (leafDecayValues[(xOffset + arrayOffset) * xArrayMult + (yOffset + arrayOffset - 1) * yArrayMult + zOffset + arrayOffset] == IS_LEAVES) { - leafDecayValues[(xOffset + arrayOffset) * xArrayMult + (yOffset + arrayOffset - 1) * yArrayMult + zOffset + arrayOffset] = sustainedValue; - } - - if (leafDecayValues[(xOffset + arrayOffset) * xArrayMult + (yOffset + arrayOffset + 1) * yArrayMult + zOffset + arrayOffset] == IS_LEAVES) { - leafDecayValues[(xOffset + arrayOffset) * xArrayMult + (yOffset + arrayOffset + 1) * yArrayMult + zOffset + arrayOffset] = sustainedValue; - } - - if (leafDecayValues[(xOffset + arrayOffset) * xArrayMult + (yOffset + arrayOffset) * yArrayMult + zOffset + arrayOffset - 1] == IS_LEAVES) { - leafDecayValues[(xOffset + arrayOffset) * xArrayMult + (yOffset + arrayOffset) * yArrayMult + zOffset + arrayOffset - 1] = sustainedValue; - } - - if (leafDecayValues[(xOffset + arrayOffset) * xArrayMult + (yOffset + arrayOffset) * yArrayMult + zOffset + arrayOffset + 1] == IS_LEAVES) { - leafDecayValues[(xOffset + arrayOffset) * xArrayMult + (yOffset + arrayOffset) * yArrayMult + zOffset + arrayOffset + 1] = sustainedValue; - } - } - } - } - } - } - } - - int sustainValue = leafDecayValues[arrayOffset * xArrayMult + arrayOffset * yArrayMult + arrayOffset]; - - if (sustainValue >= 0) { - world.setBlockState(pos, state.getBlock().getStateFromMeta(leafMeta & -9), 4); // stop trying to decay - } else { - leaves.dropBlockAsItem(world, pos, state, 0); - world.setBlockToAir(pos); - } - } - } -} diff --git a/src/main/java/forestry/arboriculture/blocks/BlockForestryLeaves.java b/src/main/java/forestry/arboriculture/blocks/BlockForestryLeaves.java index ca80bb2e4..5dd113db5 100644 --- a/src/main/java/forestry/arboriculture/blocks/BlockForestryLeaves.java +++ b/src/main/java/forestry/arboriculture/blocks/BlockForestryLeaves.java @@ -61,7 +61,6 @@ import forestry.api.core.Tabs; import forestry.api.lepidopterology.ButterflyManager; import forestry.api.lepidopterology.EnumFlutterType; import forestry.api.lepidopterology.IButterfly; -import forestry.arboriculture.LeafDecayHelper; import forestry.arboriculture.PluginArboriculture; import forestry.arboriculture.genetics.TreeDefinition; import forestry.arboriculture.tiles.TileLeaves; @@ -214,15 +213,6 @@ public class BlockForestryLeaves extends BlockLeaves implements ITileEntityProvi return Collections.singletonList(PluginArboriculture.blocks.getDecorativeLeaves(speciesUid)); } - @Override - public void beginLeavesDecay(IBlockState state, World world, BlockPos pos) { - TileLeaves tile = TileUtil.getTile(world, pos, TileLeaves.class); - if (tile == null) { - return; - } - super.beginLeavesDecay(state, world, pos); - } - @Override public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, World worldIn, BlockPos pos) { TileLeaves tileLeaves = TileUtil.getTile(worldIn, pos, TileLeaves.class); @@ -241,22 +231,14 @@ public class BlockForestryLeaves extends BlockLeaves implements ITileEntityProvi @Override public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) { + super.updateTick(world, pos, state, rand); + TileLeaves tileLeaves = TileUtil.getTile(world, pos, TileLeaves.class); - if (tileLeaves == null) { - return; - } - LeafDecayHelper.leafDecay(this, world, pos); - - // check leaves tile again because they can decay in super.updateTick - if (tileLeaves.isInvalid()) { - return; + // check leaves tile because they can decay in super.updateTick + if (tileLeaves != null && !tileLeaves.isInvalid() && world.rand.nextFloat() <= 0.1) { + tileLeaves.onBlockTick(); } - - if (world.rand.nextFloat() > 0.1) { - return; - } - tileLeaves.onBlockTick(); } /* RENDERING */