1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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) {}
}
|