Fixed picking block.

This commit is contained in:
Andrew Lalis 2022-07-28 01:08:17 +02:00
parent fbd893915b
commit 1bb4b08df8
2 changed files with 15 additions and 12 deletions

View File

@ -59,18 +59,6 @@ public class InputHandler {
} }
ClientPlayer player = client.getMyPlayer(); 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() { public boolean isForward() {
@ -179,4 +167,18 @@ public class InputHandler {
public void toggleDebugEnabled() { public void toggleDebugEnabled() {
this.debugEnabled = !debugEnabled; 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));
}
}
}
}
} }

View File

@ -20,6 +20,7 @@ public class PlayerInputMouseClickCallback implements GLFWMouseButtonCallbackI {
switch (button) { switch (button) {
case GLFW_MOUSE_BUTTON_1 -> inputHandler.setHitting(true); case GLFW_MOUSE_BUTTON_1 -> inputHandler.setHitting(true);
case GLFW_MOUSE_BUTTON_2 -> inputHandler.setInteracting(true); case GLFW_MOUSE_BUTTON_2 -> inputHandler.setInteracting(true);
case GLFW_MOUSE_BUTTON_3 -> inputHandler.pickBlock();
} }
} else if (action == GLFW_RELEASE) { } else if (action == GLFW_RELEASE) {
switch (button) { switch (button) {