sync dismount fix with minecraft

This commit is contained in:
FlorianMichael 2023-03-20 22:09:52 +01:00
parent 92bcd38508
commit a90b7b1161
6 changed files with 61 additions and 78 deletions

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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<Boolean> dismountRequests = new ConcurrentLinkedDeque<>();
public DismountRequestTracker(UserConnection user) {
super(user);
}
public Queue<Boolean> getDismountRequests() {
return dismountRequests;
}
boolean viafabricplus_isDismountVehicle();
}

View File

@ -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();
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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 = "<init>(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;
}
}

View File

@ -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<ClientboundPacke
map(Type.FLOAT); // Pitch
map(Type.BYTE); // Relative arguments
map(Type.VAR_INT); // Id
handler(wrapper -> {
final boolean dismountVehicle = wrapper.read(Type.BOOLEAN);
wrapper.user().get(DismountRequestTracker.class).getDismountRequests().add(dismountVehicle);
});
map(Type.BOOLEAN); // Dismount vehicle - handling in MC
}
}, true);
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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));
}
}

View File

@ -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"
]
}
}