From c0131732655940530d7b2c96020b726708f0a7c7 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Thu, 25 Jul 2024 19:21:58 +0200 Subject: [PATCH] Fix CC:Tweaked setSchedule entries order - Port of #5973 to 1.18 --- .../peripherals/StationPeripheral.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 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 230ade2a6..c50891fe3 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 @@ -151,6 +151,13 @@ public class StationPeripheral extends SyncedPeripheral { @LuaFunction(mainThread = true) public final void setSchedule(IArguments arguments) throws LuaException { + if (arguments.getTable(0).size() != 2) + throw new LuaException("Not a valid schedule"); + + Object entries = arguments.getTable(0).get("entries"); + if (entries instanceof Map map && map.isEmpty()) + throw new LuaException("Schedule must have at least one entry"); + Train train = getTrainOrThrow(); Schedule schedule = Schedule.fromTag(toCompoundTag(new CreateLuaTable(arguments.getTable(0)))); boolean autoSchedule = train.runtime.getSchedule() == null || train.runtime.isAutoSchedule; @@ -233,8 +240,9 @@ public class StationPeripheral extends SyncedPeripheral { return StringTag.valueOf(v); else if (value instanceof Map v && v.containsKey(1.0)) { // List ListTag list = new ListTag(); - for (Object o : v.values()) { - list.add(toNBTTag(null, o)); + for (double i = 1; i <= v.size(); i++) { + if (v.get(i) != null) + list.add(toNBTTag(null, v.get(i))); } return list;