Skip to content

ClientPlayerEntityHelper ​

com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper

Since1.0.3

Provides client-side operations for the local player.

The local player is an EntityHelpers.ClientPlayer and therefore an EntityHelpers.Player.

Position setters schedule changes on the client thread when called off-thread; their await overloads wait for the scheduled task to run. Calls from the client thread apply immediately.

js
const player = Player.getPlayer();  
if (player !== null) {
 // turn to face a point, which is the form that works from any thread
 player.lookAt(player.getX() + 10, player.getY(), player.getZ());  
 // and nudge the player along
 player.addPos(0, 1, 0);  
 Chat.log(`now at ${player.getPos()}`);  
}

Available in scripts as EntityHelpers.ClientPlayer.

Type Parameters ​

  • T: the concrete local-player type wrapped by this helper

Constructors ​

new ClientPlayerEntityHelper ​

new ClientPlayerEntityHelper(T extends LocalPlayer e)#
Wraps the supplied local player and retains that reference.

Parameters:

  • e: the local player to wrap

Methods ​

addPos ​

addPos(Pos3D pos): ClientPlayerEntityHelper<T extends LocalPlayer>Since1.8.4#
Adds the offset to the player's position and queues the resulting position change when called off the client thread. This overload does not wait for that change.

Parameters:

  • pos: the offset to move the player by
Returns: self for chaining.
addPos(Pos3D pos, boolean await): ClientPlayerEntityHelper<T extends LocalPlayer>Since1.9.0#
moves the player by an offset rather than to a position, with a choice about whether to wait for it. When called from the client thread there is nothing to hand off and nothing to wait for, so the await flag makes no difference there. Off the client thread the move is queued onto it, and the flag decides whether this call blocks until its own task has run. The offset is applied to the position read when this method is called. Concurrent queued calls can therefore compute from the same starting position; waiting for a call to finish before the next ensures the next reads the updated position.

Parameters:

  • pos: the offset to move the player by
  • await: whether to wait for the move to be applied
Returns: self for chaining.
addPos(double x, double y, double z): ClientPlayerEntityHelper<T extends LocalPlayer>Since1.8.4#
Adds the given offset to the player's position. Off the client thread, the change is queued and this call returns without waiting for it to run.

Parameters:

  • x: the offset on the x axis
  • y: the offset on the y axis
  • z: the offset on the z axis
Returns: self for chaining.
addPos(double x, double y, double z, boolean await): ClientPlayerEntityHelper<T extends LocalPlayer>Since1.9.0#
Adds the given offset to the player's position, optionally waiting for the change to run. When called from the client thread there is nothing to hand off and nothing to wait for, so the await flag makes no difference there. Off the client thread the move is queued onto it, and the flag decides whether this call blocks until its task has run.

Parameters:

  • x: the offset on the x axis
  • y: the offset on the y axis
  • z: the offset on the z axis
  • await: whether to wait for the move to be applied
Returns: self for chaining.

addVelocity ​

addVelocity(Pos3D velocity): ClientPlayerEntityHelper<T extends LocalPlayer>Since1.8.4#
Adds the supplied vector to the player's current velocity.

Parameters:

  • velocity: the movement to add, per tick
Returns: self for chaining.
addVelocity(double x, double y, double z): ClientPlayerEntityHelper<T extends LocalPlayer>Since1.8.4#
Adds the supplied components to the player's current velocity.

Parameters:

  • x: the movement to add on the x axis, per tick
  • y: the movement to add on the y axis, per tick
  • z: the movement to add on the z axis, per tick
Returns: self for chaining.

calculateMiningSpeed ​

calculateMiningSpeed(BlockStateHelper block): int#
Estimates mining duration using the player's main-hand item and current player state. The result is in ticks; 0 means instant mining and -1 means the item cannot mine the block.

Parameters:

  • block: the block to mine
Returns: the time in ticks that it will approximately take the player with the currently held item to mine said block.
calculateMiningSpeed(ItemStackHelper usedItem, BlockStateHelper blockState): intSince1.8.4#
Estimates mining duration in ticks with usedItem and the current player's state. Use an air item for the bare hand. 0 means instant mining; -1 means the item cannot mine the block. Player effects, game mode, and position affect the estimate.

Parameters:

  • usedItem: the item to mine with
  • blockState: the block to mine
Returns: the time in ticks that it will approximately take the player with the specified item to mine said block.

dropHeldItem ​

dropHeldItem(boolean dropStack): ClientPlayerEntityHelper<?>Since1.8.4#
Drops the held item, either one item or the whole stack according to dropStack.

Parameters:

  • dropStack: whether to drop the whole stack rather than one of it
Returns: this helper for chaining

getAdvancementManager ​

getAdvancementManager(): AdvancementManagerHelperSince1.8.4#
Returns a helper for the advancement tree received by this client's connection.
Returns: an advancement manager to work with advancements.

getFoodLevel ​

getFoodLevel(): intSince1.1.2#
Returns the player's food level in hunger points, from 0 to 20.
Returns: the player's food level, from zero to twenty

getItemCooldownRemainingTicks ​

getItemCooldownRemainingTicks(String item): intSince1.6.5#
Returns the named item's remaining cooldown in ticks, or -1 if no cooldown entry exists. The item id may omit the namespace, which defaults to minecraft.

Parameters:

  • item: the id of the item to look up
Returns: the ticks left on the cooldown, or -1 if the item is not on one

getItemCooldownsRemainingTicks ​

getItemCooldownsRemainingTicks(): Map<String, Integer>Since1.6.5#
Returns the active item cooldowns and their remaining duration in ticks. Items without an active cooldown are absent; the returned map is a new snapshot on each call.
Returns: a map from item id to the ticks left on its cooldown

getSaturation ​

getSaturation(): floatSince1.8.4#
Returns the player's saturation level, a floating-point food buffer consumed before food level.
Returns: the saturation level.

getTicksSinceCooldownsStart ​

getTicksSinceCooldownsStart(): Map<String, Integer>Since1.6.5#
Returns active item cooldowns mapped to start tick minus current manager tick. Values start at zero and become more negative as the cooldown runs; items without an active cooldown are absent. The returned map is a new snapshot on each call.
Returns: a map from item id to start tick minus current manager tick

getTicksSinceCooldownStart ​

getTicksSinceCooldownStart(String item): intSince1.6.5#
Returns the named item's start tick minus the current manager tick. The value starts at zero and becomes more negative as the cooldown runs; -1 also indicates no cooldown entry, so it is ambiguous. The item id may omit the namespace, which defaults to minecraft.

Parameters:

  • item: the id of the item to look up
Returns: the start tick minus current manager tick, or -1 if inactive

interactBlock ​

interactBlock(int x, int y, int z, Direction direction, boolean offHand, boolean await): ClientPlayerEntityHelper<T extends LocalPlayer>#
Attempts block interaction using the active client player and interaction manager. Off the client thread, schedules the action; await waits for that action to run, not for server confirmation or success. On the client thread or a joined thread, it runs inline regardless of await. Interrupting the wait propagates InterruptedException without cancelling the queued action, even when await is false. The supplied coordinates are both the block coordinates and hit-vector coordinates, without a center offset. Swings the selected hand when the interaction result consumes an action.

Parameters:

  • x: block x coordinate and hit-vector x coordinate
  • y: block y coordinate and hit-vector y coordinate
  • z: block z coordinate and hit-vector z coordinate
  • direction: the block face to interact with
  • offHand: whether to use the off hand instead of the main hand
  • await: whether to wait for the scheduled action when not running on the client or a joined thread
Returns: self for chaining

lookAt ​

lookAt(String direction): ClientPlayerEntityHelper<T extends LocalPlayer>Since1.8.4#
Sets the player rotation along the given axis and keeps the other axis the same. Horizontal directions set yaw and preserve pitch; vertical directions set pitch to straight up or down and preserve yaw. The name is case-insensitive. Other names cause a NullPointerException.

Parameters:

  • direction: possible values are "up", "down", "north", "south", "east", "west"
Returns: self for chaining.
lookAt(double yaw, double pitch): ClientPlayerEntityHelper<T extends LocalPlayer>Since1.0.3#
Sets the player's yaw and pitch. Yaw is wrapped to an equivalent angle nearest the current yaw; pitch is clamped to the range -90 to 90 degrees. If mounted, the vehicle is notified of the passenger's turn.

Parameters:

  • yaw: (was pitch prior to 1.2.6)
  • pitch: (was yaw prior to 1.2.6)
Returns: self for chaining.
lookAt(double x, double y, double z): ClientPlayerEntityHelper<T extends LocalPlayer>Since1.2.8#
Turns the player toward the given world coordinates, calculating the angles from the player's eye position.

Parameters:

  • x: the x coordinate to look at
  • y: the y coordinate to look at
  • z: the z coordinate to look at
Returns: this helper for chaining.

setPos ​

setPos(Pos3D pos): ClientPlayerEntityHelper<T extends LocalPlayer>Since1.8.4#
Sets the player's position. Off the client thread, the change is queued and this call returns without waiting for it to run.

Parameters:

  • pos: the position to move the player to
Returns: self for chaining.
setPos(Pos3D pos, boolean await): ClientPlayerEntityHelper<T extends LocalPlayer>Since1.9.0#
Sets the player's position, optionally waiting for the change to run. Off the client thread, the position change is queued and await=true blocks until that task runs. On the client thread, the position is set immediately regardless of await.

Parameters:

  • pos: the position to move the player to
  • await: whether to wait for the move to be applied
Returns: self for chaining.
setPos(double x, double y, double z): ClientPlayerEntityHelper<T extends LocalPlayer>Since1.8.4#
Sets the player's position to the given coordinates. Off the client thread, the change is queued and this call returns without waiting for it to run.

Parameters:

  • x: the x coordinate to move the player to
  • y: the y coordinate to move the player to
  • z: the z coordinate to move the player to
Returns: self for chaining.
setPos(double x, double y, double z, boolean await): ClientPlayerEntityHelper<T extends LocalPlayer>Since1.9.0#
Sets the player's position to the given coordinates, optionally waiting for the change to run. When called from the client thread there is nothing to hand off and nothing to wait for, so the await flag makes no difference there. Off the client thread the move is queued onto it, and the flag decides whether this call blocks until its task has run.

Parameters:

  • x: the x coordinate to move the player to
  • y: the y coordinate to move the player to
  • z: the z coordinate to move the player to
  • await: whether to wait for the move to be applied
Returns: self for chaining.

setVelocity ​

setVelocity(Pos3D velocity): ClientPlayerEntityHelper<T extends LocalPlayer>Since1.8.4#
Replaces the player's velocity with the supplied vector.

Parameters:

  • velocity: the movement to give the player, per tick
Returns: self for chaining.
setVelocity(double x, double y, double z): ClientPlayerEntityHelper<T extends LocalPlayer>Since1.8.4#
Replaces the player's velocity with the supplied components.

Parameters:

  • x: the movement on the x axis, per tick
  • y: the movement on the y axis, per tick
  • z: the movement on the z axis, per tick
Returns: self for chaining.

tryLookAt ​

tryLookAt(int x, int y, int z): booleanSince1.8.4#
Tries to turn toward the block at the given coordinates.

Parameters:

  • x: the x coordinate of the block to look at
  • y: the y coordinate of the block to look at
  • z: the z coordinate of the block to look at
Returns: true if the player is targeting the specified block, false otherwise.
tryLookAt(BlockPosHelper pos): booleanSince1.8.4#
Searches for a rotation whose block-outline ray trace hits the specified block. On success, updates the player's rotation; on failure, leaves it unchanged. An empty block shape returns false without searching.

Parameters:

  • pos: the position of the block to look at
Returns: true if the player is targeting the specified block, false otherwise.

turnBack ​

turnBack(): ClientPlayerEntityHelper<T extends LocalPlayer>Since1.8.4#
Turns the player 180 degrees while preserving pitch.
Returns: self for chaining.

turnLeft ​

turnLeft(): ClientPlayerEntityHelper<T extends LocalPlayer>Since1.8.4#
Turns the player 90 degrees left while preserving pitch.
Returns: self for chaining.

turnRight ​

turnRight(): ClientPlayerEntityHelper<T extends LocalPlayer>Since1.8.4#
Turns the player 90 degrees right while preserving pitch.
Returns: self for chaining.