From cd0aaa53a0adfb7dfa63d29e98fda851b3de4f36 Mon Sep 17 00:00:00 2001 From: orwell96 Date: Mon, 18 Dec 2017 12:21:54 +0100 Subject: Move train_load() function into advtrains_train_track --- advtrains/init.lua | 1 - advtrains/loading.lua | 46 ------------------------------------ advtrains_train_track/init.lua | 53 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 52 insertions(+), 48 deletions(-) delete mode 100644 advtrains/loading.lua diff --git a/advtrains/init.lua b/advtrains/init.lua index 5fdb57d..5975b81 100644 --- a/advtrains/init.lua +++ b/advtrains/init.lua @@ -151,7 +151,6 @@ dofile(advtrains.modpath.."/signals.lua") dofile(advtrains.modpath.."/misc_nodes.lua") dofile(advtrains.modpath.."/crafting.lua") dofile(advtrains.modpath.."/craft_items.lua") -dofile(advtrains.modpath.."/loading.lua") if minetest.global_exists("digtron") then dofile(advtrains.modpath.."/digtron.lua") diff --git a/advtrains/loading.lua b/advtrains/loading.lua deleted file mode 100644 index e2c0e09..0000000 --- a/advtrains/loading.lua +++ /dev/null @@ -1,46 +0,0 @@ --- Tracks for loading and unloading trains --- Copyright (C) 2017 Gabriel Pérez-Cerezo - -local function get_far_node(pos) - local node = minetest.get_node(pos) - if node.name == "ignore" then - minetest.get_voxel_manip():read_from_map(pos, pos) - node = minetest.get_node(pos) - end - return node -end - -local function train_load(pos, train_id, unload) - local train=advtrains.trains[train_id] - local below = get_far_node({x=pos.x, y=pos.y-1, z=pos.z}) - if not string.match(below.name, "chest") then - atprint("this is not a chest! at "..minetest.pos_to_string(pos)) - return - end - 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 - end - end -end - - diff --git a/advtrains_train_track/init.lua b/advtrains_train_track/init.lua index 425c840..2bd5e28 100644 --- a/advtrains_train_track/init.lua +++ b/advtrains_train_track/init.lua @@ -1,3 +1,5 @@ +-- Default tracks for advtrains +-- (c) orwell96 and contributors --flat advtrains.register_tracks("default", { @@ -47,7 +49,56 @@ advtrains.register_tracks("default", { formats={}, get_additional_definiton = advtrains.atc_function }, advtrains.trackpresets.t_30deg_straightonly) --- loading and unloading tracks + + +-- Tracks for loading and unloading trains +-- Copyright (C) 2017 Gabriel Pérez-Cerezo + +local function get_far_node(pos) + local node = minetest.get_node(pos) + if node.name == "ignore" then + minetest.get_voxel_manip():read_from_map(pos, pos) + node = minetest.get_node(pos) + end + return node +end + +local function train_load(pos, train_id, unload) + local train=advtrains.trains[train_id] + local below = get_far_node({x=pos.x, y=pos.y-1, z=pos.z}) + if not string.match(below.name, "chest") then + atprint("this is not a chest! at "..minetest.pos_to_string(pos)) + return + end + 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 + end + end +end + + + + advtrains.register_tracks("default", { nodename_prefix="advtrains:dtrack_unload", texture_prefix="advtrains_dtrack_unload", -- cgit v1.2.3