From 7f3ca1cfa06b227211a41503c4ae31c3cf854ba5 Mon Sep 17 00:00:00 2001 From: caelwarner Date: Mon, 13 Mar 2023 16:29:05 -0700 Subject: [PATCH] Added isTrainEnroute to station peripheral API - isTrainEnroute checks if a train is currently navigating to the station - Reworded null station exception to "station is not connected to a track" - Refactored StationPeripheral#inAssemblyMode to StationPeripheral#isInAssemblyMode - Added a check to StationPeripheral#disassemble to make sure the station isn't in assembly mode --- .../peripherals/StationPeripheral.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/peripherals/StationPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/peripherals/StationPeripheral.java index e214ec39f..2d9915d59 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/peripherals/StationPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/peripherals/StationPeripheral.java @@ -52,7 +52,10 @@ public class StationPeripheral extends SyncedPeripheral { @LuaFunction(mainThread = true) public final void disassemble() throws LuaException { - Train train = getTrainOrThrow(); + if (tile.isAssembling()) + throw new LuaException("station must not be in assembly mode"); + + getTrainOrThrow(); if (!tile.enterAssemblyMode(null)) throw new LuaException("could not disassemble train"); @@ -70,7 +73,7 @@ public class StationPeripheral extends SyncedPeripheral { } @LuaFunction - public final boolean inAssemblyMode() { + public final boolean isInAssemblyMode() { return tile.isAssembling(); } @@ -78,7 +81,7 @@ public class StationPeripheral extends SyncedPeripheral { public final String getStationName() throws LuaException { GlobalStation station = tile.getStation(); if (station == null) - throw new LuaException("train station does not exist"); + throw new LuaException("station is not connected to a track"); return station.name; } @@ -93,7 +96,7 @@ public class StationPeripheral extends SyncedPeripheral { public final boolean isTrainPresent() throws LuaException { GlobalStation station = tile.getStation(); if (station == null) - throw new LuaException("train station does not exist"); + throw new LuaException("station is not connected to a track"); return station.getPresentTrain() != null; } @@ -102,11 +105,20 @@ public class StationPeripheral extends SyncedPeripheral { public final boolean isTrainImminent() throws LuaException { GlobalStation station = tile.getStation(); if (station == null) - throw new LuaException("train station does not exist"); + throw new LuaException("station is not connected to a track"); return station.getImminentTrain() != null; } + @LuaFunction + public final boolean isTrainEnroute() throws LuaException { + GlobalStation station = tile.getStation(); + if (station == null) + throw new LuaException("station is not connected to a track"); + + return station.getNearestTrain() != null; + } + @LuaFunction public final String getTrainName() throws LuaException { Train train = getTrainOrThrow(); @@ -148,7 +160,7 @@ public class StationPeripheral extends SyncedPeripheral { private @NotNull Train getTrainOrThrow() throws LuaException { GlobalStation station = tile.getStation(); if (station == null) - throw new LuaException("train station does not exist"); + throw new LuaException("station is not connected to a track"); Train train = station.getPresentTrain(); if (train == null)