From e4ab20509f9d8d7ad77e5ebf5dee6fef6ae77412 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Fri, 12 Jan 2018 01:37:32 +0100 Subject: [PATCH] Clean up the redstone rules --- mods/ITEMS/REDSTONE/mesecons/presets.lua | 52 +++++++++++++------ mods/ITEMS/REDSTONE/mesecons_button/init.lua | 6 +-- .../REDSTONE/mesecons_noteblock/init.lua | 3 +- .../REDSTONE/mesecons_pressureplates/init.lua | 24 ++------- .../REDSTONE/mesecons_walllever/init.lua | 15 +----- mods/ITEMS/mcl_doors/api_doors.lua | 11 ---- mods/ITEMS/mcl_hoppers/init.lua | 12 ----- 7 files changed, 44 insertions(+), 79 deletions(-) diff --git a/mods/ITEMS/REDSTONE/mesecons/presets.lua b/mods/ITEMS/REDSTONE/mesecons/presets.lua index 8c3ed67bd..eca3d7354 100644 --- a/mods/ITEMS/REDSTONE/mesecons/presets.lua +++ b/mods/ITEMS/REDSTONE/mesecons/presets.lua @@ -15,22 +15,6 @@ mesecon.rules.default = {x=0, y=1, z=-1}, {x=0, y=-1, z=-1}} -mesecon.rules.pplate = mesecon.mergetable(mesecon.rules.default, {{x=0, y=-2, z=0}}) - -mesecon.rules.buttonlike = -{{x = 1, y = 0, z = 0}, - {x = 1, y = 1, z = 0}, - {x = 1, y =-1, z = 0}, - {x = 1, y =-1, z = 1}, - {x = 1, y =-1, z =-1}, - {x = 2, y = 0, z = 0}} - -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}} - mesecon.rules.alldirs = {{x= 1, y= 0, z= 0}, {x=-1, y= 0, z= 0}, @@ -39,6 +23,42 @@ mesecon.rules.alldirs = {x= 0, y= 0, z= 1}, {x= 0, y= 0, z=-1}} +mesecon.rules.pplate = +{{x = 1, y = 0, z = 0}, + {x =-1, y = 0, z = 0}, + {x = 0, y = 1, z = 0}, + {x = 0, y =-1, z = 0}, + {x = 0, y = 0, z = 1}, + {x = 0, y = 0, z =-1}, + {x = 0, y = -2, z = 0}, + {x = 1, y = -1, z = 0}, + {x =-1, y = -1, z = 0}, + {x = 0, y = -1, z = 1}, + {x = 0, y = -1, z =-1}} + +mesecon.rules.buttonlike = +{{x = 1, y = 0, z = 0}, + {x = 1, y = 1, z = 0}, + {x = 1, y =-1, z = 0}, + {x = 1, y = 0, z =-1}, + {x = 1, y = 0, z = 1}, + {x = 2, y = 0, z = 0}, + {x = 0, y = 1, z = 0}, + {x = 0, y = -1, z = 0}, + {x =-1, y = 0, z = 0}, + {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}, + {x = 2, y = 0, z = 0}, + {x =-2, y = 0, z = 0}, + {x = 0, y = 0, z = 2}, + {x = 0, y = 0, z =-2}} + mesecon.rules.buttonlike_get = function(node) local rules = mesecon.rules.buttonlike local dir = minetest.facedir_to_dir(node.param2) diff --git a/mods/ITEMS/REDSTONE/mesecons_button/init.lua b/mods/ITEMS/REDSTONE/mesecons_button/init.lua index a54361f7b..5bd9bdcde 100644 --- a/mods/ITEMS/REDSTONE/mesecons_button/init.lua +++ b/mods/ITEMS/REDSTONE/mesecons_button/init.lua @@ -2,11 +2,7 @@ -- A button that when pressed emits power for 1 second -- and then turns off again --- FIXME: Power node behind as well -local button_get_output_rules = function(node) - local rules = mesecon.rules.alldirs - return rules -end +local button_get_output_rules = mesecon.rules.buttonlike_get local boxes_off = { type = "wallmounted", diff --git a/mods/ITEMS/REDSTONE/mesecons_noteblock/init.lua b/mods/ITEMS/REDSTONE/mesecons_noteblock/init.lua index dca7762ed..191c44369 100644 --- a/mods/ITEMS/REDSTONE/mesecons_noteblock/init.lua +++ b/mods/ITEMS/REDSTONE/mesecons_noteblock/init.lua @@ -26,7 +26,8 @@ The note block will only play a note when it is below air, otherwise, it stays s mesecons = {effector = { -- play sound when activated action_on = function (pos, node) mesecon.noteblock_play(pos, node.param2) - end + end, + rules = mesecon.rules.alldirs, }}, _mcl_blast_resistance = 4, _mcl_hardness = 0.8, diff --git a/mods/ITEMS/REDSTONE/mesecons_pressureplates/init.lua b/mods/ITEMS/REDSTONE/mesecons_pressureplates/init.lua index 14d37ed17..7a4da6629 100644 --- a/mods/ITEMS/REDSTONE/mesecons_pressureplates/init.lua +++ b/mods/ITEMS/REDSTONE/mesecons_pressureplates/init.lua @@ -10,22 +10,6 @@ local pp_box_on = { fixed = { -7/16, -8/16, -7/16, 7/16, -7.5/16, 7/16 }, } -local pplate_rules = { - {x=-1, y=0, z=0}, - {x=1, y=0, z=0}, - {x=0, y=0, z=-1}, - {x=0, y=0, z=1}, - - {x=-1, y=-1, z=0}, - {x=1, y=-1, z=0}, - {x=0, y=-1, z=-1}, - {x=0, y=-1, z=1}, - - {x=0, y=-1, z=0}, - {x=0, y=-2, z=0}, - {x=0, y=1, z=0}, -} - local function pp_on_timer(pos, elapsed) local node = minetest.get_node(pos) local basename = minetest.registered_nodes[node.name].pressureplate_basename @@ -68,7 +52,7 @@ local function pp_on_timer(pos, elapsed) end if disable then minetest.set_node(pos, {name = basename .. "_off"}) - mesecon.receptor_off(pos, pplate_rules) + mesecon.receptor_off(pos, mesecon.rules.pplate) end elseif node.name == basename .. "_off" then for k, obj in pairs(objs) do @@ -76,7 +60,7 @@ local function pp_on_timer(pos, elapsed) if obj_does_activate(obj, activated_by) then if objpos.y > pos.y-1 and objpos.y < pos.y then minetest.set_node(pos, {name = basename .. "_on"}) - mesecon.receptor_on(pos, pplate_rules) + mesecon.receptor_on(pos, mesecon.rules.pplate) break end end @@ -137,7 +121,7 @@ function mesecon.register_pressure_plate(basename, description, textures_off, te groups = groups_off, tiles = textures_off, - mesecons = {receptor = { state = mesecon.state.off, rules = pplate_rules }}, + mesecons = {receptor = { state = mesecon.state.off, rules = mesecon.rules.pplate }}, _doc_items_longdesc = longdesc, },{ node_box = pp_box_on, @@ -145,7 +129,7 @@ function mesecon.register_pressure_plate(basename, description, textures_off, te groups = groups_on, tiles = textures_on, - mesecons = {receptor = { state = mesecon.state.on, rules = pplate_rules }}, + mesecons = {receptor = { state = mesecon.state.on, rules = mesecon.rules.pplate }}, _doc_items_create_entry = false, }) diff --git a/mods/ITEMS/REDSTONE/mesecons_walllever/init.lua b/mods/ITEMS/REDSTONE/mesecons_walllever/init.lua index 8a0a3649d..9db4fe743 100644 --- a/mods/ITEMS/REDSTONE/mesecons_walllever/init.lua +++ b/mods/ITEMS/REDSTONE/mesecons_walllever/init.lua @@ -1,17 +1,4 @@ -local lever_get_output_rules = function(node) - local rules = { - {x = -1, y = 0, z = 0}, - {x = 1, y = 0, z = 0}, - {x = 0, y = 0, z = -1}, - {x = 0, y = 0, z = 1}, - {x = 0, y = -1, z = 0}, - {x = 0, y = 1, z = 0}, - } - local dir = minetest.facedir_to_dir(node.param2) - dir = vector.multiply(dir, 2) - table.insert(rules, dir) - return rules -end +local lever_get_output_rules = mesecon.rules.buttonlike_get -- LEVER minetest.register_node("mesecons_walllever:wall_lever_off", { diff --git a/mods/ITEMS/mcl_doors/api_doors.lua b/mods/ITEMS/mcl_doors/api_doors.lua index c93ea846e..b32a58a58 100644 --- a/mods/ITEMS/mcl_doors/api_doors.lua +++ b/mods/ITEMS/mcl_doors/api_doors.lua @@ -235,13 +235,6 @@ function mcl_doors:register_door(name, def) end end - local mrules = { - {x = 0, y = 0, z = -1}, - {x = 1, y = 0, z = 0}, - {x = -1, y = 0, z = 0}, - {x = 0, y = 0, z = 1}, - } - minetest.register_node(name.."_b_1", { tiles = {"blank.png", tt[2].."^[transformFXR90", tb[2], tb[2].."^[transformFX", tb[1], tb[1].."^[transformFX"}, paramtype = "light", @@ -274,7 +267,6 @@ function mcl_doors:register_door(name, def) mesecons = { effector = { action_on = on_mesecons_signal_open, - rules = mrules, }}, can_dig = check_player_priv, @@ -322,7 +314,6 @@ function mcl_doors:register_door(name, def) mesecons = { effector = { action_on = on_mesecons_signal_open_top, - rules = mrules, }}, can_dig = check_player_priv, @@ -370,7 +361,6 @@ function mcl_doors:register_door(name, def) mesecons = { effector = { action_off = on_mesecons_signal_close, - rules = mrules, }}, can_dig = check_player_priv, @@ -418,7 +408,6 @@ function mcl_doors:register_door(name, def) mesecons = { effector = { action_off = on_mesecons_signal_close_top, - rules = mrules, }}, can_dig = check_player_priv, diff --git a/mods/ITEMS/mcl_hoppers/init.lua b/mods/ITEMS/mcl_hoppers/init.lua index 235ddbae2..bdf6a21d5 100644 --- a/mods/ITEMS/mcl_hoppers/init.lua +++ b/mods/ITEMS/mcl_hoppers/init.lua @@ -13,14 +13,6 @@ local mcl_hoppers_formspec = "listring[current_name;main]".. "listring[current_player;main]" -local redstone_rules = -{{x= 1, y= 0, z= 0}, - {x=-1, y= 0, z= 0}, - {x= 0, y= 1, z= 0}, - {x= 0, y= -1, z= 0}, - {x= 0, y= 0, z= 1}, - {x= 0, y= 0, z=-1}} - -- Downwards hopper (base definition) local def_hopper = { @@ -153,7 +145,6 @@ def_hopper_enabled.mesecons = { action_on = function(pos, node) minetest.swap_node(pos, {name="mcl_hoppers:hopper_disabled", param2=node.param2}) end, - rules = redstone_rules, }, } @@ -170,7 +161,6 @@ def_hopper_disabled.mesecons = { action_off = function(pos, node) minetest.swap_node(pos, {name="mcl_hoppers:hopper", param2=node.param2}) end, - rules = redstone_rules, }, } @@ -267,7 +257,6 @@ def_hopper_side_enabled.mesecons = { action_on = function(pos, node) minetest.swap_node(pos, {name="mcl_hoppers:hopper_side_disabled", param2=node.param2}) end, - rules = redstone_rules, }, } minetest.register_node("mcl_hoppers:hopper_side", def_hopper_side_enabled) @@ -279,7 +268,6 @@ def_hopper_side_disabled.mesecons = { action_off = function(pos, node) minetest.swap_node(pos, {name="mcl_hoppers:hopper_side", param2=node.param2}) end, - rules = redstone_rules, }, } minetest.register_node("mcl_hoppers:hopper_side_disabled", def_hopper_side_disabled)