mesecons_solarpanel: replace ABM on node timer

This commit is contained in:
MoNTE48 2020-04-04 17:38:36 +02:00
parent 70ddf1ed8e
commit 1e20c351be
3 changed files with 56 additions and 28 deletions

View File

@ -1,6 +1,5 @@
-- Solar Panel
mesecon.register_node("mesecons_solarpanel:solar_panel", {
description = "Solar Panel",
drawtype = "nodebox",
tiles = {"mesecons_solarpanel.png"},
inventory_image = "mesecons_solarpanel.png",
@ -15,8 +14,31 @@ mesecon.register_node("mesecons_solarpanel:solar_panel", {
wall_side = {-1/7, -0.5, -0.5, -0.5, 0.5, 0.5}
},
sounds = default.node_sound_glass_defaults(),
on_blast = mesecon.on_blastnode
on_blast = mesecon.on_blastnode,
on_timer = function(pos)
local light = minetest.get_node_light(pos)
local node = minetest.get_node(pos)
if light >= 10 and node.name == "mesecons_solarpanel:solar_panel_off" then
node.name = "mesecons_solarpanel:solar_panel_on"
minetest.swap_node(pos, node)
mesecon.receptor_on(pos, mesecon.rules.wallmounted_get(node))
elseif light < 10 and node.name == "mesecons_solarpanel:solar_panel_on" then
node.name = "mesecons_solarpanel:solar_panel_off"
minetest.swap_node(pos, node)
mesecon.receptor_off(pos, mesecon.rules.wallmounted_get(node))
end
return true
end,
on_construct = function(pos)
minetest.get_node_timer(pos):start(mesecon.setting("spanel_interval", 1))
end
},{
description = "Solar Panel",
groups = {dig_immediate = 3, attached_node = 1},
mesecons = {receptor = {
state = mesecon.state.off,
@ -38,29 +60,3 @@ minetest.register_craft({
{"group:wood", "group:wood", "group:wood"}
}
})
minetest.register_abm({
label = "Solar Panel On/Off",
nodenames = {
"mesecons_solarpanel:solar_panel_off",
"mesecons_solarpanel:solar_panel_on"
},
interval = 3,
chance = 1,
catch_up = false,
action = function(pos, node)
local light = minetest.get_node_light(pos)
if light >= 10 and node.name == "mesecons_solarpanel:solar_panel_off" then
node.name = "mesecons_solarpanel:solar_panel_on"
minetest.swap_node(pos, node)
mesecon.receptor_on(pos, mesecon.rules.wallmounted_get(node))
elseif light < 10 and node.name == "mesecons_solarpanel:solar_panel_on" then
node.name = "mesecons_solarpanel:solar_panel_off"
minetest.swap_node(pos, node)
mesecon.receptor_off(pos, mesecon.rules.wallmounted_get(node))
end
end
})
minetest.register_alias("mesecons_solarpanel:solar_panel_inverted_on", "mesecons_solarpanel:solar_panel_on")
minetest.register_alias("mesecons_solarpanel:solar_panel_inverted_off", "mesecons_solarpanel:solar_panel_off")

View File

@ -1,2 +1,3 @@
default
mesecons_pistons
mesecons_solarpanel

View File

@ -28,3 +28,34 @@ for _, n in pairs({"1", "2", "3", "11", "12", "13", "14",
"21", "22", "23", "24", "32", "33", "34", "35"}) do
minetest.register_alias("fences:fence_wood_" .. n, "default:fence_wood")
end
--== mesecons_solarpanel ==--
minetest.register_lbm({
label = "Enable timer on ABM Solar Panels",
name = ":mesecons_solarpanel:timer_start",
nodenames = {"mesecons_solarpanel:solar_panel_off", "mesecons_solarpanel:solar_panel_on"},
run_at_every_load = false,
action = function(pos)
minetest.get_node_timer(pos):start(mesecon.setting("spanel_interval", 1))
end
})
minetest.register_alias("mesecons_solarpanel:solar_panel_inverted_off", "mesecons_solarpanel:solar_panel_off")
minetest.register_alias("mesecons_solarpanel:solar_panel_inverted_on", "mesecons_solarpanel:solar_panel_on")
--== Potions ==--
minetest.register_alias("potionspack:antigravity", "pep:grav0")
minetest.register_alias("potionspack:antigravityii", "pep:gravreset")
minetest.register_alias("potionspack:speed", "pep:speedminus")
minetest.register_alias("potionspack:speedii", "pep:speedplus")
minetest.register_alias("potionspack:inversion", "pep:invisible")
minetest.register_alias("potionspack:confusion", "pep:breath")
minetest.register_alias("potionspack:whatwillthisdo", "pep:mole")
minetest.register_alias("potionspack:instanthealth", "pep:regen")
minetest.register_alias("potionspack:instanthealthii", "pep:regen2")
minetest.register_alias("potionspack:regen", "pep:regen")
minetest.register_alias("potionspack:regenii", "pep:regen2")
minetest.register_alias("potionspack:harming", "pep:gravreset")
minetest.register_alias("potionspack:harmingii", "pep:gravreset")
minetest.register_alias("pep:jumpreset", "pep:nightvision")
minetest.register_alias("pep:speedreset", "pep:invisible")