[Question] How can you get the keybind associated with something? #834
-
I am trying to add the keybind of something to a tooltip, and I am wondering if there is a way to get what the keybind of an action is currently bound to. I am trying to do something like this: ItemEvents.tooltip((e) => {
e.addAdvanced("sophisticatedbackpacks:backpack", (item, advanced, text) => {
text.add(1, "§8Press [G] to open while equipped");
}
});
}); except obviously I want [G] to be replaced with what the current keybind is set to, so that if you change the keybind it will reflect properly. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Use TextComponents. With these components you can join them in two ways, either by sticking them in a list or by appending them. |
Beta Was this translation helpful? Give feedback.
Use TextComponents.
For the colouring you can use
Text.darkGray('hello')
orText.of('hi').darkGray()
, and for keybunds you can useText.keybind('key.sneak')
, where the text inside is the keybind 'id'. You can find that in the options.txt file, it will probably be something likekey.open_backpack
. (it will definitely contain the textopen_backpack
)With these components you can join them in two ways, either by sticking them in a list or by appending them.
list:
[Text.darkGray('Press ['), Text.keybind('key.open_backpack').darkGray(), Text.darkGray('] to open while equipped')]
appending:
Text.darkGray('Press [').append(Text.keybind('key.open_backpack')).append('] to open while equipped')