Early Departures

- Fixed "Station Powered" wait condition not working correctly in non-overworld dimensions
This commit is contained in:
simibubi 2022-09-22 19:24:24 +02:00
parent a4dc6bad54
commit c571493ce4
2 changed files with 21 additions and 2 deletions

View File

@ -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<Level> tileDimension;
public BlockPos tilePos;
public BlockPos getTilePos() {
return tilePos;
}
public ResourceKey<Level> 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));
}
}

View File

@ -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<Level> 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