Skip to content

Commit

Permalink
Merge pull request #71 from MisterJulsen/1.19.2-patch
Browse files Browse the repository at this point in the history
1.19.2 patch
  • Loading branch information
MisterJulsen authored Dec 20, 2024
2 parents ad30bf1 + 2717346 commit 799cf5e
Show file tree
Hide file tree
Showing 19 changed files with 236 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.simibubi.create.content.redstone.displayLink.source.DisplaySource;
import com.simibubi.create.content.redstone.displayLink.target.DisplayTargetStats;
import com.simibubi.create.content.trains.station.GlobalStation;
import com.simibubi.create.content.trains.station.StationBlockEntity;
import com.simibubi.create.foundation.gui.ModularGuiLineBuilder;
import com.simibubi.create.foundation.utility.Lang;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static void start() {
try {
workerTasks.poll().run();
} catch (Exception e) {
CreateRailwaysNavigator.LOGGER.info("Error while process Advanced Display Data.", e);
CreateRailwaysNavigator.LOGGER.info("Error while process Advanced Display Data. " + e.getMessage(), e);
}
}
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ default T getDisplaySettings(AdvancedDisplayBlockEntity blockEntity) {
throw new IllegalArgumentException("Could not get display data of display at " + blockEntity.getBlockPos(), e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void render(BERGraphics<AdvancedDisplayBlockEntity> graphics, float pPart

@Override
public void update(Level level, BlockPos pos, BlockState state, AdvancedDisplayBlockEntity blockEntity, AdvancedDisplayRenderInstance parent, EUpdateReason reason) {
List<StationDisplayData> preds = blockEntity.getStops().stream().filter(x -> x.getStationData().getScheduledArrivalTime() < DragonLib.getCurrentWorldTime() + ModClientConfig.DISPLAY_LEAD_TIME.get() && (!x.getTrainData().isCancelled() || DragonLib.getCurrentWorldTime() < x.getStationData().getScheduledDepartureTime() + ModClientConfig.DISPLAY_LEAD_TIME.get())).toList();
List<StationDisplayData> preds = blockEntity.getStops().stream().filter(x -> x.getStationData().getRealTimeArrivalTime() < DragonLib.getCurrentWorldTime() + ModClientConfig.DISPLAY_LEAD_TIME.get() && (!x.getTrainData().isCancelled() || DragonLib.getCurrentWorldTime() < x.getStationData().getScheduledDepartureTime() + ModClientConfig.DISPLAY_LEAD_TIME.get())).toList();

showInfoLine = !preds.isEmpty() && preds.get(0).getStationData().isDepartureDelayed() && preds.get(0).getTrainData().hasStatusInfo();
if (showInfoLine) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void render(BERGraphics<AdvancedDisplayBlockEntity> graphics, float pPart

@Override
public void update(Level level, BlockPos pos, BlockState state, AdvancedDisplayBlockEntity blockEntity, AdvancedDisplayRenderInstance parent, EUpdateReason reason) {
List<StationDisplayData> preds = blockEntity.getStops().stream().filter(x -> x.getStationData().getScheduledArrivalTime() < DragonLib.getCurrentWorldTime() + ModClientConfig.DISPLAY_LEAD_TIME.get() && (!x.getTrainData().isCancelled() || DragonLib.getCurrentWorldTime() < x.getStationData().getScheduledDepartureTime() + ModClientConfig.DISPLAY_LEAD_TIME.get())).toList();
List<StationDisplayData> preds = blockEntity.getStops().stream().filter(x -> x.getStationData().getRealTimeArrivalTime() < DragonLib.getCurrentWorldTime() + ModClientConfig.DISPLAY_LEAD_TIME.get() && (!x.getTrainData().isCancelled() || DragonLib.getCurrentWorldTime() < x.getStationData().getScheduledDepartureTime() + ModClientConfig.DISPLAY_LEAD_TIME.get())).toList();

label
.setColor((0xFF << 24) | (getDisplaySettings(blockEntity).getFontColor() & 0x00FFFFFF))
Expand All @@ -88,10 +88,12 @@ public void update(Level level, BlockPos pos, BlockState state, AdvancedDisplayB
text.append(", ").append(CustomLanguage.translate("block." + CreateRailwaysNavigator.MOD_ID + ".advanced_display.ber.cancelled2").getString());
} else if (x.getStationData().isDepartureDelayed()) {
String delay = getDisplaySettings(blockEntity).getTimeDisplay() == ETimeDisplay.ETA ? ModUtils.timeRemainingString(x.getStationData().getDepartureTimeDeviation()) : String.valueOf(TimeUtils.formatToMinutes(x.getStationData().getDepartureTimeDeviation()));
text.append(", ").append(CustomLanguage.translate("block." + CreateRailwaysNavigator.MOD_ID + ".advanced_display.ber.delayed2", delay).getString());
if (getDisplaySettings(blockEntity).getTimeDisplay() == ETimeDisplay.ABS) {
text.append(" ").append(CustomLanguage.translate("block." + CreateRailwaysNavigator.MOD_ID + ".advanced_display.ber.delay_abs_suffix"));
}
String timeUnitSuffix = getDisplaySettings(blockEntity).getTimeDisplay() == ETimeDisplay.ABS ?
" " + CustomLanguage.translate("block." + CreateRailwaysNavigator.MOD_ID + ".advanced_display.ber.delay_abs_suffix").getString() :
"";

text.append(", ").append(CustomLanguage.translate("block." + CreateRailwaysNavigator.MOD_ID + ".advanced_display.ber.delayed2", delay, timeUnitSuffix).getString());

if (x.getTrainData().hasStatusInfo()) {
text.append(" ").append(CustomLanguage.translate("block." + CreateRailwaysNavigator.MOD_ID + ".advanced_display.ber.reason").getString()).append(x.getTrainData().getStatus().get(0).text());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,30 @@ public class TrainSeparationSettingsScreen extends DLScreen {
private final CompoundTag nbt;

//private String stationFilter;
private int time = 5;
private TimeUnit timeUnit = TimeUnit.SECONDS;
private int minutes = 0;
private int seconds = 5;
private int ticks = 0;
private ETrainFilter filter = ETrainFilter.ANY;

public TrainSeparationSettingsScreen(Screen lastScreen, CompoundTag nbt) {
super(title);
this.lastScreen = lastScreen;
this.nbt = nbt;
this.time = nbt.getInt(TrainSeparationCondition.NBT_TIME);
this.timeUnit = TimeUnit.values()[nbt.getInt(TrainSeparationCondition.NBT_TIME_UNIT)];
@SuppressWarnings("deprecation")
int t = nbt.contains(TrainSeparationCondition.NBT_TICKS) ? nbt.getInt(TrainSeparationCondition.NBT_TICKS) : nbt.getInt(TrainSeparationCondition.NBT_TIME) * TimeUnit.values()[nbt.getInt(TrainSeparationCondition.NBT_TIME_UNIT)].ticksPer;
ticks = t;
minutes = ticks / 1200;
ticks %= 1200;
seconds = ticks / 20;
ticks %= 20;

this.filter = ETrainFilter.getByIndex(nbt.getByte(TrainSeparationCondition.NBT_TRAIN_FILTER));
}

@Override
public void onClose() {
super.onClose();
nbt.putInt(TrainSeparationCondition.NBT_TIME, time);
nbt.putInt(TrainSeparationCondition.NBT_TIME_UNIT, timeUnit.ordinal());
nbt.putInt(TrainSeparationCondition.NBT_TICKS, minutes * TimeUnit.MINUTES.ticksPer + seconds * TimeUnit.SECONDS.ticksPer + ticks);
nbt.putByte(TrainSeparationCondition.NBT_TRAIN_FILTER, filter.getIndex());
Minecraft.getInstance().setScreen(lastScreen);
}
Expand All @@ -99,17 +105,65 @@ protected void init() {
});
});
*/

/*
builder.addLine("time_src", (line) -> {
line.add(new IconSlotWidget(line.getCurrentX(), line.y() + 2, ModGuiIcons.TIME.getAsSprite(16, 16)));
line.add(new DLCreateSelectionScrollInput(this, line.getCurrentX() + 6, line.getY() + 2, line.getRemainingWidth() - 6, 18)
.setRenderArrow(true)
.forOptions(Arrays.stream(ETimeSource.values()).map(x -> TextUtils.translate(x.getValueTranslationKey(CreateRailwaysNavigator.MOD_ID))).toList())
.titled(TextUtils.translate(timeSource.getEnumTranslationKey(CreateRailwaysNavigator.MOD_ID)))
.setState(timeSource.getIndex())
.calling((i) -> {
timeSource = ETimeSource.getByIndex(i);
})
);
});
*/

builder.addLine("times", (line) -> {
line.add(new IconSlotWidget(line.getCurrentX(), line.y() + 2, ModGuiIcons.TIME.getAsSprite(16, 16)));
line.add(new DLCreateScrollInput(this, line.getCurrentX() + 6, line.getY() + 2, 30, 18)
.setRenderArrow(true)
.titled(Lang.translateDirect("generic.unit.minutes"))
.withShiftStep(10)
.withRange(0, 901)
.setState(minutes)
.calling(x -> {
minutes = x;
})
);
line.add(new DLCreateScrollInput(this, line.getCurrentX() + 2, line.getY() + 2, 30, 18)
.titled(Lang.translateDirect("generic.unit.seconds"))
.withShiftStep(10)
.withRange(0, 60)
.setState(seconds)
.calling(x -> {
seconds = x;
})
);
line.add(new DLCreateScrollInput(this, line.getCurrentX() + 2, line.getY() + 2, 30, 18)
.titled(Lang.translateDirect("generic.unit.ticks"))
.withShiftStep(5)
.withRange(0, 20)
.setState(ticks)
.calling(x -> {
ticks = x;
})
);
});

/*
builder.addLine("time", (line) -> {
line.add(new IconSlotWidget(line.getCurrentX(), line.y() + 2, ModGuiIcons.TIME.getAsSprite(16, 16)));
line.add(new DLCreateScrollInput(this, line.getCurrentX() + 6, line.getY() + 2, 30, 18)
.setRenderArrow(true)
.titled(Lang.translateDirect("generic.duration"))
.withShiftStep(15)
.withRange(0, 121)
.setState(time)
.setState(ticks)
.calling(x -> {
time = x;
ticks = x;
})
);
Expand All @@ -123,6 +177,7 @@ protected void init() {
})
);
});
*/

builder.addLine("train_filter", (line) -> {
line.add(new IconSlotWidget(line.getCurrentX(), line.y() + 2, ModGuiIcons.TRAIN.getAsSprite(16, 16)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public class ModClientConfig {
BUILDER.push("Create Railways Navigator Config");

/* CONFIGS */
NEXT_STOP_ANNOUNCEMENT = BUILDER.comment(new String[] {"[in Ticks]", "The next stop or information about the start of the journey is announced in the specified number of ticks before the scheduled arrival at the next station. (Default: 500, 30 real life seconds)"})
.defineInRange("general.next_stop_announcement", 500, 100, 1000);
NEXT_STOP_ANNOUNCEMENT = BUILDER.comment(new String[] {"[in Ticks]", "The next stop or information about the start of the journey is announced in the specified number of ticks before the scheduled arrival at the next station. (Default: 600, 30 real life seconds)"})
.defineInRange("general.next_stop_announcement", 600, 100, 1000);
REALTIME_PRECISION_THRESHOLD = BUILDER.comment(new String[] {"[in Ticks]", "This value indicates how accurately the real-time data should be displayed. By default, only deviations above 10 in-game minutes (167 ticks, approx. 8 real life seconds) are displayed. The lower the value, the more accurate the real-time data but also the more often deviations from the schedule occur. (Default: 167, 10 in-game minutes)"})
.defineInRange("general.realtime_precision_threshold", 167, 1, 1000);
DISPLAY_LEAD_TIME = BUILDER.comment(new String[] {"[in Ticks]", "How early a train should be shown on the display. (Default: 1000, 1 in-game hour)"})
.defineInRange("general.display_lead_time", 1000, 100, 24000);
DISPLAY_LEAD_TIME = BUILDER.comment(new String[] {"[in Ticks]", "How early a train should be shown on the display. (Default: 1200, 1 real life minute)"})
.defineInRange("general.display_lead_time", 1200, 100, 24000);
OVERLAY_SCALE = BUILDER.comment("Scale of the route overlay UI. (Default: 0.75)")
.defineInRange("route_overlay.scale", 0.75f, MIN_SCALE, MAX_SCALE);
ROUTE_NOTIFICATIONS = BUILDER.comment("If active, you will receive short toasts about important events on your trip, e.g. delays, changes, ... (Default: ON)")
Expand Down
39 changes: 39 additions & 0 deletions common/src/main/java/de/mrjulsen/crn/data/ETimeSource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package de.mrjulsen.crn.data;

import java.util.Arrays;
import de.mrjulsen.mcdragonlib.core.ITranslatableEnum;

public enum ETimeSource implements ITranslatableEnum {
REAL_LIFE((byte)0, "real_life"),
IN_GAME((byte)1, "in_game");

final byte index;
final String name;

ETimeSource(byte index, String name) {
this.index = index;
this.name = name;
}

public byte getIndex() {
return index;
}

public String getName() {
return name;
}

public static ETimeSource getByIndex(int index) {
return Arrays.stream(values()).filter(x -> x.getIndex() == index).findFirst().orElse(REAL_LIFE);
}

@Override
public String getEnumName() {
return "time_source";
}

@Override
public String getEnumValueName() {
return name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,8 @@ public void closeAll() {
CRNEventsManager.getEvent(DefaultTrainDataRefreshEvent.class).unregister(CreateRailwaysNavigator.MOD_ID + "_" + id);
clearEvents();
isClosed = true;
CreateRailwaysNavigator.LOGGER.info("Route listener closed.");
if (ModCommonConfig.ADVANCED_LOGGING.get()) CreateRailwaysNavigator.LOGGER.info("Closed " + this);

if (ModCommonConfig.ADVANCED_LOGGING.get()) CreateRailwaysNavigator.LOGGER.info("Route listener closed.");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.google.common.collect.ImmutableList;

import de.mrjulsen.crn.CreateRailwaysNavigator;
import de.mrjulsen.crn.config.ModCommonConfig;
import de.mrjulsen.crn.data.train.ClientTrainStop;
import de.mrjulsen.crn.data.train.RoutePartProgressState;
import de.mrjulsen.crn.data.train.TrainStop;
Expand Down Expand Up @@ -272,7 +273,7 @@ public void update(TrainRealTimeData data) {
}

if (isCancelled()) {
CreateRailwaysNavigator.LOGGER.info("Train got cancelled. Closing route...");
if (ModCommonConfig.ADVANCED_LOGGING.get()) CreateRailwaysNavigator.LOGGER.info("Train got cancelled. Closing route...");
notifyListeners(EVENT_TRAIN_CANCELLED, new ListenerNotificationData(this, nextStop));
close();
}
Expand Down Expand Up @@ -304,7 +305,6 @@ public void close() {
}
}
stopListeningAll(this);
CreateRailwaysNavigator.LOGGER.info("CLOSED " + this);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@ public NavigatableGraph(UserSettings userSettings) throws RuntimeSideException {
addTrain(train, TrainListener.data.get(train.id));
}

CreateRailwaysNavigator.LOGGER.info(String.format("Graph generated. Took %sms. Contains %s nodes and %s edges. %s train processed.",
System.currentTimeMillis() - startTime,
nodesByTag.size(),
edgesByTag.values().stream().flatMap(x -> x.values().stream().flatMap(y -> y.stream())).count(),
trains.size()
));
if (ModCommonConfig.ADVANCED_LOGGING.get()) {
CreateRailwaysNavigator.LOGGER.info(String.format("Graph generated. Took %sms. Contains %s nodes and %s edges. %s train processed.",
System.currentTimeMillis() - startTime,
nodesByTag.size(),
edgesByTag.values().stream().flatMap(x -> x.values().stream().flatMap(y -> y.stream())).count(),
trains.size()
));
}
}

protected GlobalSettings globalSettings() {
Expand Down Expand Up @@ -419,10 +421,12 @@ public static List<Route> searchRoutes(StationTag start, StationTag destination,
int minNumber = routes.stream().mapToInt(x -> x.getTransferCount()).min().orElse(0);
routes = routes.stream().filter(x -> x.getTransferCount() == minNumber).toList();

CreateRailwaysNavigator.LOGGER.info(String.format("%s route(s) calculated. Took %sms.",
routes.size(),
System.currentTimeMillis() - startTime
));
if (ModCommonConfig.ADVANCED_LOGGING.get()) {
CreateRailwaysNavigator.LOGGER.info(String.format("%s route(s) calculated. Took %sms.",
routes.size(),
System.currentTimeMillis() - startTime
));
}
return routes.stream().sorted((a, b) -> Long.compare(a.getStart().getScheduledDepartureTime(), b.getStart().getScheduledDepartureTime())).toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import de.mrjulsen.crn.CreateRailwaysNavigator;
import de.mrjulsen.crn.client.ClientWrapper;
import de.mrjulsen.crn.data.ETimeSource;
import de.mrjulsen.crn.data.schedule.IConditionsRequiresInstruction;
import de.mrjulsen.crn.data.schedule.INavigationExtension;
import de.mrjulsen.crn.data.train.StationDepartureHistory;
Expand All @@ -29,13 +30,16 @@

public class TrainSeparationCondition extends ScheduledDelay implements IDelayedWaitCondition, IConditionsRequiresInstruction {

public static final String NBT_TIME = "Value";
@Deprecated public static final String NBT_TIME = "Value";
@Deprecated public static final String NBT_TIME_UNIT = "TimeUnit";
public static final String NBT_TICKS = "Ticks";
public static final String NBT_TRAIN_FILTER = "TrainFilter";
public static final String NBT_TIME_UNIT = "TimeUnit";
public static final String NBT_TIME_SOURCE = "TimeSource";

public TrainSeparationCondition() {
super();
data.putByte(NBT_TRAIN_FILTER, ETrainFilter.ANY.getIndex());
data.putInt(NBT_TICKS, 100);
}

@Override
Expand All @@ -48,6 +52,28 @@ public ItemStack getSecondLineIcon() {
return new ItemStack(Items.OBSERVER);
}

@Override
public int totalWaitTicks() {
if (data.contains(NBT_TICKS)) {
return data.getInt(NBT_TICKS);
}
return super.totalWaitTicks();
}

@Override
protected Component formatTime(boolean compact) {
int remainingTicks = totalWaitTicks();
int minutes = remainingTicks / 1200;
remainingTicks %= 1200;
int seconds = remainingTicks / 20;
remainingTicks %= 20;

if (compact) {
return TextUtils.text(String.format("%d:%02d,%02d", minutes, seconds, remainingTicks));
}
return TextUtils.text(String.format("%dm %ds %dt", minutes, seconds, remainingTicks));
}

@Override
public List<Component> getTitleAs(String type) {
return ImmutableList.of(
Expand Down Expand Up @@ -94,6 +120,10 @@ public ETrainFilter getTrainFilter() {
return ETrainFilter.getByIndex(data.getByte(NBT_TRAIN_FILTER));
}

public ETimeSource getTimeSource() {
return ETimeSource.getByIndex(data.getByte(NBT_TIME_SOURCE));
}

@Override
@Environment(EnvType.CLIENT)
public void initConfigurationWidgets(ModularGuiLineBuilder builder) {
Expand Down
Loading

0 comments on commit 799cf5e

Please sign in to comment.