diff options
Diffstat (limited to 'advtrains')
-rw-r--r-- | advtrains/init.lua | 4 | ||||
-rw-r--r-- | advtrains/p_mesecon_iface.lua | 54 | ||||
-rw-r--r-- | advtrains/passive.lua | 22 | ||||
-rw-r--r-- | advtrains/signals.lua | 1 |
4 files changed, 81 insertions, 0 deletions
diff --git a/advtrains/init.lua b/advtrains/init.lua index 0036037..28e104e 100644 --- a/advtrains/init.lua +++ b/advtrains/init.lua @@ -215,6 +215,10 @@ dofile(advtrains.modpath.."/craft_items.lua") dofile(advtrains.modpath.."/log.lua") dofile(advtrains.modpath.."/passive.lua") +if mesecon then + dofile(advtrains.modpath.."/p_mesecon_iface.lua") +end + dofile(advtrains.modpath.."/lzb.lua") diff --git a/advtrains/p_mesecon_iface.lua b/advtrains/p_mesecon_iface.lua new file mode 100644 index 0000000..87e1c6d --- /dev/null +++ b/advtrains/p_mesecon_iface.lua @@ -0,0 +1,54 @@ +-- p_mesecon_iface.lua +-- Mesecons interface by overriding the switch + +if not mesecon then return end + +minetest.override_item("mesecons_switch:mesecon_switch_off", { + groups = { + dig_immediate=2, + save_in_nodedb=1, + }, + on_rightclick = function (pos, node) + advtrains.ndb.swap_node(pos, {name="mesecons_switch:mesecon_switch_on", param2=node.param2}) + mesecon.receptor_on(pos) + minetest.sound_play("mesecons_switch", {pos=pos}) + end, + on_updated_from_nodedb = function(pos, node) + mesecon.receptor_off(pos) + end, + advtrains = { + getstate = "off", + setstate = function(pos, node, newstate) + if newstate=="on" then + advtrains.ndb.swap_node(pos, {name="mesecons_switch:mesecon_switch_on", param2=node.param2}) + mesecon.receptor_on(pos) + end + end, + }, +}) + +minetest.override_item("mesecons_switch:mesecon_switch_on", { + groups = { + dig_immediate=2, + save_in_nodedb=1, + not_in_creative_inventory=1, + }, + on_rightclick = function (pos, node) + advtrains.ndb.swap_node(pos, {name="mesecons_switch:mesecon_switch_off", param2=node.param2}) + mesecon.receptor_off(pos) + minetest.sound_play("mesecons_switch", {pos=pos}) + end, + on_updated_from_nodedb = function(pos, node) + mesecon.receptor_on(pos) + end, + advtrains = { + getstate = "on", + setstate = function(pos, node, newstate) + if newstate=="off" then + advtrains.ndb.swap_node(pos, {name="mesecons_switch:mesecon_switch_off", param2=node.param2}) + mesecon.receptor_off(pos) + end + end, + fallback_state = "off", + }, +}) diff --git a/advtrains/passive.lua b/advtrains/passive.lua index 07cab42..fe4790c 100644 --- a/advtrains/passive.lua +++ b/advtrains/passive.lua @@ -97,3 +97,25 @@ function advtrains.is_passive(parpos, pnode) return false end end + +-- switches a node back to fallback state, if defined. Doesn't support pcnaming. +function advtrains.set_fallback_state(pos, pnode) + local node=pnode or advtrains.ndb.get_node(pos) + local ndef=minetest.registered_nodes[node.name] + local st + if ndef and ndef.advtrains and ndef.advtrains.setstate + and ndef.advtrains.fallback_state then + if advtrains.get_train_at_pos(pos) then + return false + end + + if advtrains.interlocking and advtrains.interlocking.route.has_route_lock(minetest.pos_to_string(pos)) then + return false + end + + ndef.advtrains.setstate(pos, node, ndef.advtrains.fallback_state) + return true + end + + +end diff --git a/advtrains/signals.lua b/advtrains/signals.lua index b3dceca..e144aa6 100644 --- a/advtrains/signals.lua +++ b/advtrains/signals.lua @@ -302,6 +302,7 @@ minetest.register_node("advtrains:across_on", { advtrains.ndb.swap_node(pos, {name = "advtrains:across_off", param2 = node.param2}, true) end end, + fallback_state = "off", }, on_rightclick=function(pos, node, player) if advtrains.check_turnout_signal_protection(pos, player:get_player_name()) then |