From bf0982fbd92843671b383390dd7b510c64b7c0ba Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Thu, 28 Jul 2022 09:06:52 +0200 Subject: [PATCH] Made TCP communication async, and show selected block value. --- .../aos2_client/render/gui/GuiRenderer.java | 1 + .../aos2_server/ClientCommunicationHandler.java | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/client/src/main/java/nl/andrewl/aos2_client/render/gui/GuiRenderer.java b/client/src/main/java/nl/andrewl/aos2_client/render/gui/GuiRenderer.java index c3bc9a0..db4bc4a 100644 --- a/client/src/main/java/nl/andrewl/aos2_client/render/gui/GuiRenderer.java +++ b/client/src/main/java/nl/andrewl/aos2_client/render/gui/GuiRenderer.java @@ -321,6 +321,7 @@ public class GuiRenderer { nvgFontFaceId(vgId, jetbrainsMonoFont); nvgTextAlign(vgId, NVG_ALIGN_LEFT | NVG_ALIGN_TOP); nvgText(vgId, w - 140, h - 30, String.format("%d / %d Blocks", stack.getAmount(), block.getMaxAmount())); + nvgText(vgId, w - 140, h - 14, String.format("Selected value: %d", stack.getSelectedValue())); } private void drawChat(float w, float h, Chat chat) { diff --git a/server/src/main/java/nl/andrewl/aos2_server/ClientCommunicationHandler.java b/server/src/main/java/nl/andrewl/aos2_server/ClientCommunicationHandler.java index 656e4b3..c5bc0ef 100644 --- a/server/src/main/java/nl/andrewl/aos2_server/ClientCommunicationHandler.java +++ b/server/src/main/java/nl/andrewl/aos2_server/ClientCommunicationHandler.java @@ -22,6 +22,7 @@ import org.slf4j.LoggerFactory; import java.io.IOException; import java.net.*; import java.util.LinkedList; +import java.util.concurrent.ForkJoinPool; /** * Component which manages the establishing and maintenance of a connection @@ -71,7 +72,6 @@ public class ClientCommunicationHandler { } private void handleTcpMessage(Message msg) { - log.debug("Received TCP message from client \"{}\": {}", player.getUsername(), msg.toString()); if (msg instanceof ChunkHashMessage hashMessage) { Chunk chunk = server.getWorld().getChunkAt(new Vector3i(hashMessage.cx(), hashMessage.cy(), hashMessage.cz())); if (chunk != null && hashMessage.hash() != chunk.blockHash()) { @@ -134,11 +134,13 @@ public class ClientCommunicationHandler { } public void sendTcpMessage(Message msg) { - try { - Net.write(msg, out); - } catch (IOException e) { - e.printStackTrace(); - } + ForkJoinPool.commonPool().submit(() -> { + try { + Net.write(msg, out); + } catch (IOException e) { + e.printStackTrace(); + } + }); } public void sendDatagramPacket(Message msg) {