Code cleanup, little bugfix (some conductors placed next to receptors didn't turn on)

This commit is contained in:
Jeija 2012-08-13 13:12:19 +02:00
parent 987de2c7d5
commit b197d29bef
11 changed files with 23 additions and 57 deletions

@ -191,7 +191,7 @@ 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
@ -199,6 +199,7 @@ function mesecon:register_conductor (onstate, offstate)
mesecon.conductors[i]={}
mesecon.conductors[i].on = onstate
mesecon.conductors[i].off = offstate
mesecon.conductors[i].rules = offstate
end
mesecon:add_rules("default",

@ -325,10 +325,11 @@ 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,
@ -350,10 +351,11 @@ 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
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

@ -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},

@ -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)

@ -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"))

@ -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},

@ -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"))

@ -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({

@ -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")

@ -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({

@ -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)