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..d212149 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.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..891a9c8 --- /dev/null +++ b/viaforge-mc189/src/main/java/com/viaversion/viaforge/mixin/impl/MixinS08PacketPlayerPosLook.java @@ -0,0 +1,61 @@ +/* + * 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.interfaces.IS08; +import com.viaversion.viarewind.protocol.v1_9to1_8.storage.PlayerPositionTracker; +import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; +import io.netty.channel.Channel; +import net.minecraft.client.Minecraft; +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)) { + Channel channel = Minecraft.getMinecraft().thePlayer.sendQueue.getNetworkManager().channel(); + UserConnection connection = channel.attr(ViaForgeCommon.VF_VIA_USER).get(); + if (connection != null) { + PlayerPositionTracker tracker = connection.get(PlayerPositionTracker.class); + if (tracker != null) { + this.teleportId = tracker.getConfirmId(); + } + } + } + } + + @Override + public int getTeleportId() { + return this.teleportId; + } +} diff --git a/viaforge-mc189/src/main/java/com/viaversion/viaforge/mixin/interfaces/IS08.java b/viaforge-mc189/src/main/java/com/viaversion/viaforge/mixin/interfaces/IS08.java new file mode 100644 index 0000000..92541ba --- /dev/null +++ b/viaforge-mc189/src/main/java/com/viaversion/viaforge/mixin/interfaces/IS08.java @@ -0,0 +1,23 @@ +/* + * 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.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",