# Player

`com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer`

Functions for getting and modifying the player's state.  

An instance of this class is passed to scripts as the `Player` variable.  
The library acts on the local player. Many methods require a loaded world; where a method
relies on the player or interaction manager, it may assert that the corresponding game object
exists rather than return an empty result. [FWorld.isWorldLoaded()](FWorld.md#com.jsmacrosce.jsmacros.client.api.library.impl.FWorld_isWorldLoaded-) can be used to check
world availability. Inputs created by this library are values, not immediate actions: queue
them with [addInput(PlayerInput)](#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_addInput-PlayerInput-) or [addInputs(PlayerInput[])](#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_addInputs-PlayerInput[]-) to apply one per
tick.  
```js
// all of this only makes sense in a world
if (World.isWorldLoaded()) {
  // what is the player standing in
  const player = Player.getPlayer();  
  if (player !== null) {
    const under = World.getBlock(player.getBlockPos().down());  
    if (under !== null) {
      Chat.log(`standing in ${under.getName()}`);  
    }
  }

  // queue one second of forward movement; one call is one tick
  for (let tick = 0; tick < 20; tick += 1) {
    Player.moveForward(0);  
  }
  Client.waitTick(20);  
  Player.clearInputs();  
}
```

Accessible in scripts via the global `Player` variable.

## Methods

### addInput {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_addInput-PlayerInput-}

```js
addInput(PlayerInput input): void
```

Adds a copy of an input to the movement queue for playback.

**Parameters:**
- `input`: the PlayerInput to be executed

**Since:** 1.4.0

**See:**
- [MovementQueue](../../../../../../../../classes/com/jsmacrosce/jsmacros/client/movement/MovementQueue.md)

### addInputs {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_addInputs-PlayerInput[]-}

```js
addInputs(PlayerInput[] inputs): void
```

Adds a copy of each input to the movement queue in array order.

**Parameters:**
- `inputs`: the PlayerInputs to be executed, one per tick, in order

**Since:** 1.4.0

**See:**
- [MovementQueue](../../../../../../../../classes/com/jsmacrosce/jsmacros/client/movement/MovementQueue.md)

### clearInputs {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_clearInputs-}

```js
clearInputs(): void
```

Removes queued inputs and predictions. If prediction drawing is enabled, its empty overlay
is replaced while remaining registered.

**Since:** 1.4.0

**See:**
- [MovementQueue](../../../../../../../../classes/com/jsmacrosce/jsmacros/client/movement/MovementQueue.md)

### createPlayerInput {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_createPlayerInput-}

```js
createPlayerInput(): PlayerInput
```

Creates an input with zero movement and angles and all buttons false. It has no effect until
queued with [addInput(PlayerInput)](#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_addInput-PlayerInput-).

**Returns:** a new empty PlayerInput

**Since:** 1.4.0

**See:**
- [PlayerInput](../../../../../../../../classes/com/jsmacrosce/jsmacros/api/PlayerInput.md)

### createPlayerInput {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_createPlayerInput-double-double-double-}

```js
createPlayerInput(double movementForward, double movementSideways, double yaw): PlayerInput
```

Creates an input with the supplied movement axes and absolute yaw in degrees; pitch and
buttons default to zero/false. It has no effect until queued with [addInput(PlayerInput)](#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_addInput-PlayerInput-).

**Parameters:**
- `movementForward`: 1 = forward input (W); 0 = no input; -1 = backward input (S)
- `movementSideways`: 1 = left input (A); 0 = no input; -1 = right input (D)
- `yaw`: yaw of the player, as an absolute bearing in degrees

**Returns:** a new PlayerInput with the movement and bearing set

**Since:** 1.4.0

**See:**
- [PlayerInput](../../../../../../../../classes/com/jsmacrosce/jsmacros/api/PlayerInput.md)

### createPlayerInput {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_createPlayerInput-double-double-boolean-boolean-}

```js
createPlayerInput(double movementForward, double yaw, boolean jumping, boolean sprinting): PlayerInput
```

Creates an input with forward movement, absolute yaw in degrees, and jump/sprint buttons.  
Sideways movement and pitch are zero, and sneaking is false. It has no effect until queued
with [addInput(PlayerInput)](#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_addInput-PlayerInput-).

**Parameters:**
- `movementForward`: 1 = forward input (W); 0 = no input; -1 = backward input (S)
- `yaw`: yaw of the player, as an absolute bearing in degrees
- `jumping`: whether the jump button is held
- `sprinting`: whether the sprint button is held

**Returns:** a new PlayerInput with the forward movement, bearing and buttons set

**Since:** 1.4.0

**See:**
- [PlayerInput](../../../../../../../../classes/com/jsmacrosce/jsmacros/api/PlayerInput.md)

### createPlayerInput {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_createPlayerInput-double-double-double-double-boolean-boolean-boolean-}

```js
createPlayerInput(double movementForward, double movementSideways, double yaw, double pitch, boolean jumping, boolean sneaking, boolean sprinting): PlayerInput
```

Creates an input with both movement axes, yaw and pitch in degrees, and all three buttons
explicitly set. It has no effect until queued with [addInput(PlayerInput)](#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_addInput-PlayerInput-).

**Parameters:**
- `movementForward`: 1 = forward input (W); 0 = no input; -1 = backward input (S)
- `movementSideways`: 1 = left input (A); 0 = no input; -1 = right input (D)
- `yaw`: yaw of the player
- `pitch`: pitch of the player
- `jumping`: jump input
- `sneaking`: sneak input
- `sprinting`: sprint input

**Returns:** an input with the supplied values

**Since:** 1.4.0

### createPlayerInputsFromCsv {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_createPlayerInputsFromCsv-String-}

```js
createPlayerInputsFromCsv(String csv): List<PlayerInput>
```

Parses CSV rows into inputs using case-sensitive field-name headers. Rows with a different
number of columns than the header are skipped; omitted fields retain their defaults. Spaces
are removed, quoted values are unsupported, and headers naming no field or a private field
throw. Invalid numeric values also throw; boolean values use [Boolean.valueOf(String)](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/Boolean.html)
semantics.

**Parameters:**
- `csv`: CSV string to be parsed, one input per row under a header row

**Returns:** parsed inputs in row order; they are not queued for playback. Pass them to
        [addInputs(PlayerInput[])](#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_addInputs-PlayerInput[]-) (or individually to [addInput(PlayerInput)](#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_addInput-PlayerInput-)) to queue them

**Since:** 1.4.0

**See:**
- [PlayerInput.PlayerInput(float, float, float, float, boolean, boolean, boolean)](../../../../../../../../classes/com/jsmacrosce/jsmacros/api/PlayerInput.md#com.jsmacrosce.jsmacros.api.PlayerInput_constructor-float-float-float-float-boolean-boolean-boolean-)

### createPlayerInputsFromJson {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_createPlayerInputsFromJson-String-}

```js
createPlayerInputsFromJson(String json): PlayerInput
```

Parses a complete JSON object into one input. Keys matching input fields are case-sensitive;  
omitted fields retain defaults and unknown keys are ignored.

**Parameters:**
- `json`: JSON string to be parsed

**Returns:** the parsed input

**Since:** 1.4.0

**See:**
- [createPlayerInputsFromCsv(String)](#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_createPlayerInputsFromCsv-String-)

### detailedRayTraceBlock {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_detailedRayTraceBlock-double-boolean-}

```js
detailedRayTraceBlock(double distance, boolean fluid): HitResultHelper.Block
```

Returns the block raycast result, including its hit position and side. A miss is represented
by a result whose type is a miss, not by `null`.

**Parameters:**
- `distance`: how far to trace, in blocks
- `fluid`: whether a liquid in the way counts as the hit

**Returns:** the raycast result, whose type says whether anything was hit

**Since:** 1.9.1

### getCurrentPlayerInput {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_getCurrentPlayerInput-}

```js
getCurrentPlayerInput(): PlayerInput
```

Captures the local player's movement key states, current yaw and pitch, jump and sneak key
states, and sprinting state in a new input.

**Returns:** a PlayerInput holding the player's current movement, angles and buttons

**Since:** 1.4.0

**See:**
- [PlayerInput](../../../../../../../../classes/com/jsmacrosce/jsmacros/api/PlayerInput.md)

### getGameMode {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_getGameMode-}

```js
getGameMode(): String
```

Returns the client's current gamemode name in lowercase.

**Returns:** the client's current gamemode

**Since:** 1.0.9

### getInteractionManager {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_getInteractionManager-}

```js
getInteractionManager(): InteractionManagerHelper
```

Returns a handler for client interactions with the world, or `null` when no game
mode interaction manager exists.

**Returns:** a handle on the interaction manager, or `null` when there is no world

**Since:** 1.9.0

### getPlayer {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_getPlayer-}

```js
getPlayer(): ClientPlayerEntityHelper<LocalPlayer>
```

Returns a wrapper for the local player, or `null` when no local player exists.

**Returns:** the player entity wrapper, or `null` when there is no player

**Since:** 1.0.3

**See:**
- [ClientPlayerEntityHelper](../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/helper/world/entity/ClientPlayerEntityHelper.md)

### getReach {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_getReach-}

```js
getReach(): double
```

Returns the local player's current block interaction range, in blocks. A player must be present.

**Returns:** the block interaction range

**Since:** 1.8.4

### getStatistics {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_getStatistics-}

```js
getStatistics(): StatsHelper
```

Returns a helper over the local player's statistics counters. A player must be present.

**Returns:** a handle on the player's statistics

**Since:** 2.1.0

### interactions {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_interactions-}

```js
interactions(): InteractionManagerHelper
```

Alias for [getInteractionManager()](#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_getInteractionManager-).

**Returns:** a handle on the interaction manager, or `null` when none exists

**Since:** 1.9.0

### moveBackward {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_moveBackward-double-}

```js
moveBackward(double yaw): void
```

Queues one tick of backward movement using a yaw offset in degrees from the player's current yaw; positive offsets turn right.

**Parameters:**
- `yaw`: the relative yaw for the player, where positive turns right

**Since:** 1.4.0

### moveForward {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_moveForward-double-}

```js
moveForward(double yaw): void
```

Queues one tick of forward movement using a yaw offset in degrees from the player's current yaw; positive offsets turn right.

**Parameters:**
- `yaw`: the relative yaw for the player, where positive turns right

**Since:** 1.4.0

### moveStrafeLeft {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_moveStrafeLeft-double-}

```js
moveStrafeLeft(double yaw): void
```

Queues one tick of leftward strafe using a yaw offset in degrees from the player's current yaw; positive offsets turn right.

**Parameters:**
- `yaw`: the relative yaw for the player, where positive turns right

**Since:** 1.4.2

### moveStrafeRight {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_moveStrafeRight-double-}

```js
moveStrafeRight(double yaw): void
```

Queues one tick of rightward strafe using a yaw offset in degrees from the player's current yaw; positive offsets turn right.

**Parameters:**
- `yaw`: the relative yaw for the player, where positive turns right

**Since:** 1.4.2

### openInventory {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_openInventory-}

```js
openInventory(): Inventory<?>
```

Returns a handler for the local player's inventory. Inventory operations through the
handler act on the live inventory.

**Returns:** the local player's inventory handler

**See:**
- [Inventory](../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/classes/inventory/Inventory.md)

### predictInput {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_predictInput-PlayerInput-}

```js
predictInput(PlayerInput input): Pos3D
```

Predicts the position after one tick of the input without drawing a marker or moving the player.

**Parameters:**
- `input`: the PlayerInput for the prediction

**Returns:** the predicted position after one tick

**Since:** 1.4.0

### predictInput {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_predictInput-PlayerInput-boolean-}

```js
predictInput(PlayerInput input, boolean draw): Pos3D
```

Predicts the position after one tick, optionally adding an orange marker to the 3D overlay. The real player is not moved.  

Markers remain in the overlay until it is cleared with [FHud.clearDraw3Ds()](FHud.md#com.jsmacrosce.jsmacros.client.api.library.impl.FHud_clearDraw3Ds-).

**Parameters:**
- `input`: the PlayerInput for the prediction
- `draw`: whether to visualize the result or not

**Returns:** the predicted position after one tick

**Since:** 1.4.0

### predictInputs {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_predictInputs-PlayerInput[]-}

```js
predictInputs(PlayerInput[] inputs): List<Pos3D>
```

Predicts the positions resulting from applying inputs in order, without drawing or moving the player. Prediction starts at the player's current state.

**Parameters:**
- `inputs`: the PlayerInputs for each tick for the prediction

**Returns:** one predicted position per input, in input order

**Since:** 1.4.0

### predictInputs {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_predictInputs-PlayerInput[]-boolean-}

```js
predictInputs(PlayerInput[] inputs, boolean draw): List<Pos3D>
```

Predicts positions by applying inputs in order from the player's current state, optionally adding an orange marker for each position. The real player is not moved.  

Markers remain in the overlay until it is cleared with [FHud.clearDraw3Ds()](FHud.md#com.jsmacrosce.jsmacros.client.api.library.impl.FHud_clearDraw3Ds-).

**Parameters:**
- `inputs`: the PlayerInputs for each tick for the prediction
- `draw`: whether to visualize the result or not

**Returns:** one predicted position per input, in input order

**Since:** 1.4.0

### rayTraceBlock {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_rayTraceBlock-double-boolean-}

```js
rayTraceBlock(double distance, boolean fluid): BlockDataHelper
```

Traces from the player's view and returns the hit block, or `null` for a miss or
void-air hit. The `fluid` argument controls whether fluids are considered by the
trace; this result is independent of any target set on the interaction manager.

**Parameters:**
- `distance`: how far to trace, in blocks
- `fluid`: whether the trace considers fluids

**Returns:** the hit block, or `null` for a miss or void air

**Since:** 1.0.5

**See:**
- [BlockDataHelper](../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/helper/world/BlockDataHelper.md)

### rayTraceEntity {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_rayTraceEntity-int-}

```js
rayTraceEntity(int distance): EntityHelper<?>
```

Traces from the player's eyes along their view and returns the first targeted entity, or
`null` if there is no entity within range. The distance is in blocks. This performs
a fresh trace; [InteractionManagerHelper.getTargetedEntity()](../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/helper/InteractionManagerHelper.md#com.jsmacrosce.jsmacros.client.api.helper.InteractionManagerHelper_getTargetedEntity-) returns the existing
crosshair pick instead.

**Parameters:**
- `distance`: how far to trace, in blocks

**Returns:** entity the player entity is currently looking at (if any).

**Since:** 1.8.3

### setDrawPredictions {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_setDrawPredictions-boolean-}

```js
setDrawPredictions(boolean val): void
```

Enables or disables drawing predicted positions for queued movement inputs.

**Parameters:**
- `val`: `true` to show the predicted positions, `false` to hide them

**Since:** 2.1.0

### setGameMode {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_setGameMode-String-}

```js
setGameMode(String gameMode): void
```

Sets the local client's gamemode; the server may subsequently override it.

**Parameters:**
- `gameMode`: gamemode name; names are case-insensitive and unrecognized names leave the current mode unchanged

**Since:** 1.8.4

### takePanorama {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_takePanorama-String-int-int-MethodWrapper-}

```js
takePanorama(String folder, int width, int height, MethodWrapper<TextHelper, Object, Object, ?> callback): void
```

Captures a panorama of the current world as six PNGs, `panorama_0.png` through
`panorama_5.png`, under `<macro folder>/<folder>/screenshots/`.  

On the client thread the six directions are rendered before this method returns; from any
other thread the capture is queued and the method returns immediately. The optional callback
receives the game's success or failure message for the capture routine; on success that
message names the folder. The six files are written asynchronously after each grab, so the
callback does not guarantee that they exist.

**Parameters:**
- `folder`: the folder under the profile's macro folder to save into; it must already
                exist, and its `screenshots` child is created
- `width`: retained for compatibility; ignored on 1.21.8 and later
- `height`: retained for compatibility; ignored on 1.21.8 and later
- `callback`: called with the capture routine's message as a text helper, or `null`
                for none

**Since:** 1.8.4

### takePanorama {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_takePanorama-String-MethodWrapper-}

```js
takePanorama(String folder, MethodWrapper<TextHelper, Object, Object, ?> callback): void
```

Captures a panorama with both dimensions set to the 4096 default. Behaves like the
four-argument overload with `4096` for both dimensions, including its callback and
asynchronous file writes.

**Parameters:**
- `folder`: the folder under the profile's macro folder to save into; it must already
                exist, and its `screenshots` child is created
- `callback`: called with the capture routine's message as a text helper, or `null`
                for none

**Since:** 2.1.0

### takeScreenshot {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_takeScreenshot-String-MethodWrapper-}

```js
takeScreenshot(String folder, MethodWrapper<TextHelper, Object, Object, ?> callback): void
```

Captures the current render target to a game-named PNG under
`<macro folder>/<folder>/screenshots/`. The file is written asynchronously, so this
method returns before it exists; use the callback rather than the method's return to know
when the capture has finished. Use the overload with a `file` parameter to choose the
file name.

**Parameters:**
- `folder`: the folder under the profile's macro folder to save into; it must already
              exist, and its `screenshots` child is created
- `callback`: called with the game's success or failure message after the write attempt,  
                or `null` for no callback

**Since:** 1.2.6

### takeScreenshot {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_takeScreenshot-String-String-MethodWrapper-}

```js
takeScreenshot(String folder, String file, MethodWrapper<TextHelper, Object, Object, ?> callback): void
```

Captures the current render target to `<macro folder>/<folder>/screenshots/<file>`.  
The file is written asynchronously, so this method returns before it exists; use the
callback rather than the method's return to know when the capture has finished.

**Parameters:**
- `folder`: the folder under the profile's macro folder to save into; it must already
              exist, and its `screenshots` child is created
- `file`: the file name to save under that `screenshots` directory
- `callback`: called with the game's success or failure message after the write attempt,  
                or `null` for no callback

**Since:** 1.2.6

### writeSign {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_writeSign-String-String-String-String-}

```js
writeSign(String l1, String l2, String l3, String l4): boolean
```

Writes up to four lines, top to bottom, to the open sign editor. A `null` line is left
unchanged; returns `false` if no sign editor is open.

**Parameters:**
- `l1`: the first line of the sign, or `null` to leave it unchanged
- `l2`: the second line of the sign, or `null` to leave it unchanged
- `l3`: the third line of the sign, or `null` to leave it unchanged
- `l4`: the fourth line of the sign, or `null` to leave it unchanged

**Returns:** whether a sign editor is open

**Since:** 1.2.2

### writeSign {#com.jsmacrosce.jsmacros.client.api.library.impl.FPlayer_writeSign-int-String-}

```js
writeSign(int index, String message): boolean
```

Write a line to a sign screen if a sign screen is currently open.  

Writes one line to the open sign editor. The index is zero-based from the top and must be
from 0 through 3; it is checked even when no sign editor is open. Unlike the four-line
overload, this method does not accept `null` to leave a line unchanged.

**Parameters:**
- `index`: zero-based sign line, from 0 through 3
- `message`: the message to write

**Returns:** whether a sign editor is open

**Since:** 2.1.0
