From 535b3a06a47941abf31bf55483b41d82c7d6522b Mon Sep 17 00:00:00 2001 From: TudbuT Date: Fri, 31 May 2024 20:35:54 +0200 Subject: [PATCH] fix numbering and selection splitting --- .../client/event/remote/RemoteEventManager.java | 11 ++++++----- .../client/event/remote/events/RemoteInitEvent.java | 5 +++-- .../com/baseband/client/util/interact/BlockUtils.java | 2 +- .../java/com/baseband/client/util/type/Selection.java | 4 ++-- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Client/src/main/java/com/baseband/client/event/remote/RemoteEventManager.java b/Client/src/main/java/com/baseband/client/event/remote/RemoteEventManager.java index 5e27007..d7b251b 100644 --- a/Client/src/main/java/com/baseband/client/event/remote/RemoteEventManager.java +++ b/Client/src/main/java/com/baseband/client/event/remote/RemoteEventManager.java @@ -27,7 +27,7 @@ public class RemoteEventManager { public final ArrayList clients = new ArrayList<>(); public ServerSocket server = null; - private int id = 0, maxID = 0; + private int id = -1, peers = 0, maxID = 0; private final Queue toSend = new LinkedList<>(); private final Queue toProcess = new LinkedList<>(); @@ -90,7 +90,7 @@ public class RemoteEventManager { s.getOutputStream().flush(); s.setSoTimeout(1); clients.add(s); - publish(new RemoteInitEvent(++maxID)); + publish(new RemoteInitEvent(++maxID, clients.size())); BaseBand.notify("[Remote] Client connected."); } else { s.close(); @@ -181,13 +181,14 @@ public class RemoteEventManager { while(!toProcess.isEmpty()) { RemoteEvent event = toProcess.poll(); if(event instanceof RemoteInitEvent) { + peers = ((RemoteInitEvent) event).clients; if(id == -1) { id = ((RemoteInitEvent) event).id; - BaseBand.notify("[Remote] Received ID: " + id + "."); + BaseBand.notify("[Remote] Received ID: " + id + ". Peers connected: " + peers + "."); } else { maxID = ((RemoteInitEvent) event).id; - BaseBand.notify("[Remote] Someone connected with ID " + maxID + "."); + BaseBand.notify("[Remote] Someone connected with ID " + maxID + ". Peers connected: " + peers + "."); } } else { @@ -203,7 +204,7 @@ public class RemoteEventManager { } public int getPeers() { - return maxID + 1; + return peers; } } diff --git a/Client/src/main/java/com/baseband/client/event/remote/events/RemoteInitEvent.java b/Client/src/main/java/com/baseband/client/event/remote/events/RemoteInitEvent.java index 2c961aa..ca79877 100644 --- a/Client/src/main/java/com/baseband/client/event/remote/events/RemoteInitEvent.java +++ b/Client/src/main/java/com/baseband/client/event/remote/events/RemoteInitEvent.java @@ -5,9 +5,10 @@ import de.tudbut.obj.Save; public class RemoteInitEvent extends RemoteEvent { @Save - public int id; + public int id, clients; - public RemoteInitEvent(int id) { + public RemoteInitEvent(int id, int clients) { this.id = id; + this.clients = clients; } } diff --git a/Client/src/main/java/com/baseband/client/util/interact/BlockUtils.java b/Client/src/main/java/com/baseband/client/util/interact/BlockUtils.java index 426ea73..a56bcf8 100644 --- a/Client/src/main/java/com/baseband/client/util/interact/BlockUtils.java +++ b/Client/src/main/java/com/baseband/client/util/interact/BlockUtils.java @@ -16,7 +16,7 @@ public class BlockUtils { xSideLength = sideLength; else zSideLength = sideLength; - for (int i = 0; i <= selections.length; i++) { + for (int i = 0; i < selections.length; i++) { BlockPos pos1 = selection.pos1.add(xSideLength * i, 0, zSideLength * i); BlockPos pos2 = selection.pos2.add(Math.min(xSideLength * (i + 1), size.getX()), 0, Math.min(zSideLength * (i + 1), size.getZ())); selections[i] = new Selection(pos1, pos2); diff --git a/Client/src/main/java/com/baseband/client/util/type/Selection.java b/Client/src/main/java/com/baseband/client/util/type/Selection.java index d636043..c1f995e 100644 --- a/Client/src/main/java/com/baseband/client/util/type/Selection.java +++ b/Client/src/main/java/com/baseband/client/util/type/Selection.java @@ -22,12 +22,12 @@ public class Selection { } public long longestSide() { - Vec3i size = pos2.subtract(pos1); + Vec3i size = size(); return Math.max(Math.max(size.getX(), size.getY()), size.getZ()); } public long longestSideH() { - Vec3i size = pos2.subtract(pos1); + Vec3i size = size(); return Math.max(size.getX(), size.getZ()); } }