HomeJavaDatapacksPlayer Input
Player Input
DatapacksJava

Player Input

by MulverineX · on Modrinth

Handles polling based input detection, made possible by the type-specific input field on players, provides easy & useful DX for tracking and acting on…

⬇ Download on Modrinth

Player Input

Player Input is a library specifically designed for handling polling based input detection, made possible by the type specific input field on players that gives us 20hz access to the keybinds forward, backward, left, right, jump, sneak, sprint at all times, in all game modes, regardless of context, except within GUIs.

The goal of this library is two fold:

  1. Optimize actionable retrieval of this data; many packs need this data but its worse for performance for all of them to be polling at the same time.
  2. Create easy & useful DX for tracking and acting on changes in this data.

Usage

Packs that need access to this input data for few out of many players in specific scenarios should use the capture/player path to begin tracking of the data.

Packs that need access to input data for most/all of players should use the capture/players path to begin tracking of the data, and call the release/players when the data is no longer needed (use #minecraft:unload if the data is needed all of the time)

When data is being received, the exclusive player_input.* /tag labels are always made available.

Packs that need to do their own custom tracking every tick regardless of if the binds change can use the raw entrypoint. If only some players need to be checked use the #player_input:player/raw function tag (called as/at each player) and use your own /tag label to filter players your pack is operating with as the function tag will be called for all usage of the library.

Events:

These entrypoints are called as/at players that match the required state along with context data made available to functions in each tag, enabling event-based handling, instead of checking for state every tick.

To subscribe to any of these, call the appropriate capture function, then to clean up after usage, call the release function.

As with raw, make sure to /tag players that your pack is specifically handling, as the function tag will be called for all usage of the library.

Example

jetpack:jetpack/equip

tag @s add jetpack.equipped

function player_input:capture/player/key_update

# Jetpack Things...

jetpack:input_received

execute if entity @s[tag=jetpack.equipped] run function jetpack:jetpack/control

jetpack:jetpack/control

# Handle changes to player input

jetpack:jetpack/unequipped

tag @s remove jetpack.equipped

function player_input:release/player/key_update

# Jetpack Things...

#player_input:player/key_update

{
    "values": [
        "jetpack:input_received"
    ],
    "replace": false
}

Plans

Quick facts

Install steps are the general flow for this file type — see the MC Java Mods guides for the full walkthrough.

Verified by MCModsHub

These come from our own check of the pack file, not from the source page.

Explore more