Fix CC:Tweaked setSchedule entries order

- Port of #5973 to 1.18
This commit is contained in:
simibubi 2024-07-25 19:21:58 +02:00
parent f8cc7ab73c
commit c013173265

View file

@ -151,6 +151,13 @@ public class StationPeripheral extends SyncedPeripheral<StationBlockEntity> {
@LuaFunction(mainThread = true) @LuaFunction(mainThread = true)
public final void setSchedule(IArguments arguments) throws LuaException { 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(); Train train = getTrainOrThrow();
Schedule schedule = Schedule.fromTag(toCompoundTag(new CreateLuaTable(arguments.getTable(0)))); Schedule schedule = Schedule.fromTag(toCompoundTag(new CreateLuaTable(arguments.getTable(0))));
boolean autoSchedule = train.runtime.getSchedule() == null || train.runtime.isAutoSchedule; boolean autoSchedule = train.runtime.getSchedule() == null || train.runtime.isAutoSchedule;
@ -233,8 +240,9 @@ public class StationPeripheral extends SyncedPeripheral<StationBlockEntity> {
return StringTag.valueOf(v); return StringTag.valueOf(v);
else if (value instanceof Map<?, ?> v && v.containsKey(1.0)) { // List else if (value instanceof Map<?, ?> v && v.containsKey(1.0)) { // List
ListTag list = new ListTag(); ListTag list = new ListTag();
for (Object o : v.values()) { for (double i = 1; i <= v.size(); i++) {
list.add(toNBTTag(null, o)); if (v.get(i) != null)
list.add(toNBTTag(null, v.get(i)));
} }
return list; return list;