How to get the item from ChangeBlockEvent.Break

I want to know if there´s a way to get the item that the player used to break the block. I red the “Cause” type from the event, and it says this:

"sponge:used_item"=SpongeItemStackSnapshot{itemType=minecraft:diamond_pickaxe, quantity=1}]

How can I take this, and place it in a ItemStack or ItemType variable?

Thanks for your time, and sorry for my bad english.

You can use the EventContext of the cause,

public void onBreak(ChangeBlockEvent.Break event, @Root Player player) {
  event.getCause().getContext().get(EventContextKeys.USED_ITEM).ifPresent(itemUsed -> {
    // do something in here now that you have the item stack used.
1 Like