Buttons New

The 66 input buttons of PlayerAuthInputPacket with their index, their exact schema name and what the createmove layer can do with them.

A button is one input flag of PlayerAuthInputPacket (Input Data in the game schema). The game build 1.26.6201.0 names 66 of them, indexed 0 to 65; xiao.cmd.buttons maps each Lua name to its index.

At a glance

Method Returns Purpose
get_buttons() number[] indices of the buttons that are down, ascending
set_buttons(list) nothing replaces every button by the list
has_button(button) boolean true when the button is down
set_button(button, down) nothing presses (default) or releases one button
remove_button(button) nothing releases one button

In authinput every index from 0 to 127 works (indices past 65 have no name in this build). In createmove only the buttons the client simulates exist:

Button createmove What the client sends for it
jump_down read and write jump_down, jumping, want_up
sprint_down read and write sprint_down, sprinting
sneak_down read and write sneak_down, sneaking, want_down
up, down, left, right read only, they follow the move vector the same buttons
any other error button 'x' is only available in authinput -

Functions

cmd:get_buttons(): number[]

cmd:get_buttons(): number[]

Returns: the indices of the buttons that are down, ascending. In authinput every flag of the packet ({48, 50} for a player standing still); in createmove only the buttons of the table above.

for _, index in ipairs(cmd:get_buttons()) do print(xiao.cmd.button_name(index)) end

cmd:set_buttons(list)

cmd:set_buttons(list: (string | number)[])

Replaces every button: the listed buttons are down, all others are up. In createmove it sets jump_down, sprint_down and sneak_down from the list.

Name Type Description
list table array of button names or indices

Returns: nothing.

Errors:

Message Cause
set_buttons: entry 2 is not a button name or index 0-127 an entry that is not a button name or an integer from 0 to 127
button 'x' is only available in authinput createmove: a button the client cannot simulate
button 'up' follows the move vector in createmove (use set_move) createmove: up, down, left or right in the list
cmd:set_buttons({"sneak_down", xiao.cmd.buttons.block_breaking_delay_enabled})

cmd:has_button(button): boolean

cmd:has_button(button: string | number): boolean
Name Type Description
button string or number button name or index from 0 to 127

Returns: true when the button is down.

Errors:

Message Cause
bad argument #1 to 'has_button' (button name or index 0-127 expected) an unknown name, or an index out of 0 to 127
button 'x' is only available in authinput createmove: a button that is not in the table above
if cmd:has_button("sneak_down") then return end

cmd:set_button(button, down)

cmd:set_button(button: string | number, down: boolean = true)
Name Type Description
button string or number button name or index from 0 to 127
down boolean false releases; true, nil or omitted presses

Returns: nothing.

Errors: as has_button; in createmove, up, down, left and right raise button 'up' follows the move vector in createmove (use set_move).

cmd:set_button("jump_down")
cmd:set_button(xiao.cmd.buttons.sprint_down, false)

cmd:remove_button(button)

cmd:remove_button(button: string | number)

Same as set_button(button, false).

Name Type Description
button string or number button name or index from 0 to 127

Returns: nothing.

Errors: as set_button.

cmd:remove_button("sprint_down")

Direction buttons

up, down, left and right say which way the move vector points. In authinput, set_move and rotate_movement set them again from the new vector (up when forward is positive, left when left is positive); a set_button after that wins. The diagonal buttons (up_left, up_right, down_left, down_right) belong to the touch d-pad: a keyboard sends up + right for W+D, never up_right, so they are never changed for you.

Table of buttons

Exact names read in the game schema of build 1.26.6201.0 (enum PlayerAuthInputData). The Lua name is the schema name in lower case with _ between words. The "client source" column is where the client takes the flag from when it builds the packet (MoveInputComponent flag bit, state bit at +96, or event of the tick).

Index Lua name Schema name Client source Meaning
0 ascend Ascend flag bit 17 going up while flying or swimming
1 descend Descend flag bit 18 going down while flying or swimming
2 north_jump NorthJump - legacy, not sent
3 jump_down JumpDown flag bit 7 jump key held
4 sprint_down SprintDown flag bit 8 sprint key held
5 change_height ChangeHeight flag bit 19 flying height change
6 jumping Jumping state bit 4 a jump is in progress
7 auto_jumping_in_water AutoJumpingInWater state bit 5 automatic jump out of water
8 sneaking Sneaking state bit 0 the player is sneaking
9 sneak_down SneakDown flag bit 0 sneak key held
10 up Up flag bit 13 forward
11 down Down flag bit 14 backward
12 left Left flag bit 15 strafe left
13 right Right flag bit 16 strafe right
14 up_left UpLeft flag bit 9 touch d-pad diagonal
15 up_right UpRight flag bit 10 touch d-pad diagonal
16 want_up WantUp state bit 2 wants to go up (jump held)
17 want_down WantDown state bit 3 wants to go down (sneak held)
18 want_down_slow WantDownSlow flag bit 2 slow descent
19 want_up_slow WantUpSlow flag bit 3 slow ascent
20 sprinting Sprinting state bit 1 the player is sprinting
21 ascend_block AscendBlock flag bit 5 climbing scaffolding
22 descend_block DescendBlock flag bit 6 going down scaffolding
23 sneak_toggle_down SneakToggleDown flag bit 1 toggle sneak key
24 persist_sneak PersistSneak state bit 7 sneak kept without the key
25 start_sprinting StartSprinting tick event sprint started this tick
26 stop_sprinting StopSprinting tick event sprint stopped this tick
27 start_sneaking StartSneaking tick event sneak started this tick
28 stop_sneaking StopSneaking tick event sneak stopped this tick
29 start_swimming StartSwimming tick event swimming started
30 stop_swimming StopSwimming tick event swimming stopped
31 start_jumping StartJumping tick event jump started this tick
32 start_gliding StartGliding tick event elytra gliding started
33 stop_gliding StopGliding tick event elytra gliding stopped
34 perform_item_interaction PerformItemInteraction tick event the packet carries an item use
35 perform_block_actions PerformBlockActions tick event the packet carries block actions
36 perform_item_stack_request PerformItemStackRequest tick event the packet carries an item stack request
37 handled_teleport HandledTeleport tick event a server teleport was applied
38 emoting Emoting tick event an emote is playing
39 missed_swing MissedSwing tick event an attack swing hit nothing
40 start_crawling StartCrawling tick event crawling started
41 stop_crawling StopCrawling tick event crawling stopped
42 start_flying StartFlying tick event flying started
43 stop_flying StopFlying tick event flying stopped
44 client_ack_server_data ClientAckServerData tick event server data acknowledged
45 is_in_client_predicted_vehicle IsInClientPredictedVehicle tick event riding a vehicle the client predicts
46 paddling_left PaddlingLeft byte +98 boat left paddle
47 paddling_right PaddlingRight byte +99 boat right paddle
48 block_breaking_delay_enabled BlockBreakingDelayEnabled game setting block breaking delay on (always sent)
49 horizontal_collision HorizontalCollision simulation touching a wall
50 vertical_collision VerticalCollision simulation touching the ground or a ceiling
51 down_left DownLeft flag bit 11 touch d-pad diagonal
52 down_right DownRight flag bit 12 touch d-pad diagonal
53 start_using_item StartUsingItem tick event started using an item
54 is_camera_relative_movement_enabled IsCameraRelativeMovementEnabled game setting camera relative movement
55 is_rot_controlled_by_move_direction IsRotControlledByMoveDirection game setting rotation follows the movement
56 start_spin_attack StartSpinAttack tick event trident riptide started
57 stop_spin_attack StopSpinAttack tick event trident riptide stopped
58 is_hotbar_only_touch IsHotbarOnlyTouch game setting touch hotbar only
59 jump_released_raw JumpReleasedRaw raw bit 24 raw jump released
60 jump_pressed_raw JumpPressedRaw raw bit 25 raw jump pressed
61 jump_current_raw JumpCurrentRaw raw bit 26 raw jump held
62 sneak_released_raw SneakReleasedRaw raw bit 22 raw sneak released
63 sneak_pressed_raw SneakPressedRaw raw bit 23 raw sneak pressed
64 sneak_current_raw SneakCurrentRaw raw bit 21 raw sneak held
65 internal_update InternalUpdate - internal, last entry of the enum

"Raw bit" is the second state word of MoveInputComponent (+16). The flag, state, raw and byte sources are read in the game function that copies MoveInputComponent into the packet; "tick event", "game setting" and "simulation" only describe where the other flags come from. The packet log decoder (input_flag of msg:fields(), Copy as Lua, Copy as receiver) reads its names from the same table, so a flag has the same name in xiao.cmd and in the packet log. The short names the decoder used before are still accepted by the encoder, see Renamed fields.


Complete example

Hold sneak on the server only while the player stands still, and print every tick event the client sends.

local events = {}
for name, index in pairs(xiao.cmd.buttons) do
    if name:find("^start_") or name:find("^stop_") then events[index] = name end
end

xiao.cmd.hook("authinput", "buttons_demo", function(cmd)
    local forward, left = cmd:get_move()
    if forward == 0 and left == 0 then
        cmd:set_button("sneak_down")
        cmd:set_button("sneaking")
    end
    for _, index in ipairs(cmd:get_buttons()) do
        if events[index] then print(cmd:command_number(), events[index]) end
    end
end)