Interaction Events
dev.architectury.event.events.common.InteractionEvent
Fires when a player clicks blocks, entities, items, or the air. These are the hooks for right-click / left-click behavior.
Events
| Event | Listener method | Returns |
|---|---|---|
LEFT_CLICK_BLOCK | click(Player, InteractionHand, BlockPos, Direction face) | EventResult |
RIGHT_CLICK_BLOCK | click(Player, InteractionHand, BlockPos, Direction face) | EventResult |
RIGHT_CLICK_ITEM | click(Player, InteractionHand) | EventResult |
INTERACT_ENTITY | interact(Player, Entity, InteractionHand) | EventResult |
FARMLAND_TRAMPLE | trample(Level, BlockPos, BlockState, double distance, Entity) | EventResult |
CLIENT_LEFT_CLICK_AIR | click(Player, InteractionHand) | void - client only |
CLIENT_RIGHT_CLICK_AIR | click(Player, InteractionHand) | void - client only |
Examples
Right-clicking a specific block opens your custom UI:
InteractionEvent.RIGHT_CLICK_BLOCK.register((player, hand, pos, face) -> {
BlockState state = player.level().getBlockState(pos);
if (state.is(MyBlocks.MY_MACHINE.get())) {
// ...open your menu...
return EventResult.interruptTrue(); // handled - stop here
}
return EventResult.pass();
});
Cancel interacting with a protected entity:
InteractionEvent.INTERACT_ENTITY.register((player, entity, hand) -> {
if (isProtected(entity)) {
return EventResult.interruptFalse();
}
return EventResult.pass();
});
warning
CLIENT_LEFT_CLICK_AIR and CLIENT_RIGHT_CLICK_AIR only fire on the client, and the player is
always the LocalPlayer. Only register them from client-side code.