From 517fad7a62c62d7b4955d344f634481d814da33f Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Tue, 12 Apr 2022 04:02:10 +0200 Subject: [PATCH] Destination display hotfix --- .../management/schedule/ScheduleRuntime.java | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/management/schedule/ScheduleRuntime.java b/src/main/java/com/simibubi/create/content/logistics/trains/management/schedule/ScheduleRuntime.java index a2825a2db..035eb0568 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/management/schedule/ScheduleRuntime.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/management/schedule/ScheduleRuntime.java @@ -332,21 +332,28 @@ public class ScheduleRuntime { } private TrainDeparturePrediction createPrediction(int index, String destination, String currentTitle, int time) { - if (index >= schedule.entries.size()) { + int size = schedule.entries.size(); + if (index >= size) { if (!schedule.cyclic) return new TrainDeparturePrediction(train, time, new TextComponent(" "), destination); - index %= schedule.entries.size(); + index %= size; } - ScheduleEntry scheduleEntry = schedule.entries.get(index); - if (!(scheduleEntry.instruction instanceof DestinationInstruction instruction)) - return null; + String text = currentTitle; + if (text.isBlank()) { + for (int i = 1; i < size; i++) { + int j = (index + i) % size; + ScheduleEntry scheduleEntry = schedule.entries.get(j); + if (!(scheduleEntry.instruction instanceof DestinationInstruction instruction)) + continue; + text = instruction.getFilter() + .replaceAll("\\*", "") + .trim(); + break; + } + } - return new TrainDeparturePrediction(train, time, - new TextComponent(currentTitle.isBlank() ? instruction.getFilter() - .replaceAll("\\*", "") - .trim() : currentTitle), - destination); + return new TrainDeparturePrediction(train, time, new TextComponent(text), destination); } public CompoundTag write() {