@@ 171,3 171,90 @@ minetest.register_node("falling_nodes:wood", {
dig_immediate = 3,
},
})
+
+-- Electronics
+--------------
+
+-- Time from powered to semi_powered.
+local METAL_POWERED_DECAY_TIME = minetest.settings:get("abm_interval") * 2
+-- Time from semi_powered to normal metal.
+-- Has to be a certain amount higher than METAL_POWERED_DECAY_TIME to avoid
+-- producing electricity loops (semi_powered metal is not conductive).
+local METAL_SEMI_POWERED_DECAY_TIME = METAL_POWERED_DECAY_TIME * 3
+
+minetest.register_node("falling_nodes:metal", {
+ description = "Metal",
+ tiles = {"[fill:1x1:#404060"},
+ groups = {
+ ["falling_nodes:material"] = 1,
+ ["falling_nodes:solid"] = 1,
+ dig_immediate = 3,
+ },
+})
+
+minetest.register_node("falling_nodes:metal_powered", {
+ description = "Metal (powered)",
+ tiles = {"[fill:1x1:#FFFF80"},
+ groups = {
+ ["falling_nodes:material"] = 1,
+ ["falling_nodes:solid"] = 1,
+ dig_immediate = 3,
+ not_in_creative_inventory = 1,
+ },
+ on_construct = function(pos)
+ minetest.get_node_timer(pos):start(METAL_POWERED_DECAY_TIME)
+ end,
+ 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)
+ end
+ end
+ minetest.get_node_timer(pos):start(METAL_SEMI_POWERED_DECAY_TIME)
+ end,
+})
+
+minetest.register_node("falling_nodes:metal_semi_powered", {
+ description = "Metal (unpowering)",
+ tiles = {"[fill:1x1:#9F9F70"},
+ groups = {
+ ["falling_nodes:material"] = 1,
+ ["falling_nodes:solid"] = 1,
+ dig_immediate = 3,
+ not_in_creative_inventory = 1,
+ },
+ on_construct = function(pos)
+ minetest.get_node_timer(pos):start(METAL_SEMI_POWERED_DECAY_TIME)
+ end,
+ on_timer = function(pos)
+ minetest.swap_node(pos, {name = "falling_nodes:metal"})
+ end,
+})
+
+minetest.register_node("falling_nodes:battery", {
+ description = "Battery\nGenerates electricity",
+ short_description = "Battery",
+ tiles = {"[fill:1x1:#858505"},
+ groups = {
+ ["falling_nodes:material"] = 1,
+ ["falling_nodes:solid"] = 1,
+ dig_immediate = 3,
+ },
+})
+
+minetest.register_abm {
+ label = "Battery power generation",
+ nodenames = {"falling_nodes:metal"},
+ 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)
+ end,
+}
+
+-- TODO add spark tool