feat: Change grass logic to grow next to grass
This commit is contained in:
parent
fd6fcf950c
commit
f9b78f4236
@ -30,7 +30,7 @@ public class GrassGrowingLogic implements CustomLogicInterface {
|
||||
List<Block> blocks = world[y][x];
|
||||
if (blocks.stream().anyMatch(block -> block.getBlockId().equals("dirt"))) {
|
||||
// Dirt
|
||||
if (world[y - 1][x].stream().allMatch(block -> block.isGhost() || block.isMob() || block.getBlockId().equals("air")) && random.nextInt(3) < 1) {
|
||||
if (world[y - 1][x].stream().allMatch(block -> block.isGhost() || block.isMob() || block.getBlockId().equals("air")) && random.nextInt(3) < 1 && isGrassBesides(world, x, y)) {
|
||||
world[y][x].removeIf(block -> block.getBlockId().equals("dirt"));
|
||||
world[y][x].add(ItemBlockSupplier.getBlock("grass"));
|
||||
}
|
||||
@ -46,4 +46,35 @@ public class GrassGrowingLogic implements CustomLogicInterface {
|
||||
|
||||
}
|
||||
|
||||
private boolean isGrass(List<Block>[][] world, int x, int y) {
|
||||
return world[y][x].stream().anyMatch(i -> i.getBlockId().equals("grass"));
|
||||
}
|
||||
|
||||
private boolean isGrassBesides(List<Block>[][] world, int x, int y) {
|
||||
if (isGrass(world, x + 1, y)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isGrass(world, x + 1, y + 1)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isGrass(world, x + 1, y - 1)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isGrass(world, x - 1, y)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isGrass(world, x - 1, y + 1)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isGrass(world, x - 1, y - 1)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user