PlayerInput
com.jsmacrosce.jsmacros.api.PlayerInput
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
Creates an input with all axes and angles set to zero and all key states false.
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
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 degreesjumping: jump inputsprinting: sprint input
new PlayerInput(double movementForward, double movementSideways, double yaw, double pitch, boolean jumping, boolean sneaking, boolean sprinting)Since1.4.0#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 degreespitch: absolute pitch of the player, in degreesjumping: jump inputsneaking: sneak inputsprinting: sprint input
new PlayerInput(float movementForward, float movementSideways, float yaw, float pitch, boolean jumping, boolean sneaking, boolean sprinting)Since1.4.0#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 degreespitch: absolute pitch of the player, in degreesjumping: jump inputsneaking: sneak inputsprinting: sprint input
Copies all fields from
input into an independent object.Parameters:
input: thePlayerInputobject to be cloned
Fields
jumping
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
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
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
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
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
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
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
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 copyfromCsv
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, private field names throw IllegalAccessException, and invalid numeric values throw NumberFormatException. Boolean values are parsed with Boolean.valueOf(String).
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
fromJson
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. // 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
toString
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), or provide a header for fromCsv(String).Parameters:
varNames: whether to include field names in the output
Returns: The field representation described above