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.*;
|
2023-03-17 20:28:51 +01:00
|
|
|
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;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2023-03-17 20:28:51 +01:00
|
|
|
import net.minecraft.predicate.entity.EntityPredicates;
|
2022-09-20 23:50:15 +02:00
|
|
|
import net.minecraft.sound.SoundEvent;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
SoundEvent soundEvent = stack.getEquipSound();
|
|
|
|
if (soundEvent != null) {
|
|
|
|
entity.playSound(soundEvent, 1, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// @Override
|
2022-09-21 15:08:52 +02:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2023-03-17 20:28:51 +01:00
|
|
|
@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) {
|
|
|
|
item.getAttributeModifiers(wearable.getPreferredSlot(stack));
|
|
|
|
}
|
|
|
|
return modifiers;
|
|
|
|
}
|
|
|
|
}
|