From a90b7b11614567155f7e019d60e9ce57e72a481e Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Mon, 20 Mar 2023 22:09:52 +0100 Subject: [PATCH] sync dismount fix with minecraft --- .../access/IPlayerPositionLookS2CPacket.java} | 22 ++------- .../MixinClientPlayNetworkHandler.java | 16 ++----- .../MixinPlayerPositionLookS2CPacket.java | 48 +++++++++++++++++++ .../MixinEntityPackets.java | 8 +--- .../MixinProtocol1_19_4to1_19_3.java | 35 -------------- src/main/resources/viafabricplus.mixins.json | 10 ++-- 6 files changed, 61 insertions(+), 78 deletions(-) rename src/main/java/de/florianmichael/viafabricplus/{definition/v1_19_4/DismountRequestTracker.java => injection/access/IPlayerPositionLookS2CPacket.java} (53%) create mode 100644 src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/packet/MixinPlayerPositionLookS2CPacket.java delete mode 100644 src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/protocol1_19_4to1_19_3/MixinProtocol1_19_4to1_19_3.java diff --git a/src/main/java/de/florianmichael/viafabricplus/definition/v1_19_4/DismountRequestTracker.java b/src/main/java/de/florianmichael/viafabricplus/injection/access/IPlayerPositionLookS2CPacket.java similarity index 53% rename from src/main/java/de/florianmichael/viafabricplus/definition/v1_19_4/DismountRequestTracker.java rename to src/main/java/de/florianmichael/viafabricplus/injection/access/IPlayerPositionLookS2CPacket.java index 2375fa74..5973e2d6 100644 --- a/src/main/java/de/florianmichael/viafabricplus/definition/v1_19_4/DismountRequestTracker.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/access/IPlayerPositionLookS2CPacket.java @@ -1,6 +1,6 @@ /* * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus - * Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (EnZaXD) and contributors + * Copyright (C) 2021-2023 FlorianMichael/EnZaXD 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 @@ -15,23 +15,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.definition.v1_19_4; +package de.florianmichael.viafabricplus.injection.access; -import com.viaversion.viaversion.api.connection.StoredObject; -import com.viaversion.viaversion.api.connection.UserConnection; +public interface IPlayerPositionLookS2CPacket { -import java.util.Queue; -import java.util.concurrent.ConcurrentLinkedDeque; - -public class DismountRequestTracker extends StoredObject { - - private final Queue dismountRequests = new ConcurrentLinkedDeque<>(); - - public DismountRequestTracker(UserConnection user) { - super(user); - } - - public Queue getDismountRequests() { - return dismountRequests; - } + boolean viafabricplus_isDismountVehicle(); } diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinClientPlayNetworkHandler.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinClientPlayNetworkHandler.java index 5136370a..a20f2634 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinClientPlayNetworkHandler.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinClientPlayNetworkHandler.java @@ -18,10 +18,8 @@ package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft; import com.mojang.authlib.GameProfile; -import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; -import de.florianmichael.viafabricplus.definition.v1_19_4.DismountRequestTracker; -import de.florianmichael.viafabricplus.protocolhack.ProtocolHack; +import de.florianmichael.viafabricplus.injection.access.IPlayerPositionLookS2CPacket; import de.florianmichael.viafabricplus.settings.groups.VisualSettings; import de.florianmichael.vialoadingbase.ViaLoadingBase; import net.minecraft.client.MinecraftClient; @@ -32,14 +30,12 @@ import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.network.PlayerListEntry; import net.minecraft.client.network.ServerInfo; import net.minecraft.client.util.telemetry.WorldSession; -import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.EntityType; import net.minecraft.entity.vehicle.BoatEntity; import net.minecraft.network.ClientConnection; import net.minecraft.network.packet.s2c.play.*; import net.minecraft.screen.ScreenHandler; import net.minecraft.util.math.Vec3d; -import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -50,7 +46,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.LinkedHashSet; import java.util.Set; -import java.util.UUID; @SuppressWarnings("DataFlowIssue") @Mixin(ClientPlayNetworkHandler.class) @@ -153,13 +148,8 @@ public abstract class MixinClientPlayNetworkHandler { @Inject(method = "onPlayerPositionLook", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetworkThreadUtils;forceMainThread(Lnet/minecraft/network/packet/Packet;Lnet/minecraft/network/listener/PacketListener;Lnet/minecraft/util/thread/ThreadExecutor;)V", shift = At.Shift.AFTER)) public void dismountIfRequested(PlayerPositionLookS2CPacket packet, CallbackInfo ci) { - if (ViaLoadingBase.getClassWrapper().getTargetVersion().isNewerThanOrEqualTo(ProtocolVersion.v1_19_4)) return; - - if (connection.channel.hasAttr(ProtocolHack.LOCAL_VIA_CONNECTION)) { - final UserConnection userConnection = connection.channel.attr(ProtocolHack.LOCAL_VIA_CONNECTION).get(); - if (userConnection.get(DismountRequestTracker.class).getDismountRequests().poll().equals(Boolean.TRUE)) { - client.player.dismountVehicle(); - } + if (((IPlayerPositionLookS2CPacket) packet).viafabricplus_isDismountVehicle()) { + client.player.dismountVehicle(); } } diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/packet/MixinPlayerPositionLookS2CPacket.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/packet/MixinPlayerPositionLookS2CPacket.java new file mode 100644 index 00000000..7a0341f6 --- /dev/null +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/packet/MixinPlayerPositionLookS2CPacket.java @@ -0,0 +1,48 @@ +/* + * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus + * Copyright (C) 2021-2023 FlorianMichael/EnZaXD 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 de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.packet; + +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; +import de.florianmichael.viafabricplus.injection.access.IPlayerPositionLookS2CPacket; +import de.florianmichael.vialoadingbase.ViaLoadingBase; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.network.packet.s2c.play.PlayerPositionLookS2CPacket; +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; + +@Mixin(PlayerPositionLookS2CPacket.class) +public class MixinPlayerPositionLookS2CPacket implements IPlayerPositionLookS2CPacket { + + @Unique + private boolean viafabricplus_dismountVehicle; + + @Inject(method = "(Lnet/minecraft/network/PacketByteBuf;)V", at = @At("RETURN")) + public void readDismountVehicle(PacketByteBuf buf, CallbackInfo ci) { + if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_19_3)) { + viafabricplus_dismountVehicle = buf.readBoolean(); + } + } + + @Override + public boolean viafabricplus_isDismountVehicle() { + return viafabricplus_dismountVehicle; + } +} diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/protocol1_19_4to1_19_3/MixinEntityPackets.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/protocol1_19_4to1_19_3/MixinEntityPackets.java index 3fae5257..b28be5b8 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/protocol1_19_4to1_19_3/MixinEntityPackets.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/protocol1_19_4to1_19_3/MixinEntityPackets.java @@ -1,6 +1,6 @@ /* * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus - * Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (EnZaXD) and contributors + * Copyright (C) 2021-2023 FlorianMichael/EnZaXD 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 @@ -24,7 +24,6 @@ import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ClientboundPac import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.Protocol1_19_4To1_19_3; import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.packets.EntityPackets; import com.viaversion.viaversion.rewriter.EntityRewriter; -import de.florianmichael.viafabricplus.definition.v1_19_4.DismountRequestTracker; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -49,10 +48,7 @@ public abstract class MixinEntityPackets extends EntityRewriter { - final boolean dismountVehicle = wrapper.read(Type.BOOLEAN); - wrapper.user().get(DismountRequestTracker.class).getDismountRequests().add(dismountVehicle); - }); + map(Type.BOOLEAN); // Dismount vehicle - handling in MC } }, true); } diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/protocol1_19_4to1_19_3/MixinProtocol1_19_4to1_19_3.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/protocol1_19_4to1_19_3/MixinProtocol1_19_4to1_19_3.java deleted file mode 100644 index 5839f74e..00000000 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/protocol1_19_4to1_19_3/MixinProtocol1_19_4to1_19_3.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus - * Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (EnZaXD) 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 de.florianmichael.viafabricplus.injection.mixin.fixes.viaversion.protocol1_19_4to1_19_3; - -import com.viaversion.viaversion.api.connection.UserConnection; -import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.Protocol1_19_4To1_19_3; -import de.florianmichael.viafabricplus.definition.v1_19_4.DismountRequestTracker; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(value = Protocol1_19_4To1_19_3.class, remap = false) -public class MixinProtocol1_19_4to1_19_3 { - - @Inject(method = "init", at = @At("RETURN")) - public void hookDismountRequestTracker(UserConnection user, CallbackInfo ci) { - user.put(new DismountRequestTracker(user)); - } -} diff --git a/src/main/resources/viafabricplus.mixins.json b/src/main/resources/viafabricplus.mixins.json index a5717417..234d7dc9 100644 --- a/src/main/resources/viafabricplus.mixins.json +++ b/src/main/resources/viafabricplus.mixins.json @@ -145,13 +145,11 @@ "fixes.viaversion.protocol1_9to1_8.MixinEntityTracker1_9", "fixes.viaversion.protocol1_9to1_8.MixinMetadataRewriter1_9To1_8", "fixes.viaversion.protocol1_9to1_8.MixinMovementTracker", - "fixes.viaversion.protocol1_9to1_8.MixinViaIdleThread" + "fixes.viaversion.protocol1_9to1_8.MixinViaIdleThread", + "fixes.minecraft.packet.MixinPlayerPositionLookS2CPacket", + "fixes.viaversion.protocol1_19_4to1_19_3.MixinEntityPackets" ], "injectors": { "defaultRequire": 1 - }, - "mixins": [ - "fixes.viaversion.protocol1_19_4to1_19_3.MixinEntityPackets", - "fixes.viaversion.protocol1_19_4to1_19_3.MixinProtocol1_19_4to1_19_3" - ] + } }