From 4f9be588716406583b3b0927585a75cfd6817708 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sat, 13 Jan 2018 04:08:40 +0100 Subject: [PATCH] Fix incorrect power transmission of buttons --- mods/ITEMS/REDSTONE/mesecons/internal.lua | 51 ----------------- mods/ITEMS/REDSTONE/mesecons/presets.lua | 58 +++++++++++++++----- mods/ITEMS/REDSTONE/mesecons/util.lua | 53 ++++++++++++++++++ mods/ITEMS/REDSTONE/mesecons_button/init.lua | 2 +- mods/ITEMS/REDSTONE/mesecons_torch/init.lua | 4 +- 5 files changed, 100 insertions(+), 68 deletions(-) diff --git a/mods/ITEMS/REDSTONE/mesecons/internal.lua b/mods/ITEMS/REDSTONE/mesecons/internal.lua index 3f1fb737..ffde3b66 100644 --- a/mods/ITEMS/REDSTONE/mesecons/internal.lua +++ b/mods/ITEMS/REDSTONE/mesecons/internal.lua @@ -550,55 +550,4 @@ function mesecon.is_powered(pos, rule) else return sourcepos end end ---Rules rotation Functions: -function mesecon.rotate_rules_right(rules) - local nr = {} - for i, rule in ipairs(rules) do - table.insert(nr, { - x = -rule.z, - y = rule.y, - z = rule.x, - name = rule.name, - spread = rule.spread,}) - end - return nr -end -function mesecon.rotate_rules_left(rules) - local nr = {} - for i, rule in ipairs(rules) do - table.insert(nr, { - x = rule.z, - y = rule.y, - z = -rule.x, - name = rule.name, - spread = rule.spread,}) - end - return nr -end - -function mesecon.rotate_rules_down(rules) - local nr = {} - for i, rule in ipairs(rules) do - table.insert(nr, { - x = -rule.y, - y = rule.x, - z = rule.z, - name = rule.name, - spread = rule.spread,}) - end - return nr -end - -function mesecon.rotate_rules_up(rules) - local nr = {} - for i, rule in ipairs(rules) do - table.insert(nr, { - x = rule.y, - y = -rule.x, - z = rule.z, - name = rule.name, - spread = rule.spread,}) - end - return nr -end diff --git a/mods/ITEMS/REDSTONE/mesecons/presets.lua b/mods/ITEMS/REDSTONE/mesecons/presets.lua index 3d65cfe7..f624c52f 100644 --- a/mods/ITEMS/REDSTONE/mesecons/presets.lua +++ b/mods/ITEMS/REDSTONE/mesecons/presets.lua @@ -42,12 +42,22 @@ mesecon.rules.buttonlike = {x =-1, y = 0, z = 0}, {x = 1, y = 0, z = 0, spread = true}} +mesecon.rules.floor = +{{x = 1, y = 0, z = 0}, + {x =-1, y = 0, z = 0}, + {x = 0, y = 1, z = 0}, + {x = 0, y =-1, z = 0, spread = true}, + {x = 0, y = 0, z = 1}, + {x = 0, y = 0, z =-1}} + mesecon.rules.flat = {{x = 1, y = 0, z = 0}, {x =-1, y = 0, z = 0}, {x = 0, y = 0, z = 1}, {x = 0, y = 0, z =-1}} + + -- NOT IN ORIGNAL MESECONS mesecon.rules.mcl_alldirs_spread = {{x= 1, y= 0, z= 0, spread = true}, @@ -59,23 +69,41 @@ mesecon.rules.mcl_alldirs_spread = -- END OF UNOFFICIAL RULES +local rules_buttonlike = { + xp = mesecon.rules.buttonlike, + xn = mesecon.rotate_rules_right(mesecon.rotate_rules_right(mesecon.rules.buttonlike)), + yp = mesecon.rotate_rules_down(mesecon.rules.buttonlike), + yn = mesecon.rotate_rules_up(mesecon.rules.buttonlike), + zp = mesecon.rotate_rules_right(mesecon.rules.buttonlike), + zn = mesecon.rotate_rules_left(mesecon.rules.buttonlike), +} + +local rules_wallmounted = { + xp = mesecon.rotate_rules_down(mesecon.rules.floor), + xn = mesecon.rotate_rules_up(mesecon.rules.floor), + yp = mesecon.rotate_rules_up(mesecon.rotate_rules_up(mesecon.rules.floor)), + yn = mesecon.rules.floor, + zp = mesecon.rotate_rules_left(mesecon.rotate_rules_up(mesecon.rules.floor)), + zn = mesecon.rotate_rules_right(mesecon.rotate_rules_up(mesecon.rules.floor)), +} + +local function rules_from_dir(ruleset, dir) + if dir.x == 1 then return ruleset.xp end + if dir.y == 1 then return ruleset.yp end + if dir.z == 1 then return ruleset.zp end + if dir.x == -1 then return ruleset.xn end + if dir.y == -1 then return ruleset.yn end + if dir.z == -1 then return ruleset.zn end +end + mesecon.rules.buttonlike_get = function(node) - local rules = mesecon.rules.buttonlike local dir = minetest.facedir_to_dir(node.param2) - if dir.x == 1 then - -- No action needed - elseif dir.z == -1 then - rules=mesecon.rotate_rules_left(rules) - elseif dir.x == -1 then - rules=mesecon.rotate_rules_right(mesecon.rotate_rules_right(rules)) - elseif dir.z == 1 then - rules=mesecon.rotate_rules_right(rules) - elseif dir.y == -1 then - rules=mesecon.rotate_rules_up(rules) - elseif dir.y == 1 then - rules=mesecon.rotate_rules_down(rules) - end - return rules + return rules_from_dir(rules_buttonlike, dir) +end + +mesecon.rules.wallmounted_get = function(node) + local dir = minetest.wallmounted_to_dir(node.param2) + return rules_from_dir(rules_wallmounted, dir) end mesecon.state.on = "on" diff --git a/mods/ITEMS/REDSTONE/mesecons/util.lua b/mods/ITEMS/REDSTONE/mesecons/util.lua index fc7e1f2e..f6dac3f5 100644 --- a/mods/ITEMS/REDSTONE/mesecons/util.lua +++ b/mods/ITEMS/REDSTONE/mesecons/util.lua @@ -6,6 +6,59 @@ function mesecon.move_node(pos, newpos) minetest.get_meta(pos):from_table(meta) end +--Rules rotation Functions: +function mesecon.rotate_rules_right(rules) + local nr = {} + for i, rule in ipairs(rules) do + table.insert(nr, { + x = -rule.z, + y = rule.y, + z = rule.x, + name = rule.name, + spread = rule.spread,}) + end + return nr +end + +function mesecon.rotate_rules_left(rules) + local nr = {} + for i, rule in ipairs(rules) do + table.insert(nr, { + x = rule.z, + y = rule.y, + z = -rule.x, + name = rule.name, + spread = rule.spread,}) + end + return nr +end + +function mesecon.rotate_rules_down(rules) + local nr = {} + for i, rule in ipairs(rules) do + table.insert(nr, { + x = -rule.y, + y = rule.x, + z = rule.z, + name = rule.name, + spread = rule.spread,}) + end + return nr +end + +function mesecon.rotate_rules_up(rules) + local nr = {} + for i, rule in ipairs(rules) do + table.insert(nr, { + x = rule.y, + y = -rule.x, + z = rule.z, + name = rule.name, + spread = rule.spread,}) + end + return nr +end + function mesecon.flattenrules(allrules) --[[ { diff --git a/mods/ITEMS/REDSTONE/mesecons_button/init.lua b/mods/ITEMS/REDSTONE/mesecons_button/init.lua index 5bd9bdcd..ff6f7f4b 100644 --- a/mods/ITEMS/REDSTONE/mesecons_button/init.lua +++ b/mods/ITEMS/REDSTONE/mesecons_button/init.lua @@ -2,7 +2,7 @@ -- A button that when pressed emits power for 1 second -- and then turns off again -local button_get_output_rules = mesecon.rules.buttonlike_get +local button_get_output_rules = mesecon.rules.wallmounted_get local boxes_off = { type = "wallmounted", diff --git a/mods/ITEMS/REDSTONE/mesecons_torch/init.lua b/mods/ITEMS/REDSTONE/mesecons_torch/init.lua index 579f1c1d..35e339d3 100644 --- a/mods/ITEMS/REDSTONE/mesecons_torch/init.lua +++ b/mods/ITEMS/REDSTONE/mesecons_torch/init.lua @@ -16,7 +16,9 @@ local rotate_torch_rules = function (rules, param2) end end -local torch_get_output_rules = mesecon.rules.alldirs +local torch_get_output_rules = function() + return mesecon.rules.mcl_alldirs_spread +end local torch_get_input_rules = function(node) local rules = {{x = -2, y = 0, z = 0},