Skip to content

InteractionManagerHelper ​

com.jsmacrosce.jsmacros.client.api.helper.InteractionManagerHelper

Since1.9.0

Controls client-side player interactions with the world through the current interaction manager.

Obtain it with Player.interactions(), which is null when no interaction manager is available. Block and entity target overrides affect operations that use the crosshair until cleared; range and block checks may also clear or turn an override into a miss.

An await option waits for the queued client-thread invocation when called from outside the client thread and its joined-thread stack; it does not wait for server confirmation.
Calls on that stack execute directly. breakBlock() rejects waiting on that stack after checking for an immediate result; timed holdInteract(int) calls reject it before enabling the hold. Waiting can be interrupted; interruption during a timed hold can leave the interact override enabled.

js
const interactions = Player.interactions();  
if (interactions === null) { throw new Error("not in a world"); }

interactions.breakBlockAsync(JavaWrapper.methodToJava(function (result) {
 Chat.log(`break finished as ${result.reason}`);  
}));

Constructors ​

new InteractionManagerHelper ​

new InteractionManagerHelper(MultiPlayerGameMode base)#
Wraps the supplied interaction manager as this helper's initial reference.

Parameters:

  • base: initial interaction manager to wrap

Fields ​

autoUpdateBase ​

autoUpdateBase: boolean#
Whether methods refresh this helper's wrapped manager when it differs from the client's current manager. Defaults to true; when disabled, a mismatch throws RuntimeException. If no replacement manager exists, updating fails and retains the wrapped manager. See checkBase(boolean) for the exact result.

Methods ​

attack ​

attack(): InteractionManagerHelperSince1.5.0#
Returns: self for chaining
attack(boolean await): InteractionManagerHelperSince1.6.0#

Parameters:

  • await: whether to wait for the queued client-thread attack call to finish when called outside the client thread and its joined-thread stack; calls on that stack execute directly. This does not wait for server confirmation
Returns: self for chaining
attack(EntityHelper<?> entity): InteractionManagerHelperSince1.5.0#
Attacks the entity and swings the main-hand item. Does nothing if the interaction manager is unavailable.

Parameters:

  • entity: entity to attack; targeting the local player throws AssertionError
Returns: self for chaining
attack(EntityHelper<?> entity, boolean await): InteractionManagerHelperSince1.6.0#
Attacks the entity and swings the main-hand item. Does nothing if the interaction manager is unavailable.

Parameters:

  • entity: entity to attack; targeting the local player throws AssertionError
  • await: whether to wait for the queued attack and swing to finish when called outside the client thread and its joined-thread stack; calls on that stack execute directly. This does not wait for server confirmation
Returns: self for chaining
attack(int x, int y, int z, String direction): InteractionManagerHelperSince1.8.4#
Starts breaking the block at the given block coordinates and swings the main-hand item.

Parameters:

  • x: block x coordinate
  • y: block y coordinate
  • z: block z coordinate
  • direction: block face name: up, down, north, south, east, or west
Returns: self for chaining.
attack(int x, int y, int z, int direction): InteractionManagerHelperSince1.5.0#
Starts breaking the block at the given block coordinates and swings the main-hand item.

Parameters:

  • x: block x coordinate
  • y: block y coordinate
  • z: block z coordinate
  • direction: face's 3D data value (0-5: down, up, north, south, west, east)
Returns: self for chaining
attack(int x, int y, int z, String direction, boolean await): InteractionManagerHelperSince1.8.4#
Starts breaking the block at the given block coordinates and swings the main-hand item.

Parameters:

  • x: block x coordinate
  • y: block y coordinate
  • z: block z coordinate
  • direction: block face name: up, down, north, south, east, or west
  • await: whether to wait for the queued block-breaking call and swing to finish when called outside the client thread and its joined-thread stack; calls on that stack execute directly. This does not wait for server confirmation
Returns: self for chaining.
attack(int x, int y, int z, int direction, boolean await): InteractionManagerHelperSince1.6.0#
Starts breaking the block at the given block coordinates and swings the main-hand item.

Parameters:

  • x: block x coordinate
  • y: block y coordinate
  • z: block z coordinate
  • direction: face's 3D data value (0-5: down, up, north, south, west, east)
  • await: whether to wait for the queued block-breaking call and swing to finish when called outside the client thread and its joined-thread stack; calls on that stack execute directly. This does not wait for server confirmation
Returns: self for chaining

breakBlock ​

Breaks the currently targeted block and waits for the break result. An immediate result is checked first; otherwise, calling on the client thread or a thread joined to it throws IllegalThreadStateException. No targeted block is reported by a callback outcome such as NO_TARGET, not by returning null.
Returns: the reported break result, or UNAVAILABLE when the immediate check finds no interaction manager
breakBlock(int x, int y, int z): InteractionProxy.Break.BreakBlockResultSince1.9.0#
Attempts to break the block at the given position, temporarily overriding the target when needed.

Parameters:

  • x: block x coordinate
  • y: block y coordinate
  • z: block z coordinate
Returns: the break result, or null if the position cannot be targeted
Attempts to break the block at pos, temporarily overriding the target when needed.

Parameters:

  • pos: position to break
Returns: the break result, or null if the position cannot be targeted

breakBlockAsync ​

Starts breaking the currently targeted block and delivers the outcome to callback. A null callback starts the break without registering for its outcome. SUCCESS means the client completed the break; it does not guarantee server acceptance. Immediate-result callbacks are submitted to the client thread, and normal game-driven completion runs there. Cancellation, target clearing, reset, or a break-override query can instead invoke pending callbacks synchronously on the calling thread.
const interactions = Player.interactions();
if (interactions === null) { throw new Error("not in a world"); }

// start it and carry on, with the outcome arriving later
interactions.breakBlockAsync(JavaWrapper.methodToJava(function (result) {
  if (result !== null) {
    Chat.log(`break finished as ${result.reason}`);
  }
}));

Parameters:

  • callback: receives the break outcome
Returns: self for chaining

cancelBreakBlock ​

cancelBreakBlock(): InteractionManagerHelperSince1.9.0#
Cancels the active block-break override and reports CANCELLED to registered callbacks. Callbacks run synchronously on the caller's thread.
Returns: self for chaining

checkBase ​

checkBase(boolean update): boolean#
Checks whether the wrapped manager is current, optionally replacing it with the client's current manager. Matching references return true, including when both are null. A mismatch with update == false throws RuntimeException.

Parameters:

  • update: whether to replace a stale manager with a non-null current manager
Returns: true if the references match or replacement succeeds; false if replacement was requested but the current manager is null, leaving the wrapped manager unchanged

clearTargetOverride ​

clearTargetOverride(): InteractionManagerHelperSince1.9.0#
Clears the crosshair target override. Revalidating the pending break override can end it and invoke its callbacks on the caller's thread.
Returns: self for chaining

getGameMode ​

getGameMode(): StringSince1.9.0#
Returns: the wrapped manager's current game mode

getTarget ​

getTarget(): HitResultHelper<?>Since1.9.1#
Returns: the current crosshair hit result, or null if none is available

getTargetedBlock ​

getTargetedBlock(): BlockPosHelperSince1.9.0#
Returns: the targeted block position, or null when the current hit result is not a block hit

getTargetedEntity ​

getTargetedEntity(): EntityHelper<?>Since1.9.0#
Returns: the entity currently under the crosshair, or null when there is no crosshair entity

hasBreakBlockOverride ​

hasBreakBlockOverride(): booleanSince1.9.0#
Checks whether a break override is active. This can terminate an invalid override and dispatch pending callbacks synchronously on the caller's thread.
Returns: true while a valid break override remains active

hasInteractOverride ​

hasInteractOverride(): booleanSince1.9.0#
Returns: whether the hold-interact override is active

hasTargetOverride ​

hasTargetOverride(): booleanSince1.9.0#
Returns: whether a crosshair target override is set, including a miss override

holdInteract ​

holdInteract(boolean holding): InteractionManagerHelperSince1.9.0#
Starts or stops the continuous interact override.

Parameters:

  • holding: whether to enable or disable the override
Returns: this helper for chaining
holdInteract(boolean holding, boolean awaitFirstClick): InteractionManagerHelperSince1.9.0#
Starts or stops the continuous interact override. Disabling runs directly on the caller's thread. Enabling runs directly on the client or joined-thread stack, otherwise it is queued on the client thread.

Parameters:

  • holding: whether to enable or disable the override
  • awaitFirstClick: whether to wait for queued enabling work, not server confirmation; ignored when disabling
Returns: this helper for chaining
holdInteract(int ticks): intSince1.9.0#
Holds interact for up to the specified number of unpaused game ticks, stopping when paused or when the override stops. Calling on the client or joined-thread stack throws IllegalThreadStateException. The hold is released on normal return; interruption while waiting can leave it active.

Parameters:

  • ticks: number of ticks to hold
Returns: ticks not yet elapsed; nonzero if the hold was stopped by pausing with stopOnPause enabled or if the override stopped, and 0 when the full duration elapsed
holdInteract(int ticks, boolean stopOnPause): intSince1.9.0#
Holds interact for up to the specified number of unpaused game ticks. Calling on the client or joined-thread stack throws IllegalThreadStateException. The hold is released on normal return; interruption while waiting can leave it active.

Parameters:

  • ticks: number of unpaused ticks to hold
  • stopOnPause: whether to stop when the game is paused; if false, paused ticks do not count and the hold resumes after unpausing
Returns: ticks remaining; nonzero if paused with stopOnPause enabled or if the override stopped, and 0 when the full duration elapsed

interact ​

interact(): InteractionManagerHelperSince1.5.0#
Starts using the main-hand item.
Returns: self for chaining
interact(boolean await): InteractionManagerHelperSince1.6.0#

Parameters:

  • await: whether to wait for the queued client-thread invocation; calls on the client or joined-thread stack execute directly, and no server confirmation is awaited
Returns: self for chaining

interactBlock ​

interactBlock(int x, int y, int z, String direction, boolean offHand): InteractionManagerHelperSince1.8.4#
Interacts with the block at the given coordinates, using the face named by direction.

Parameters:

  • x: block x coordinate
  • y: block y coordinate
  • z: block z coordinate
  • direction: face name: up, down, north, south, east, or west
  • offHand: whether to use the off hand instead of the main hand
Returns: this helper for chaining
interactBlock(int x, int y, int z, int direction, boolean offHand): InteractionManagerHelperSince1.5.0#
Interacts with the block at the given coordinates, using the face selected by its 3D data value.

Parameters:

  • x: block x coordinate
  • y: block y coordinate
  • z: block z coordinate
  • direction: face data value: 0 down, 1 up, 2 north, 3 south, 4 west, 5 east
  • offHand: whether to use the off hand instead of the main hand
Returns: self for chaining

Note: renamed from interact in 1.6.0

interactBlock(int x, int y, int z, String direction, boolean offHand, boolean await): InteractionManagerHelperSince1.8.4#
Interacts with the block at the given coordinates, using the face named by direction.

Parameters:

  • x: block x coordinate
  • y: block y coordinate
  • z: block z coordinate
  • direction: face name: up, down, north, south, east, or west
  • offHand: whether to use the off hand instead of the main hand
  • await: whether to wait for the queued client-thread task to run; it does not wait for server confirmation
Returns: this helper for chaining
interactBlock(int x, int y, int z, int direction, boolean offHand, boolean await): InteractionManagerHelperSince1.5.0#
Interacts with the block at the given coordinates, using the face selected by its 3D data value.

Parameters:

  • x: block x coordinate
  • y: block y coordinate
  • z: block z coordinate
  • direction: face data value: 0 down, 1 up, 2 north, 3 south, 4 west, 5 east
  • offHand: whether to use the off hand instead of the main hand
  • await: whether to wait for the queued client-thread task to run; it does not wait for server confirmation
Returns: this helper for chaining

Note: renamed from interact in 1.6.0

interactEntity ​

interactEntity(EntityHelper<?> entity, boolean offHand): InteractionManagerHelperSince1.5.0#
Interacts with entity using the selected hand.

Parameters:

  • entity: entity to interact with; the local player's entity causes AssertionError
  • offHand: whether to use the off hand instead of the main hand
Returns: self for chaining

Note: renamed from interact in 1.6.0

interactEntity(EntityHelper<?> entity, boolean offHand, boolean await): InteractionManagerHelperSince1.6.0#
Interacts with an entity using the selected hand.

Parameters:

  • entity: entity to interact with; the player's own entity causes an AssertionError
  • offHand: whether to use the off hand instead of the main hand
  • await: whether to wait for the queued client-thread task to run; it does not wait for server confirmation
Returns: self for chaining

interactItem ​

interactItem(boolean offHand): InteractionManagerHelperSince1.5.0#
Uses the selected hand's held item.

Parameters:

  • offHand: whether to use the off hand instead of the main hand
Returns: self for chaining

Note: renamed from interact in 1.6.0

interactItem(boolean offHand, boolean await): InteractionManagerHelperSince1.6.0#
Uses the selected hand's held item.

Parameters:

  • offHand: whether to use the off hand instead of the main hand
  • await: whether to wait for the queued client-thread task to run; it does not wait for server confirmation
Returns: self for chaining

isBreakingBlock ​

isBreakingBlock(): booleanSince1.8.0#
Returns: whether the current interaction manager is destroying a block

resetTargetChecks ​

resetTargetChecks(): InteractionManagerHelperSince1.9.0#
Resets the checks to defaults: range checking enabled and clears out-of-range targets; air checking disabled and retains air targets; shape checking enabled and turns empty shapes into misses.
Returns: self for chaining

setGameMode ​

setGameMode(String gameMode): InteractionManagerHelperSince1.9.0#
Sets the client's local game mode; it does not change the server's game mode.

Parameters:

  • gameMode: game mode name; recognized names are case-insensitive, and unrecognized names retain the current mode
Returns: self for chaining

setTarget ​

setTarget(int x, int y, int z): InteractionManagerHelperSince1.9.0#
Overrides the crosshair hit result with the block at these coordinates and its down face.

Parameters:

  • x: block x coordinate
  • y: block y coordinate
  • z: block z coordinate
Returns: self for chaining
setTarget(int x, int y, int z, String direction): InteractionManagerHelperSince1.9.0#
Overrides the crosshair hit result with the block at these coordinates and the named face. This is an override, not a read: it tells the game that the calls acting on "whatever the player is looking at" should act on this block instead. It stays in place until clearTargetOverride() puts it back, so a script that sets one and does not clear it has changed the game for everything that runs after it. The override remains until cleared or removed by configured target checks. The other overloads accept a BlockPosHelper, a 3D face data value, or an entity.
const interactions = Player.interactions();
if (interactions === null) { throw new Error("not in a world"); }

// act on the top face of a specific block, then put the crosshair back
interactions.setTarget(10, 64, -10, "up");
interactions.interactBlock(10, 64, -10, "up", false);
interactions.clearTargetOverride();

Parameters:

  • x: block x coordinate
  • y: block y coordinate
  • z: block z coordinate
  • direction: block face name: up, down, north, south, east, or west
Returns: self for chaining
setTarget(int x, int y, int z, int direction): InteractionManagerHelperSince1.9.0#
Overrides the crosshair hit result with the block at these coordinates and the face identified by its 3D data value.

Parameters:

  • x: block x coordinate
  • y: block y coordinate
  • z: block z coordinate
  • direction: face's 3D data value (0-5: down, up, north, south, west, east)
Returns: self for chaining
setTarget(BlockPosHelper pos): InteractionManagerHelperSince1.9.0#
Overrides the crosshair hit result with the block at pos and its down face.

Parameters:

  • pos: block position
Returns: self for chaining
setTarget(BlockPosHelper pos, String direction): InteractionManagerHelperSince1.9.0#
Overrides the crosshair hit result with the block at pos and the named face.

Parameters:

  • pos: block position
  • direction: block face name: up, down, north, south, east, or west
Returns: self for chaining
setTarget(BlockPosHelper pos, int direction): InteractionManagerHelperSince1.9.0#
Overrides the crosshair hit result with the block at pos and the face identified by its 3D data value.

Parameters:

  • pos: block position
  • direction: face's 3D data value (0-5: down, up, north, south, west, east)
Returns: self for chaining
setTarget(EntityHelper<?> entity): InteractionManagerHelperSince1.9.0#
Overrides the crosshair hit result with the entity. Throws an AssertionError if the entity is not pickable or is the local player.

Parameters:

  • entity: entity to target
Returns: self for chaining

setTargetAirCheck ​

setTargetAirCheck(boolean enabled, boolean autoClear): InteractionManagerHelperSince1.9.0#

Parameters:

  • enabled: whether to check if a block target is air; defaults to false
  • autoClear: whether an air-block override is cleared; if false, it becomes a miss
Returns: self for chaining

setTargetMissed ​

setTargetMissed(): InteractionManagerHelperSince1.9.0#
Overrides the crosshair hit result with a miss.
Returns: self for chaining

setTargetRangeCheck ​

setTargetRangeCheck(boolean enabled, boolean autoClear): InteractionManagerHelperSince1.9.0#

Parameters:

  • enabled: whether to check override range; defaults to true
  • autoClear: whether an out-of-range override is cleared; if false, it becomes a miss
Returns: self for chaining

setTargetShapeCheck ​

setTargetShapeCheck(boolean enabled, boolean autoClear): InteractionManagerHelperSince1.9.0#
Controls whether block-target overrides are rejected when the block's collision shape is empty. Air blocks are excluded from this check; use setTargetAirCheck(boolean, boolean) to check air.

Parameters:

  • enabled: whether to check for an empty block shape; defaults to true
  • autoClear: whether an override with an empty shape is cleared; otherwise it becomes a miss. Defaults to false
Returns: self for chaining