aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Pérez-Cerezo <gabriel@gpcf.eu>2021-04-11 12:45:17 +0200
committerGabriel Pérez-Cerezo <gabriel@gpcf.eu>2021-04-11 12:45:17 +0200
commite04c21be78f6c915537f7dc8fdbf8110d7eadcd0 (patch)
treeb729ce281337b2965088a28c88df4d3e7bd187cc
parent9dd0313b710e537ec7bc1285111ff0c8bd43089d (diff)
downloadadvtrains-e04c21be78f6c915537f7dc8fdbf8110d7eadcd0.tar.gz
advtrains-e04c21be78f6c915537f7dc8fdbf8110d7eadcd0.tar.bz2
advtrains-e04c21be78f6c915537f7dc8fdbf8110d7eadcd0.zip
Add check for box inventory
this fixes a crash when the new technic train battery wagon passes over a loading / unloading track.
-rwxr-xr-xadvtrains_train_track/init.lua38
1 files changed, 19 insertions, 19 deletions
diff --git a/advtrains_train_track/init.lua b/advtrains_train_track/init.lua
index 744d86b..6bb8b33 100755
--- a/advtrains_train_track/init.lua
+++ b/advtrains_train_track/init.lua
@@ -226,25 +226,25 @@ local function train_load(pos, train_id, unload)
local inv = minetest.get_inventory({type="node", pos={x=pos.x, y=pos.y-1, z=pos.z}})
if inv and train.velocity < 2 then
for k, v in ipairs(train.trainparts) do
-
- local i=minetest.get_inventory({type="detached", name="advtrains_wgn_"..v})
- if i then
- if not unload then
- for _, item in ipairs(inv:get_list("main")) do
- if i:get_list("box") and i:room_for_item("box", item) then
- i:add_item("box", item)
- inv:remove_item("main", item)
- end
- end
- else
- for _, item in ipairs(i:get_list("box")) do
- if inv:get_list("main") and inv:room_for_item("main", item) then
- i:remove_item("box", item)
- inv:add_item("main", item)
- end
- end
- end
- end
+
+ local i=minetest.get_inventory({type="detached", name="advtrains_wgn_"..v})
+ if i and i:get_list("box") then
+ if not unload then
+ for _, item in ipairs(inv:get_list("main")) do
+ if i:get_list("box") and i:room_for_item("box", item) then
+ i:add_item("box", item)
+ inv:remove_item("main", item)
+ end
+ end
+ else
+ for _, item in ipairs(i:get_list("box")) do
+ if inv:get_list("main") and inv:room_for_item("main", item) then
+ i:remove_item("box", item)
+ inv:add_item("main", item)
+ end
+ end
+ end
+ end
end
end
end