-
-
Save izzyaxel/0891aaf1a58e407c20e5315c02db1510 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class KeyHandler | |
{ | |
private static Map<KeyBinding, List<IKeyReceiver>> callbacks = new HashMap<KeyBinding, List<IKeyReceiver>>(); | |
public static void registerKeybindForNotification(KeyBinding keyBinding, IKeyReceiver callbackReceiver) | |
{ | |
if(!callbacks.containsKey(keyBinding)) | |
{ | |
List<IKeyReceiver> receivers = new ArrayList<IKeyReceiver>(); | |
receivers.add(callbackReceiver); | |
callbacks.put(keyBinding, receivers); | |
} | |
else | |
{ | |
List<IKeyReceiver> receivers = callbacks.get(keyBinding); | |
receivers.add(callbackReceiver); | |
callbacks.put(keyBinding, receivers); | |
} | |
} | |
@SubscribeEvent | |
public void clientKeyListener(TickEvent.PlayerTickEvent event) | |
{ | |
if(event.side == Side.CLIENT && event.phase == TickEvent.Phase.START) | |
{ | |
for(KeyBinding k : Minecraft.getMinecraft().gameSettings.keyBindings) | |
{ | |
if(callbacks.containsKey(k) && k.isKeyDown()) | |
{ | |
List<IKeyReceiver> receivers = callbacks.get(k); | |
for(IKeyReceiver receiver : receivers) | |
{ | |
receiver.onKeypress(event.player, k); | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment