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) {} }