From f74ef2a45693f89537e44e92fcee971b78a2f513 Mon Sep 17 00:00:00 2001 From: orwell96 Date: Fri, 3 Feb 2017 14:14:45 +0100 Subject: add wallmounted light signal --- .../advtrains/models/advtrains_signal_wall_l.b3d | Bin 0 -> 40514 bytes .../advtrains/models/advtrains_signal_wall_r.b3d | Bin 0 -> 40514 bytes advtrains/advtrains/signals.lua | 114 +++++++++++++++++++++ .../textures/advtrains_signal_wall_off.png | Bin 0 -> 3056 bytes .../textures/advtrains_signal_wall_on.png | Bin 0 -> 3043 bytes 5 files changed, 114 insertions(+) create mode 100644 advtrains/advtrains/models/advtrains_signal_wall_l.b3d create mode 100644 advtrains/advtrains/models/advtrains_signal_wall_r.b3d create mode 100644 advtrains/advtrains/textures/advtrains_signal_wall_off.png create mode 100644 advtrains/advtrains/textures/advtrains_signal_wall_on.png (limited to 'advtrains') diff --git a/advtrains/advtrains/models/advtrains_signal_wall_l.b3d b/advtrains/advtrains/models/advtrains_signal_wall_l.b3d new file mode 100644 index 0000000..b1bcbcf Binary files /dev/null and b/advtrains/advtrains/models/advtrains_signal_wall_l.b3d differ diff --git a/advtrains/advtrains/models/advtrains_signal_wall_r.b3d b/advtrains/advtrains/models/advtrains_signal_wall_r.b3d new file mode 100644 index 0000000..cf26389 Binary files /dev/null and b/advtrains/advtrains/models/advtrains_signal_wall_r.b3d differ diff --git a/advtrains/advtrains/signals.lua b/advtrains/advtrains/signals.lua index b475d3c..cdf610e 100644 --- a/advtrains/advtrains/signals.lua +++ b/advtrains/advtrains/signals.lua @@ -1,5 +1,33 @@ --advtrains by orwell96 --signals.lua + +--this code /should/ work but does not. +local mrules_wallsignal_l, mrules_wallsignal_r +if mesecon then + mrules_wallsignal_l = function(node, isright) + local rules = mesecon.rules.buttonlike + if node.param2 == 1 then + rules=mesecon.rotate_rules_left(rules) + elseif node.param2 == 2 then + rules=mesecon.rotate_rules_right(mesecon.rotate_rules_right(rules)) + elseif node.param2 == 3 then + rules=mesecon.rotate_rules_right(rules) + end + return rules + end + mrules_wallsignal_r = function(node) + local rules = mesecon.rules.buttonlike + if node.param2 == 3 then + rules=mesecon.rotate_rules_left(rules) + elseif node.param2 == 0 then + rules=mesecon.rotate_rules_right(mesecon.rotate_rules_right(rules)) + elseif node.param2 == 1 then + rules=mesecon.rotate_rules_right(rules) + end + return rules + end +end + for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red", als="green"}}) do advtrains.trackplacer.register_tracktype("advtrains:retrosignal", "") @@ -32,6 +60,7 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red", save_in_nodedb=1, }, mesecons = {effector = { + rules=advtrains.meseconrules, ["action_"..f.as] = function (pos, node) advtrains.ndb.swap_node(pos, {name = "advtrains:retrosignal_"..f.as..rotation, param2 = node.param2}) end @@ -65,6 +94,7 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red", light_source = 1, sunlight_propagates=true, mesecons = {effector = { + rules=advtrains.meseconrules, ["action_"..f.as] = function (pos, node) advtrains.ndb.swap_node(pos, {name = "advtrains:signal_"..f.as..rotation, param2 = node.param2}) end @@ -83,4 +113,88 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red", }) advtrains.trackplacer.add_worked("advtrains:signal", r, rotation, nil) end + + local crea=1 + if r=="off" then crea=0 end + + --tunnel signals. no rotations. + minetest.register_node("advtrains:signal_wall_l_"..r, { + drawtype = "mesh", + paramtype="light", + paramtype2="facedir", + walkable = false, + selection_box = { + type = "fixed", + fixed = {-1/2, -1/2, -1/4, 0, 1/2, 1/4}, + }, + mesh = "advtrains_signal_wall_l.b3d", + tiles = {"advtrains_signal_wall_"..r..".png"}, + drop="advtrains:signal_wall_l_off", + description=attrans("Wallmounted Signal, left"), + groups = { + choppy=3, + not_blocking_trains=1, + not_in_creative_inventory=crea, + save_in_nodedb=1, + }, + light_source = 1, + sunlight_propagates=true, + mesecons = {effector = { + mrules_wallsignal_l, + ["action_"..f.as] = function (pos, node) + advtrains.ndb.swap_node(pos, {name = "advtrains:signal_wall_l_"..f.as, param2 = node.param2}) + end + }}, + luaautomation = { + getstate = f.ls, + setstate = function(pos, node, newstate) + if newstate == f.als then + advtrains.ndb.swap_node(pos, {name = "advtrains:signal_wall_l_"..f.as, param2 = node.param2}) + end + end, + }, + on_rightclick=function(pos, node, clicker) + advtrains.ndb.swap_node(pos, {name = "advtrains:signal_wall_l_"..f.as, param2 = node.param2}) + end, + }) + minetest.register_node("advtrains:signal_wall_r_"..r, { + drawtype = "mesh", + paramtype="light", + paramtype2="facedir", + walkable = false, + selection_box = { + type = "fixed", + fixed = {0, -1/2, -1/4, 1/2, 1/2, 1/4}, + }, + mesh = "advtrains_signal_wall_r.b3d", + tiles = {"advtrains_signal_wall_"..r..".png"}, + drop="advtrains:signal_wall_r_off", + description=attrans("Wallmounted Signal, right"), + groups = { + choppy=3, + not_blocking_trains=1, + not_in_creative_inventory=crea, + save_in_nodedb=1, + }, + light_source = 1, + sunlight_propagates=true, + mesecons = {effector = { + rules = mrules_wallsignal_r, + ["action_"..f.as] = function (pos, node) + advtrains.ndb.swap_node(pos, {name = "advtrains:signal_wall_r_"..f.as, param2 = node.param2}) + end + }}, + luaautomation = { + getstate = f.ls, + setstate = function(pos, node, newstate) + if newstate == f.als then + advtrains.ndb.swap_node(pos, {name = "advtrains:signal_wall_r_"..f.as, param2 = node.param2}) + end + end, + }, + on_rightclick=function(pos, node, clicker) + advtrains.ndb.swap_node(pos, {name = "advtrains:signal_wall_r_"..f.as, param2 = node.param2}) + end, + }) + end diff --git a/advtrains/advtrains/textures/advtrains_signal_wall_off.png b/advtrains/advtrains/textures/advtrains_signal_wall_off.png new file mode 100644 index 0000000..3e7b1e1 Binary files /dev/null and b/advtrains/advtrains/textures/advtrains_signal_wall_off.png differ diff --git a/advtrains/advtrains/textures/advtrains_signal_wall_on.png b/advtrains/advtrains/textures/advtrains_signal_wall_on.png new file mode 100644 index 0000000..b628c7e Binary files /dev/null and b/advtrains/advtrains/textures/advtrains_signal_wall_on.png differ -- cgit v1.2.3