-
Notifications
You must be signed in to change notification settings - Fork 71
Utility Systems
The Minecraft player client controls sprinting. The server cannot reliably control it. Instead, you have to use some tricks to cancel or prevent sprinting. Players can sprint by double-tapping their Forward control (W by default) or using their Sprint key.
You can cancel sprinting for a player by:
- flashing a menu at them
- giving them the
blindnesspotion effect for a short duration - setting their food level to 6 (3 bars), which is under the sprint requirement
If they have Sprinting set to the Hold option, then double-tab only initiates sprint on that action, not if they stop sprinting at a later point. Other actions that let the player sprint try to ensure that whatever stops them from sprinting (like being stopped by a block) restart sprinting if that sprint action is active. So, most of the ways that cancel sprinting will just resume them if you don't ensure happen every time the player starts sprinting and end when they stop.
The easiest way to cancel sprinting is by removing the sprinting modifier from their movement attribute. The player remains in "sprinting" mode, but the speed is modified as if they are not sprinting.
Modifier details:
Attribute: "minecraft:movement_speed"
ID: "minecraft:sprinting"
Operation: add
Value: 0.3Example spell:
sprint_cancel:
spell-class: ".targeted.EntityEditSpell"
helper-spell: true
target-self: true
remove: true
attributes:
# Remove action only cares about the ID, but I left the value anyway.
- movement_speed 0.3 add_number * minecraft:sprinting