Port lightstones (as reference for effectors) + blinky plant to the new nodedef system

This commit is contained in:
Jeija 2012-12-08 19:02:34 +01:00
parent 472650f099
commit 8578fd89c8
3 changed files with 70 additions and 45 deletions

View File

@ -2,7 +2,7 @@
--Receptors --Receptors
function mesecon:is_receptor_node(nodename) function mesecon:is_receptor_node(nodename)
if minetest.registered_nodes[nodename] if minetest.registered_nodes[nodename]
and minetest.registered_nodes[nodename].mesecons and minetest.registered_nodes[nodename].mesecons
and minetest.registered_nodes[nodename].mesecons.receptor and minetest.registered_nodes[nodename].mesecons.receptor
and minetest.registered_nodes[nodename].mesecons.receptor.state == mesecon.state.on then and minetest.registered_nodes[nodename].mesecons.receptor.state == mesecon.state.on then
@ -43,7 +43,7 @@ function mesecon:receptor_get_rules(node)
return rules return rules
end end
end end
for i, receptor in ipairs(mesecon.receptors) do --TODO for _, receptor in ipairs(mesecon.receptors) do --TODO
if receptor.onstate == node.name or receptor.offstate == node.name then if receptor.onstate == node.name or receptor.offstate == node.name then
if receptor.get_rules ~= nil then if receptor.get_rules ~= nil then
return receptor.get_rules(node.param2) return receptor.get_rules(node.param2)
@ -59,38 +59,38 @@ end
-- Effectors -- Effectors
function mesecon:is_effector_on(nodename) function mesecon:is_effector_on(nodename)
for i, effector in ipairs(mesecon.effectors) do --TODO
if effector.onstate == nodename then
return true
end
end
if minetest.registered_nodes[nodename] if minetest.registered_nodes[nodename]
and minetest.registered_nodes[nodename].mesecons and minetest.registered_nodes[nodename].mesecons
and minetest.registered_nodes[nodename].mesecons.effector and minetest.registered_nodes[nodename].mesecons.effector
and minetest.registered_nodes[nodename].mesecons.effector.state == mesecon.state.on then and minetest.registered_nodes[nodename].mesecons.effector.state == mesecon.state.on then
return true return true
end end
for i, effector in ipairs(mesecon.effectors) do --TODO
if effector.onstate == nodename then
return true
end
end
return false return false
end end
function mesecon:is_effector_off(nodename) function mesecon:is_effector_off(nodename)
for i, effector in ipairs(mesecon.effectors) do --TODO
if effector.offstate == nodename then
return true
end
end
if minetest.registered_nodes[nodename] if minetest.registered_nodes[nodename]
and minetest.registered_nodes[nodename].mesecons and minetest.registered_nodes[nodename].mesecons
and minetest.registered_nodes[nodename].mesecons.effector and minetest.registered_nodes[nodename].mesecons.effector
and minetest.registered_nodes[nodename].mesecons.effector.state == mesecon.state.off then and minetest.registered_nodes[nodename].mesecons.effector.state == mesecon.state.off then
return true return true
end end
for i, effector in ipairs(mesecon.effectors) do --TODO
if effector.offstate == nodename then
return true
end
end
return false return false
end end
function mesecon:is_effector(nodename) function mesecon:is_effector(nodename)
if minetest.registered_nodes[nodename] if minetest.registered_nodes[nodename]
and minetest.registered_nodes[nodename].mesecons and minetest.registered_nodes[nodename].mesecons
and minetest.registered_nodes[nodename].mesecons.effector then and minetest.registered_nodes[nodename].mesecons.effector then
return true return true
end end
@ -125,22 +125,40 @@ end
--Signals --Signals
function mesecon:activate(pos) --TODO function mesecon:activate(pos)
local node = minetest.env:get_node(pos) local node = minetest.env:get_node(pos)
for i, action in ipairs(mesecon.actions_on) do if minetest.registered_nodes[node.name]
and minetest.registered_nodes[node.name].mesecons
and minetest.registered_nodes[node.name].mesecons.effector
and minetest.registered_nodes[node.name].mesecons.effector.action_on then
minetest.registered_nodes[node.name].mesecons.effector.action_on (pos, node)
end
for _, action in ipairs(mesecon.actions_on) do --TODO
action(pos, node) action(pos, node)
end end
end end
function mesecon:deactivate(pos) --TODO function mesecon:deactivate(pos) --TODO
local node = minetest.env:get_node(pos) local node = minetest.env:get_node(pos)
for i, action in ipairs(mesecon.actions_off) do if minetest.registered_nodes[node.name]
and minetest.registered_nodes[node.name].mesecons
and minetest.registered_nodes[node.name].mesecons.effector
and minetest.registered_nodes[node.name].mesecons.effector.action_off then
minetest.registered_nodes[node.name].mesecons.effector.action_off(pos, node)
end
for _, action in ipairs(mesecon.actions_off) do
action(pos, node) action(pos, node)
end end
end end
function mesecon:changesignal(pos) --TODO function mesecon:changesignal(pos) --TODO
local node = minetest.env:get_node(pos) local node = minetest.env:get_node(pos)
if minetest.registered_nodes[nodename]
and minetest.registered_nodes[nodename].mesecons
and minetest.registered_nodes[nodename].mesecons.effector
and minetest.registered_nodes[nodename].mesecons.effector.action_change then
minetest.registered_nodes[nodename].mesecons.action_change(pos, node)
end
for i, action in ipairs(mesecon.actions_change) do for i, action in ipairs(mesecon.actions_change) do
action(pos, node) action(pos, node)
end end
@ -221,7 +239,7 @@ function mesecon:is_conductor_off(nodename)
end end
function mesecon:is_conductor(nodename) function mesecon:is_conductor(nodename)
--TODO: simplify --TODO
return mesecon:is_conductor_on(nodename) or mesecon:is_conductor_off(nodename) return mesecon:is_conductor_on(nodename) or mesecon:is_conductor_off(nodename)
end end

View File

@ -13,6 +13,9 @@ minetest.register_node("mesecons_blinkyplant:blinky_plant_off", {
type = "fixed", type = "fixed",
fixed = {-0.1, -0.5, -0.1, 0.1, -0.5+0.6, 0.1}, fixed = {-0.1, -0.5, -0.1, 0.1, -0.5+0.6, 0.1},
}, },
mesecons = {receptor = {
state = mesecon.state.off
}}
}) })
minetest.register_node("mesecons_blinkyplant:blinky_plant_on", { minetest.register_node("mesecons_blinkyplant:blinky_plant_on", {
@ -30,6 +33,9 @@ minetest.register_node("mesecons_blinkyplant:blinky_plant_on", {
type = "fixed", type = "fixed",
fixed = {-0.1, -0.5, -0.1, 0.1, -0.5+0.6, 0.1}, fixed = {-0.1, -0.5, -0.1, 0.1, -0.5+0.6, 0.1},
}, },
mesecons = {receptor = {
state = mesecon.state.on
}}
}) })
minetest.register_craft({ minetest.register_craft({

View File

@ -1,30 +1,32 @@
function mesecon:lightstone_add(name, base_item, texture_off, texture_on) function mesecon:lightstone_add(name, base_item, texture_off, texture_on)
minetest.register_node("mesecons_lightstone:lightstone_" .. name .. "_off", { minetest.register_node("mesecons_lightstone:lightstone_" .. name .. "_off", {
tiles = {texture_off}, tiles = {texture_off},
inventory_image = minetest.inventorycube(texture_off), inventory_image = minetest.inventorycube(texture_off),
groups = {cracky=2, mesecon_effector_off = 1, mesecon = 2}, groups = {cracky=2, mesecon_effector_off = 1, mesecon = 2},
description=name.." Lightstone", description=name.." Lightstone",
mesecons = {effector = {
state = mesecon.state.off,
action_on = function (pos, node)
minetest.env:add_node(pos, {name="mesecons_lightstone:lightstone_" .. name .. "_on"})
mesecon:receptor_on(pos)
end
}}
}) })
minetest.register_node("mesecons_lightstone:lightstone_" .. name .. "_on", { minetest.register_node("mesecons_lightstone:lightstone_" .. name .. "_on", {
tiles = {texture_on}, tiles = {texture_on},
inventory_image = minetest.inventorycube(texture_on), inventory_image = minetest.inventorycube(texture_on),
groups = {cracky=2,not_in_creative_inventory=1, mesecon = 2}, groups = {cracky=2,not_in_creative_inventory=1, mesecon = 2},
drop = "node mesecons_lightstone:lightstone_" .. name .. "_off 1", drop = "node mesecons_lightstone:lightstone_" .. name .. "_off 1",
light_source = LIGHT_MAX-2, light_source = LIGHT_MAX-2,
description=name.." Lightstone", mesecons = {effector = {
state = mesecon.state.on,
action_off = function (pos, node)
minetest.env:add_node(pos, {name="mesecons_lightstone:lightstone_" .. name .. "_off"})
mesecon:receptor_off(pos)
end
}}
}) })
assert(loadstring('mesecon:register_on_signal_on(function(pos, node) \n \
if node.name == "mesecons_lightstone:lightstone_' .. name .. '_off" then \n \
minetest.env:add_node(pos, {name="mesecons_lightstone:lightstone_' .. name .. '_on"}) \n \
nodeupdate(pos) \n \
end \n \
end)'))()
assert(loadstring('mesecon:register_on_signal_off(function(pos, node) \n \
if node.name == "mesecons_lightstone:lightstone_' .. name .. '_on" then \n \
minetest.env:add_node(pos, {name="mesecons_lightstone:lightstone_' .. name .. '_off"}) \n \
nodeupdate(pos) \n \
end \n \
end)'))()
minetest.register_craft({ minetest.register_craft({
output = "node mesecons_lightstone:lightstone_" .. name .. "_off 1", output = "node mesecons_lightstone:lightstone_" .. name .. "_off 1",
recipe = { recipe = {
@ -33,7 +35,6 @@ function mesecon:lightstone_add(name, base_item, texture_off, texture_on)
{'','group:mesecon_conductor_craftable',''}, {'','group:mesecon_conductor_craftable',''},
} }
}) })
mesecon:register_effector("mesecons_lightstone:lightstone_" .. name .. "_on", "mesecons_lightstone:lightstone_" .. name .. "_off")
end end