diff options
| author | Tyler Murphy <tylerm@tylerm.dev> | 2023-04-17 12:12:01 -0400 |
|---|---|---|
| committer | Tyler Murphy <tylerm@tylerm.dev> | 2023-04-17 12:12:01 -0400 |
| commit | 180aad05decc7eefa87e4e45d6747c48f40e5361 (patch) | |
| tree | 51545197f7c94b4022acab880772c9f4fc65db0e /src/main/java/net/tylermurphy/Minecraft/Input/GameInput.java | |
| download | minecraftjava-180aad05decc7eefa87e4e45d6747c48f40e5361.tar.gz minecraftjava-180aad05decc7eefa87e4e45d6747c48f40e5361.tar.bz2 minecraftjava-180aad05decc7eefa87e4e45d6747c48f40e5361.zip | |
save
Diffstat (limited to '')
| -rwxr-xr-x | src/main/java/net/tylermurphy/Minecraft/Input/GameInput.java | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/src/main/java/net/tylermurphy/Minecraft/Input/GameInput.java b/src/main/java/net/tylermurphy/Minecraft/Input/GameInput.java new file mode 100755 index 0000000..5da40a6 --- /dev/null +++ b/src/main/java/net/tylermurphy/Minecraft/Input/GameInput.java @@ -0,0 +1,85 @@ +package net.tylermurphy.Minecraft.Input;
+
+import static net.tylermurphy.Minecraft.UI.UIMaster.*;
+
+import net.tylermurphy.Minecraft.Scene.Objects.WorldOrigin;
+import org.lwjgl.glfw.GLFW;
+import org.joml.Vector3f;
+
+import net.tylermurphy.Minecraft.Chunk.Cube;
+import net.tylermurphy.Minecraft.Scene.World;
+import net.tylermurphy.Minecraft.Util.Flags;
+import net.tylermurphy.Minecraft.Util.MousePicker;
+
+public class GameInput extends IInput {
+
+ byte blockId = 1;
+
+ public void keyPressed(int keyCode) {
+ switch(keyCode) {
+ case GLFW.GLFW_KEY_ESCAPE:
+ Flags.actionForceClose = true; break;
+ case GLFW.GLFW_KEY_F3:
+ bindUI(1);
+ setEnabled(!isEnabled());
+ break;
+ case GLFW.GLFW_KEY_EQUAL:
+ do {
+ blockId++;
+ if (blockId > (byte) (Cube.blocks.size() - 1)) blockId = 0;
+ } while (!Cube.getBlock(blockId).placeable);
+ bindUI(1);
+ getText("block").setText("Block Selected: minecraft:"+Cube.getBlock(blockId).name);
+ break;
+ case GLFW.GLFW_KEY_MINUS:
+ do {
+ blockId--;
+ if (blockId < 0) blockId = (byte) (Cube.blocks.size() - 1);
+ } while (!Cube.getBlock(blockId).placeable);
+ bindUI(1);
+ getText("block").setText("Block Selected: minecraft:"+Cube.getBlock(blockId).name);
+ break;
+ case GLFW.GLFW_KEY_F2:
+ World.player.isFlying = !World.player.isFlying;
+ break;
+ case GLFW.GLFW_KEY_K:
+ if(World.player.isDead) {
+ World.player.isDead = false;
+ World.player.health = 20;
+ World.world_origin = new WorldOrigin(0,0);
+ World.player.getTransform().setPosition(new Vector3f(0, World.getHighestBlock(0, 0)+1,0));
+ bindUI(0);
+ getText("dead").setEnabled(false);
+ getImage("crosshair").setEnabled(true);
+ }
+ break;
+ case GLFW.GLFW_KEY_SLASH:
+ this.enabled = false;
+ Input.setEnabled("CommandInput", true);
+ bindUI(3);
+ setEnabled(true);
+ World.player.isPaused = true;
+ break;
+ }
+ }
+
+ public void keyRelesed(int keyCode) {}
+
+ public void mousePressed(int mouseButton) {
+ switch(mouseButton) {
+ case GLFW.GLFW_MOUSE_BUTTON_1:
+ if(MousePicker.breakPos!=null)
+ World.setBlock((int)MousePicker.breakPos.x,(int)MousePicker.breakPos.y,(int)MousePicker.breakPos.z, Cube.AIR);
+ break;
+ case GLFW.GLFW_MOUSE_BUTTON_2:
+ if(MousePicker.placePos!=null && !World.player.collides(MousePicker.placePos.x,MousePicker.placePos.y,MousePicker.placePos.z))
+ World.setBlock((int)MousePicker.placePos.x,(int)MousePicker.placePos.y,(int)MousePicker.placePos.z, blockId);
+ break;
+ }
+ }
+
+ public void mouseRelesed(int mouseButton) {}
+
+ public void charAction(char c) {}
+
+}
|