From b197d29bef365947d0f288287ebaf09fab07cd86 Mon Sep 17 00:00:00 2001 From: Jeija Date: Mon, 13 Aug 2012 13:12:19 +0200 Subject: [PATCH] Code cleanup, little bugfix (some conductors placed next to receptors didn't turn on) --- mesecons/init.lua | 7 ++++--- mesecons/internal.lua | 20 +++++++++++--------- mesecons_blinkyplant/init.lua | 3 --- mesecons_button/init.lua | 3 --- mesecons_detector/init.lua | 7 ++----- mesecons_powerplant/init.lua | 6 ------ mesecons_pressureplates/init.lua | 18 ++++++------------ mesecons_solarpanel/init.lua | 3 --- mesecons_switch/init.lua | 3 --- mesecons_torch/init.lua | 7 ------- mesecons_walllever/init.lua | 3 --- 11 files changed, 23 insertions(+), 57 deletions(-) diff --git a/mesecons/init.lua b/mesecons/init.lua index 9ecd007..48209d7 100644 --- a/mesecons/init.lua +++ b/mesecons/init.lua @@ -191,14 +191,15 @@ function mesecon:register_on_signal_change(action) mesecon.actions_change[i]=action end -function mesecon:register_conductor (onstate, offstate) +function mesecon:register_conductor (onstate, offstate, rules) local i=0 while mesecon.conductors[i]~=nil do i=i+1 end mesecon.conductors[i]={} - mesecon.conductors[i].on=onstate - mesecon.conductors[i].off=offstate + mesecon.conductors[i].on = onstate + mesecon.conductors[i].off = offstate + mesecon.conductors[i].rules = offstate end mesecon:add_rules("default", diff --git a/mesecons/internal.lua b/mesecons/internal.lua index d47c25c..68bc6b5 100644 --- a/mesecons/internal.lua +++ b/mesecons/internal.lua @@ -325,14 +325,15 @@ function mesecon:is_powered_by_receptor(pos) local i = 1 local j = 1 local k = 1 + local rules local pos_checked = false while mesecon.rules[i]~=nil do - j=1 + local j=1 while mesecon.rules[i].rules[j]~=nil do rcpt_pos = { - x = pos.x-mesecon.rules[i].rules[j].x, - y = pos.y-mesecon.rules[i].rules[j].y, + x = pos.x-mesecon.rules[i].rules[j].x, + y = pos.y-mesecon.rules[i].rules[j].y, z = pos.z-mesecon.rules[i].rules[j].z} k = 1 @@ -350,14 +351,15 @@ function mesecon:is_powered_by_receptor(pos) if mesecon:is_receptor_node(rcpt.name) then rules = mesecon:receptor_get_rules(rcpt) + j = 1 while rules[j] ~= nil do - if pos.x + rules[j].x == rcpt_pos.x - and pos.y + rules[j].y == rcpt_pos.y - and pos.z + rules[j].z == rcpt_pos.z then - return true + if rcpt_pos.x + rules[j].x == pos.x + and rcpt_pos.y + rules[j].y == pos.y + and rcpt_pos.z + rules[j].z == pos.z then + return true + end + j=j+1 end - j=j+1 - end end end j=j+1 diff --git a/mesecons_blinkyplant/init.lua b/mesecons_blinkyplant/init.lua index b8abac7..949e291 100644 --- a/mesecons_blinkyplant/init.lua +++ b/mesecons_blinkyplant/init.lua @@ -26,9 +26,6 @@ minetest.register_node("mesecons_blinkyplant:blinky_plant_on", { drop='"mesecons_blinkyplant:blinky_plant_off" 1', light_source = LIGHT_MAX-7, description = "Blinky Plant", - after_dig_node = function(pos) - mesecon:receptor_off(pos) - end, selection_box = { type = "fixed", fixed = {-0.1, -0.5, -0.1, 0.1, -0.5+0.6, 0.1}, diff --git a/mesecons_button/init.lua b/mesecons_button/init.lua index 7ea2210..dfccc48 100644 --- a/mesecons_button/init.lua +++ b/mesecons_button/init.lua @@ -56,9 +56,6 @@ minetest.register_node("mesecons_button:button_on", { groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon = 1}, drop = 'mesecons_button:button_off', description = "Button", - after_dig_node = function(pos, oldnode) - mesecon:receptor_off(pos, mesecon.button_get_rules(oldnode.param2)) - end }) minetest.register_on_punchnode(function(pos, node, puncher) diff --git a/mesecons_detector/init.lua b/mesecons_detector/init.lua index 3ac0a4f..145b1b7 100644 --- a/mesecons_detector/init.lua +++ b/mesecons_detector/init.lua @@ -14,9 +14,6 @@ minetest.register_node("mesecons_detector:object_detector_on", { groups = {cracky=3,not_in_creative_inventory=1, mesecon = 2}, drop = 'mesecons_detector:object_detector_off', description="Player Detector", - after_dig_node = function(pos) - mesecon:receptor_off(pos, mesecon:get_rules("pressureplate")) - end }) minetest.register_craft({ @@ -76,5 +73,5 @@ minetest.register_abm( end, }) -mesecon:add_receptor_node("mesecons_detector:object_detector_on") -mesecon:add_receptor_node_off("mesecons_detector:object_detector_off") +mesecon:add_receptor_node("mesecons_detector:object_detector_on", mesecon:get_rules("pressureplate")) +mesecon:add_receptor_node_off("mesecons_detector:object_detector_off", mesecon:get_rules("pressureplate")) diff --git a/mesecons_powerplant/init.lua b/mesecons_powerplant/init.lua index d32e838..bd94272 100644 --- a/mesecons_powerplant/init.lua +++ b/mesecons_powerplant/init.lua @@ -10,12 +10,6 @@ minetest.register_node("mesecons_powerplant:power_plant", { groups = {dig_immediate=3, mesecon = 2}, light_source = LIGHT_MAX-9, description="Power Plant", - after_place_node = function(pos) - mesecon:receptor_on(pos) - end, - after_dig_node = function(pos) - mesecon:receptor_off(pos) - end, selection_box = { type = "fixed", fixed = {-0.1, -0.5, -0.1, 0.1, -0.5+0.6, 0.1}, diff --git a/mesecons_pressureplates/init.lua b/mesecons_pressureplates/init.lua index fc23dba..cf16081 100644 --- a/mesecons_pressureplates/init.lua +++ b/mesecons_pressureplates/init.lua @@ -36,9 +36,6 @@ minetest.register_node("mesecons_pressureplates:pressure_plate_wood_on", { }, groups = {snappy=2,choppy=2,oddly_breakable_by_hand=3,not_in_creative_inventory=1, mesecon = 2}, drop='"mesecons_pressureplates:pressure_plate_wood_off" 1', - after_dig_node = function(pos) - mesecon:receptor_off(pos, mesecon:get_rules("pressureplate")) - end }) minetest.register_craft({ @@ -77,9 +74,6 @@ minetest.register_abm( end, }) -mesecon:add_receptor_node("mesecons_pressureplates:pressure_plate_wood_on") -mesecon:add_receptor_node_off("mesecons_pressureplates:pressure_plate_wood_off") - -- PRESSURE PLATE STONE minetest.register_node("mesecons_pressureplates:pressure_plate_stone_off", { @@ -118,9 +112,6 @@ minetest.register_node("mesecons_pressureplates:pressure_plate_stone_on", { }, groups = {snappy=2,choppy=2,oddly_breakable_by_hand=3,not_in_creative_inventory=1, mesecon = 2}, drop='"mesecons_pressureplates:pressure_plate_stone_off" 1', - after_dig_node = function(pos) - mesecon:receptor_off(pos, mesecon:get_rules("pressureplate")) - end }) minetest.register_craft({ @@ -159,9 +150,6 @@ minetest.register_abm( end, }) -mesecon:add_receptor_node("mesecons_pressureplates:pressure_plate_stone_on") -mesecon:add_receptor_node_off("mesecons_pressureplates:pressure_plate_stone_off") - mesecon:add_rules("pressureplate", {{x=0, y=1, z=-1}, {x=0, y=0, z=-1}, @@ -178,3 +166,9 @@ mesecon:add_rules("pressureplate", {x=0, y=-1, z=0}, {x=0, y=-2, z=0}, {x=0, y=1, z=0}}) + +mesecon:add_receptor_node("mesecons_pressureplates:pressure_plate_wood_on", mesecon:get_rules("pressureplate")) +mesecon:add_receptor_node_off("mesecons_pressureplates:pressure_plate_wood_off", mesecon:get_rules("pressureplate")) + +mesecon:add_receptor_node("mesecons_pressureplates:pressure_plate_stone_on", mesecon:get_rules("pressureplate")) +mesecon:add_receptor_node_off("mesecons_pressureplates:pressure_plate_stone_off", mesecon:get_rules("pressureplate")) diff --git a/mesecons_solarpanel/init.lua b/mesecons_solarpanel/init.lua index f26c89d..42abf55 100644 --- a/mesecons_solarpanel/init.lua +++ b/mesecons_solarpanel/init.lua @@ -23,9 +23,6 @@ minetest.register_node("mesecons_solarpanel:solar_panel", { furnace_burntime = 5, groups = {dig_immediate=3, mesecon = 2}, description="Solar Panel", - after_dig_node = function(pos, node, digger) - mesecon:receptor_off(pos) - end, }) minetest.register_craft({ diff --git a/mesecons_switch/init.lua b/mesecons_switch/init.lua index 7282e61..bca2e50 100644 --- a/mesecons_switch/init.lua +++ b/mesecons_switch/init.lua @@ -13,9 +13,6 @@ minetest.register_node("mesecons_switch:mesecon_switch_on", { groups = {dig_immediate=2,not_in_creative_inventory=1, mesecon = 2}, drop='"mesecons_switch:mesecon_switch_off" 1', description="Switch", - after_dig_node = function(pos) - mesecon:receptor_off(pos) - end }) mesecon:add_receptor_node("mesecons_switch:mesecon_switch_on") diff --git a/mesecons_torch/init.lua b/mesecons_torch/init.lua index ad2eeed..c97fec8 100644 --- a/mesecons_torch/init.lua +++ b/mesecons_torch/init.lua @@ -46,13 +46,6 @@ minetest.register_node("mesecons_torch:mesecon_torch_on", { groups = {dig_immediate=3, mesecon = 2}, light_source = LIGHT_MAX-5, description="Mesecon Torch", - after_place_node = function(pos) - local rules = mesecon.torch_get_rules(minetest.env:get_node(pos).param2) - mesecon:receptor_on(pos, rules) - end, - after_dig_node = function(pos) - mesecon:receptor_off(pos) - end }) minetest.register_abm({ diff --git a/mesecons_walllever/init.lua b/mesecons_walllever/init.lua index 6270e5e..1904085 100644 --- a/mesecons_walllever/init.lua +++ b/mesecons_walllever/init.lua @@ -59,9 +59,6 @@ minetest.register_node("mesecons_walllever:wall_lever_on", { groups = {dig_immediate=2,not_in_creative_inventory=1, mesecon = 1}, drop = '"mesecons_walllever:wall_lever_off" 1', description="Lever", - after_dig_node = function(pos, oldnode) - mesecon:receptor_off(pos, mesecon.button_get_rules(oldnode.param2)) - end }) minetest.register_on_punchnode(function(pos, node, puncher)