fix(server): move players to another dimension with execute in ... run tp

On a dedicated server, `execute in <dimension> run tp @s ...` from a player
moved them inside the level they were in. It now does what vanilla's
TeleportCommand does: ServerPlayer.teleport into the other level, with the
Respawn packet keeping all data and no portal sound, then the feedback. The
players there are tracked to them and they are removed from the ones they
left.

tools/test_server_dimension_players_parity.py joins two players to a vanilla
and a Horizon server and compares, step by step, the players each is sent and
loses and the dimensions it respawns into, while they go to the Nether and
the End by command and through an End portal. LocatorBarClient gains
`players on` and `still NAME` (the position reminder a still client sends).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-18 02:14:03 +02:00
parent ce571f789c
commit 9a2d87ec97
9 changed files with 287 additions and 12 deletions
@@ -76,11 +76,16 @@ import net.minecraft.world.phys.Vec3;
* line at a time: {@code step LABEL} (the label the next packets are recorded
* under), {@code join NAME}, {@code cmd NAME COMMAND...}, {@code shift NAME
* on|off} (the shift key, as ServerboundPlayerInputPacket), {@code fly NAME
* on|off} (ServerboundPlayerAbilitiesPacket), {@code quit NAME} and {@code
* end}, which writes each player's lines to OUT.
* on|off} (ServerboundPlayerAbilitiesPacket), {@code still NAME} (the
* position reminder LocalPlayer.sendPosition sends every 20 ticks standing
* still), {@code quit NAME}, {@code
* players on|off} (whether each player also records the other players added
* to and removed from its level, and its own respawns into a dimension) and
* {@code end}, which writes each player's lines to OUT.
*/
public final class LocatorBarClient {
private static volatile String step = "start";
private static volatile boolean players;
private static final Map<UUID, String> NAMES = new LinkedHashMap<>();
public static void main(String[] args) throws Exception {
@@ -110,7 +115,9 @@ public final class LocatorBarClient {
abilities.flying = w[2].equals("on");
players.get(w[1]).send(new net.minecraft.network.protocol.game.ServerboundPlayerAbilitiesPacket(abilities));
}
case "still" -> players.get(w[1]).still();
case "quit" -> players.get(w[1]).close();
case "players" -> LocatorBarClient.players = w[1].equals("on");
case "end" -> {
try (PrintWriter out = new PrintWriter(Files.newBufferedWriter(output, StandardCharsets.UTF_8))) {
for (Player p : players.values()) {
@@ -166,8 +173,10 @@ public final class LocatorBarClient {
private int threshold = -1;
private ProtocolInfo<?> inbound;
private ProtocolInfo<?> outbound;
private PositionMoveRotation position = new PositionMoveRotation(Vec3.ZERO, Vec3.ZERO, 0, 0);
private volatile PositionMoveRotation position = new PositionMoveRotation(Vec3.ZERO, Vec3.ZERO, 0, 0);
private boolean loaded;
/** The other players this one was sent, by entity id. */
private final Map<Integer, String> seen = new java.util.HashMap<>();
private final Object replyLock = new Object();
private int replies;
@@ -198,6 +207,14 @@ public final class LocatorBarClient {
}
}
void still() throws Exception {
PositionMoveRotation at = position;
// A tick of its own: the server takes one position per client tick (receivedPositionThisTick).
send(net.minecraft.network.protocol.game.ServerboundClientTickEndPacket.INSTANCE);
send(new ServerboundMovePlayerPacket.PosRot(at.position(), at.yRot(), at.xRot(), false, false));
send(net.minecraft.network.protocol.game.ServerboundClientTickEndPacket.INSTANCE);
}
void close() throws Exception {
if (socket != null) socket.close();
}
@@ -266,7 +283,20 @@ public final class LocatorBarClient {
while (true) {
Received r = read();
Packet<?> p = r.packet;
if (p instanceof ClientboundTrackedWaypointPacket) {
if (p instanceof net.minecraft.network.protocol.game.ClientboundAddEntityPacket a
&& a.getType() == net.minecraft.world.entity.EntityTypes.PLAYER) {
String who = NAMES.getOrDefault(a.getUUID(), "uuid?");
seen.put(a.getId(), who);
if (players) record("add " + who + " at " + a.getX() + "," + a.getY() + "," + a.getZ());
} else if (p instanceof net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket rm) {
rm.entityIds().forEach(id -> {
String who = seen.remove(id);
if (who != null && players) record("remove " + who);
});
} else if (p instanceof net.minecraft.network.protocol.game.ClientboundRespawnPacket rs) {
if (players) record("respawn " + rs.commonPlayerSpawnInfo().dimension().identifier());
seen.clear();
} else if (p instanceof ClientboundTrackedWaypointPacket) {
record(waypoint(r.payload));
} else if (p instanceof ClientboundSystemChatPacket) {
synchronized (replyLock) {