@@ 9,6 9,7 @@ function falling_nodes.register_material(name, original_def)
falling_nodes.registered_materials[name] = {}
-- TODO validation
for _,field in ipairs {
+ "electricity_action",
} do
falling_nodes.registered_materials[name][field] = def[field]
def[field] = nil
@@ 181,7 182,12 @@ falling_nodes.register_material("falling_nodes:metal", {
tiles = {"[fill:1x1:#404060"},
groups = {
["falling_nodes:solid"] = 1,
+ ["falling_nodes:conductive"] = 1,
},
+ electricity_action = function(pos)
+ minetest.swap_node(pos, {name = "falling_nodes:metal_powered"})
+ minetest.get_node_timer(pos):start(METAL_POWERED_DECAY_TIME)
+ end,
})
falling_nodes.register_material("falling_nodes:metal_powered", {
@@ 197,9 203,9 @@ falling_nodes.register_material("falling_nodes:metal_powered", {
on_timer = function(pos)
minetest.swap_node(pos, {name = "falling_nodes:metal_semi_powered"})
for _,p in ipairs(utils.get_neighbors(pos)) do
- if minetest.get_node(p).name == "falling_nodes:metal" then
- minetest.swap_node(p, {name = "falling_nodes:metal_powered"})
- minetest.get_node_timer(p):start(METAL_POWERED_DECAY_TIME)
+ local name = minetest.get_node(p).name
+ if minetest.get_item_group(name, "falling_nodes:conductive") == 1 then
+ falling_nodes.registered_materials[name].electricity_action(p)
end
end
minetest.get_node_timer(pos):start(METAL_SEMI_POWERED_DECAY_TIME)
@@ 232,13 238,12 @@ falling_nodes.register_material("falling_nodes:battery", {
minetest.register_abm {
label = "Battery power generation",
- nodenames = {"falling_nodes:metal"},
+ nodenames = {"group:falling_nodes:conductive"},
neighbors = {"falling_nodes:battery"},
interval = minetest.settings:get("abm_interval") * 4,
chance = 1,
catch_up = false,
- action = function(pos)
- minetest.swap_node(pos, {name = "falling_nodes:metal_powered"})
- minetest.get_node_timer(pos):start(METAL_POWERED_DECAY_TIME)
+ action = function(pos, node)
+ falling_nodes.registered_materials[node.name].electricity_action(pos)
end,
}
@@ 4,9 4,9 @@ minetest.register_tool("falling_nodes:spark", {
inventory_image = "[fill:1x1:#FFFF80",
on_place = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.under
- if minetest.get_node(pos).name == "falling_nodes:metal" then
- minetest.swap_node(pos, {name = "falling_nodes:metal_powered"})
- minetest.get_node_timer(pos):start(0)
+ local name = minetest.get_node(pos).name
+ if minetest.get_item_group(name, "falling_nodes:conductive") == 1 then
+ falling_nodes.registered_materials[name].electricity_action(pos)
end
end,
})