# PlayerInput

`com.jsmacrosce.jsmacros.api.PlayerInput`

**Since:** 1.4.0

Data for one tick of queued player input. Playback uses the signs of the movement axes to select
 key presses and sets the player's yaw and pitch from this input; fractional magnitudes do not
 scale movement. Prediction also uses the axis magnitudes and angles. Inputs are copied when
 queued, so later changes to this object do not affect the queued copy.  
 ```js
// one tick of "hold forward" facing south, level pitch, nothing else pressed
const step = Player.createPlayerInput(1, 0, 0, 0, false, false, false);  
// where that single tick would end up, without adding it to the movement queue
Chat.log(`one tick of walking puts me at ${Player.predictInput(step)}`);  

// a second of walking is the same input twenty times over
for (let tick = 0; tick !== 20; tick += 1) {
  Player.addInput(step);  
}
 ```

## Constructors

### new PlayerInput {#com.jsmacrosce.jsmacros.api.PlayerInput_constructor-}

```js
new PlayerInput()
```

Creates an input with all axes and angles set to zero and all key states false.

**Since:** 1.4.0

### new PlayerInput {#com.jsmacrosce.jsmacros.api.PlayerInput_constructor-float-float-float-}

```js
new PlayerInput(float movementForward, float movementSideways, float yaw)
```

Creates an input with the supplied forward and sideways axes and yaw; pitch and key states
 default to zero/false.

**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`: absolute yaw of the player, in degrees

**Since:** 1.4.0

### new PlayerInput {#com.jsmacrosce.jsmacros.api.PlayerInput_constructor-float-float-boolean-boolean-}

```js
new PlayerInput(float movementForward, float yaw, boolean jumping, boolean sprinting)
```

Creates an input with the supplied forward axis, yaw and key states; sideways movement and
 pitch default to zero, and sneaking defaults to false. The second argument is yaw, not the
 sideways axis; use the seven-argument constructor to supply sideways movement.

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

**Since:** 1.4.0

### new PlayerInput {#com.jsmacrosce.jsmacros.api.PlayerInput_constructor-double-double-double-double-boolean-boolean-boolean-}

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

Creates an input from double-precision axis and angle values, narrowing them to floats.

**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`: absolute yaw of the player, in degrees
- `pitch`: absolute pitch of the player, in degrees
- `jumping`: jump input
- `sneaking`: sneak input
- `sprinting`: sprint input

**Since:** 1.4.0

### new PlayerInput {#com.jsmacrosce.jsmacros.api.PlayerInput_constructor-float-float-float-float-boolean-boolean-boolean-}

```js
new PlayerInput(float movementForward, float movementSideways, float yaw, float pitch, boolean jumping, boolean sneaking, boolean sprinting)
```

Creates an input with every field explicitly supplied.

**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`: absolute yaw of the player, in degrees
- `pitch`: absolute pitch of the player, in degrees
- `jumping`: jump input
- `sneaking`: sneak input
- `sprinting`: sprint input

**Since:** 1.4.0

### new PlayerInput {#com.jsmacrosce.jsmacros.api.PlayerInput_constructor-PlayerInput-}

```js
new PlayerInput(PlayerInput input)
```

Copies all fields from `input` into an independent object.

**Parameters:**
- `input`: the `PlayerInput` object to be cloned

**Since:** 1.4.0

## Fields

### jumping {#com.jsmacrosce.jsmacros.api.PlayerInput_jumping}

```js
jumping: boolean
```

Whether jump is requested for this tick. In prediction, it only jumps when grounded and
 its cooldown is zero; holding this value true does not reset the cooldown.

### movementForward {#com.jsmacrosce.jsmacros.api.PlayerInput_movementForward}

```js
movementForward: float
```

Forward/back movement input; positive is forward, negative is backward, and zero is neutral.  
 Prediction passes this value through as the forward component of movement input.

### movementSideways {#com.jsmacrosce.jsmacros.api.PlayerInput_movementSideways}

```js
movementSideways: float
```

Sideways movement input; positive is left, negative is right, and zero is neutral. Prediction
 passes this value through as the sideways component of movement input.

### pitch {#com.jsmacrosce.jsmacros.api.PlayerInput_pitch}

```js
pitch: float
```

Absolute pitch in degrees; positive values point down and negative values point up. Playback
 sets the player's pitch from this value; prediction sets the simulated entity's pitch from it.

### sneaking {#com.jsmacrosce.jsmacros.api.PlayerInput_sneaking}

```js
sneaking: boolean
```

Whether sneak is requested for this tick. Prediction applies crouch movement scaling based
 on the dummy's crouching state at the start of the tick, so the scaling lags a tick behind
 changes to this value.

### sprinting {#com.jsmacrosce.jsmacros.api.PlayerInput_sprinting}

```js
sprinting: boolean
```

Whether sprint is requested for this tick. Prediction starts sprinting only when this is
 true, sneaking is false, and the forward axis is positive; an existing sprint ends when the
 forward axis is not positive or a horizontal collision occurs.

### yaw {#com.jsmacrosce.jsmacros.api.PlayerInput_yaw}

```js
yaw: float
```

Absolute yaw in degrees: 0 faces south, +90 west, 180 north, and -90 east. Playback sets the
 player's yaw from this value; prediction sets the simulated entity's yaw from it.

## Methods

### clone {#com.jsmacrosce.jsmacros.api.PlayerInput_clone-}

```js
clone(): PlayerInput
```

Copies the seven movement, rotation, and action fields into a new base `PlayerInput`;  
 fields added by a subclass are not retained.

**Returns:** An independent base `PlayerInput` copy

### fromCsv {#com.jsmacrosce.jsmacros.api.PlayerInput_fromCsv-String-}

```js
static fromCsv(String csv): List<PlayerInput>
```

Parses CSV rows into inputs. The first line supplies case-sensitive field-name headers;  
 subsequent rows must have the same number of columns or are skipped. Fields omitted from
 the header retain their defaults. Values are comma-separated, spaces are removed, and
 quoted CSV values are not supported. For parsed rows, unknown field names throw
 [NoSuchFieldException](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/NoSuchFieldException.html), private field names throw [IllegalAccessException](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/IllegalAccessException.html),  
 and invalid numeric values throw [NumberFormatException](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/NumberFormatException.html). Boolean values are parsed
 with [Boolean.valueOf(String)](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/Boolean.html).  
 ```js
const csv = `movementForward,movementSideways,yaw,pitch,jumping,sneaking,sprinting
1,0,90,0,false,false,true
1,0,90,0,false,false,true`;  
// queue two input ticks
const steps = Player.createPlayerInputsFromCsv(csv);  
let i = 0;  
while (i !== steps.size()) {
  Player.addInput(steps.get(i));  
  i += 1;  
}
 ```

**Parameters:**
- `csv`: CSV string to be parsed

**Returns:** Inputs parsed from rows with the expected number of columns

**Since:** 1.4.0

### fromJson {#com.jsmacrosce.jsmacros.api.PlayerInput_fromJson-String-}

```js
static fromJson(String json): PlayerInput
```

Parses a JSON value into a `PlayerInput`. Keys use the field names; keys not matching
 fields are ignored, and omitted fields retain their defaults. The JSON must be a complete
 object, including braces.  
 ```js
// Parse one input from JSON
const step = Player.createPlayerInputsFromJson('{"movementForward": 1, "yaw": 90, "sprinting": true}');  
Player.addInput(step);  
 ```

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

**Returns:** The parsed input

**Since:** 1.4.0

### toString {#com.jsmacrosce.jsmacros.api.PlayerInput_toString-boolean-}

```js
toString(boolean varNames): String
```

Returns the fields as comma-separated text. With `varNames` true, it returns quoted
 field names and values (a JSON object body without braces); otherwise, it returns values
 only (a CSV row without a header). Neither result alone is accepted by the corresponding
 parser: wrap the named form in braces for [fromJson(String)](#com.jsmacrosce.jsmacros.api.PlayerInput_fromJson-String-), or provide a header for
 [fromCsv(String)](#com.jsmacrosce.jsmacros.api.PlayerInput_fromCsv-String-).

**Parameters:**
- `varNames`: whether to include field names in the output

**Returns:** The field representation described above

**Since:** 1.4.0

### toString {#com.jsmacrosce.jsmacros.api.PlayerInput_toString-}

```js
toString(): String
```

Returns the public fields declared by `PlayerInput` as `PlayerInput{name=value, ...}`.  
 Field order is not guaranteed.

**Returns:** A representation of this input's declared public fields
