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.
// 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
Parameters:
input: the PlayerInput to be executed
See:
addInputs
Parameters:
inputs: the PlayerInputs to be executed, one per tick, in order
See:
clearInputs
See:
createPlayerInput
See:
createPlayerInput(double movementForward, double movementSideways, double yaw): PlayerInputSince1.4.0#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
See:
createPlayerInput(double movementForward, double yaw, boolean jumping, boolean sprinting): PlayerInputSince1.4.0#Parameters:
movementForward: 1 = forward input (W); 0 = no input; -1 = backward input (S)yaw: yaw of the player, as an absolute bearing in degreesjumping: whether the jump button is heldsprinting: whether the sprint button is held
See:
createPlayerInput(double movementForward, double movementSideways, double yaw, double pitch, boolean jumping, boolean sneaking, boolean sprinting): PlayerInputSince1.4.0#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 playerpitch: pitch of the playerjumping: jump inputsneaking: sneak inputsprinting: sprint input
createPlayerInputsFromCsv
Parameters:
csv: CSV string to be parsed, one input per row under a header row
See:
createPlayerInputsFromJson
Parameters:
json: JSON string to be parsed
See:
detailedRayTraceBlock
null.Parameters:
distance: how far to trace, in blocksfluid: whether a liquid in the way counts as the hit
getCurrentPlayerInput
See:
getGameMode
getInteractionManager
null when no game mode interaction manager exists.null when there is no worldgetPlayer
null when no local player exists.null when there is no playerSee:
getReach
getStatistics
interactions
null when none existsmoveBackward
Parameters:
yaw: the relative yaw for the player, where positive turns right
moveForward
Parameters:
yaw: the relative yaw for the player, where positive turns right
moveStrafeLeft
Parameters:
yaw: the relative yaw for the player, where positive turns right
moveStrafeRight
Parameters:
yaw: the relative yaw for the player, where positive turns right
openInventory
predictInput
Parameters:
input: the PlayerInput for the prediction
Parameters:
input: the PlayerInput for the predictiondraw: whether to visualize the result or not
predictInputs
Parameters:
inputs: the PlayerInputs for each tick for the prediction
Parameters:
inputs: the PlayerInputs for each tick for the predictiondraw: whether to visualize the result or not
rayTraceBlock
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 blocksfluid: whether the trace considers fluids
null for a miss or void airSee:
rayTraceEntity
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
setDrawPredictions
Parameters:
val:trueto show the predicted positions,falseto hide them
setGameMode
takePanorama
takePanorama(String folder, int width, int height, MethodWrapper<TextHelper, Object, Object, ?> callback): voidSince1.8.4#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 itsscreenshotschild is createdwidth: retained for compatibility; ignored on 1.21.8 and laterheight: retained for compatibility; ignored on 1.21.8 and latercallback: called with the capture routine's message as a text helper, ornullfor none
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 itsscreenshotschild is createdcallback: called with the capture routine's message as a text helper, ornullfor none
takeScreenshot
takeScreenshot(String folder, MethodWrapper<TextHelper, Object, Object, ?> callback): voidSince1.2.6#<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 itsscreenshotschild is createdcallback: called with the game's success or failure message after the write attempt, ornullfor no callback
takeScreenshot(String folder, String file, MethodWrapper<TextHelper, Object, Object, ?> callback): voidSince1.2.6#<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 itsscreenshotschild is createdfile: the file name to save under thatscreenshotsdirectorycallback: called with the game's success or failure message after the write attempt, ornullfor no callback
writeSign
null line is left unchanged; returns false if no sign editor is open.Parameters:
l1: the first line of the sign, ornullto leave it unchangedl2: the second line of the sign, ornullto leave it unchangedl3: the third line of the sign, ornullto leave it unchangedl4: the fourth line of the sign, ornullto leave it unchanged
null to leave a line unchanged.Parameters:
index: zero-based sign line, from 0 through 3message: the message to write