Computercraft Lua Table of train schematic to Java HashMap destination order mismatch
svemat01 opened this issue ยท 2 comments
Describe the Bug
When setting a train schedule from computercraft using the setSchedule
method it is not guaranteed that the order of the destination list in lua will match the schematic given to the train.
I think I've got it down to the issue originating from StationPeripheral.java#155 where the lua table is converted to a Java HashMap. This by itself is not the complete issue but when the lua table is then to be converted to a NBT tag at StationPeripheral.java#236 it is being enumerated using HashMap#values()
which does not guarantee that the insertion order matches the enumeration order.
The issue is not that the setSchedule
and getSchedule
don't match (still an issue but not the issue) but rather that the setSchedule
does not match the schedule the train actually performs.
Reproduction Steps
- Create a train schedule using computer craft with a confirmable order of destinations.
- run
station.setSchedule
on the station - run
station.getSchedule
and compare the input and output.
Example of a script:
station-order.lua
local inputSchedule = {
cyclic = true,
entries = {
{
instruction = {
id = "create:destination",
data = {
text = "Station 1",
},
},
conditions = {
{
{
id = "create:delay",
data = {
value = 5,
time_unit = 1,
},
},
},
},
},
{
instruction = {
id = "create:destination",
data = {
text = "Station 2",
},
},
conditions = {
{
{
id = "create:delay",
data = {
value = 5,
time_unit = 1,
},
},
},
},
},
{
instruction = {
id = "create:destination",
data = {
text = "Station 3",
},
},
conditions = {
{
{
id = "create:delay",
data = {
value = 5,
time_unit = 1,
},
},
},
},
},
{
instruction = {
id = "create:destination",
data = {
text = "Station 4",
},
},
conditions = {
{
{
id = "create:delay",
data = {
value = 5,
time_unit = 1,
},
},
},
},
},
{
instruction = {
id = "create:destination",
data = {
text = "Station 5",
},
},
conditions = {
{
{
id = "create:delay",
data = {
value = 5,
time_unit = 1,
},
},
},
},
},
},
}
local station = peripheral.wrap("left")
station.setSchedule(inputSchedule)
local outputSchedule = station.getSchedule()
-- Loop through the entries and compare the station names to see if they are the same order
local output = "Input: "
for index, value in ipairs(inputSchedule.entries) do
output = output .. value.instruction.data.text .. ", "
end
output = output .. "\nOutput: "
for index, value in ipairs(outputSchedule.entries) do
output = output .. value.instruction.data.text .. ", "
end
print(output)
Expected Result
I expect that the destination list I set should match the one actually being given to the train.
Screenshots and Videos
Crash Report or Log
No response
Operating System
MacOS
Mod Version
0.5.1c
Minecraft Version
1.19.2
Forge Version
43.2.23
Other Mods
CC: Tweaked version 1.101.3
Additional Context
CC @caelwarner who seems responsible for the computercraft integration per the wiki
I really appreciate this mod and all it introduces.
Thanks for looking into this!
Is there any update on this? I'm on the latest version of Create on Forge 1.20.1 and this is still an issue almost 8 months later.