From c2f437c6222eb2520748f5fd6524792c0579bd57 Mon Sep 17 00:00:00 2001 From: Ghost <53552261+Ghost-Kokoro@users.noreply.github.com> Date: Sun, 22 Mar 2026 00:42:41 +0800 Subject: [PATCH 1/2] Fix: Resolve unexpected teleport confirmation id kick on 1.9+ (Fix #245) --- .../mixin/impl/MixinNetHandlerPlayClient.java | 21 ++++++++ .../impl/MixinS08PacketPlayerPosLook.java | 50 +++++++++++++++++++ .../viaforge/mixin/impl/interfaces/IS08.java | 24 +++++++++ .../src/main/resources/mixins.viaforge.json | 1 + 4 files changed, 96 insertions(+) create mode 100644 viaforge-mc189/src/main/java/com/viaversion/viaforge/mixin/impl/MixinS08PacketPlayerPosLook.java create mode 100644 viaforge-mc189/src/main/java/com/viaversion/viaforge/mixin/impl/interfaces/IS08.java diff --git a/viaforge-mc189/src/main/java/com/viaversion/viaforge/mixin/impl/MixinNetHandlerPlayClient.java b/viaforge-mc189/src/main/java/com/viaversion/viaforge/mixin/impl/MixinNetHandlerPlayClient.java index 61b49a1..893592c 100644 --- a/viaforge-mc189/src/main/java/com/viaversion/viaforge/mixin/impl/MixinNetHandlerPlayClient.java +++ b/viaforge-mc189/src/main/java/com/viaversion/viaforge/mixin/impl/MixinNetHandlerPlayClient.java @@ -18,12 +18,19 @@ package com.viaversion.viaforge.mixin.impl; +import com.viaversion.viaforge.mixin.impl.interfaces.IS08; +import com.viaversion.viarewind.protocol.v1_9to1_8.Protocol1_9To1_8; import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; +import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.connection.ConnectionDetails; import com.viaversion.viaforge.common.ViaForgeCommon; +import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ServerboundPackets1_9; import io.netty.channel.Channel; import net.minecraft.client.Minecraft; import net.minecraft.client.network.NetHandlerPlayClient; +import net.minecraft.network.play.server.S08PacketPlayerPosLook; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -43,4 +50,18 @@ public void sendConnectionDetails(CallbackInfo ci) { ConnectionDetails.sendConnectionDetails(connection, ConnectionDetails.MOD_CHANNEL); } + @Inject(method = "handlePlayerPosLook", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/EntityPlayer;setPositionAndRotation(DDDFF)V", shift = At.Shift.AFTER)) + public void handleTeleportPacket(S08PacketPlayerPosLook packetIn, CallbackInfo ci) { + final Channel channel = Minecraft.getMinecraft().thePlayer.sendQueue.getNetworkManager().channel(); + final UserConnection connection = channel.attr(ViaForgeCommon.VF_VIA_USER).get(); + if (connection == null) { + return; + } + + if (ViaForgeCommon.getManager().getTargetVersion().newerThanOrEqualTo(ProtocolVersion.v1_9)) { + PacketWrapper packet = PacketWrapper.create(ServerboundPackets1_9.ACCEPT_TELEPORTATION, connection); + packet.write(Types.VAR_INT, ((IS08)packetIn).getTeleportId()); + packet.sendToServer(Protocol1_9To1_8.class); + } + } } diff --git a/viaforge-mc189/src/main/java/com/viaversion/viaforge/mixin/impl/MixinS08PacketPlayerPosLook.java b/viaforge-mc189/src/main/java/com/viaversion/viaforge/mixin/impl/MixinS08PacketPlayerPosLook.java new file mode 100644 index 0000000..d78a1ff --- /dev/null +++ b/viaforge-mc189/src/main/java/com/viaversion/viaforge/mixin/impl/MixinS08PacketPlayerPosLook.java @@ -0,0 +1,50 @@ +/* + * This file is part of ViaForge - https://github.com/ViaVersion/ViaForge + * Copyright (C) 2021-2026 Florian Reuth and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.viaversion.viaforge.mixin.impl; + +import com.viaversion.viaforge.common.ViaForgeCommon; +import com.viaversion.viaforge.mixin.impl.interfaces.IS08; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; +import net.minecraft.network.PacketBuffer; +import net.minecraft.network.play.server.S08PacketPlayerPosLook; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.io.IOException; + +@Mixin(S08PacketPlayerPosLook.class) +public class MixinS08PacketPlayerPosLook implements IS08 { + + @Unique + private int teleportId; + + @Inject(method = "readPacketData", at = @At("RETURN")) + public void onReadPacketData(PacketBuffer buf, CallbackInfo ci) throws IOException { + if (ViaForgeCommon.getManager().getTargetVersion().newerThanOrEqualTo(ProtocolVersion.v1_9)) { + this.teleportId = buf.readVarIntFromBuffer(); + } + } + + @Override + public int getTeleportId() { + return this.teleportId; + } +} diff --git a/viaforge-mc189/src/main/java/com/viaversion/viaforge/mixin/impl/interfaces/IS08.java b/viaforge-mc189/src/main/java/com/viaversion/viaforge/mixin/impl/interfaces/IS08.java new file mode 100644 index 0000000..c317730 --- /dev/null +++ b/viaforge-mc189/src/main/java/com/viaversion/viaforge/mixin/impl/interfaces/IS08.java @@ -0,0 +1,24 @@ +/* + * This file is part of ViaForge - https://github.com/ViaVersion/ViaForge + * Copyright (C) 2021-2026 Florian Reuth and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.viaversion.viaforge.mixin.impl.interfaces; + +public interface IS08 { + + int getTeleportId(); +} diff --git a/viaforge-mc189/src/main/resources/mixins.viaforge.json b/viaforge-mc189/src/main/resources/mixins.viaforge.json index abfb881..a6c1385 100644 --- a/viaforge-mc189/src/main/resources/mixins.viaforge.json +++ b/viaforge-mc189/src/main/resources/mixins.viaforge.json @@ -11,6 +11,7 @@ "MixinGuiScreenAddServer", "MixinGuiScreenServerList", "MixinNetHandlerPlayClient", + "MixinS08PacketPlayerPosLook", "MixinServerData", "compatibility.patcher.MixinProtocolVersionDetector", "connect.MixinGuiConnecting_1", From 8265e268abeac7103de697bb33b28945ec25d0bd Mon Sep 17 00:00:00 2001 From: Ghost <53552261+Ghost-Kokoro@users.noreply.github.com> Date: Sun, 22 Mar 2026 11:34:23 +0800 Subject: [PATCH 2/2] Fix: Resolve unexpected teleport confirmation ID kick on 1.9+ servers --- .../mixin/impl/MixinNetHandlerPlayClient.java | 14 ++++-- .../impl/MixinS08PacketPlayerPosLook.java | 50 ------------------- .../viaforge/mixin/impl/interfaces/IS08.java | 24 --------- .../src/main/resources/mixins.viaforge.json | 1 - 4 files changed, 10 insertions(+), 79 deletions(-) delete mode 100644 viaforge-mc189/src/main/java/com/viaversion/viaforge/mixin/impl/MixinS08PacketPlayerPosLook.java delete mode 100644 viaforge-mc189/src/main/java/com/viaversion/viaforge/mixin/impl/interfaces/IS08.java diff --git a/viaforge-mc189/src/main/java/com/viaversion/viaforge/mixin/impl/MixinNetHandlerPlayClient.java b/viaforge-mc189/src/main/java/com/viaversion/viaforge/mixin/impl/MixinNetHandlerPlayClient.java index 893592c..9d42bce 100644 --- a/viaforge-mc189/src/main/java/com/viaversion/viaforge/mixin/impl/MixinNetHandlerPlayClient.java +++ b/viaforge-mc189/src/main/java/com/viaversion/viaforge/mixin/impl/MixinNetHandlerPlayClient.java @@ -18,8 +18,8 @@ package com.viaversion.viaforge.mixin.impl; -import com.viaversion.viaforge.mixin.impl.interfaces.IS08; import com.viaversion.viarewind.protocol.v1_9to1_8.Protocol1_9To1_8; +import com.viaversion.viarewind.protocol.v1_9to1_8.storage.PlayerPositionTracker; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; @@ -59,9 +59,15 @@ public void handleTeleportPacket(S08PacketPlayerPosLook packetIn, CallbackInfo c } if (ViaForgeCommon.getManager().getTargetVersion().newerThanOrEqualTo(ProtocolVersion.v1_9)) { - PacketWrapper packet = PacketWrapper.create(ServerboundPackets1_9.ACCEPT_TELEPORTATION, connection); - packet.write(Types.VAR_INT, ((IS08)packetIn).getTeleportId()); - packet.sendToServer(Protocol1_9To1_8.class); + PlayerPositionTracker tracker = connection.get(PlayerPositionTracker.class); + if (tracker != null && tracker.getConfirmId() != -1) { + + PacketWrapper packet = PacketWrapper.create(ServerboundPackets1_9.ACCEPT_TELEPORTATION, connection); + packet.write(Types.VAR_INT, tracker.getConfirmId()); + packet.sendToServer(Protocol1_9To1_8.class); + + tracker.setConfirmId(-1); + } } } } diff --git a/viaforge-mc189/src/main/java/com/viaversion/viaforge/mixin/impl/MixinS08PacketPlayerPosLook.java b/viaforge-mc189/src/main/java/com/viaversion/viaforge/mixin/impl/MixinS08PacketPlayerPosLook.java deleted file mode 100644 index d78a1ff..0000000 --- a/viaforge-mc189/src/main/java/com/viaversion/viaforge/mixin/impl/MixinS08PacketPlayerPosLook.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * This file is part of ViaForge - https://github.com/ViaVersion/ViaForge - * Copyright (C) 2021-2026 Florian Reuth and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.viaversion.viaforge.mixin.impl; - -import com.viaversion.viaforge.common.ViaForgeCommon; -import com.viaversion.viaforge.mixin.impl.interfaces.IS08; -import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; -import net.minecraft.network.PacketBuffer; -import net.minecraft.network.play.server.S08PacketPlayerPosLook; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import java.io.IOException; - -@Mixin(S08PacketPlayerPosLook.class) -public class MixinS08PacketPlayerPosLook implements IS08 { - - @Unique - private int teleportId; - - @Inject(method = "readPacketData", at = @At("RETURN")) - public void onReadPacketData(PacketBuffer buf, CallbackInfo ci) throws IOException { - if (ViaForgeCommon.getManager().getTargetVersion().newerThanOrEqualTo(ProtocolVersion.v1_9)) { - this.teleportId = buf.readVarIntFromBuffer(); - } - } - - @Override - public int getTeleportId() { - return this.teleportId; - } -} diff --git a/viaforge-mc189/src/main/java/com/viaversion/viaforge/mixin/impl/interfaces/IS08.java b/viaforge-mc189/src/main/java/com/viaversion/viaforge/mixin/impl/interfaces/IS08.java deleted file mode 100644 index c317730..0000000 --- a/viaforge-mc189/src/main/java/com/viaversion/viaforge/mixin/impl/interfaces/IS08.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * This file is part of ViaForge - https://github.com/ViaVersion/ViaForge - * Copyright (C) 2021-2026 Florian Reuth and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.viaversion.viaforge.mixin.impl.interfaces; - -public interface IS08 { - - int getTeleportId(); -} diff --git a/viaforge-mc189/src/main/resources/mixins.viaforge.json b/viaforge-mc189/src/main/resources/mixins.viaforge.json index a6c1385..abfb881 100644 --- a/viaforge-mc189/src/main/resources/mixins.viaforge.json +++ b/viaforge-mc189/src/main/resources/mixins.viaforge.json @@ -11,7 +11,6 @@ "MixinGuiScreenAddServer", "MixinGuiScreenServerList", "MixinNetHandlerPlayClient", - "MixinS08PacketPlayerPosLook", "MixinServerData", "compatibility.patcher.MixinProtocolVersionDetector", "connect.MixinGuiConnecting_1",