Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* This file is part of ViaForge - https://github.com/ViaVersion/ViaForge
* Copyright (C) 2021-2026 Florian Reuth <git@florianreuth.de> 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 <http://www.gnu.org/licenses/>.
*/

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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* This file is part of ViaForge - https://github.com/ViaVersion/ViaForge
* Copyright (C) 2021-2026 Florian Reuth <git@florianreuth.de> 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 <http://www.gnu.org/licenses/>.
*/

package com.viaversion.viaforge.mixin.interfaces;

public interface IS08 {
int getTeleportId();
}
1 change: 1 addition & 0 deletions viaforge-mc189/src/main/resources/mixins.viaforge.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"MixinGuiScreenAddServer",
"MixinGuiScreenServerList",
"MixinNetHandlerPlayClient",
"MixinS08PacketPlayerPosLook",
"MixinServerData",
"compatibility.patcher.MixinProtocolVersionDetector",
"connect.MixinGuiConnecting_1",
Expand Down