Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
709648d
commit 095affc
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/main/java/org/auioc/mcmod/arnicalib/game/input/KeyDownRule.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.auioc.mcmod.arnicalib.game.input; | ||
|
||
import org.auioc.mcmod.arnicalib.base.function.VoidPredicate; | ||
import net.minecraftforge.api.distmarker.Dist; | ||
import net.minecraftforge.api.distmarker.OnlyIn; | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
public enum KeyDownRule implements VoidPredicate { | ||
|
||
ALWAYS(() -> true), NEVER(() -> false), // | ||
ON_SHIFT_KEY_DOWN(KeyboardUtils::isShiftKeyDown), // | ||
ON_CTRL_KEY_DOWN(KeyboardUtils::isCtrlKeyDown), // | ||
ON_ALT_KEY_DOWN(KeyboardUtils::isAltKeyDown), // | ||
ON_SPACE_KEY_DOWN(KeyboardUtils::isSpaceKeyDown); | ||
|
||
private final VoidPredicate predicate; | ||
|
||
private KeyDownRule(VoidPredicate predicate) { | ||
this.predicate = predicate; | ||
} | ||
|
||
@Override | ||
public boolean test() { | ||
return predicate.test(); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/org/auioc/mcmod/arnicalib/game/input/KeyboardUtils.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.auioc.mcmod.arnicalib.game.input; | ||
|
||
import org.lwjgl.glfw.GLFW; | ||
import com.mojang.blaze3d.platform.InputConstants; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraftforge.api.distmarker.Dist; | ||
import net.minecraftforge.api.distmarker.OnlyIn; | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
public class KeyboardUtils { | ||
|
||
private static final Minecraft MC = Minecraft.getInstance(); | ||
|
||
public static boolean isKeyDown(int key) { | ||
return InputConstants.isKeyDown(MC.getWindow().getWindow(), key); | ||
} | ||
|
||
public static boolean isShiftKeyDown() { | ||
return isKeyDown(GLFW.GLFW_KEY_LEFT_SHIFT) || isKeyDown(GLFW.GLFW_KEY_RIGHT_SHIFT); | ||
} | ||
|
||
public static boolean isCtrlKeyDown() { | ||
return isKeyDown(GLFW.GLFW_KEY_LEFT_CONTROL) || isKeyDown(GLFW.GLFW_KEY_RIGHT_CONTROL); | ||
} | ||
|
||
public static boolean isAltKeyDown() { | ||
return isKeyDown(GLFW.GLFW_KEY_LEFT_ALT) || isKeyDown(GLFW.GLFW_KEY_RIGHT_ALT); | ||
} | ||
|
||
public static boolean isSpaceKeyDown() { | ||
return isKeyDown(GLFW.GLFW_KEY_SPACE); | ||
} | ||
|
||
} |