Skip to content

Commit

Permalink
Fix crash with trinkets
Browse files Browse the repository at this point in the history
  • Loading branch information
OroArmor committed Mar 23, 2021
1 parent b7ed5fc commit d162041
Showing 1 changed file with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -24,45 +21,45 @@
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;
import net.minecraft.world.World;

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 = "<init>", 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<Text> 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)
Expand Down

0 comments on commit d162041

Please sign in to comment.