Skip to content

Commit

Permalink
sync dismount fix with minecraft
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Mar 20, 2023
1 parent 92bcd38 commit a90b7b1
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,14 +30,12 @@
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;
Expand All @@ -50,7 +46,6 @@

import java.util.LinkedHashSet;
import java.util.Set;
import java.util.UUID;

@SuppressWarnings("DataFlowIssue")
@Mixin(ClientPlayNetworkHandler.class)
Expand Down Expand Up @@ -153,13 +148,8 @@ public void removeNewWarning(Logger instance, String s, Object o) {

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

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,7 +24,6 @@
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;
Expand All @@ -49,10 +48,7 @@ protected void register() {
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);
}
Expand Down

This file was deleted.

10 changes: 4 additions & 6 deletions src/main/resources/viafabricplus.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
}

0 comments on commit a90b7b1

Please sign in to comment.