Skip to content

Commit

Permalink
Merge pull request #6 from MisterJulsen/1.18.2-fix
Browse files Browse the repository at this point in the history
1.18.2 patch
  • Loading branch information
MisterJulsen authored Apr 11, 2024
2 parents b743fd7 + 617737d commit 6ea116b
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 49 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
org.gradle.jvmargs=-Xmx6G
org.gradle.daemon=false

mod_version = 0.4.0-beta
mod_version = 0.4.1-beta
mod_minecraft_version = 1.18.2
mod_filename = createrailwaysnavigator
mod_root_path = de.mrjulsen.crn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos, Pla
be.setColor(dye == DyeColor.ORANGE ? 0xFF9900 : dye.getMaterialColor().col);
be.notifyUpdate();
});

if (pLevel.isClientSide) {
blockEntity.getRenderer().update(pLevel, pPos, pState, blockEntity, EUpdateReason.BLOCK_CHANGED);
}

return InteractionResult.SUCCESS;
}

Expand All @@ -252,6 +257,11 @@ public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos, Pla
be.setGlowing(true);
be.notifyUpdate();
});

if (pLevel.isClientSide) {
blockEntity.getRenderer().update(pLevel, pPos, pState, blockEntity, EUpdateReason.BLOCK_CHANGED);
}

return InteractionResult.SUCCESS;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.simibubi.create.content.redstone.displayLink.target.DisplayBoardTarget;
import com.simibubi.create.content.redstone.displayLink.target.DisplayTargetStats;
import com.simibubi.create.content.trains.display.GlobalTrainDisplayData;
import com.simibubi.create.content.trains.entity.Train;

import de.mrjulsen.crn.block.be.AdvancedDisplayBlockEntity;
import de.mrjulsen.crn.data.DeparturePrediction;
Expand Down Expand Up @@ -44,20 +45,24 @@ public void acceptFlapText(int line, List<List<MutableComponent>> text, DisplayL

if (!preds.isEmpty()) {
SimpleDeparturePrediction pred = preds.iterator().next();
SimulatedTrainSchedule sched = SimpleTrainSchedule.of(TrainUtils.getTrainStopsSorted(pred.trainId(), context.blockEntity().getLevel())).simulate(TrainUtils.getTrain(pred.trainId()), 0, pred.stationName());
Train train = TrainUtils.getTrain(pred.trainId());

if (train != null) {
SimulatedTrainSchedule sched = SimpleTrainSchedule.of(TrainUtils.getTrainStopsSorted(pred.trainId(), context.blockEntity().getLevel())).simulate(train, 0, pred.stationName());

List<TrainStop> stops = new ArrayList<>(sched.getAllStops());
boolean foundStart = false;

if (!stops.isEmpty()) {
for (int i = 0; i < stops.size() - 1; i++) {
TrainStop x = stops.get(i);
if (foundStart) {
stopovers.add(x.getStationAlias().getAliasName().get());
List<TrainStop> stops = new ArrayList<>(sched.getAllStops());
boolean foundStart = false;

if (!stops.isEmpty()) {
for (int i = 0; i < stops.size() - 1; i++) {
TrainStop x = stops.get(i);
if (foundStart) {
stopovers.add(x.getStationAlias().getAliasName().get());
}
foundStart = foundStart || x.getPrediction().getStationName().equals(pred.stationName());
}
foundStart = foundStart || x.getPrediction().getStationName().equals(pred.stationName());
}
}
}
}

controller.setDepartureData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.mojang.blaze3d.vertex.PoseStack;

import de.mrjulsen.crn.Constants;
import de.mrjulsen.crn.block.be.AdvancedDisplayBlockEntity;
import de.mrjulsen.crn.client.ber.AdvancedDisplayRenderInstance;
import de.mrjulsen.crn.client.ber.base.BERText;
Expand Down Expand Up @@ -150,8 +151,8 @@ private void updateDefault(Level level, BlockPos pos, BlockState state, Advanced
Utils.text(blockEntity.getTrainData().trainName()).append(" ").append(Utils.text(blockEntity.getTrainData().getNextStop().get().scheduleTitle())),
Utils.text("" + (int)Math.abs(Math.round(blockEntity.getTrainData().speed() * 20 * 3.6F))).append(" km/h"),
isSingleBlock ?
Utils.text(TimeUtils.parseTime((int)(blockEntity.getLevel().dayTime() % 24000), ModClientConfig.TIME_FORMAT.get())) :
Utils.translate(keyDate, blockEntity.getLevel().getDayTime() / 24000, TimeUtils.parseTime((int)(blockEntity.getLevel().dayTime() % 24000), ModClientConfig.TIME_FORMAT.get()))
Utils.text(TimeUtils.parseTime((int)(blockEntity.getLevel().getDayTime() % 24000 + Constants.TIME_SHIFT), ModClientConfig.TIME_FORMAT.get())) :
Utils.translate(keyDate, blockEntity.getLevel().getDayTime() / 24000, TimeUtils.parseTime((int)(blockEntity.getLevel().dayTime() % 24000 + Constants.TIME_SHIFT), ModClientConfig.TIME_FORMAT.get()))
), 0)
.withIsCentered(true)
.withMaxWidth(maxWidth, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void update(Level level, BlockPos pos, BlockState state, AdvancedDisplayB
return;
}

generateTitleBar(level, pos, state, blockEntity, parent);
generateTitleBar(level, pos, state, blockEntity, parent, reason);

if (this.state == State.BEFORE_NEXT_STOP && this.nextConnections != null && !this.nextConnections.isEmpty()) {
return;
Expand Down Expand Up @@ -279,7 +279,7 @@ private float generateTimeLabel(Level level, BlockPos pos, BlockState state, Adv
return rawTextWidth + arrowOffset;
}

private void generateTitleBar(Level level, BlockPos pos, BlockState state, AdvancedDisplayBlockEntity blockEntity, AdvancedDisplayRenderInstance parent) {
private void generateTitleBar(Level level, BlockPos pos, BlockState state, AdvancedDisplayBlockEntity blockEntity, AdvancedDisplayRenderInstance parent, EUpdateReason reason) {
int displayWidth = blockEntity.getXSizeScaled();

float maxWidth = displayWidth * 16 - 6 - (this.state != State.WHILE_TRAVELING && blockEntity.relativeExitDirection.get() != TrainExitSide.UNKNOWN ? 4 : 0);
Expand All @@ -299,18 +299,18 @@ private void generateTitleBar(Level level, BlockPos pos, BlockState state, Advan
}
}

if (titleLabel != null && line.getString().equals(titleLabel.getCurrentText().getString())) {
if (titleLabel != null && line.getString().equals(titleLabel.getCurrentText().getString()) && reason == EUpdateReason.DATA_CHANGED) {
return;
}

titleLabel = new BERText(parent.getFontUtils(), line, 0)
.withIsCentered(false)
.withMaxWidth(maxWidth - timeWidth, true)
.withStretchScale(0.3f, 0.5f)
.withStretchScale(0.15f, 0.25f)
.withStencil(0, maxWidth - timeWidth)
.withCanScroll(true, 0.5f)
.withColor((0xFF << 24) | (blockEntity.getColor() & 0x00FFFFFF))
.withPredefinedTextTransformation(new TextTransformation(3.0f, 2.5f, 0.0f, 0.5f, 0.25f))
.withPredefinedTextTransformation(new TextTransformation(3.0f, 2.5f, 0.0f, 1, 0.25f))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private BERText[] addLine(Level level, BlockPos pos, BlockState state, AdvancedD

public void setTimer(Level level, BlockPos pos, BlockState state, AdvancedDisplayBlockEntity blockEntity, AdvancedDisplayRenderInstance parent, EUpdateReason reason, float y) {
float displayWidth = blockEntity.getXSizeScaled() * 16 - 6;
timeLabel = new BERText(parent.getFontUtils(), () -> List.of(Utils.translate(keyTime, TimeUtils.parseTime((int)(blockEntity.getLevel().getDayTime() % 24000 + 6000), ModClientConfig.TIME_FORMAT.get()))), 0)
timeLabel = new BERText(parent.getFontUtils(), () -> List.of(Utils.translate(keyTime, TimeUtils.parseTime((int)(blockEntity.getLevel().getDayTime() % 24000 + Constants.TIME_SHIFT), ModClientConfig.TIME_FORMAT.get()))), 0)
.withIsCentered(true)
.withMaxWidth(displayWidth, true)
.withStretchScale(0.4f, 0.4f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import com.mojang.blaze3d.vertex.PoseStack;

import de.mrjulsen.crn.Constants;
import de.mrjulsen.crn.block.be.AdvancedDisplayBlockEntity;
import de.mrjulsen.crn.client.ber.AdvancedDisplayRenderInstance;
import de.mrjulsen.crn.client.ber.base.BERText;
Expand All @@ -27,6 +28,7 @@
public class BERPlatformSimple implements IBERRenderSubtype<AdvancedDisplayBlockEntity, AdvancedDisplayRenderInstance, Boolean> {

private static final String keyTrainDeparture = "gui.createrailwaysnavigator.route_overview.notification.journey_begins";
private static final String keyTrainDepartureWithPlatform = "gui.createrailwaysnavigator.route_overview.notification.journey_begins_with_platform";
private static final String keyTime = "gui.createrailwaysnavigator.time";

private Collection<UUID> lastTrainOrder = new ArrayList<>();
Expand Down Expand Up @@ -62,8 +64,13 @@ public void update(Level level, BlockPos pos, BlockState state, AdvancedDisplayB
float maxWidth = displayWidth * 16 - 6;
parent.labels.add(new BERText(parent.getFontUtils(), () -> {
List<Component> texts = new ArrayList<>();
texts.add(Utils.translate(keyTime, TimeUtils.parseTime((int)(blockEntity.getLevel().getDayTime() % 24000 + 6000), ModClientConfig.TIME_FORMAT.get())));
texts.addAll(preds.stream().map(x -> Utils.translate(keyTrainDeparture, x.trainName(), x.scheduleTitle(), TimeUtils.parseTime((int)(blockEntity.getLastRefreshedTime() % 24000 + 6000 + x.departureTicks()), ModClientConfig.TIME_FORMAT.get()), x.stationInfo().platform())).toList());
texts.add(Utils.translate(keyTime, TimeUtils.parseTime((int)(blockEntity.getLevel().getDayTime() % 24000 + Constants.TIME_SHIFT), ModClientConfig.TIME_FORMAT.get())));
texts.addAll(preds.stream().map(x -> {
if (x.stationInfo().platform() == null || x.stationInfo().platform().isBlank()) {
return Utils.translate(keyTrainDeparture, x.trainName(), x.scheduleTitle(), TimeUtils.parseTime((int)(blockEntity.getLastRefreshedTime() % 24000 + Constants.TIME_SHIFT + x.departureTicks()), ModClientConfig.TIME_FORMAT.get()), x.stationInfo().platform());
}
return Utils.translate(keyTrainDepartureWithPlatform, x.trainName(), x.scheduleTitle(), TimeUtils.parseTime((int)(blockEntity.getLastRefreshedTime() % 24000 + Constants.TIME_SHIFT + x.departureTicks()), ModClientConfig.TIME_FORMAT.get()));
}).toList());

return List.of(ModUtils.concat(texts.toArray(Component[]::new)));
}, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public class RouteDetailsOverlayScreen implements IHudOverlay, IJourneyListenerC
private static final String keyTrainDetails = "gui.createrailwaysnavigator.route_overview.train_details";
private static final String keyTrainSpeed = "gui.createrailwaysnavigator.route_overview.train_speed";
private static final String keyTransfer = "gui.createrailwaysnavigator.route_overview.transfer";
private static final String keyTransferWithPlatform = "gui.createrailwaysnavigator.route_overview.transfer_with_platform";
private static final String keyTransferCount = "gui.createrailwaysnavigator.navigator.route_entry.transfer";
private static final String keyTrainCanceled = "gui.createrailwaysnavigator.route_overview.stop_canceled";
private static final String keyAfterJourney = "gui.createrailwaysnavigator.route_overview.after_journey";
Expand Down Expand Up @@ -356,7 +357,13 @@ private void setPageTransfer() {
currentPage = Page.TRANSFER;
StationEntry station = getListener().currentStation();
if (station != null) {
this.messageLabel = MultiLineLabel.create(shadowlessFont, Utils.translate(keyTransfer,
this.messageLabel = MultiLineLabel.create(shadowlessFont,
station.getInfo().platform() == null || station.getInfo().platform().isBlank() ?
Utils.translate(keyTransfer,
station.getTrain().trainName(),
station.getTrain().scheduleTitle()
) :
Utils.translate(keyTransferWithPlatform,
station.getTrain().trainName(),
station.getTrain().scheduleTitle(),
station.getInfo().platform()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public SimulatedTrainSchedule simulate(Train train, int simulationTime, String s
v += cycleDuration;
}
return v;
}).min().getAsInt();
}).min().orElse(0);
int simToTargetTime = simulationTime + timeToTargetAfterSim;

return new SimulatedTrainSchedule(getAllStops().parallelStream().map(x -> {
Expand Down
Loading

0 comments on commit 6ea116b

Please sign in to comment.