Compare commits

...

2 Commits

Author SHA1 Message Date
tastybento 3f4647b547 Refactor to reduce complexity 2023-06-04 17:44:01 -07:00
tastybento e75780e710 Refactor to reduce complexity 2023-06-04 17:36:08 -07:00
2 changed files with 41 additions and 42 deletions

View File

@ -241,36 +241,39 @@ public class EcoSystemManager {
for (double z = ibb.getMinZ(); z < ibb.getMaxZ(); z++) { for (double z = ibb.getMinZ(); z < ibb.getMaxZ(); z++) {
for (double y = ibb.getMaxY() - 1; y >= bb.getMinY(); y--) { for (double y = ibb.getMaxY() - 1; y >= bb.getMinY(); y--) {
Block b = gh.getWorld().getBlockAt(NumberConversions.floor(x), NumberConversions.floor(y), NumberConversions.floor(z)); Block b = gh.getWorld().getBlockAt(NumberConversions.floor(x), NumberConversions.floor(y), NumberConversions.floor(z));
if (checkBlock(result, b, ignoreLiquid)) {
// Check floor blocks break;
if (!ignoreLiquid) {
// Check ceiling blocks
if (b.isEmpty() && !b.getRelative(BlockFace.UP).isEmpty()) {
result.add(new GrowthBlock(b, false));
}
if (!b.isEmpty() && !Tag.LEAVES.isTagged(b.getType())
&& (b.getRelative(BlockFace.UP).isEmpty()
|| b.getRelative(BlockFace.UP).isPassable()
|| Tag.LEAVES.isTagged(b.getRelative(BlockFace.UP).getType())
)
) {
result.add(new GrowthBlock(b.getRelative(BlockFace.UP), true));
break;
}
} else {
if (!b.isEmpty() && !b.isLiquid() && b.getRelative(BlockFace.UP).isLiquid()) {
result.add(new GrowthBlock(b.getRelative(BlockFace.UP), true));
break;
}
} }
} }
} }
} }
return result; return result;
} }
private boolean checkBlock(List<GrowthBlock> result, Block b, boolean ignoreLiquid) {
// Check floor blocks
if (!ignoreLiquid) {
// Check ceiling blocks
if (b.isEmpty() && !b.getRelative(BlockFace.UP).isEmpty()) {
result.add(new GrowthBlock(b, false));
}
if (!b.isEmpty() && !Tag.LEAVES.isTagged(b.getType())
&& (b.getRelative(BlockFace.UP).isEmpty()
|| b.getRelative(BlockFace.UP).isPassable()
|| Tag.LEAVES.isTagged(b.getRelative(BlockFace.UP).getType())
)
) {
result.add(new GrowthBlock(b.getRelative(BlockFace.UP), true));
return true;
}
} else {
if (!b.isEmpty() && !b.isLiquid() && b.getRelative(BlockFace.UP).isLiquid()) {
result.add(new GrowthBlock(b.getRelative(BlockFace.UP), true));
return true;
}
}
return false;
}
private int getBoneMeal(Greenhouse gh) { private int getBoneMeal(Greenhouse gh) {
Hopper hopper = getHopper(gh); Hopper hopper = getHopper(gh);

View File

@ -33,7 +33,7 @@ public class GreenhouseFinder {
/** /**
* This is the count of the various items * This is the count of the various items
*/ */
private CounterCheck cc = new CounterCheck(); private CounterCheck counterCheck = new CounterCheck();
private Roof roof; private Roof roof;
static class CounterCheck { static class CounterCheck {
@ -97,30 +97,26 @@ public class GreenhouseFinder {
*/ */
CompletableFuture<Set<GreenhouseResult>> checkGreenhouse(AsyncWorldCache cache, Roof roof, Walls walls) { CompletableFuture<Set<GreenhouseResult>> checkGreenhouse(AsyncWorldCache cache, Roof roof, Walls walls) {
CompletableFuture<Set<GreenhouseResult>> r = new CompletableFuture<>(); CompletableFuture<Set<GreenhouseResult>> r = new CompletableFuture<>();
Bukkit.getScheduler().runTaskAsynchronously(BentoBox.getInstance(), () -> checkGHAsync(r, cache, roof, walls)); Bukkit.getScheduler().runTaskAsynchronously(BentoBox.getInstance(), () -> checkGreenhouseAsync(r, cache, roof, walls));
return r; return r;
} }
private Set<GreenhouseResult> checkGHAsync(CompletableFuture<Set<GreenhouseResult>> r, AsyncWorldCache cache, private Set<GreenhouseResult> checkGreenhouseAsync(CompletableFuture<Set<GreenhouseResult>> r, AsyncWorldCache cache,
Roof roof, Walls walls) { Roof roof, Walls walls) {
cc = new CounterCheck(); counterCheck = new CounterCheck();
int y; int y;
for (y = roof.getHeight(); y > walls.getFloor(); y--) { for (y = roof.getHeight(); y > walls.getFloor(); y--) {
wallBlockCount = 0; wallBlockCount = 0;
for (int x = walls.getMinX(); x <= walls.getMaxX(); x++) { for (int x = walls.getMinX(); x <= walls.getMaxX(); x++) {
for (int z = walls.getMinZ(); z <= walls.getMaxZ(); z++) { for (int z = walls.getMinZ(); z <= walls.getMaxZ(); z++) {
checkBlock(cc, cache.getBlockType(x,y,z), roof, walls, new Vector(x, y, z)); checkBlock(counterCheck, cache.getBlockType(x,y,z), roof, walls, new Vector(x, y, z));
} }
} }
if (wallBlockCount == 0 && y < roof.getHeight()) { if (wallBlockCount == 0 && y < roof.getHeight()) {
// This is the floor // This is the floor
break; break;
} else { } else if (counterCheck.otherBlock && otherBlockLayer < 0) {
if (cc.otherBlock) { otherBlockLayer = y;
if (otherBlockLayer < 0) {
otherBlockLayer = y;
}
}
} }
} }
@ -252,28 +248,28 @@ public class GreenhouseFinder {
* @return the wallDoors * @return the wallDoors
*/ */
int getWallDoors() { int getWallDoors() {
return cc.doorCount; return counterCheck.doorCount;
} }
/** /**
* @return the ghHopper * @return the ghHopper
*/ */
int getGhHopper() { int getGhHopper() {
return cc.hopperCount; return counterCheck.hopperCount;
} }
/** /**
* @return the airHoles * @return the airHoles
*/ */
boolean isAirHoles() { boolean isAirHoles() {
return cc.airHole; return counterCheck.airHole;
} }
/** /**
* @return the otherBlocks * @return the otherBlocks
*/ */
boolean isOtherBlocks() { boolean isOtherBlocks() {
return cc.otherBlock; return counterCheck.otherBlock;
} }
/** /**
@ -326,21 +322,21 @@ public class GreenhouseFinder {
} }
public void setGhHopper(int i) { public void setGhHopper(int i) {
cc.hopperCount = i; counterCheck.hopperCount = i;
} }
public void setWallDoors(int i) { public void setWallDoors(int i) {
cc.doorCount = i; counterCheck.doorCount = i;
} }
public void setAirHoles(boolean b) { public void setAirHoles(boolean b) {
cc.airHole = b; counterCheck.airHole = b;
} }
public void setOtherBlocks(boolean b) { public void setOtherBlocks(boolean b) {
cc.otherBlock = b; counterCheck.otherBlock = b;
} }