dev.polymodloader.api.event.interaction
This page is generated from the source's Javadoc by ./gradlew apiReference. Do not edit it; fix the source comment and generate it again.
| Type | Kind | Description |
|---|---|---|
AttackEntityListener | functional interface | Listener for InteractionEvents.ATTACK_ENTITY. |
InteractionEvents | class | A player interacting with the world: right-clicking blocks, items, and entities, and attacking entities. |
UseBlockListener | functional interface | Listener for InteractionEvents.USE_BLOCK. |
UseEntityListener | functional interface | Listener for InteractionEvents.USE_ENTITY. |
UseItemListener | functional interface | Listener for InteractionEvents.USE_ITEM. |
AttackEntityListener
functional interface · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier
public interface AttackEntityListener
Listener for InteractionEvents.ATTACK_ENTITY.
onAttackEntity(PlayerView, EntityView)
EventResult onAttackEntity(PlayerView player, EntityView target)
Since 0.1.0-alpha.4 or earlier
Called on the server thread. The views are valid only during the call.
| Parameter | Type | Description |
|---|---|---|
player | PlayerView | the attacker |
target | EntityView | the attacked entity |
Returns EventResult — DENY to cancel the attack (no damage, knockback, or durability loss); ALLOW or PASS to let it happen
InteractionEvents
class · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier
public final class InteractionEvents
A player interacting with the world: right-clicking blocks, items, and entities, and attacking entities. Fired on the server thread when the server handles the player's action, for connected and mock players alike. The client's own prediction of the click is not an event yet; when a listener refuses an action the server corrects the client as it does for any refused action.
Results: these are decision events (see EventResult): listeners run in priority order until one decides. The use events take a InteractionResult: PASS lets the next listener and then the game handle the click; SUCCESS or CONSUME ends it as handled, so the game's own behaviour (opening a chest, placing a block, eating) does not happen; FAIL ends it as refused. The attack event takes an EventResult: DENY cancels the attack.
Fabric API: UseBlockCallback, UseItemCallback, UseEntityCallback, AttackEntityCallback. NeoForge: PlayerInteractEvent.RightClickBlock, RightClickItem, EntityInteract, AttackEntityEvent.
| Constant or field | Type | Description |
|---|---|---|
USE_BLOCK | EventKey<UseBlockListener> | A player right-clicks a block, before the held item or the block reacts. Fired once per hand the game tries: the main hand first, then the off hand when the main hand passed. |
USE_ITEM | EventKey<UseItemListener> | A player right-clicks with an item in the air (not at a block or entity), before the item reacts. |
USE_ENTITY | EventKey<UseEntityListener> | A player right-clicks an entity, before the entity or the held item reacts. |
ATTACK_ENTITY | EventKey<AttackEntityListener> | A player attacks (left-clicks) an entity, before damage and knockback. |
UseBlockListener
functional interface · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier
public interface UseBlockListener
Listener for InteractionEvents.USE_BLOCK.
onUseBlock(PlayerView, Hand, ItemStackRef, BlockPos, Direction)
InteractionResult onUseBlock(PlayerView player, Hand hand, ItemStackRef stack, BlockPos pos, Direction face)
Since 0.1.0-alpha.4 or earlier
Called on the server thread. The views are valid only during the call.
| Parameter | Type | Description |
|---|---|---|
player | PlayerView | who clicked; player.world() is the world of the block |
hand | Hand | the hand the game is trying |
stack | ItemStackRef | the live stack in that hand, possibly empty |
pos | BlockPos | the clicked block |
face | Direction | the clicked face of the block |
Returns InteractionResult — PASS to let others and the game handle it; anything else ends the click
UseEntityListener
functional interface · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier
public interface UseEntityListener
Listener for InteractionEvents.USE_ENTITY.
onUseEntity(PlayerView, Hand, ItemStackRef, EntityView)
InteractionResult onUseEntity(PlayerView player, Hand hand, ItemStackRef stack, EntityView target)
Since 0.1.0-alpha.4 or earlier
Called on the server thread. The views are valid only during the call.
| Parameter | Type | Description |
|---|---|---|
player | PlayerView | who clicked |
hand | Hand | the hand the game is trying |
stack | ItemStackRef | the live stack in that hand, possibly empty |
target | EntityView | the clicked entity |
Returns InteractionResult — PASS to let others and the game handle it; anything else ends the click, so the entity's reaction (trading, mounting, shearing) does not happen
UseItemListener
functional interface · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier
public interface UseItemListener
Listener for InteractionEvents.USE_ITEM.
onUseItem(PlayerView, Hand, ItemStackRef)
InteractionResult onUseItem(PlayerView player, Hand hand, ItemStackRef stack)
Since 0.1.0-alpha.4 or earlier
Called on the server thread, also for an empty hand. The views are valid only during the call.
| Parameter | Type | Description |
|---|---|---|
player | PlayerView | who used the item |
hand | Hand | the hand holding it |
stack | ItemStackRef | the live stack in that hand, possibly empty |
Returns InteractionResult — PASS to let others and the game handle it; anything else ends the use, so the item's own behaviour (eating, throwing, drawing a bow) does not start