aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgpcf <gabriel@gpcf.eu>2017-05-31 21:32:05 +0200
committerorwell96 <mono96.mml@gmail.com>2017-05-31 21:32:05 +0200
commit92af0b53e57248b004115ebc50bbd2f2ec630d50 (patch)
treeee56fe69c7681f2e02513ba3ae2ec4253518691f
parent93250ca3a2a6fd5bf8704b2f8075be874fd815c2 (diff)
downloadadvtrains-92af0b53e57248b004115ebc50bbd2f2ec630d50.tar.gz
advtrains-92af0b53e57248b004115ebc50bbd2f2ec630d50.tar.bz2
advtrains-92af0b53e57248b004115ebc50bbd2f2ec630d50.zip
Add loading/unloading rails (#63)
Pull request by gpcf Will update zip file with next release
-rw-r--r--advtrains/advtrains/init.lua1
-rw-r--r--advtrains/advtrains/loading.lua99
-rw-r--r--advtrains/advtrains/textures/advtrains_dtrack_load_placer.pngbin0 -> 1248 bytes
-rw-r--r--advtrains/advtrains/textures/advtrains_dtrack_shared_load.pngbin0 -> 7339 bytes
-rw-r--r--advtrains/advtrains/textures/advtrains_dtrack_shared_unload.pngbin0 -> 7338 bytes
-rw-r--r--advtrains/advtrains/textures/advtrains_dtrack_unload_placer.pngbin0 -> 1260 bytes
6 files changed, 100 insertions, 0 deletions
diff --git a/advtrains/advtrains/init.lua b/advtrains/advtrains/init.lua
index 7793a42..1bb356d 100644
--- a/advtrains/advtrains/init.lua
+++ b/advtrains/advtrains/init.lua
@@ -142,6 +142,7 @@ 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 digtron then
dofile(advtrains.modpath.."/digtron.lua")
diff --git a/advtrains/advtrains/loading.lua b/advtrains/advtrains/loading.lua
new file mode 100644
index 0000000..8ac7b00
--- /dev/null
+++ b/advtrains/advtrains/loading.lua
@@ -0,0 +1,99 @@
+-- Tracks for loading and unloading trains
+-- Copyright (C) 2017 Gabriel PĂ©rez-Cerezo <gabriel@gpcf.eu>
+
+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",
+ models_prefix="advtrains_dtrack",
+ models_suffix=".b3d",
+ shared_texture="advtrains_dtrack_shared_unload.png",
+ description=attrans("Unloading Track"),
+ formats={},
+ get_additional_definiton = function(def, preset, suffix, rotation)
+ return {
+ after_dig_node=function(pos)
+ advtrains.invalidate_all_paths()
+ advtrains.ndb.clear(pos)
+ -- local pts=minetest.pos_to_string(pos)
+ -- atc.controllers[pts]=nil
+ end,
+ -- on_receive_fields = function(pos, formname, fields, player)
+ -- if minetest.is_protected(pos, player:get_player_name()) then
+ -- minetest.chat_send_player(player:get_player_name(), attrans("This position is protected!"))
+ -- return
+ -- end
+ -- end,
+ advtrains = {
+ on_train_enter = function(pos, train_id)
+ train_load(pos, train_id, true)
+ end,
+ },
+ }
+ end
+ }, advtrains.trackpresets.t_30deg_straightonly)
+advtrains.register_tracks("default", {
+ nodename_prefix="advtrains:dtrack_load",
+ texture_prefix="advtrains_dtrack_load",
+ models_prefix="advtrains_dtrack",
+ models_suffix=".b3d",
+ shared_texture="advtrains_dtrack_shared_load.png",
+ description=attrans("Loading Track"),
+ formats={},
+ get_additional_definiton = function(def, preset, suffix, rotation)
+ return {
+ after_dig_node=function(pos)
+ advtrains.invalidate_all_paths()
+ advtrains.ndb.clear(pos)
+ end,
+
+ advtrains = {
+ on_train_enter = function(pos, train_id)
+ train_load(pos, train_id, false)
+ end,
+ },
+ }
+ end
+ }, advtrains.trackpresets.t_30deg_straightonly)
diff --git a/advtrains/advtrains/textures/advtrains_dtrack_load_placer.png b/advtrains/advtrains/textures/advtrains_dtrack_load_placer.png
new file mode 100644
index 0000000..427c011
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_dtrack_load_placer.png
Binary files differ
diff --git a/advtrains/advtrains/textures/advtrains_dtrack_shared_load.png b/advtrains/advtrains/textures/advtrains_dtrack_shared_load.png
new file mode 100644
index 0000000..5fd0d7a
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_dtrack_shared_load.png
Binary files differ
diff --git a/advtrains/advtrains/textures/advtrains_dtrack_shared_unload.png b/advtrains/advtrains/textures/advtrains_dtrack_shared_unload.png
new file mode 100644
index 0000000..e9fc5bd
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_dtrack_shared_unload.png
Binary files differ
diff --git a/advtrains/advtrains/textures/advtrains_dtrack_unload_placer.png b/advtrains/advtrains/textures/advtrains_dtrack_unload_placer.png
new file mode 100644
index 0000000..486861e
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_dtrack_unload_placer.png
Binary files differ