# ClientPlayerEntityHelper

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

**Since:** 1.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 {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_constructor-T-}

```js
new ClientPlayerEntityHelper(T extends LocalPlayer e)
```

Wraps the supplied local player and retains that reference.

**Parameters:**
- `e`: the local player to wrap

## Methods

### addPos {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_addPos-Pos3D-}

```js
addPos(Pos3D pos): ClientPlayerEntityHelper<T extends LocalPlayer>
```

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.

**Since:** 1.8.4

### addPos {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_addPos-Pos3D-boolean-}

```js
addPos(Pos3D pos, boolean await): ClientPlayerEntityHelper<T extends LocalPlayer>
```

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.

**Since:** 1.9.0

### addPos {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_addPos-double-double-double-}

```js
addPos(double x, double y, double z): ClientPlayerEntityHelper<T extends LocalPlayer>
```

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.

**Since:** 1.8.4

### addPos {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_addPos-double-double-double-boolean-}

```js
addPos(double x, double y, double z, boolean await): ClientPlayerEntityHelper<T extends LocalPlayer>
```

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.

**Since:** 1.9.0

### addVelocity {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_addVelocity-Pos3D-}

```js
addVelocity(Pos3D velocity): ClientPlayerEntityHelper<T extends LocalPlayer>
```

Adds the supplied vector to the player's current velocity.

**Parameters:**
- `velocity`: the movement to add, per tick

**Returns:** self for chaining.

**Since:** 1.8.4

### addVelocity {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_addVelocity-double-double-double-}

```js
addVelocity(double x, double y, double z): ClientPlayerEntityHelper<T extends LocalPlayer>
```

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.

**Since:** 1.8.4

### calculateMiningSpeed {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_calculateMiningSpeed-BlockStateHelper-}

```js
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 {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_calculateMiningSpeed-ItemStackHelper-BlockStateHelper-}

```js
calculateMiningSpeed(ItemStackHelper usedItem, BlockStateHelper blockState): int
```

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.

**Since:** 1.8.4

### dropHeldItem {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_dropHeldItem-boolean-}

```js
dropHeldItem(boolean dropStack): ClientPlayerEntityHelper<?>
```

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

**Since:** 1.8.4

### getAdvancementManager {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_getAdvancementManager-}

```js
getAdvancementManager(): AdvancementManagerHelper
```

Returns a helper for the advancement tree received by this client's connection.

**Returns:** an advancement manager to work with advancements.

**Since:** 1.8.4

### getFoodLevel {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_getFoodLevel-}

```js
getFoodLevel(): int
```

Returns the player's food level in hunger points, from `0` to `20`.

**Returns:** the player's food level, from zero to twenty

**Since:** 1.1.2

### getItemCooldownRemainingTicks {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_getItemCooldownRemainingTicks-String-}

```js
getItemCooldownRemainingTicks(String item): int
```

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

**Since:** 1.6.5

### getItemCooldownsRemainingTicks {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_getItemCooldownsRemainingTicks-}

```js
getItemCooldownsRemainingTicks(): Map<String, Integer>
```

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

**Since:** 1.6.5

### getSaturation {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_getSaturation-}

```js
getSaturation(): float
```

Returns the player's saturation level, a floating-point food buffer consumed before food level.

**Returns:** the saturation level.

**Since:** 1.8.4

### getTicksSinceCooldownsStart {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_getTicksSinceCooldownsStart-}

```js
getTicksSinceCooldownsStart(): Map<String, Integer>
```

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

**Since:** 1.6.5

### getTicksSinceCooldownStart {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_getTicksSinceCooldownStart-String-}

```js
getTicksSinceCooldownStart(String item): int
```

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

**Since:** 1.6.5

### interactBlock {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_interactBlock-int-int-int-Direction-boolean-boolean-}

```js
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 {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_lookAt-String-}

```js
lookAt(String direction): ClientPlayerEntityHelper<T extends LocalPlayer>
```

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](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/NullPointerException.html).

**Parameters:**
- `direction`: possible values are "up", "down", "north", "south", "east", "west"

**Returns:** self for chaining.

**Since:** 1.8.4

### lookAt {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_lookAt-double-double-}

```js
lookAt(double yaw, double pitch): ClientPlayerEntityHelper<T extends LocalPlayer>
```

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.

**Since:** 1.0.3

### lookAt {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_lookAt-double-double-double-}

```js
lookAt(double x, double y, double z): ClientPlayerEntityHelper<T extends LocalPlayer>
```

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.

**Since:** 1.2.8

### setPos {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_setPos-Pos3D-}

```js
setPos(Pos3D pos): ClientPlayerEntityHelper<T extends LocalPlayer>
```

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.

**Since:** 1.8.4

### setPos {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_setPos-Pos3D-boolean-}

```js
setPos(Pos3D pos, boolean await): ClientPlayerEntityHelper<T extends LocalPlayer>
```

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.

**Since:** 1.9.0

### setPos {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_setPos-double-double-double-}

```js
setPos(double x, double y, double z): ClientPlayerEntityHelper<T extends LocalPlayer>
```

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.

**Since:** 1.8.4

### setPos {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_setPos-double-double-double-boolean-}

```js
setPos(double x, double y, double z, boolean await): ClientPlayerEntityHelper<T extends LocalPlayer>
```

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.

**Since:** 1.9.0

### setVelocity {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_setVelocity-Pos3D-}

```js
setVelocity(Pos3D velocity): ClientPlayerEntityHelper<T extends LocalPlayer>
```

Replaces the player's velocity with the supplied vector.

**Parameters:**
- `velocity`: the movement to give the player, per tick

**Returns:** self for chaining.

**Since:** 1.8.4

### setVelocity {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_setVelocity-double-double-double-}

```js
setVelocity(double x, double y, double z): ClientPlayerEntityHelper<T extends LocalPlayer>
```

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.

**Since:** 1.8.4

### tryFindAngles {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_tryFindAngles-BlockPosHelper-}

```js
tryFindAngles(BlockPosHelper pos): float[]
```

Finds a way to aim at a block without turning the player.  
 The search checks for an unobstructed ray to the block's outline, not whether
 the block is within interaction reach.

**Parameters:**
- `pos`: the block to aim at

**Returns:** `[yaw, pitch]` in degrees, or `null` if no hit was found

**Since:** 2.1.0

### tryFindAngles {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_tryFindAngles-BlockPosHelper-String-}

```js
tryFindAngles(BlockPosHelper pos, String face): float[]
```

Finds a way to aim at a particular face of a block without turning the player.  
 Like [tryFindAngles(BlockPosHelper)](#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_tryFindAngles-BlockPosHelper-), this does not check interaction reach.

**Parameters:**
- `pos`: the block to aim at
- `face`: the side to hit: `north`, `south`, `east`, `west`,  
             `up`, or `down`, ignoring case

**Returns:** `[yaw, pitch]` in degrees, or `null` if the face is unknown,  
         missing, or no hit on that face was found

**Since:** 2.1.0

### tryLookAt {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_tryLookAt-int-int-int-}

```js
tryLookAt(int x, int y, int z): boolean
```

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.

**Since:** 1.8.4

### tryLookAt {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_tryLookAt-BlockPosHelper-}

```js
tryLookAt(BlockPosHelper pos): boolean
```

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.

**Since:** 1.8.4

### turnBack {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_turnBack-}

```js
turnBack(): ClientPlayerEntityHelper<T extends LocalPlayer>
```

Turns the player 180 degrees while preserving pitch.

**Returns:** self for chaining.

**Since:** 1.8.4

### turnLeft {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_turnLeft-}

```js
turnLeft(): ClientPlayerEntityHelper<T extends LocalPlayer>
```

Turns the player 90 degrees left while preserving pitch.

**Returns:** self for chaining.

**Since:** 1.8.4

### turnRight {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.ClientPlayerEntityHelper_turnRight-}

```js
turnRight(): ClientPlayerEntityHelper<T extends LocalPlayer>
```

Turns the player 90 degrees right while preserving pitch.

**Returns:** self for chaining.

**Since:** 1.8.4
