ItemCraft Event


#1

Hello.
How I Can track if user crafted the item?
Trying to do smth like:

@Listener
public void onItemCraft(ClickInventoryEvent event, @Root Player player, @Getter(“getTargetInventory”) Inventory inventory) {

if (inventory.getArchetype() == InventoryArchetypes.PLAYER || inventory.getArchetype() == InventoryArchetypes.WORKBENCH) {

    Inventory craftingOutputs = inventory.query(CraftingOutput.class);

    craftingOutputs.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> {
        String itemId = itemStack.getItem().getType().getId();
            Utils.Utils.sendMessage(player, "Вы скрафтили: [", TextColors.BLUE, itemId, "]");
    }));
}

But, have a problem, player get message after compile items at workbench to create smth.

How to check if user click on crafting output field?


#2

Check the transactions in event.getTransactions() - for each one, check if its slot is a CraftingOutput.


#3

So, how I can do it?
Please help


#4

… what?
Are you asking how to call a method?


#5

Yep, sorry, but I’m so dumb for this…

            if(event.getTransactions().equals(craftingOutputs)){
                Utils.Utils.sendMessage(player, "Вы скрафтили: [", TextColors.BLUE, itemId, "]");    
            }

This code doesn’t work


#6

Now trying do this:

Inventory craftingOutputs = inventory.query(CraftingOutput.class);

        craftingOutputs.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> {
            String itemId = itemStack.getItem().getType().getId();
                for (Iterator<SlotTransaction> i = event.getTransactions().iterator(); i.hasNext();) {
                    SlotTransaction item = i.next();
                    if(item.getSlot().equals(slot)){
                        Utils.Utils.sendMessage(player, "Вы скрафтили: [", TextColors.BLUE, itemId, "]");   
                    }
                }
               
        }));

Not success, again


#7

The main question is - how I Can get the craftring output slot?


#8

In the line Inventory craftingOutputs = inventory.query(CraftingOutput.class);, replace Inventory craftingOutputs with CraftingOutput slot. This is the crafting output slot. You don’t need to use slots() with this.