mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-16 10:44:46 +00:00
Implemented KeyPressed event.
This commit is contained in:
1 parent
1ee14920ff
commit
6c8c7671b8
7 files changed
+57
-18
No files matched your search
@@ -14,11 +14,14 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.InputEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
public class ClientTickHandler{
|
||||
|
||||
private World prevWorld;
|
||||
private boolean otherContainer = false;
|
||||
private int buttonPressed = -1;
|
||||
private long buttonTime = 0L;
|
||||
private final int[] ignoreKeys = new int[]{157, 29, 54, 42, 184, 56, 220, 219};
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.LOWEST)
|
||||
public void onClientTick(TickEvent.ClientTickEvent event){
|
||||
@@ -50,6 +53,40 @@ public class ClientTickHandler{
|
||||
else if(mc.currentScreen instanceof GuiQuestLog)
|
||||
mc.setIngameFocus();
|
||||
}
|
||||
|
||||
int key = Keyboard.getEventKey();
|
||||
long time = Keyboard.getEventNanoseconds();
|
||||
if(Keyboard.getEventKeyState()) {
|
||||
if(!this.isIgnoredKey(key)) {
|
||||
this.buttonTime = time;
|
||||
this.buttonPressed = key;
|
||||
}
|
||||
} else {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
if(key == this.buttonPressed && time - this.buttonTime < 500000000L && mc.currentScreen == null) {
|
||||
boolean isCtrlPressed = Keyboard.isKeyDown(157) || Keyboard.isKeyDown(29);
|
||||
boolean isShiftPressed = Keyboard.isKeyDown(54) || Keyboard.isKeyDown(42);
|
||||
boolean isAltPressed = Keyboard.isKeyDown(184) || Keyboard.isKeyDown(56);
|
||||
boolean isMetaPressed = Keyboard.isKeyDown(220) || Keyboard.isKeyDown(219);
|
||||
NoppesUtilPlayer.sendData(EnumPlayerPacket.KeyPressed, new Object[]{Integer.valueOf(key), Boolean.valueOf(isCtrlPressed), Boolean.valueOf(isShiftPressed), Boolean.valueOf(isAltPressed), Boolean.valueOf(isMetaPressed)});
|
||||
}
|
||||
|
||||
this.buttonPressed = -1;
|
||||
this.buttonTime = 0L;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isIgnoredKey(int key) {
|
||||
int[] var2 = this.ignoreKeys;
|
||||
int var3 = var2.length;
|
||||
|
||||
for(int var4 = 0; var4 < var3; ++var4) {
|
||||
int i = var2[var4];
|
||||
if(i == key) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user