Curios API (Forge/NeoForge)

Curios API (Forge/NeoForge)

204M Downloads

Check if an item is equipped in a slot.

Regocenlo opened this issue ยท 1 comments

commented

I want to get the item that is equipped in a certain slot. This is the same way I get the item by slot: getItemBySlot(EquipmentSlot.OFFHAND)

public static void onEntityDeath(LivingDeathEvent event) {
DamageSource source = event.getSource();
if (source.getDirectEntity() instanceof Player) {
Player playerEntity = (Player) source.getDirectEntity();
ItemStack stack = playerEntity.getItemBySlot(EquipmentSlot.OFFHAND);
Item item = stack.getItem();
if (item == ItemInit.RING_OF_EXPERIENCE.get() && event.getEntity() instanceof LivingEntity) {
Mob entity = (Mob) event.getEntity();
int xp = entity.xpReward;
entity.xpReward = xp + 1;
}
}
}

commented

Checking if an item is equipped:

CuriosApi.getCuriosInventory(player).ifPresent(inventory -> {
  boolean isEquipped = inventory.isEquipped(ItemInit.RING_OF_EXPERIENCE.get());
  // rest of the code
});