From f7abb83501ac8eb610c4a760704547805bbc92ae Mon Sep 17 00:00:00 2001 From: Samuel Hulme <41990982+ajh123@users.noreply.github.com> Date: Thu, 15 May 2025 17:43:32 +0100 Subject: [PATCH 1/2] Add Lua functions to retrieve train information from the station --- .../peripherals/StationPeripheral.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StationPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StationPeripheral.java index 3f40a9f210..3fe47ea558 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StationPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StationPeripheral.java @@ -4,6 +4,8 @@ import javax.annotation.Nullable; +import com.simibubi.create.content.trains.graph.DimensionPalette; + import org.jetbrains.annotations.NotNull; import com.simibubi.create.AllPackets; @@ -102,6 +104,20 @@ public final boolean isTrainPresent() throws LuaException { return station.getPresentTrain() != null; } + @LuaFunction + public final CreateLuaTable getPresentTrain() throws LuaException { + GlobalStation station = blockEntity.getStation(); + if (station == null) + throw new LuaException("station is not connected to a track"); + + if (station.getPresentTrain() == null) { + return null; + } + + DimensionPalette dimensions = new DimensionPalette(); + return fromCompoundTag(station.getPresentTrain().write(dimensions)); + } + @LuaFunction public final boolean isTrainImminent() throws LuaException { GlobalStation station = blockEntity.getStation(); @@ -111,6 +127,20 @@ public final boolean isTrainImminent() throws LuaException { return station.getImminentTrain() != null; } + @LuaFunction + public final CreateLuaTable getImminentTrain() throws LuaException { + GlobalStation station = blockEntity.getStation(); + if (station == null) + throw new LuaException("station is not connected to a track"); + + if (station.getPresentTrain() == null) { + return null; + } + + DimensionPalette dimensions = new DimensionPalette(); + return fromCompoundTag(station.getPresentTrain().write(dimensions)); + } + @LuaFunction public final boolean isTrainEnroute() throws LuaException { GlobalStation station = blockEntity.getStation(); @@ -120,6 +150,20 @@ public final boolean isTrainEnroute() throws LuaException { return station.getNearestTrain() != null; } + @LuaFunction + public final CreateLuaTable getEnrouteTrain() throws LuaException { + GlobalStation station = blockEntity.getStation(); + if (station == null) + throw new LuaException("station is not connected to a track"); + + if (station.getPresentTrain() == null) { + return null; + } + + DimensionPalette dimensions = new DimensionPalette(); + return fromCompoundTag(station.getPresentTrain().write(dimensions)); + } + @LuaFunction public final String getTrainName() throws LuaException { Train train = getTrainOrThrow(); From da96ef69aef475179c8099931f9e4c5df7848536 Mon Sep 17 00:00:00 2001 From: Samuel Hulme <41990982+ajh123@users.noreply.github.com> Date: Sat, 17 May 2025 18:08:33 +0100 Subject: [PATCH 2/2] Fix code style in null checks for trains, also use the correct get trains methods --- .../peripherals/StationPeripheral.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StationPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StationPeripheral.java index 3fe47ea558..bbf29d063d 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StationPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StationPeripheral.java @@ -110,9 +110,8 @@ public final CreateLuaTable getPresentTrain() throws LuaException { if (station == null) throw new LuaException("station is not connected to a track"); - if (station.getPresentTrain() == null) { + if (station.getPresentTrain() == null) return null; - } DimensionPalette dimensions = new DimensionPalette(); return fromCompoundTag(station.getPresentTrain().write(dimensions)); @@ -133,12 +132,11 @@ public final CreateLuaTable getImminentTrain() throws LuaException { if (station == null) throw new LuaException("station is not connected to a track"); - if (station.getPresentTrain() == null) { + if (station.getImminentTrain() == null) return null; - } DimensionPalette dimensions = new DimensionPalette(); - return fromCompoundTag(station.getPresentTrain().write(dimensions)); + return fromCompoundTag(station.getImminentTrain().write(dimensions)); } @LuaFunction @@ -156,12 +154,11 @@ public final CreateLuaTable getEnrouteTrain() throws LuaException { if (station == null) throw new LuaException("station is not connected to a track"); - if (station.getPresentTrain() == null) { + if (station.getNearestTrain() == null) return null; - } DimensionPalette dimensions = new DimensionPalette(); - return fromCompoundTag(station.getPresentTrain().write(dimensions)); + return fromCompoundTag(station.getNearestTrain().write(dimensions)); } @LuaFunction