Made TCP communication async, and show selected block value.

This commit is contained in:
Andrew Lalis 2022-07-28 09:06:52 +02:00
parent e321979c3c
commit bf0982fbd9
2 changed files with 9 additions and 6 deletions

View File

@ -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) {

View File

@ -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) {