mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-24 05:44:24 +00:00
Fix #1204 Leaves do not decay
This commit is contained in:
1 parent
78a955e3ea
commit
62368d4e40
2 files changed
+5
-125
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user