Fixed incompatibility with ItemScroller

This commit is contained in:
FlorianMichael 2023-05-16 14:08:07 +02:00
parent ff8aa10f0a
commit 5a7147eaaf

View File

@ -17,6 +17,7 @@
*/ */
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft; package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft;
import com.llamalad7.mixinextras.injector.WrapWithCondition;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
@ -29,7 +30,6 @@ import de.florianmichael.viafabricplus.injection.access.IScreenHandler;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack; import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import de.florianmichael.viafabricplus.protocolhack.provider.viaversion.ViaFabricPlusHandItemProvider; import de.florianmichael.viafabricplus.protocolhack.provider.viaversion.ViaFabricPlusHandItemProvider;
import de.florianmichael.viafabricplus.protocolhack.usage.ItemTranslator; import de.florianmichael.viafabricplus.protocolhack.usage.ItemTranslator;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.network.ClientPlayerEntity;
@ -61,9 +61,12 @@ public abstract class MixinClientPlayerInteractionManager {
@Final @Final
private MinecraftClient client; private MinecraftClient client;
@Shadow protected abstract ActionResult interactBlockInternal(ClientPlayerEntity player, Hand hand, BlockHitResult hitResult); @Shadow
protected abstract ActionResult interactBlockInternal(ClientPlayerEntity player, Hand hand, BlockHitResult hitResult);
@Shadow @Final private ClientPlayNetworkHandler networkHandler; @Shadow
@Final
private ClientPlayNetworkHandler networkHandler;
@Unique @Unique
private ItemStack viafabricplus_oldCursorStack; private ItemStack viafabricplus_oldCursorStack;
@ -93,14 +96,15 @@ public abstract class MixinClientPlayerInteractionManager {
if (type == SlotActionType.QUICK_CRAFT) return true; if (type == SlotActionType.QUICK_CRAFT) return true;
// quick move always uses empty stack for verification since 1.12 // quick move always uses empty stack for verification since 1.12
if (type == SlotActionType.QUICK_MOVE && ProtocolHack.getTargetVersion().isNewerThan(ProtocolVersion.v1_11_1)) return true; if (type == SlotActionType.QUICK_MOVE && ProtocolHack.getTargetVersion().isNewerThan(ProtocolVersion.v1_11_1))
return true;
// pickup with slot -999 (outside window) to throw items always uses empty stack for verification // pickup with slot -999 (outside window) to throw items always uses empty stack for verification
return type == SlotActionType.PICKUP && slot == -999; return type == SlotActionType.PICKUP && slot == -999;
} }
@Redirect(method = "clickSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;sendPacket(Lnet/minecraft/network/packet/Packet;)V")) @WrapWithCondition(method = "clickSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;sendPacket(Lnet/minecraft/network/packet/Packet;)V"))
private void modifySlotClickPacket(ClientPlayNetworkHandler instance, Packet<?> packet) { private boolean modifySlotClickPacket(ClientPlayNetworkHandler instance, Packet<?> packet) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_16_4) && packet instanceof ClickSlotC2SPacket clickSlot) { if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_16_4) && packet instanceof ClickSlotC2SPacket clickSlot) {
ItemStack slotItemBeforeModification; ItemStack slotItemBeforeModification;
@ -131,16 +135,15 @@ public abstract class MixinClientPlayerInteractionManager {
try { try {
clickSlotPacket.sendToServer(Protocol1_17To1_16_4.class); clickSlotPacket.sendToServer(Protocol1_17To1_16_4.class);
} catch (Exception ignored) {} } catch (Exception ignored) {
}
}); });
viafabricplus_oldCursorStack = null; viafabricplus_oldCursorStack = null;
viafabricplus_oldItems = null; viafabricplus_oldItems = null;
return false;
return;
} }
return true;
instance.sendPacket(packet);
} }
@Redirect(method = "interactItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;sendPacket(Lnet/minecraft/network/packet/Packet;)V", ordinal = 0), @Redirect(method = "interactItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;sendPacket(Lnet/minecraft/network/packet/Packet;)V", ordinal = 0),