Accessories API
Open
Accessories API
Created by: nutellamanxd
This isnt a bug, but I dont understand how to allow the stats from an accessory to be used when in a certain slot in my inventory. Any help would be much appreciated.
Created by: Indyuce
MMOItems has an interface called PlayerInventory which lets you define what items MMOItems should check when doing inventory updates. For instance, the default PlayerInventory instance only checks for the two hand slots + the 4 armor slots.
When using MMOInventory, you get the 6 default slots, plus any custom accessory slots. It looks something like this
public class MMOItemsCompatibility implements PlayerInventory { @Override public List<EquippedItem> getInventory(Player player) { List<EquippedItem> list = new ArrayList<>(); // hand items list.add(new EquippedItem(player.getInventory().getItemInMainHand(), EquipmentSlot.MAIN_HAND)); list.add(new EquippedItem(player.getInventory().getItemInOffHand(), EquipmentSlot.OFF_HAND)); // armor items for (ItemStack armor : player.getInventory().getArmorContents()) list.add(new EquippedItem(armor, EquipmentSlot.ARMOR)); // all the custom accessory slots MMOInventory.plugin.getDataManager().getInventory(player).getExtraItems().forEach(item -> list.add(new EquippedItem(item, EquipmentSlot.ACCESSORY))); // returns list with every registered inventory item // mmoitems will then "filter" that list based on item restrictions and calculate the stats that must be given to the player return list; } }
This is the code for the EquippedItem class, it's a MMOItems class used to register items in a player inventory.
public class EquippedItem { private final NBTItem item; private final EquipmentSlot slot; public EquippedItem(ItemStack item, EquipmentSlot slot) { this(MMOLib.plugin.getNMS().getNBTItem(item), slot); } public EquippedItem(NBTItem item, EquipmentSlot slot) { this.item = item; this.slot = slot; } public NBTItem newNBTItem() { return item; } public boolean matches(Type type) { return slot == EquipmentSlot.ANY || (type.getEquipmentType() == EquipmentSlot.BOTH_HANDS ? slot.isHand() : slot == EquipmentSlot.BOTH_HANDS ? type.getEquipmentType().isHand() : slot == type.getEquipmentType()); } }
You would have to create your own PlayerInventory subclass with whatever slot you want and throw MMOItems inventory updates using
PlayerData.get(UUID).updateInventory()
. Also keep in mind the inv update updates ALL the items so it's rather heavy method in terms of performance. This is something I'd like to rework to make it more intelligent i.e be able to update specific slots of the inventory instead of the whole inv every time.