Skip to content

InteractEntity ​

com.jsmacrosce.jsmacros.client.api.event.impl.player.EventInteractEntity

Not cancellable

Fires after the local player's entity-interact action returns, except when it returns InteractionResult.FAIL. result is true when the result consumes the action and false when it does not; false is not an event rejection. This event reports the interact action, not attacks, which use EventAttackEntity.

js
JsMacros.on("InteractEntity", JavaWrapper.methodToJava(function (event) {
 Chat.log(`${event.result ? "Consumed" : "Passed"}: ${event.entity.getType()}`);  
}))
js
JsMacros.on("InteractEntity", JavaWrapper.methodToJava(function (event) {
 if (event.result) {
   Chat.log(`${event.offhand ? "Off hand" : "Main hand"} used on ${event.entity.getType()}`);  
 }
}))

Constructors ​

new EventInteractEntity ​

new EventInteractEntity(boolean offhand, boolean accepted, Entity entity)#
Stores the interaction hand, consumption flag, and wrapped entity; this constructor does not perform or dispatch an interaction.

Parameters:

  • offhand: whether the supplied hand flag indicates the off hand; false indicates the main hand
  • accepted: the supplied action-consumption flag, stored as result
  • entity: the Minecraft entity to wrap; wrapping fails with NullPointerException if it is null

Fields ​

entity ​

entity: EntityHelper<?>read-only#
The clicked entity, wrapped in the most specific EntityHelper subclass for its type, so it can be narrowed with instanceof EntityHelpers.Player and the other namespace types; asLiving(), asPlayer() and the other as...() helpers are casts. Its type is available from getType() and its name from getName().

offhand ​

offhand: booleanread-only#
true if the click was made with the off hand, false if it was made with the main hand.

result ​

result: booleanread-only#
true if the interaction result consumes the action, false if it does not. The event is not fired when the result is FAIL.

Methods ​

toString ​

toString(): String#
Returns this event's diagnostic string, including its event name, entity representation, and stored result flag.
Returns: a string formatted as %s:{"entity": %s, "result": "%s"}; the entity field uses the helper's runtime representation, and the offhand flag is omitted