From 9d9955444b7eb79b5ef77f3caf4f1d4ff4d8cdc0 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Thu, 1 May 2025 10:21:18 +0700 Subject: [PATCH] refactor: make core increment use bitwise operators + some fixes and improvements line 351 > - int y = -64 > + int y = bot.world.minY; this makes the core never resize when in worlds like the end or nether (which has the min y level as 0) i'm also limiting the maximum resizing Y level now to the world's maximum y level so it won't overflow also for some reason when i switch to flatlands using `/world 3` the server doesn't send the current dimension's data (like `min_y` and `height`), so i think the server sends them before at like, login? or are we meant to default to overworld's values? --- build-number.txt | 2 +- .../chomens_bot/plugins/CorePlugin.java | 45 ++++++++++--------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/build-number.txt b/build-number.txt index b05b3409..966f6062 100644 --- a/build-number.txt +++ b/build-number.txt @@ -1 +1 @@ -2988 \ No newline at end of file +3015 \ No newline at end of file diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/CorePlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/CorePlugin.java index fab346a2..571f6f66 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/CorePlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/CorePlugin.java @@ -51,12 +51,14 @@ public class CorePlugin implements Listener { public volatile Vector3i block = null; + public final AtomicInteger index = new AtomicInteger(); + public final Queue placeBlockQueue = new ConcurrentLinkedQueue<>(); public final Queue pendingCommands = new ConcurrentLinkedQueue<>(); - public final AtomicInteger commandsPerTick = new AtomicInteger(0); - public final AtomicInteger commandsPerSecond = new AtomicInteger(0); + public final AtomicInteger commandsPerTick = new AtomicInteger(); + public final AtomicInteger commandsPerSecond = new AtomicInteger(); private final AtomicInteger positionChangesPerSecond = new AtomicInteger(0); @@ -156,6 +158,8 @@ public class CorePlugin implements Listener { if (!bot.serverFeatures.hasNamespaces) command = StringUtilities.removeNamespace(command); + incrementBlock(0); + if (bot.serverFeatures.hasExtras) { bot.session.send(new ServerboundSetCommandBlockPacket( block, @@ -184,8 +188,6 @@ public class CorePlugin implements Listener { true )); } - - incrementBlock(); } public void run (final String command) { @@ -341,12 +343,12 @@ public class CorePlugin implements Listener { if (!ready) return; // fixes a bug where the block positions are more than the ones in from and to - if (!isCore(block)) reset(); + if (!isCore(block)) recalculateRelativePositions(); final Vector3i oldSize = toSize; final int x = toSize.getX(); - int y = -64; + int y = bot.world.minY; final int z = toSize.getZ(); while (commandsPerTick.get() > 16 * 16) { @@ -354,6 +356,8 @@ public class CorePlugin implements Listener { commandsPerTick.getAndAdd(-(16 * 16)); } + y = Math.min(y, bot.world.maxY); + toSize = Vector3i.from(x, y, z); if (oldSize.getY() != toSize.getY()) { @@ -420,24 +424,22 @@ public class CorePlugin implements Listener { position.getZ() >= from.getZ() && position.getZ() <= to.getZ(); } - private synchronized void incrementBlock () { - int x = block.getX() + 1; - int y = block.getY(); - int z = block.getZ(); + private void incrementBlock (final int times) { + if (times > 256) return; - if (x > to.getX()) { - x = from.getX(); - z++; - if (z > to.getZ()) { - z = from.getZ(); - y++; - if (y > to.getY()) { - y = from.getY(); - } - } - } + final int currentIndex = index.get(); + + final int x = from.getX() + (currentIndex & 15); + final int z = from.getZ() + ((currentIndex >> 4) & 15); + final int y = (currentIndex >> 8) + bot.world.minY; block = Vector3i.from(x, y, z); + + index.set((currentIndex + 1) % (256 * Math.max(1, to.getY() - from.getY()))); + + if (!isCommandBlockState(bot.world.getBlock(x, y, z))) { + incrementBlock(times + 1); + } } @Override @@ -505,6 +507,7 @@ public class CorePlugin implements Listener { recalculateRelativePositions(); block = Vector3i.from(from); + index.set(0); } public void refill () { refill(true); }