fabric-events-interaction-v0: UseEntityCallback cancelling not completely cancelling interaction
nickrobson opened this issue · 0 comments
Hey there!
It looks like subscribing to events using the UseEntityCallback.EVENT
callback and returning a ActionResult.FAIL
doesn't actually prevent the entire entity interaction. The mixin seems to only be listening to/affecting the interact at
interaction type and not the interact
type, which the Minecraft client will fall back to if the former fails on the client side (see the ENTITY
handling block in MinecraftClient#doItemUse
(yarn mappings)) - and cancelling this fallback too works as expected.
Code to reproduce (just right-click a villager and you'll see the UI still opens)
UseEntityCallback.EVENT.register((player, world, hand, entity, hitResult) -> {
return ActionResult.FAIL;
});
I'd love to see this fixed as I'm writing a mod that involves cancelling entity interactions, so I've had to do the double injection to work around this!
To fix this, I see two ways of doing it:
-
Adding another injection point at the start of the
interact
method in the same class as theinteractAt
injection point. This has the positive of being simple, but the negative of meaning each handler is called twice, which may be a deal-breaker – or will at least need a way of differentiating the two interaction types. -
Lifting the injection point up one layer so that it covers both
interact
andinteractAt
in one go, so aFAIL
result skips bothinteract at
andinteract
attempts. I believe this would be the preferred option as each listener would be called only once and would be able to truly allow/deny the entire entity interaction.