fix: some core refilling issues when switching to dimensions with different minimum Y levels like minecraft:the_end

This commit is contained in:
ChomeNS
2025-03-13 09:02:18 +07:00
parent 2a225b9169
commit f6a3cad40a
4 changed files with 36 additions and 16 deletions

View File

@@ -80,6 +80,7 @@ public class Bot extends SessionAdapter {
public SelfCarePlugin selfCare;
public QueryPlugin query;
public ExtrasMessengerPlugin extrasMessenger;
public WorldPlugin world;
public CorePlugin core;
public TeamPlugin team;
public PlayersPlugin players;
@@ -103,7 +104,6 @@ public class Bot extends SessionAdapter {
public PacketSnifferPlugin packetSniffer;
public VoiceChatPlugin voiceChat;
public TeamJoinerPlugin teamJoiner;
public WorldPlugin world;
public AuthPlugin auth;
public ScreensharePlugin screenshare;
public FormatCheckerPlugin formatChecker;
@@ -132,6 +132,7 @@ public class Bot extends SessionAdapter {
this.selfCare = new SelfCarePlugin(this);
this.query = new QueryPlugin(this);
this.extrasMessenger = new ExtrasMessengerPlugin(this);
this.world = new WorldPlugin(this);
this.core = new CorePlugin(this);
this.team = new TeamPlugin(this);
this.players = new PlayersPlugin(this);
@@ -155,7 +156,6 @@ public class Bot extends SessionAdapter {
this.packetSniffer = new PacketSnifferPlugin(this);
this.voiceChat = new VoiceChatPlugin(this);
this.teamJoiner = new TeamJoinerPlugin(this);
this.world = new WorldPlugin(this);
this.auth = new AuthPlugin(this);
// this.screenshare = new ScreensharePlugin(this);
this.formatChecker = new FormatCheckerPlugin(this);

View File

@@ -26,7 +26,10 @@ import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.S
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundPlayerActionPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundUseItemOnPacket;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ScheduledFuture;
@@ -103,6 +106,13 @@ public class CorePlugin extends PositionPlugin.Listener {
}
});
bot.world.addListener(new WorldPlugin.Listener() {
@Override
public void worldChanged (String dimension) {
CorePlugin.this.worldChanged();
}
});
bot.tick.addListener(new TickPlugin.Listener() {
@Override
public void onTick() {
@@ -392,18 +402,6 @@ public class CorePlugin extends PositionPlugin.Listener {
Math.abs(botChunkPosX - coreChunkPosX) > bot.world.simulationDistance ||
Math.abs(botChunkPosZ - coreChunkPosZ) > bot.world.simulationDistance
) {
from = Vector3i.from(
fromSize.getX() + botChunkPosX * 16,
MathUtilities.clamp(fromSize.getY(), bot.world.minY, bot.world.maxY),
fromSize.getZ() + botChunkPosZ * 16
);
to = Vector3i.from(
toSize.getX() + botChunkPosX * 16,
MathUtilities.clamp(toSize.getY(), bot.world.minY, bot.world.maxY),
toSize.getZ() + botChunkPosZ * 16
);
reset();
refill();
}
@@ -416,7 +414,27 @@ public class CorePlugin extends PositionPlugin.Listener {
}
}
public void worldChanged () {
reset();
refill();
}
public void reset () {
final int botChunkPosX = (int) Math.floor(bot.position.position.getX() / 16);
final int botChunkPosZ = (int) Math.floor(bot.position.position.getZ() / 16);
from = Vector3i.from(
fromSize.getX() + botChunkPosX * 16,
MathUtilities.clamp(fromSize.getY(), bot.world.minY, bot.world.maxY),
fromSize.getZ() + botChunkPosZ * 16
);
to = Vector3i.from(
toSize.getX() + botChunkPosX * 16,
MathUtilities.clamp(toSize.getY(), bot.world.minY, bot.world.maxY),
toSize.getZ() + botChunkPosZ * 16
);
block = Vector3i.from(from);
}

View File

@@ -131,6 +131,8 @@ public class WorldPlugin extends Bot.Listener {
chunks.get(chunkPos).setBlock(x & 15, y, z & 15, id);
}
public void addListener (Listener listener) { listeners.add(listener); }
public static class Listener {
public void worldChanged (String dimension) {}
}