Unicopia/src/main/java/com/minelittlepony/unicopia/trinkets/UnicopiaTrinket.java

72 lines
2.4 KiB
Java
Raw Normal View History

2022-09-20 23:50:15 +02:00
package com.minelittlepony.unicopia.trinkets;
import java.util.UUID;
import com.google.common.collect.Multimap;
import com.minelittlepony.unicopia.item.FriendshipBraceletItem;
import com.minelittlepony.unicopia.item.WearableItem;
import dev.emi.trinkets.api.*;
import net.minecraft.enchantment.EnchantmentHelper;
2022-09-20 23:50:15 +02:00
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.attribute.EntityAttribute;
import net.minecraft.entity.attribute.EntityAttributeModifier;
2023-06-02 21:20:30 +02:00
import net.minecraft.item.Equipment;
2022-09-20 23:50:15 +02:00
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.predicate.entity.EntityPredicates;
2022-09-20 23:50:15 +02:00
public class UnicopiaTrinket implements Trinket {
private final Item item;
public UnicopiaTrinket(Item item) {
this.item = item;
}
@Override
public void onEquip(ItemStack stack, SlotReference slot, LivingEntity entity) {
if (entity.isSpectator() || stack.isEmpty()) {
return;
}
2023-06-02 21:20:30 +02:00
if (stack.getItem() instanceof Equipment q) {
entity.playSound( q.getEquipSound(), 1, 1);
2022-09-20 23:50:15 +02:00
}
}
// @Override
public int getMaxCount(ItemStack stack, SlotReference slot) {
2022-09-20 23:50:15 +02:00
// https://github.com/emilyploszaj/trinkets/issues/215
return 1;
}
@Override
public boolean canEquip(ItemStack stack, SlotReference slot, LivingEntity entity) {
if (item instanceof FriendshipBraceletItem && !FriendshipBraceletItem.isSigned(stack)) {
return false;
}
return slot.inventory().getStack(slot.index()).isEmpty();
}
@Override
public boolean canUnequip(ItemStack stack, SlotReference slot, LivingEntity entity) {
return !(EnchantmentHelper.hasBindingCurse(stack) && EntityPredicates.EXCEPT_CREATIVE_OR_SPECTATOR.test(entity));
}
2022-09-20 23:50:15 +02:00
@Override
public void tick(ItemStack stack, SlotReference slot, LivingEntity entity) {
item.inventoryTick(stack, entity.world, entity, slot.index(), false);
}
@Override
public Multimap<EntityAttribute, EntityAttributeModifier> getModifiers(ItemStack stack, SlotReference slot, LivingEntity entity, UUID uuid) {
Multimap<EntityAttribute, EntityAttributeModifier> modifiers = Trinket.super.getModifiers(stack, slot, entity, uuid);
if (item instanceof WearableItem wearable) {
2023-06-02 21:20:30 +02:00
item.getAttributeModifiers(wearable.getSlotType(stack));
2022-09-20 23:50:15 +02:00
}
return modifiers;
}
}