From d2b765c60d0cd2bb1ab272d39467cbba29f11952 Mon Sep 17 00:00:00 2001 From: FlorianMichael Date: Fri, 2 Aug 2024 00:30:06 +0200 Subject: [PATCH] Fixup knowledge book interactions in <= 1.20.6 --- .../viafabricplus/ViaFabricPlus.java | 10 ---- .../item/MixinKnowledgeBookItem.java | 47 +++++++++++++++++++ src/main/resources/viafabricplus.mixins.json | 3 +- 3 files changed, 49 insertions(+), 11 deletions(-) create mode 100644 src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinKnowledgeBookItem.java diff --git a/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java b/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java index 7ef7c0a9..2b714e75 100644 --- a/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java +++ b/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java @@ -42,17 +42,7 @@ import java.util.concurrent.CompletableFuture; * * TODO | Port 1.21 * - ClientPlayerEntity#tickMovement nether portal logic has new screen conditions and changed - * - Entity#interact now handles leashables interface which was previously handled in MobEntity - * - shouldCancelInteraction condition in ChestBoatEntity#interact is new * - HangingEntity/ItemFrame/Painting bounding box calculation changed - * - PlayerEntity#attack got refactored (?) - * - LivingEntity#takeKnockback with 1.0E-5F for loop is new - * - KnowledgeBookItem#use decrementUnlessCreative is new - * - JukeboxBlock#onUse override is new (added state.get(HAS_RECORD) condition) - * - BoatEntity#updateVelocity isSpaceEmpty condition new - * - LivingEntity#remove -> added activeEffects.clear call - * - PlayerEntity#tickMovement getSaturationLevel/setSaturationLevel handling is new - * - Check WorldBorder bounds check * * TODO | General * - Make recipe fixes dynamic instead of a data dump in java classes diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinKnowledgeBookItem.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinKnowledgeBookItem.java new file mode 100644 index 00000000..964c1d26 --- /dev/null +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinKnowledgeBookItem.java @@ -0,0 +1,47 @@ +/* + * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus + * Copyright (C) 2021-2024 FlorianMichael/EnZaXD and RK_01/RaphiMC + * Copyright (C) 2023-2024 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.item; + +import com.llamalad7.mixinextras.sugar.Local; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; +import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.item.KnowledgeBookItem; +import net.minecraft.util.Hand; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(KnowledgeBookItem.class) +public abstract class MixinKnowledgeBookItem { + + @Redirect(method = "use", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;decrementUnlessCreative(ILnet/minecraft/entity/LivingEntity;)V")) + private void removeFullStack(ItemStack instance, int amount, LivingEntity entity, @Local(argsOnly = true) Hand hand) { + if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_20_5)) { + if (!entity.isInCreativeMode()) { + entity.setStackInHand(hand, ItemStack.EMPTY); + } + } else { + instance.decrementUnlessCreative(amount, entity); + } + } + +} diff --git a/src/main/resources/viafabricplus.mixins.json b/src/main/resources/viafabricplus.mixins.json index 3b246060..9c779635 100644 --- a/src/main/resources/viafabricplus.mixins.json +++ b/src/main/resources/viafabricplus.mixins.json @@ -205,7 +205,8 @@ "fixes.viaversion.MixinWorldPacketRewriter1_19", "viabedrock.MixinJoinPackets", "vialegacy.MixinExtensionProtocolMetadataStorage", - "vialegacy.MixinViaLegacyConfig" + "vialegacy.MixinViaLegacyConfig", + "fixes.minecraft.item.MixinKnowledgeBookItem" ], "injectors": { "defaultRequire": 1