Skip to content

Commit

Permalink
fix: 1.12 bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Uhutown committed Oct 10, 2024
1 parent 80940ae commit 68a95d3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ public void compact(final Point point) {
}
}, point);
resetAllTrainNumbers(data.getTrainNumberDisplays());
sendTrainNumberUpdates();
data.compact(point);
updateSignalsOnClient(redSignals);
updateTrainNumber(trainNumber);
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@
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;
import com.troblecodings.signals.properties.PredicatedPropertyBase.ConfigProperty;

public final class SignalConfig {

private static final LoadHolder<Class<SignalConfig>> LOAD_HOLDER = new LoadHolder<>(
SignalConfig.class);

private SignalConfig() {
}

Expand Down Expand Up @@ -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<Class<?>, Object> object = new HashMap<>();
object.put(Boolean.class, info.isRepeater);
object.put(Map.class, oldProperties);
Expand All @@ -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);
});
}

Expand All @@ -86,16 +92,17 @@ public static void loadDisable(final ConfigInfo info) {
}

private static void changeIfPresent(final List<ConfigProperty> 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);
});

}

Expand All @@ -112,8 +119,7 @@ private static void changeSignals(final List<ConfigProperty> 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())
Expand All @@ -123,17 +129,27 @@ private static void changeSignals(final List<ConfigProperty> values, final Confi
private static void loadWithoutPredicate(final List<ConfigProperty> values,
final SignalStateInfo current) {
if (values != null) {
SignalStateHandler.runTaskWhenSignalLoaded(current, (info, oldProperties, _u) -> {
loadSignalAndRunTask(current, (info, oldProperties, _u) -> {
final Map<SEProperty, String> 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));
}
}

0 comments on commit 68a95d3

Please sign in to comment.