Fabric API

Fabric API

108M Downloads

UseItemCallback doesn't work with `Item.useOnBlock`

Zailer43 opened this issue ยท 1 comments

commented

Code:

UseItemCallback.EVENT.register((player, world, hand) -> TypedActionResult.fail(player.getStackInHand(hand)));

Expected behavior:

Cancel the use of all items

Current behavior:

Items are canceled when using Item.use but are not canceled when using Item.useOnBlock

Items that I have seen affected:

  • Minecarts
  • Armor stands
  • Item frames
  • Painting
commented

To cancel block interactions, you use
https://github.com/FabricMC/fabric/blob/1.18.2/fabric-events-interaction-v0/src/main/java/net/fabricmc/fabric/api/event/player/UseBlockCallback.java

There is also a separate entity interaction.

The plain item use callback is a fallback event when neither of those handle the interaction.
e.g. placing a minecart on rails would succeed in the block event part and therefore never call the plain item use part.