From 68a95d3e3a26f4da74d08e932847d2181c7d2089 Mon Sep 17 00:00:00 2001 From: Cedric Date: Thu, 10 Oct 2024 23:53:38 +0200 Subject: [PATCH] fix: 1.12 bugs --- .../signals/guis/ContainerSignalBox.java | 2 +- .../signals/signalbox/SignalBoxPathway.java | 3 +- .../signalbox/config/SignalConfig.java | 50 ++++++++++++------- 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/troblecodings/signals/guis/ContainerSignalBox.java b/src/main/java/com/troblecodings/signals/guis/ContainerSignalBox.java index 22ba8d5f3..8368c99b4 100644 --- a/src/main/java/com/troblecodings/signals/guis/ContainerSignalBox.java +++ b/src/main/java/com/troblecodings/signals/guis/ContainerSignalBox.java @@ -282,7 +282,7 @@ public void deserializeClient(final ReadBuffer buffer) { final int size = buffer.getInt(); for (int i = 0; i < size; i++) { final Point point = Point.of(buffer); - grid.getNode(point).readUpdateNetwork(buffer); + grid.getNode(point).readNetwork(buffer); updates.add(point); } trainNumberUpdater.accept(updates); diff --git a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java index 6b8f52a96..31b5498e6 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java +++ b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java @@ -473,6 +473,7 @@ public void compact(final Point point) { } }, point); resetAllTrainNumbers(data.getTrainNumberDisplays()); + sendTrainNumberUpdates(); data.compact(point); updateSignalsOnClient(redSignals); updateTrainNumber(trainNumber); @@ -592,7 +593,7 @@ private void sendTrainNumberUpdates() { trainNumberDisplays.forEach(ident -> { final SignalBoxNode node = grid.getNode(ident.point); node.getPoint().writeNetwork(buffer); - node.writeUpdateNetwork(buffer); + node.writeNetwork(buffer); }); OpenSignalsMain.network.sendTo(tile.get(0).getPlayer(), buffer); } diff --git a/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java b/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java index 5e2abaddd..074dd39f4 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java +++ b/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java @@ -11,6 +11,9 @@ import com.troblecodings.signals.contentpacks.ChangeConfigParser; import com.troblecodings.signals.contentpacks.OneSignalNonPredicateConfigParser; import com.troblecodings.signals.contentpacks.OneSignalPredicateConfigParser; +import com.troblecodings.signals.core.LoadHolder; +import com.troblecodings.signals.core.SignalStateListener; +import com.troblecodings.signals.core.SignalStateLoadHoler; import com.troblecodings.signals.enums.PathType; import com.troblecodings.signals.handler.SignalStateHandler; import com.troblecodings.signals.handler.SignalStateInfo; @@ -18,6 +21,9 @@ public final class SignalConfig { + private static final LoadHolder> LOAD_HOLDER = new LoadHolder<>( + SignalConfig.class); + private SignalConfig() { } @@ -58,7 +64,7 @@ public static void reset(final ResetInfo info) { .get(info.current.signal); if (resetValues == null) return; - SignalStateHandler.runTaskWhenSignalLoaded(info.current, (stateInfo, oldProperties, _u) -> { + loadSignalAndRunTask(info.current, (stateInfo, oldProperties, _u) -> { final Map, Object> object = new HashMap<>(); object.put(Boolean.class, info.isRepeater); object.put(Map.class, oldProperties); @@ -68,12 +74,12 @@ public static void reset(final ResetInfo info) { if (property.test(object)) { propertiesToSet.putAll(property.state.entrySet().stream() .filter(entry -> oldProperties.containsKey(entry.getKey())) - .collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, - Map.Entry::getValue))); + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); } }); if (!propertiesToSet.isEmpty()) SignalStateHandler.setStates(info.current, propertiesToSet); + unloadSignal(stateInfo); }); } @@ -86,16 +92,17 @@ public static void loadDisable(final ConfigInfo info) { } private static void changeIfPresent(final List values, final ConfigInfo info) { - SignalStateHandler.runTaskWhenSignalLoaded(info.currentinfo, - (stateInfo, oldProperties, _u) -> { - if (info.nextinfo != null) { - SignalStateHandler.runTaskWhenSignalLoaded(info.nextinfo, - (nextInfo, nextProperties, _u2) -> changeSignals(values, info, - oldProperties, nextProperties)); - } else { - changeSignals(values, info, oldProperties, null); - } + loadSignalAndRunTask(info.currentinfo, (stateInfo, oldProperties, _u) -> { + if (info.nextinfo != null) { + loadSignalAndRunTask(info.nextinfo, (nextInfo, nextProperties, _u2) -> { + changeSignals(values, info, oldProperties, nextProperties); + unloadSignal(nextInfo); }); + } else { + changeSignals(values, info, oldProperties, null); + } + unloadSignal(stateInfo); + }); } @@ -112,8 +119,7 @@ private static void changeSignals(final List values, final Confi if (property.test(object)) { propertiesToSet.putAll(property.state.entrySet().stream() .filter(entry -> oldProperties.containsKey(entry.getKey())) - .collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, - Map.Entry::getValue))); + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); } }); if (!propertiesToSet.isEmpty()) @@ -123,17 +129,27 @@ private static void changeSignals(final List values, final Confi private static void loadWithoutPredicate(final List values, final SignalStateInfo current) { if (values != null) { - SignalStateHandler.runTaskWhenSignalLoaded(current, (info, oldProperties, _u) -> { + loadSignalAndRunTask(current, (info, oldProperties, _u) -> { final Map propertiesToSet = new HashMap<>(); values.forEach(property -> { propertiesToSet.putAll(property.state.entrySet().stream() .filter(entry -> oldProperties.containsKey(entry.getKey())) - .collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, - Map.Entry::getValue))); + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); }); if (!propertiesToSet.isEmpty()) SignalStateHandler.setStates(current, propertiesToSet); + unloadSignal(info); }); } } + + private static void loadSignalAndRunTask(final SignalStateInfo info, + final SignalStateListener task) { + SignalStateHandler.loadSignal(new SignalStateLoadHoler(info, LOAD_HOLDER)); + SignalStateHandler.runTaskWhenSignalLoaded(info, task); + } + + private static void unloadSignal(final SignalStateInfo info) { + SignalStateHandler.unloadSignal(new SignalStateLoadHoler(info, LOAD_HOLDER)); + } } \ No newline at end of file