From 1bb4b08df8b809f0a610fd4e3faf5e4bf93d2c97 Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Thu, 28 Jul 2022 01:08:17 +0200 Subject: [PATCH] Fixed picking block. --- .../aos2_client/control/InputHandler.java | 26 ++++++++++--------- .../PlayerInputMouseClickCallback.java | 1 + 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/client/src/main/java/nl/andrewl/aos2_client/control/InputHandler.java b/client/src/main/java/nl/andrewl/aos2_client/control/InputHandler.java index db7d566..b136c86 100644 --- a/client/src/main/java/nl/andrewl/aos2_client/control/InputHandler.java +++ b/client/src/main/java/nl/andrewl/aos2_client/control/InputHandler.java @@ -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)); + } + } + } + } } diff --git a/client/src/main/java/nl/andrewl/aos2_client/control/PlayerInputMouseClickCallback.java b/client/src/main/java/nl/andrewl/aos2_client/control/PlayerInputMouseClickCallback.java index 9c4f872..eb8bc4a 100644 --- a/client/src/main/java/nl/andrewl/aos2_client/control/PlayerInputMouseClickCallback.java +++ b/client/src/main/java/nl/andrewl/aos2_client/control/PlayerInputMouseClickCallback.java @@ -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) {