mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-18 11:19:28 +00:00
Clean up LeafDecayHelper
This commit is contained in:
1 parent
586ecec9fe
commit
a84ad5c828
1 file changed
+20
-24
@@ -8,8 +8,6 @@ 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 in {@link BlockLeaves#updateTick(World, BlockPos, IBlockState, Random)}
|
||||
* but accepts leaves that are connected further from a trunk
|
||||
@@ -19,10 +17,10 @@ public class LeafDecayHelper {
|
||||
private static final byte NOT_SUSTAINS_LEAVES = -1;
|
||||
private static final byte IS_LEAVES = -2;
|
||||
private static final int ARRAY_SIZE = 32;
|
||||
private static final byte[] leafDecayValues;
|
||||
private static final byte[][][] leafDecayValues;
|
||||
|
||||
static {
|
||||
leafDecayValues = new byte[ARRAY_SIZE * ARRAY_SIZE * ARRAY_SIZE];
|
||||
leafDecayValues = new byte[ARRAY_SIZE][ARRAY_SIZE][ARRAY_SIZE];
|
||||
}
|
||||
|
||||
public static void leafDecay(BlockLeaves leaves, World world, BlockPos pos) {
|
||||
@@ -33,11 +31,9 @@ public class LeafDecayHelper {
|
||||
|
||||
if (state.getValue(BlockLeaves.CHECK_DECAY) && state.getValue(BlockLeaves.DECAYABLE)) {
|
||||
byte radius = 4;
|
||||
int xArrayMult = ARRAY_SIZE * ARRAY_SIZE;
|
||||
int arrayOffset = ARRAY_SIZE / 2;
|
||||
|
||||
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)) {
|
||||
if (world.isAreaLoaded(pos, radius + 1)) {
|
||||
for (int xOffset = -radius; xOffset <= radius; ++xOffset) {
|
||||
for (int yOffset = -radius; yOffset <= radius; ++yOffset) {
|
||||
for (int zOffset = -radius; zOffset <= radius; ++zOffset) {
|
||||
@@ -46,12 +42,12 @@ public class LeafDecayHelper {
|
||||
Block block = blockState.getBlock();
|
||||
if (!block.canSustainLeaves(blockState, world, blockPos)) {
|
||||
if (block.isLeaves(blockState, world, blockPos)) {
|
||||
leafDecayValues[(xOffset + arrayOffset) * xArrayMult + (yOffset + arrayOffset) * ARRAY_SIZE + zOffset + arrayOffset] = IS_LEAVES;
|
||||
leafDecayValues[xOffset + arrayOffset][yOffset + arrayOffset][zOffset + arrayOffset] = IS_LEAVES;
|
||||
} else {
|
||||
leafDecayValues[(xOffset + arrayOffset) * xArrayMult + (yOffset + arrayOffset) * ARRAY_SIZE + zOffset + arrayOffset] = NOT_SUSTAINS_LEAVES;
|
||||
leafDecayValues[xOffset + arrayOffset][yOffset + arrayOffset][zOffset + arrayOffset] = NOT_SUSTAINS_LEAVES;
|
||||
}
|
||||
} else {
|
||||
leafDecayValues[(xOffset + arrayOffset) * xArrayMult + (yOffset + arrayOffset) * ARRAY_SIZE + zOffset + arrayOffset] = SUSTAINS_LEAVES;
|
||||
leafDecayValues[xOffset + arrayOffset][yOffset + arrayOffset][zOffset + arrayOffset] = SUSTAINS_LEAVES;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,29 +57,29 @@ public class LeafDecayHelper {
|
||||
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) * ARRAY_SIZE + zOffset + arrayOffset] == sustainedValue - 1) {
|
||||
if (leafDecayValues[(xOffset + arrayOffset - 1) * xArrayMult + (yOffset + arrayOffset) * ARRAY_SIZE + zOffset + arrayOffset] == IS_LEAVES) {
|
||||
leafDecayValues[(xOffset + arrayOffset - 1) * xArrayMult + (yOffset + arrayOffset) * ARRAY_SIZE + zOffset + arrayOffset] = sustainedValue;
|
||||
if (leafDecayValues[xOffset + arrayOffset][yOffset + arrayOffset][zOffset + arrayOffset] == sustainedValue - 1) {
|
||||
if (leafDecayValues[(xOffset + arrayOffset - 1)][yOffset + arrayOffset][zOffset + arrayOffset] == IS_LEAVES) {
|
||||
leafDecayValues[(xOffset + arrayOffset - 1)][yOffset + arrayOffset][zOffset + arrayOffset] = sustainedValue;
|
||||
}
|
||||
|
||||
if (leafDecayValues[(xOffset + arrayOffset + 1) * xArrayMult + (yOffset + arrayOffset) * ARRAY_SIZE + zOffset + arrayOffset] == IS_LEAVES) {
|
||||
leafDecayValues[(xOffset + arrayOffset + 1) * xArrayMult + (yOffset + arrayOffset) * ARRAY_SIZE + zOffset + arrayOffset] = sustainedValue;
|
||||
if (leafDecayValues[(xOffset + arrayOffset + 1)][yOffset + arrayOffset][zOffset + arrayOffset] == IS_LEAVES) {
|
||||
leafDecayValues[(xOffset + arrayOffset + 1)][yOffset + arrayOffset][zOffset + arrayOffset] = sustainedValue;
|
||||
}
|
||||
|
||||
if (leafDecayValues[(xOffset + arrayOffset) * xArrayMult + (yOffset + arrayOffset - 1) * ARRAY_SIZE + zOffset + arrayOffset] == IS_LEAVES) {
|
||||
leafDecayValues[(xOffset + arrayOffset) * xArrayMult + (yOffset + arrayOffset - 1) * ARRAY_SIZE + zOffset + arrayOffset] = sustainedValue;
|
||||
if (leafDecayValues[xOffset + arrayOffset][(yOffset + arrayOffset - 1)][zOffset + arrayOffset] == IS_LEAVES) {
|
||||
leafDecayValues[xOffset + arrayOffset][(yOffset + arrayOffset - 1)][zOffset + arrayOffset] = sustainedValue;
|
||||
}
|
||||
|
||||
if (leafDecayValues[(xOffset + arrayOffset) * xArrayMult + (yOffset + arrayOffset + 1) * ARRAY_SIZE + zOffset + arrayOffset] == IS_LEAVES) {
|
||||
leafDecayValues[(xOffset + arrayOffset) * xArrayMult + (yOffset + arrayOffset + 1) * ARRAY_SIZE + zOffset + arrayOffset] = sustainedValue;
|
||||
if (leafDecayValues[xOffset + arrayOffset][(yOffset + arrayOffset + 1)][zOffset + arrayOffset] == IS_LEAVES) {
|
||||
leafDecayValues[xOffset + arrayOffset][(yOffset + arrayOffset + 1)][zOffset + arrayOffset] = sustainedValue;
|
||||
}
|
||||
|
||||
if (leafDecayValues[(xOffset + arrayOffset) * xArrayMult + (yOffset + arrayOffset) * ARRAY_SIZE + zOffset + arrayOffset - 1] == IS_LEAVES) {
|
||||
leafDecayValues[(xOffset + arrayOffset) * xArrayMult + (yOffset + arrayOffset) * ARRAY_SIZE + zOffset + arrayOffset - 1] = sustainedValue;
|
||||
if (leafDecayValues[xOffset + arrayOffset][yOffset + arrayOffset][zOffset + arrayOffset - 1] == IS_LEAVES) {
|
||||
leafDecayValues[xOffset + arrayOffset][yOffset + arrayOffset][zOffset + arrayOffset - 1] = sustainedValue;
|
||||
}
|
||||
|
||||
if (leafDecayValues[(xOffset + arrayOffset) * xArrayMult + (yOffset + arrayOffset) * ARRAY_SIZE + zOffset + arrayOffset + 1] == IS_LEAVES) {
|
||||
leafDecayValues[(xOffset + arrayOffset) * xArrayMult + (yOffset + arrayOffset) * ARRAY_SIZE + zOffset + arrayOffset + 1] = sustainedValue;
|
||||
if (leafDecayValues[xOffset + arrayOffset][yOffset + arrayOffset][zOffset + arrayOffset + 1] == IS_LEAVES) {
|
||||
leafDecayValues[xOffset + arrayOffset][yOffset + arrayOffset][zOffset + arrayOffset + 1] = sustainedValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,7 +88,7 @@ public class LeafDecayHelper {
|
||||
}
|
||||
}
|
||||
|
||||
byte sustainValue = leafDecayValues[arrayOffset * xArrayMult + arrayOffset * ARRAY_SIZE + arrayOffset];
|
||||
byte sustainValue = leafDecayValues[arrayOffset][arrayOffset][arrayOffset];
|
||||
|
||||
if (sustainValue >= 0) {
|
||||
world.setBlockState(pos, state.withProperty(BlockLeaves.CHECK_DECAY, false), 4); // stop trying to decay
|
||||
|
||||
Reference in new issue
Block a user