refactor: just make getBlock return 0 when it fails

This commit is contained in:
ChomeNS
2025-05-22 17:24:04 +07:00
parent f3d3355bd2
commit 8fd2f2ebb3
3 changed files with 17 additions and 18 deletions

View File

@@ -1 +1 @@
3266
3268

View File

@@ -377,11 +377,9 @@ public class CorePlugin implements Listener {
for (int y = from.getY(); y <= to.getY(); y++) {
for (int z = from.getZ(); z <= to.getZ(); z++) {
for (int x = from.getX(); x <= to.getX(); x++) {
try {
final int block = bot.world.getBlock(x, y, z);
final int block = bot.world.getBlock(x, y, z);
if (!isCommandBlockState(block)) return false;
} catch (final Exception ignored) { }
if (!isCommandBlockState(block)) return false;
}
}
}
@@ -400,11 +398,9 @@ public class CorePlugin implements Listener {
for (int y = from.getY(); y <= to.getY(); y++) {
for (int z = from.getZ(); z <= to.getZ(); z++) {
for (int x = from.getX(); x <= to.getX(); x++) {
try {
final int block = bot.world.getBlock(x, y, z);
final int block = bot.world.getBlock(x, y, z);
if (isCommandBlockState(block)) return true;
} catch (final Exception ignored) { }
if (isCommandBlockState(block)) return true;
}
}
}
@@ -560,16 +556,14 @@ public class CorePlugin implements Listener {
for (int y = from.getY(); y <= to.getY(); y++) {
for (int z = from.getZ(); z <= to.getZ(); z++) {
for (int x = from.getX(); x <= to.getX(); x++) {
try {
final int block = bot.world.getBlock(x, y, z);
final int block = bot.world.getBlock(x, y, z);
final Boolean refilled = refilledMap.get(y);
final Boolean refilled = refilledMap.get(y);
if (
(!force && isCommandBlockState(block)) ||
(refilled != null && refilled)
) continue;
} catch (final Exception ignored) { }
if (
(!force && isCommandBlockState(block)) ||
(refilled != null && refilled)
) continue;
final boolean useChat = positionChangesPerSecond.get() > 10;

View File

@@ -136,7 +136,12 @@ public class WorldPlugin implements Listener {
public int getBlock (final int x, final int y, final int z) {
final ChunkPos chunkPos = new ChunkPos(Math.floorDiv(x, 16), Math.floorDiv(z, 16));
final ChunkColumn chunk = chunks.get(chunkPos);
return chunk == null ? 0 : chunks.get(chunkPos).getBlock(x & 15, y, z & 15);
try {
return chunk == null ? 0 : chunks.get(chunkPos).getBlock(x & 15, y, z & 15);
} catch (final Exception e) {
return 0;
}
}
// should this be public?