2015-08-28 12:24:33 +02:00
|
|
|
local toggle_timer = function (pos, restart)
|
|
|
|
local timer = minetest.get_node_timer(pos)
|
2016-04-27 18:42:20 +02:00
|
|
|
if timer:is_started()
|
|
|
|
and not restart then
|
2015-08-28 12:24:33 +02:00
|
|
|
timer:stop()
|
|
|
|
else
|
2016-04-27 18:42:20 +02:00
|
|
|
timer:start(tonumber(minetest.get_meta(pos):get_string("interval")) or 0)
|
2015-08-28 12:24:33 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-27 18:42:20 +02:00
|
|
|
local on_timer = function(pos)
|
|
|
|
if mesecon.flipstate(pos, minetest.get_node(pos)) == "on" then
|
2015-08-28 12:24:33 +02:00
|
|
|
mesecon.receptor_on(pos)
|
|
|
|
else
|
|
|
|
mesecon.receptor_off(pos)
|
|
|
|
end
|
|
|
|
toggle_timer(pos, false)
|
|
|
|
end
|
|
|
|
|
|
|
|
mesecon.register_node("moremesecons_adjustable_blinkyplant:adjustable_blinky_plant", {
|
|
|
|
description="Adjustable Blinky Plant",
|
|
|
|
drawtype = "plantlike",
|
2015-08-30 11:49:32 +02:00
|
|
|
inventory_image = "moremesecons_blinky_plant_off.png",
|
2015-08-28 12:24:33 +02:00
|
|
|
paramtype = "light",
|
|
|
|
walkable = false,
|
|
|
|
sounds = default.node_sound_leaves_defaults(),
|
|
|
|
selection_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {-0.3, -0.5, -0.3, 0.3, -0.5+0.7, 0.3},
|
|
|
|
},
|
|
|
|
on_timer = on_timer,
|
|
|
|
on_construct = function(pos)
|
2016-04-27 18:42:20 +02:00
|
|
|
minetest.get_meta(pos):set_string("formspec", "field[interval;interval;${interval}]")
|
2015-08-28 12:24:33 +02:00
|
|
|
toggle_timer(pos, true)
|
|
|
|
end,
|
2016-04-27 18:42:20 +02:00
|
|
|
on_receive_fields = function(pos, _, fields, player)
|
|
|
|
local interval = tonumber(fields.interval)
|
|
|
|
if interval
|
|
|
|
and not minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
minetest.get_meta(pos):set_string("interval", interval)
|
|
|
|
toggle_timer(pos, true)
|
|
|
|
end
|
|
|
|
end,
|
2015-08-28 12:24:33 +02:00
|
|
|
},{
|
2015-08-30 11:49:32 +02:00
|
|
|
tiles = {"moremesecons_blinky_plant_off.png"},
|
2015-08-28 12:24:33 +02:00
|
|
|
groups = {dig_immediate=3},
|
|
|
|
mesecons = {receptor = { state = mesecon.state.off }}
|
|
|
|
},{
|
2015-08-30 11:49:32 +02:00
|
|
|
tiles = {"moremesecons_blinky_plant_on.png"},
|
2015-08-28 12:24:33 +02:00
|
|
|
groups = {dig_immediate=3, not_in_creative_inventory=1},
|
|
|
|
mesecons = {receptor = { state = mesecon.state.on }},
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "moremesecons_adjustable_blinkyplant:adjustable_blinky_plant_off 1",
|
|
|
|
recipe = { {"mesecons_blinkyplant:blinky_plant_off"},
|
|
|
|
{"default:mese_crystal_fragment"},}
|
|
|
|
})
|