feat: Change grass logic to grow next to grass

This commit is contained in:
Jakub Žitník 2025-03-13 10:39:00 +01:00
parent fd6fcf950c
commit f9b78f4236
Signed by: jzitnik
GPG Key ID: C577A802A6AF4EF3

View File

@ -30,7 +30,7 @@ public class GrassGrowingLogic implements CustomLogicInterface {
List<Block> blocks = world[y][x]; List<Block> blocks = world[y][x];
if (blocks.stream().anyMatch(block -> block.getBlockId().equals("dirt"))) { if (blocks.stream().anyMatch(block -> block.getBlockId().equals("dirt"))) {
// 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].removeIf(block -> block.getBlockId().equals("dirt"));
world[y][x].add(ItemBlockSupplier.getBlock("grass")); 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;
}
} }