From c571493ce44ee1bb823eeb247acd01a589e6e8c9 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Thu, 22 Sep 2022 19:24:24 +0200 Subject: [PATCH] Early Departures - Fixed "Station Powered" wait condition not working correctly in non-overworld dimensions --- .../edgePoint/signal/SingleTileEdgePoint.java | 11 +++++++++++ .../schedule/condition/StationPoweredCondition.java | 12 ++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/signal/SingleTileEdgePoint.java b/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/signal/SingleTileEdgePoint.java index 732625e04..f18b78390 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/signal/SingleTileEdgePoint.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/signal/SingleTileEdgePoint.java @@ -5,20 +5,29 @@ import com.simibubi.create.content.logistics.trains.DimensionPalette; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtUtils; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.block.entity.BlockEntity; public abstract class SingleTileEdgePoint extends TrackEdgePoint { + public ResourceKey tileDimension; public BlockPos tilePos; public BlockPos getTilePos() { return tilePos; } + + public ResourceKey getTileDimension() { + return tileDimension; + } @Override public void tileAdded(BlockEntity tile, boolean front) { this.tilePos = tile.getBlockPos(); + this.tileDimension = tile.getLevel() + .dimension(); } @Override @@ -42,12 +51,14 @@ public abstract class SingleTileEdgePoint extends TrackEdgePoint { if (migration) return; tilePos = NbtUtils.readBlockPos(nbt.getCompound("TilePos")); + tileDimension = dimensions.decode(nbt.contains("TileDimension") ? nbt.getInt("TileDimension") : -1); } @Override public void write(CompoundTag nbt, DimensionPalette dimensions) { super.write(nbt, dimensions); nbt.put("TilePos", NbtUtils.writeBlockPos(tilePos)); + nbt.putInt("TileDimension", dimensions.encode(tileDimension)); } } diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/management/schedule/condition/StationPoweredCondition.java b/src/main/java/com/simibubi/create/content/logistics/trains/management/schedule/condition/StationPoweredCondition.java index 7760bc585..2f57368af 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/management/schedule/condition/StationPoweredCondition.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/management/schedule/condition/StationPoweredCondition.java @@ -10,7 +10,10 @@ import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; +import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; @@ -26,9 +29,14 @@ public class StationPoweredCondition extends ScheduleWaitCondition { if (currentStation == null) return false; BlockPos stationPos = currentStation.getTilePos(); - if (!level.isLoaded(stationPos)) + ResourceKey stationDim = currentStation.getTileDimension(); + MinecraftServer server = level.getServer(); + if (server == null) return false; - return level.hasNeighborSignal(stationPos); + ServerLevel stationLevel = server.getLevel(stationDim); + if (stationLevel == null || !stationLevel.isLoaded(stationPos)) + return false; + return stationLevel.hasNeighborSignal(stationPos); } @Override