Skip to content

Movement API

The Movement API is there to make the Player move. You have full control over the Player, yet you can only move the Player like a normal Client could.
Therefore this library does NOT enable you to code (e.g.) any flight cheats or similar.
Every action is subject to normal Client behaviour.

If you're here to search for a specific method or just a quick explanation of how something works, you may find it useful to scroll through your IDE tooltips of your IMovement instance. This is a good method for discovering all possibilities you have, as Actor also has extensive Javadocs.

Obtaining the Movement

You can obtain the API surface like this:

java
var movement = YOUR_ACTOR.getMovement();

Using the Movement

Here is some info on how to use the Movement API:

Move directions

When executing any walk action, you have to pass an EnumSet<MoveDirection> of directions to walk to.

java
movement.walk(EnumSet.of(MoveDirection.RELATIVE_FRONT));

TIP

Move directions are labeled as relative. That means that a Player can only move relative to that player's rotation.
E.g. if the player is looking in ANY direction, MoveDirection.RELATIVE_FRONT will move the Player forward relative to that "looking direction" and not in a fixed direction of SOUTH, NORTH, ... .

You can combine directions like this:

java
movement.walk(EnumSet.of(MoveDirection.RELATIVE_FRONT, MoveDirection.RELATIVE_LEFT));

This will make the Player strafe to the front left relative to where the Player is looking.

WARNING

Opposing MoveDirections will cancel.
E.g. movement.walk(EnumSet.of(MoveDirection.RELATIVE_FRONT, MoveDirection.RELATIVE_BACK)); will result in no movement on the front-back-axis.

Duration options

The above examples will only walk the Player for a single tick.
To give you, the programmer, more flexibility most movement actions have three overloads:

  1. Once (single tick)
  2. For a number of ticks
  3. While a BooleanSupplier returns true
java
// Walk for 20 ticks
movement.walk(EnumSet.of(MoveDirection.RELATIVE_FRONT), 20);
// Walk while the Player is in water
movement.walk(EnumSet.of(MoveDirection.RELATIVE_FRONT), () -> player.isInWater());

Indefinite actions

If you want your action to move indefinitely, you can do the following: Pass -1 as the number of ticks to keep an action running until you change it.

java
// Walk forever
movement.walk(EnumSet.of(MoveDirection.RELATIVE_FRONT), -1);

Movement States

Besides walking, you also control movement flags such as whether the Player is sprinting, jumping or sneaking.
These generally default to false.
You can control these in the same way you can control walking:

java
// Jump while the player is on the ground
movement.jump(() -> player.onGround());
// Sneak for 50 ticks
movement.sneak(50);
// Sprint for a single tick
movement.sprint();

Here's a quick list of methods you can use to control a player's movement:

java
// walk
void walk(EnumSet<MoveDirection> dirs);
void walk(EnumSet<MoveDirection> dirs, int ticks);
void walk(EnumSet<MoveDirection> dirs, BooleanSupplier active);

// sprint
void sprint();
void sprint(int ticks);
void sprint(BooleanSupplier active);

// sneak
void sneak();
void sneak(int ticks);
void sneak(BooleanSupplier active);

// jump
void jump();
void jump(int ticks);
void jump(BooleanSupplier active);

Persistent movement flags

You also have the option to set a movement flag once and make every movement action after that subject to that flag.
These flags stay active until you change them.

java
// Player is now always sprinting
movement.setSprinting(true);
// Sprint for 20 ticks
movement.walk(EnumSet.of(MoveDirection.RELATIVE_FRONT), 20);

The same applies to sneaking and jumping:

java
movement.setJumping(true);
movement.setSneaking(true);
movement.setSprinting(true);

The boolean you pass is just whether the flag should be true or false (e.g. jumping or not jumping).