Fixed picking block.
This commit is contained in:
parent
fbd893915b
commit
1bb4b08df8
|
@ -59,18 +59,6 @@ public class InputHandler {
|
|||
}
|
||||
|
||||
ClientPlayer player = client.getMyPlayer();
|
||||
|
||||
// Check for "pick block" functionality.
|
||||
if (glfwGetMouseButton(windowId, GLFW_MOUSE_BUTTON_3) == GLFW_PRESS && player.getInventory().getSelectedItemStack() instanceof BlockItemStack stack) {
|
||||
Hit hit = client.getWorld().getLookingAtPos(player.getEyePosition(), player.getViewVector(), 50);
|
||||
if (hit != null) {
|
||||
byte selectedBlock = client.getWorld().getBlockAt(hit.pos().x, hit.pos().y, hit.pos().z);
|
||||
if (selectedBlock > 0) {
|
||||
stack.setSelectedValue(selectedBlock);
|
||||
comm.sendDatagramPacket(new BlockColorMessage(player.getId(), selectedBlock));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isForward() {
|
||||
|
@ -179,4 +167,18 @@ public class InputHandler {
|
|||
public void toggleDebugEnabled() {
|
||||
this.debugEnabled = !debugEnabled;
|
||||
}
|
||||
|
||||
public void pickBlock() {
|
||||
var player = client.getMyPlayer();
|
||||
if (player.getInventory().getSelectedItemStack() instanceof BlockItemStack stack) {
|
||||
Hit hit = client.getWorld().getLookingAtPos(player.getEyePosition(), player.getViewVector(), 50);
|
||||
if (hit != null) {
|
||||
byte selectedBlock = client.getWorld().getBlockAt(hit.pos().x, hit.pos().y, hit.pos().z);
|
||||
if (selectedBlock > 0) {
|
||||
stack.setSelectedValue(selectedBlock);
|
||||
comm.sendDatagramPacket(new BlockColorMessage(player.getId(), selectedBlock));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ public class PlayerInputMouseClickCallback implements GLFWMouseButtonCallbackI {
|
|||
switch (button) {
|
||||
case GLFW_MOUSE_BUTTON_1 -> inputHandler.setHitting(true);
|
||||
case GLFW_MOUSE_BUTTON_2 -> inputHandler.setInteracting(true);
|
||||
case GLFW_MOUSE_BUTTON_3 -> inputHandler.pickBlock();
|
||||
}
|
||||
} else if (action == GLFW_RELEASE) {
|
||||
switch (button) {
|
||||
|
|
Loading…
Reference in New Issue