From 642b4de7a007f131fc8d2b257b4f46097ef3693f Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Sat, 27 Apr 2024 23:19:59 +0200 Subject: [PATCH] Port attribute modifier tooltip fix --- .../mixin/fixes/minecraft/item/MixinItemStack.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinItemStack.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinItemStack.java index ff8836df..3661e315 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinItemStack.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinItemStack.java @@ -26,6 +26,8 @@ import net.minecraft.component.ComponentMap; import net.minecraft.component.DataComponentType; import net.minecraft.component.DataComponentTypes; import net.minecraft.enchantment.Enchantment; +import net.minecraft.entity.attribute.EntityAttribute; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.TooltipAppender; @@ -33,6 +35,7 @@ import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtElement; import net.minecraft.nbt.NbtList; import net.minecraft.registry.Registries; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; @@ -41,6 +44,8 @@ import org.spongepowered.asm.mixin.Shadow; 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.Redirect; +import org.spongepowered.asm.mixin.injection.Slice; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.Optional; @@ -75,6 +80,15 @@ public abstract class MixinItemStack { } } + @Redirect(method = "appendAttributeModifierTooltip", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;getAttributeBaseValue(Lnet/minecraft/registry/entry/RegistryEntry;)D", ordinal = 0)) + private double removeAttackDamageValueFromCalculation(PlayerEntity instance, RegistryEntry registryEntry) { + if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_8)) { + return 0; + } else { + return instance.getAttributeBaseValue(registryEntry); + } + } + @Unique private void viaFabricPlus$appendEnchantments1_14_4(final String name, final NbtCompound nbt, final Consumer tooltip) { final NbtList enchantments = nbt.getList(name, NbtElement.COMPOUND_TYPE);