From 52593a2ae93eafb361a185f5d4c560bc3c36543d Mon Sep 17 00:00:00 2001 From: grimmauld Date: Sun, 29 Jan 2023 16:07:19 +0100 Subject: [PATCH] fix nullability crash in Carriage.java --- .../content/logistics/trains/entity/Carriage.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/entity/Carriage.java b/src/main/java/com/simibubi/create/content/logistics/trains/entity/Carriage.java index 6b4b71e51..d4e530695 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/entity/Carriage.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/entity/Carriage.java @@ -16,6 +16,8 @@ import java.util.function.Function; import javax.annotation.Nullable; +import net.minecraft.server.MinecraftServer; + import org.apache.commons.lang3.mutable.MutableDouble; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; @@ -129,7 +131,7 @@ public class Carriage { boolean onTwoBogeys = isOnTwoBogeys(); double stress = train.derailed ? 0 : onTwoBogeys ? bogeySpacing - getAnchorDiff() : 0; blocked = false; - + MutableDouble distanceMoved = new MutableDouble(distance); boolean iterateFromBack = distance < 0; @@ -141,7 +143,7 @@ public class Carriage { CarriageBogey bogey = bogeys.get(actuallyFirstBogey); double bogeyCorrection = stress * (actuallyFirstBogey ? 0.5d : -0.5d); double bogeyStress = bogey.getStress(); - + for (boolean firstWheel : Iterate.trueAndFalse) { boolean actuallyFirstWheel = firstWheel ^ iterateFromBack; TravellingPoint point = bogey.points.get(actuallyFirstWheel); @@ -249,8 +251,11 @@ public class Carriage { boolean discard = !currentlyTraversedDimensions.isEmpty() && !currentlyTraversedDimensions.contains(entry.getKey()); - ServerLevel currentLevel = level.getServer() - .getLevel(entry.getKey()); + + MinecraftServer server = level.getServer(); + if (server == null) + continue; + ServerLevel currentLevel = server.getLevel(entry.getKey()); if (currentLevel == null) continue; @@ -848,7 +853,7 @@ public class Carriage { train.carriageWaitingForChunks = id; return; } - + if (entity.getPassengers() .stream() .anyMatch(p -> p instanceof Player)