From d16204168c396ebf5d3ac40a3e0dc221c24e135d Mon Sep 17 00:00:00 2001 From: OroArmor Date: Mon, 22 Mar 2021 22:08:48 -0700 Subject: [PATCH] Fix crash with trinkets --- .../mixin/trinkets/NetheriteElytraMixin.java | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/fabric/src/main/java/com/oroarmor/netherite_plus/mixin/trinkets/NetheriteElytraMixin.java b/fabric/src/main/java/com/oroarmor/netherite_plus/mixin/trinkets/NetheriteElytraMixin.java index 1d8f638..938cbaa 100644 --- a/fabric/src/main/java/com/oroarmor/netherite_plus/mixin/trinkets/NetheriteElytraMixin.java +++ b/fabric/src/main/java/com/oroarmor/netherite_plus/mixin/trinkets/NetheriteElytraMixin.java @@ -1,21 +1,18 @@ package com.oroarmor.netherite_plus.mixin.trinkets; import java.util.List; +import java.util.Objects; import com.oroarmor.netherite_plus.compatibility.NetheritePlusTrinketsRenderer; import com.oroarmor.netherite_plus.config.NetheritePlusConfig; import com.oroarmor.netherite_plus.item.NetheriteElytraItem; -import dev.emi.trinkets.api.Slots; -import dev.emi.trinkets.api.Trinket; -import dev.emi.trinkets.api.TrinketItem; -import dev.emi.trinkets.api.TrinketsApi; +import dev.emi.trinkets.api.*; 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; import net.minecraft.block.DispenserBlock; -import net.minecraft.client.item.TooltipContext; import net.minecraft.client.network.AbstractClientPlayerEntity; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.entity.model.PlayerEntityModel; @@ -24,7 +21,6 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.text.Text; import net.minecraft.text.TranslatableText; import net.minecraft.util.Hand; import net.minecraft.util.TypedActionResult; @@ -32,37 +28,38 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback; @Mixin(NetheriteElytraItem.class) public class NetheriteElytraMixin extends Item implements Trinket { - public NetheriteElytraMixin(Settings settings) { + private NetheriteElytraMixin(Settings settings) { super(settings); } @Inject(method = "", at = @At("TAIL")) public void init(Item.Settings settings, CallbackInfo info) { DispenserBlock.registerBehavior(this, TrinketItem.TRINKET_DISPENSER_BEHAVIOR); - } - @Override - public void appendTooltip(ItemStack stack, World world, List tooltip, TooltipContext context) { - tooltip.add(new TranslatableText("warning.netherite_elytra.trinkets")); - super.appendTooltip(stack, world, tooltip, context); + ItemTooltipCallback.EVENT.register((stack, context, lines) -> { + if (stack.getItem() == this) { + lines.add(new TranslatableText("warning.netherite_elytra.trinkets")); + } + }); } @Override public boolean canWearInSlot(String group, String slot) { - return slot.equals(Slots.CAPE); + return slot.equals(Slots.CAPE) || group.equals(SlotGroups.CHEST); } @Override public void onEquip(PlayerEntity player, ItemStack stack) { - player.getAttributes().getCustomInstance(EntityAttributes.GENERIC_ARMOR).setBaseValue(NetheritePlusConfig.DAMAGE.ELYTRA_ARMOR_POINTS.getValue() + player.getAttributes().getCustomInstance(EntityAttributes.GENERIC_ARMOR).getBaseValue()); + Objects.requireNonNull(player.getAttributes().getCustomInstance(EntityAttributes.GENERIC_ARMOR)).setBaseValue(NetheritePlusConfig.DAMAGE.ELYTRA_ARMOR_POINTS.getValue() + Objects.requireNonNull(player.getAttributes().getCustomInstance(EntityAttributes.GENERIC_ARMOR)).getBaseValue()); } @Override public void onUnequip(PlayerEntity player, ItemStack stack) { - player.getAttributes().getCustomInstance(EntityAttributes.GENERIC_ARMOR).setBaseValue(-NetheritePlusConfig.DAMAGE.ELYTRA_ARMOR_POINTS.getValue() + player.getAttributes().getCustomInstance(EntityAttributes.GENERIC_ARMOR).getBaseValue()); + Objects.requireNonNull(player.getAttributes().getCustomInstance(EntityAttributes.GENERIC_ARMOR)).setBaseValue(-NetheritePlusConfig.DAMAGE.ELYTRA_ARMOR_POINTS.getValue() + Objects.requireNonNull(player.getAttributes().getCustomInstance(EntityAttributes.GENERIC_ARMOR)).getBaseValue()); } @Environment(EnvType.CLIENT)