forked from jzitnik/twodcraft
fix: Leaves falling when base out of loaded radius
This commit is contained in:
parent
0bd9dfb412
commit
c1674d7866
@ -10,6 +10,7 @@ import java.util.*;
|
|||||||
@CustomLogic
|
@CustomLogic
|
||||||
public class LeavesFallingLogic implements CustomLogicInterface {
|
public class LeavesFallingLogic implements CustomLogicInterface {
|
||||||
private static final int RADIUS = 30;
|
private static final int RADIUS = 30;
|
||||||
|
private static final int SAFE_MARGIN = 5;
|
||||||
private final Random random = new Random();
|
private final Random random = new Random();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -40,13 +41,21 @@ public class LeavesFallingLogic implements CustomLogicInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!fallingLeaves.isEmpty() && random.nextInt(4) < 1) {
|
if (!fallingLeaves.isEmpty() && random.nextInt(4) < 1) {
|
||||||
int[] leafToRemove = fallingLeaves.get(random.nextInt(fallingLeaves.size()));
|
List<int[]> safeFallingLeaves = fallingLeaves.stream()
|
||||||
|
.filter(leaf -> leaf[0] > startX + SAFE_MARGIN &&
|
||||||
|
leaf[0] < endX - SAFE_MARGIN &&
|
||||||
|
leaf[1] > startY + SAFE_MARGIN &&
|
||||||
|
leaf[1] < endY - SAFE_MARGIN)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
if (!safeFallingLeaves.isEmpty()) {
|
||||||
|
int[] leafToRemove = safeFallingLeaves.get(random.nextInt(safeFallingLeaves.size()));
|
||||||
int leafX = leafToRemove[0];
|
int leafX = leafToRemove[0];
|
||||||
int leafY = leafToRemove[1];
|
int leafY = leafToRemove[1];
|
||||||
|
|
||||||
world[leafY][leafX].removeIf(block -> block.getBlockId().equals("oak_leaves"));
|
world[leafY][leafX].removeIf(block -> block.getBlockId().equals("oak_leaves"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Set<String> findSupportedLeaves(List<Block>[][] world, int startX, int startY, int endX, int endY) {
|
private Set<String> findSupportedLeaves(List<Block>[][] world, int startX, int startY, int endX, int endY) {
|
||||||
Set<String> supportedLeaves = new HashSet<>();
|
Set<String> supportedLeaves = new HashSet<>();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user