Skip to content

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() can be used to check world availability. Inputs created by this library are values, not immediate actions: queue them with addInput(PlayerInput) or 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 ​

addInput(PlayerInput input): voidSince1.4.0#
Adds a copy of an input to the movement queue for playback.

Parameters:

  • input: the PlayerInput to be executed

See:

addInputs ​

addInputs(PlayerInput[] inputs): voidSince1.4.0#
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

See:

clearInputs ​

clearInputs(): voidSince1.4.0#
Removes queued inputs and predictions. If prediction drawing is enabled, its empty overlay is replaced while remaining registered.

See:

createPlayerInput ​

createPlayerInput(): PlayerInputSince1.4.0#
Creates an input with zero movement and angles and all buttons false. It has no effect until queued with addInput(PlayerInput).
Returns: a new empty PlayerInput

See:

createPlayerInput(double movementForward, double movementSideways, double yaw): PlayerInputSince1.4.0#
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).

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

See:

createPlayerInput(double movementForward, double yaw, boolean jumping, boolean sprinting): PlayerInputSince1.4.0#
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).

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

See:

createPlayerInput(double movementForward, double movementSideways, double yaw, double pitch, boolean jumping, boolean sneaking, boolean sprinting): PlayerInputSince1.4.0#
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).

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

createPlayerInputsFromCsv ​

createPlayerInputsFromCsv(String csv): List<PlayerInput>Since1.4.0#
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) 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[]) (or individually to addInput(PlayerInput)) to queue them

See:

createPlayerInputsFromJson ​

createPlayerInputsFromJson(String json): PlayerInputSince1.4.0#
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

See:

detailedRayTraceBlock ​

detailedRayTraceBlock(double distance, boolean fluid): HitResultHelper.BlockSince1.9.1#
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

getCurrentPlayerInput ​

getCurrentPlayerInput(): PlayerInputSince1.4.0#
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

See:

getGameMode ​

getGameMode(): StringSince1.0.9#
Returns the client's current gamemode name in lowercase.
Returns: the client's current gamemode

getInteractionManager ​

getInteractionManager(): InteractionManagerHelperSince1.9.0#
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

getPlayer ​

getPlayer(): ClientPlayerEntityHelper<LocalPlayer>Since1.0.3#
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

See:

getReach ​

getReach(): doubleSince1.8.4#
Returns the local player's current block interaction range, in blocks. A player must be present.
Returns: the block interaction range

getStatistics ​

getStatistics(): StatsHelperSince2.0.0#
Returns a helper over the local player's statistics counters. A player must be present.
Returns: a handle on the player's statistics

interactions ​

interactions(): InteractionManagerHelperSince1.9.0#
Returns: a handle on the interaction manager, or null when none exists

moveBackward ​

moveBackward(double yaw): voidSince1.4.0#
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

moveForward ​

moveForward(double yaw): voidSince1.4.0#
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

moveStrafeLeft ​

moveStrafeLeft(double yaw): voidSince1.4.2#
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

moveStrafeRight ​

moveStrafeRight(double yaw): voidSince1.4.2#
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

openInventory ​

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:

predictInput ​

predictInput(PlayerInput input): Pos3DSince1.4.0#
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
predictInput(PlayerInput input, boolean draw): Pos3DSince1.4.0#
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().

Parameters:

  • input: the PlayerInput for the prediction
  • draw: whether to visualize the result or not
Returns: the predicted position after one tick

predictInputs ​

predictInputs(PlayerInput[] inputs): List<Pos3D>Since1.4.0#
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
predictInputs(PlayerInput[] inputs, boolean draw): List<Pos3D>Since1.4.0#
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().

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

rayTraceBlock ​

rayTraceBlock(double distance, boolean fluid): BlockDataHelperSince1.0.5#
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

See:

rayTraceEntity ​

rayTraceEntity(int distance): EntityHelper<?>Since1.8.3#
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() 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).

setDrawPredictions ​

setDrawPredictions(boolean val): voidSince2.0.0#
Enables or disables drawing predicted positions for queued movement inputs.

Parameters:

  • val: true to show the predicted positions, false to hide them

setGameMode ​

setGameMode(String gameMode): voidSince1.8.4#
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

takePanorama ​

takePanorama(String folder, int width, int height, MethodWrapper<TextHelper, Object, Object, ?> callback): voidSince1.8.4#
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
takePanorama(String folder, MethodWrapper<TextHelper, Object, Object, ?> callback): voidSince2.0.0#
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

takeScreenshot ​

takeScreenshot(String folder, MethodWrapper<TextHelper, Object, Object, ?> callback): voidSince1.2.6#
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
takeScreenshot(String folder, String file, MethodWrapper<TextHelper, Object, Object, ?> callback): voidSince1.2.6#
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

writeSign ​

writeSign(String l1, String l2, String l3, String l4): booleanSince1.2.2#
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
writeSign(int index, String message): booleanSince2.0.0#
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