mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-17 02:55:04 +00:00
Initial Commit
This commit is contained in:
commit
bd9d0a4eff
149 files changed
+18486
No files matched your search
@@ -0,0 +1,52 @@
|
||||
package codechicken.nei;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
* Good old down/held/up keystate tracker
|
||||
*/
|
||||
public class KeyManager
|
||||
{
|
||||
public static interface IKeyStateTracker
|
||||
{
|
||||
public void tickKeyStates();
|
||||
}
|
||||
|
||||
public static class KeyState
|
||||
{
|
||||
public boolean down;
|
||||
public boolean held;
|
||||
public boolean up;
|
||||
}
|
||||
|
||||
public static HashMap<String, KeyState> keyStates = new HashMap<String, KeyState>();
|
||||
public static LinkedList<IKeyStateTracker> trackers = new LinkedList<IKeyStateTracker>();
|
||||
|
||||
public static void tickKeyStates()
|
||||
{
|
||||
for(Entry<String, KeyState> entry : keyStates.entrySet())
|
||||
{
|
||||
int keyCode = NEIClientConfig.getKeyBinding(entry.getKey());
|
||||
boolean down = keyCode != 0 && Keyboard.isKeyDown(keyCode);
|
||||
KeyState state = entry.getValue();
|
||||
if(down)
|
||||
{
|
||||
state.down = !state.held;
|
||||
state.up = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
state.up = state.held;
|
||||
state.down = false;
|
||||
}
|
||||
state.held = down;
|
||||
}
|
||||
|
||||
for(IKeyStateTracker tracker : trackers)
|
||||
tracker.tickKeyStates();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user