From 6f7273c2795816a4d7bf99b3280b2ccf77bbc566 Mon Sep 17 00:00:00 2001 From: Cedric Date: Mon, 23 Oct 2023 13:03:20 +0200 Subject: [PATCH] fix: issues with PathwayRequeseter --- .../signals/guis/PathwayRequesterGui.java | 4 ++-- .../signals/handler/SignalBoxHandler.java | 12 ++++++++++++ .../signals/signalbox/PathwayHolder.java | 2 +- .../tileentitys/PathwayRequesterTileEntity.java | 11 +++++++++-- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/troblecodings/signals/guis/PathwayRequesterGui.java b/src/main/java/com/troblecodings/signals/guis/PathwayRequesterGui.java index b31ae1051..2d591a6b8 100644 --- a/src/main/java/com/troblecodings/signals/guis/PathwayRequesterGui.java +++ b/src/main/java/com/troblecodings/signals/guis/PathwayRequesterGui.java @@ -69,7 +69,7 @@ private void initOwn() { if (!container.validEnds.isEmpty()) { inner.add(GuiElements.createEnumElement(end, e -> { - container.end = container.validStarts.get(e); + container.end = container.validEnds.get(e); }, container.end != null ? container.end.equals(new Point()) ? 0 : container.validEnds.indexOf(container.end) : 0)); } else { @@ -122,4 +122,4 @@ private void sendToServer() { OpenSignalsMain.network.sendTo(player, buffer); } -} +} \ No newline at end of file diff --git a/src/main/java/com/troblecodings/signals/handler/SignalBoxHandler.java b/src/main/java/com/troblecodings/signals/handler/SignalBoxHandler.java index 947380414..f26a7ebb5 100644 --- a/src/main/java/com/troblecodings/signals/handler/SignalBoxHandler.java +++ b/src/main/java/com/troblecodings/signals/handler/SignalBoxHandler.java @@ -139,6 +139,18 @@ public static boolean arePointsValidStartAndEnd(final PosIdentifier identifier, return grid.isValidStart(start) && grid.isValidEnd(end); } + public static SignalBoxNode getNodeFromGrid(final PosIdentifier identifier, final Point point) { + if (identifier.world.isClientSide) + return new SignalBoxNode(); + PathwayHolder grid; + synchronized (ALL_GRIDS) { + grid = ALL_GRIDS.get(identifier); + } + if (grid == null) + return new SignalBoxNode(); + return grid.getNode(point); + } + public static boolean requesetInterSignalBoxPathway(final PosIdentifier startBox, final Point start, final Point end) { if (startBox.world.isClientSide) diff --git a/src/main/java/com/troblecodings/signals/signalbox/PathwayHolder.java b/src/main/java/com/troblecodings/signals/signalbox/PathwayHolder.java index 9869ea83a..9194053d7 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/PathwayHolder.java +++ b/src/main/java/com/troblecodings/signals/signalbox/PathwayHolder.java @@ -103,7 +103,7 @@ public List getAllInConnections() { public SignalBoxNode getNode(final Point point) { checkTileWasLoaded(); - return modeGrid.get(point); + return modeGrid.getOrDefault(point, new SignalBoxNode()); } public List getGreenSignals() { diff --git a/src/main/java/com/troblecodings/signals/tileentitys/PathwayRequesterTileEntity.java b/src/main/java/com/troblecodings/signals/tileentitys/PathwayRequesterTileEntity.java index 1a1cc0892..2ccc25147 100644 --- a/src/main/java/com/troblecodings/signals/tileentitys/PathwayRequesterTileEntity.java +++ b/src/main/java/com/troblecodings/signals/tileentitys/PathwayRequesterTileEntity.java @@ -56,8 +56,15 @@ public void saveWrapper(final NBTWrapper wrapper) { public void requestPathway() { final PosIdentifier identifier = new PosIdentifier(linkedSignalBox, level); - if (!SignalBoxHandler.requestPathway(identifier, pathway.getKey(), pathway.getValue())) { - SignalBoxHandler.addNextPathway(identifier, pathway.getKey(), pathway.getValue()); + if (SignalBoxHandler.getNodeFromGrid(identifier, pathway.getValue()) + .containsOutConnection()) { + SignalBoxHandler.requesetInterSignalBoxPathway(identifier, pathway.getKey(), + pathway.getValue()); + } else { + if (!SignalBoxHandler.requestPathway(identifier, pathway.getKey(), + pathway.getValue())) { + SignalBoxHandler.addNextPathway(identifier, pathway.getKey(), pathway.getValue()); + } } }