-
-
Save izzyaxel/dad0c5dd4f0aa79be21e9befca48d864 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 interface IKeyReceiver | |
{ | |
void onKeypress(EntityPlayer player, KeyBinding ... keyBindings); | |
} |
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 List<RegisteredKeybinding> registered = new ArrayList<RegisteredKeybinding>(); | |
public static void registerKeybindsForNotification(IKeyReceiver callbackReceiver, KeyBinding... keyBindings) | |
{ | |
registered.add(new RegisteredKeybinding(callbackReceiver, keyBindings)); | |
} | |
@SubscribeEvent | |
public void clientKeyListener(TickEvent.PlayerTickEvent event) | |
{ | |
if(event.side == Side.CLIENT && event.phase == TickEvent.Phase.START) | |
{ | |
for(RegisteredKeybinding reg : registered) | |
{ | |
for(KeyBinding k : reg.keyBindings) | |
{ | |
if(k.isKeyDown()) | |
{ | |
reg.receiver.onKeypress(event.player, reg.keyBindings); | |
break; | |
} | |
} | |
} | |
} | |
} | |
} |
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 RegisteredKeybinding | |
{ | |
KeyBinding[] keyBindings; | |
IKeyReceiver receiver; | |
public RegisteredKeybinding(IKeyReceiver receiver, KeyBinding ... keyBindings) | |
{ | |
this.keyBindings = keyBindings; | |
this.receiver = receiver; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment