11package net .immortaldevs .bindcmd ;
22
3- import net . minecraft . client . input . KeyInput ;
4- import net .minecraft .client .option . KeyBinding ;
5- import net .minecraft .client .util . InputUtil ;
6- import net .minecraft .util .Identifier ;
3+ import com . mojang . blaze3d . platform . InputConstants ;
4+ import net .minecraft .client .KeyMapping ;
5+ import net .minecraft .client .input . KeyEvent ;
6+ import net .minecraft .resources .Identifier ;
77
88public class CommandBinding {
9- private static final KeyBinding .Category CATEGORY = new KeyBinding .Category (
10- Identifier .of ("bindcmd" , "category" )
9+ private static final KeyMapping .Category CATEGORY = new KeyMapping .Category (
10+ Identifier .fromNamespaceAndPath ("bindcmd" , "category" )
1111 );
1212
1313 public boolean wasPressed = false ;
1414 public String command ;
1515
1616 private BindSource source = BindSource .CLIENT ;
17- private KeyBinding key ;
17+ private KeyMapping key ;
1818
19- public CommandBinding (String command , KeyBinding key ) {
19+ public CommandBinding (String command , KeyMapping key ) {
2020 this .command = command ;
2121 this .key = key ;
2222 }
2323
2424 public CommandBinding (String command ) {
25- this (command , new KeyBinding ("key.keyboard.unknown" , -1 , CATEGORY ));
25+ this (command , new KeyMapping ("key.keyboard.unknown" , -1 , CATEGORY ));
2626 }
2727
2828 public CommandBinding (String command , String translationKey , BindSource source ) {
2929 this (command );
3030 this .command = command ;
3131 this .source = source ;
32- InputUtil .Key keyFromTranslation = InputUtil . fromTranslationKey (translationKey );
33- int keyCode = keyFromTranslation .getCode ();
34- InputUtil .Type type = translationKey .startsWith ("key.mouse" ) ? InputUtil .Type .MOUSE : InputUtil .Type .KEYSYM ;
35- this .key = new KeyBinding (translationKey , type , keyCode , CATEGORY );
32+ InputConstants .Key keyFromTranslation = InputConstants . getKey (translationKey );
33+ int keyCode = keyFromTranslation .getValue ();
34+ InputConstants .Type type = translationKey .startsWith ("key.mouse" ) ? InputConstants .Type .MOUSE : InputConstants .Type .KEYSYM ;
35+ this .key = new KeyMapping (translationKey , type , keyCode , CATEGORY );
3636 }
3737
38- public KeyBinding getKey () {
38+ public KeyMapping getKey () {
3939 return this .key ;
4040 }
4141
@@ -44,31 +44,31 @@ public BindSource getSource() {
4444 }
4545
4646 public String getTranslationKey () {
47- return this .key .getBoundKeyTranslationKey ();
47+ return this .key .saveString ();
4848 }
4949
5050 public boolean isUnknown () {
5151 return getTranslationKey ().endsWith ("unknown" );
5252 }
5353
5454 public boolean isPressed () {
55- return key .isPressed ();
55+ return key .isDown ();
5656 }
5757
58- public void setBoundKey (KeyInput keyInput ) {
58+ public void setBoundKey (KeyEvent keyInput ) {
5959 unbind ();
60- InputUtil .Key inpuKey = keyInput .isEscape () ? InputUtil . UNKNOWN_KEY : InputUtil . fromKeyCode (keyInput );
61- key = new KeyBinding (inpuKey .getTranslationKey (), inpuKey .getCode (), CATEGORY );
60+ InputConstants .Key inpuKey = keyInput .isEscape () ? InputConstants . UNKNOWN : InputConstants . getKey (keyInput );
61+ key = new KeyMapping (inpuKey .getName (), inpuKey .getValue (), CATEGORY );
6262 }
6363
6464 public void setBoundMouse (int button ) {
6565 unbind ();
66- InputUtil .Key inpuKey = InputUtil .Type .MOUSE .createFromCode (button );
67- key = new KeyBinding (inpuKey .getTranslationKey (), InputUtil .Type .MOUSE , inpuKey .getCode (), CATEGORY );
66+ InputConstants .Key inpuKey = InputConstants .Type .MOUSE .getOrCreate (button );
67+ key = new KeyMapping (inpuKey .getName (), InputConstants .Type .MOUSE , inpuKey .getValue (), CATEGORY );
6868 }
6969
7070 public void unbind () {
71- KeyBinding . KEYS_BY_ID .remove (getTranslationKey ());
72- KeyBinding . updateKeysByCode ();
71+ KeyMapping . ALL .remove (getTranslationKey ());
72+ KeyMapping . resetMapping ();
7373 }
7474}
0 commit comments