Help With InventoryAPI

I’m trying to develop something for my plugin where when a item with a specific name is moved into an input slot on a Crafting Tablet, Furnace, Anvil, etc., the item will be immediately destroyed. I’m having some major difficulty with this, however, as there does not appear to be any current documentation on how to do this. Has anyone had any luck with figuring out the InventoryAPI, and wouldn’t mind sharing their information? If you could find recent documentation, I would be fine with that as well.

The main part that I’m struggling with is finding out if the slot type that the item is being moved into during the ChangeInventoryEvent is one of these previously mentioned.

Based on what you have currently said. Your best bet is to get the Inventories Archetype. Not sure it you can get it from the slot, but if you have the original inventory (from the ItemChangeEvent you should). You can just do

InventoryArchetype type = inv.getArchetype();
if(type.equals(InventoryArchetypes.FURNACE){

And that will tell you if the slot came from a Furnace slot.

However because your seeing if the slot being inputted is a input slot, you can just check for the instanceof the slot and check it is a InputSlot using one of these
https://github.com/SpongePowered/SpongeAPI/tree/bleeding/src/main/java/org/spongepowered/api/item/inventory/slot

I am on my phone so no code is tested

edit(jamierocks, 09/08/2018): InventoryArchitecture -> InventoryArchetype

1 Like

I did use (SlotTransaction#getSlot() instanceof InputSlot), however, neither that nor (SlotTransaction#getSlot()#parent() instanceof InputSlot) resulted in a true. SlotTransaction was obtained through ChangeInventoryEvent#getTransactions().

Here’s the listener in its entirety, perhaps there’s somewhere else in it that I messed up… @Listener public void onStickIntoCrafting(ChangeInventoryEvent event, @First - Pastebin.com