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?
This commit is contained in:
@@ -1 +1 @@
|
||||
2988
|
||||
3015
|
||||
@@ -51,12 +51,14 @@ public class CorePlugin implements Listener {
|
||||
|
||||
public volatile Vector3i block = null;
|
||||
|
||||
public final AtomicInteger index = new AtomicInteger();
|
||||
|
||||
public final Queue<String> placeBlockQueue = new ConcurrentLinkedQueue<>();
|
||||
|
||||
public final Queue<String> 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); }
|
||||
|
||||
Reference in New Issue
Block a user