Update to 1.21.4
This commit is contained in:
@@ -1,29 +1,23 @@
|
||||
package systems.brn.plasticgun.lib;
|
||||
|
||||
import dev.emi.trinkets.TrinketSlot;
|
||||
import dev.emi.trinkets.api.*;
|
||||
|
||||
import net.minecraft.entity.EquipmentSlot;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.registry.entry.RegistryEntry;
|
||||
import net.minecraft.sound.SoundEvent;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.event.GameEvent;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static systems.brn.plasticgun.lib.Util.id;
|
||||
|
||||
public class TrinketPolymerItem extends SimpleItem implements Trinket {
|
||||
public class TrinketPolymerItem extends SimpleItem {
|
||||
|
||||
public TrinketPolymerItem(Item.Settings settings, String name) {
|
||||
super(settings, id(name), Items.STICK);
|
||||
TrinketsApi.registerTrinket(this, this);
|
||||
super(settings.equippable(EquipmentSlot.CHEST), id(name), Items.STICK);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -40,31 +34,8 @@ public class TrinketPolymerItem extends SimpleItem implements Trinket {
|
||||
}
|
||||
|
||||
public static boolean equipItem(LivingEntity user, ItemStack stack) {
|
||||
Optional<TrinketComponent> optional = TrinketsApi.getTrinketComponent(user);
|
||||
if (optional.isPresent()) {
|
||||
TrinketComponent comp = optional.get();
|
||||
for (Map<String, TrinketInventory> group : comp.getInventory().values()) {
|
||||
for (TrinketInventory inv : group.values()) {
|
||||
for (int i = 0; i < inv.size(); i++) {
|
||||
if (inv.getStack(i).isEmpty()) {
|
||||
SlotReference ref = new SlotReference(inv, i);
|
||||
if (TrinketSlot.canInsert(stack, ref, user)) {
|
||||
ItemStack newStack = stack.copy();
|
||||
inv.setStack(i, newStack);
|
||||
Trinket trinket = TrinketsApi.getTrinket(stack.getItem());
|
||||
RegistryEntry<SoundEvent> soundEvent = trinket.getEquipSound(stack, ref, user);
|
||||
if (!stack.isEmpty() && soundEvent != null) {
|
||||
user.emitGameEvent(GameEvent.EQUIP);
|
||||
user.playSound(soundEvent.value(), 1.0F, 1.0F);
|
||||
}
|
||||
stack.setCount(0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
user.equipStack(EquipmentSlot.CHEST, stack);
|
||||
user.playSound(SoundEvents.ITEM_ARMOR_EQUIP_CHAIN.value());
|
||||
return false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user