Add key hints to buttons which have corresponding keybindings
This commit is contained in:
@@ -51,12 +51,16 @@ public class KeyBindingRegistry extends EventRegistrations {
|
||||
private Multimap<KeyBinding, Runnable> repeatedKeyBindingHandlers = ArrayListMultimap.create();
|
||||
private Multimap<Integer, Runnable> rawHandlers = ArrayListMultimap.create();
|
||||
|
||||
public void registerKeyBinding(String name, int keyCode, Runnable whenPressed, boolean onlyInRepay) {
|
||||
keyBindingHandlers.put(registerKeyBinding(name, keyCode, onlyInRepay), whenPressed);
|
||||
public KeyBinding registerKeyBinding(String name, int keyCode, Runnable whenPressed, boolean onlyInRepay) {
|
||||
KeyBinding keyBinding = registerKeyBinding(name, keyCode, onlyInRepay);
|
||||
keyBindingHandlers.put(keyBinding, whenPressed);
|
||||
return keyBinding;
|
||||
}
|
||||
|
||||
public void registerRepeatedKeyBinding(String name, int keyCode, Runnable whenPressed, boolean onlyInRepay) {
|
||||
repeatedKeyBindingHandlers.put(registerKeyBinding(name, keyCode, onlyInRepay), whenPressed);
|
||||
public KeyBinding registerRepeatedKeyBinding(String name, int keyCode, Runnable whenPressed, boolean onlyInRepay) {
|
||||
KeyBinding keyBinding = registerKeyBinding(name, keyCode, onlyInRepay);
|
||||
repeatedKeyBindingHandlers.put(keyBinding, whenPressed);
|
||||
return keyBinding;
|
||||
}
|
||||
|
||||
private KeyBinding registerKeyBinding(String name, int keyCode, boolean onlyInRepay) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.replaymod.replaystudio.us.myles.ViaVersion.api.protocol.ProtocolVersi
|
||||
import com.replaymod.replaystudio.us.myles.ViaVersion.packets.State;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.options.KeyBinding;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.client.render.Tessellator;
|
||||
import net.minecraft.client.render.entity.EntityRenderDispatcher;
|
||||
@@ -748,6 +749,23 @@ public class MCVer {
|
||||
//#endif
|
||||
}
|
||||
|
||||
public static String getBoundKey(KeyBinding keyBinding) {
|
||||
try {
|
||||
//#if MC>=11600
|
||||
return keyBinding.getBoundKeyLocalizedText().asString();
|
||||
//#else
|
||||
//#if MC>=11400
|
||||
//$$ return keyBinding.getLocalizedName();
|
||||
//#else
|
||||
//$$ return Keyboard.getKeyName(keyBinding.getKeyCode());
|
||||
//#endif
|
||||
//#endif
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
// Apparently windows likes to press strange keys, see https://www.replaymod.com/forum/thread/55
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
//#if MC>=11400
|
||||
private static Boolean hasOptifine;
|
||||
public static boolean hasOptifine() {
|
||||
@@ -893,6 +911,10 @@ public class MCVer {
|
||||
//$$ public static boolean getEventKeyState() {
|
||||
//$$ return org.lwjgl.input.Keyboard.getEventKeyState();
|
||||
//$$ }
|
||||
//$$
|
||||
//$$ public static String getKeyName(int code) {
|
||||
//$$ return org.lwjgl.input.Keyboard.getKeyName(code);
|
||||
//$$ }
|
||||
//#endif
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user