Re-implement settings system:

Settings can now be retrieved by mesecon.setting(<name>, <default>) and can be modified without
editing the source code by adding the setting to minetest.conf
For instance, you can add mesecon.blinky_plant_interval = 0.5 to minetest.conf in order to
increase the blinking speed.
Rewrite the blinky plant with nodetimers.
Fixes #161
This commit is contained in:
Jeija 2014-11-22 22:09:26 +01:00
parent 80d136125e
commit f977ac821a
9 changed files with 64 additions and 109 deletions

@ -57,9 +57,12 @@ local get_highest_priority = function (actions)
end
local m_time = 0
local resumetime = mesecon.setting("resumetime", 4)
minetest.register_globalstep(function (dtime)
m_time = m_time + dtime
if (m_time < MESECONS_RESUMETIME) then return end -- don't even try if server has not been running for XY seconds
-- don't even try if server has not been running for XY seconds; resumetime = time to wait
-- after starting the server before processing the ActionQueue, don't set this too low
if (m_time < resumetime) then return end
local actions = mesecon.tablecopy(mesecon.queue.actions)
local actions_now={}

@ -61,7 +61,7 @@ mesecon.do_overheat = function(pos)
heat = heat + 1
meta:set_int("heat", heat)
if heat < OVERHEAT_MAX then
if heat < mesecon.setting("overheat_max", 20) then
mesecon.queue:add_action(pos, "cooldown", {}, 1, nil, 0)
else
return true

@ -1,14 +1,10 @@
-- SETTINGS
BLINKY_PLANT_INTERVAL = 3
NEW_STYLE_WIRES = true -- true = new nodebox wires, false = old raillike wires
PRESSURE_PLATE_INTERVAL = 0.1
OBJECT_DETECTOR_RADIUS = 6
PISTON_MAXIMUM_PUSH = 15
MOVESTONE_MAXIMUM_PUSH = 100
MESECONS_RESUMETIME = 4 -- time to wait when starting the server before
-- processing the ActionQueue, don't set this too low
OVERHEAT_MAX = 20 -- maximum heat of any component that directly sends an output
-- signal when the input changes (e.g. luacontroller, gates)
-- Unit: actions per second, checks are every 1 second
STACK_SIZE = 3000 -- Recursive functions will abort when this is reached. Therefore,
-- this is also limits the maximum circuit size.
function mesecon.setting(setting, default)
if type(default) == "bool" then
return minetest.setting_getbool("mesecon."..setting) or default
elseif type(default) == "string" then
return minetest.setting_get("mesecon."..setting) or default
elseif type(default) == "number" then
return tonumber(minetest.setting_get("mesecon."..setting) or default)
end
end

@ -1,98 +1,51 @@
-- The BLINKY_PLANT
minetest.register_node("mesecons_blinkyplant:blinky_plant", {
drawtype = "plantlike",
visual_scale = 1,
tiles = {"jeija_blinky_plant_off.png"},
inventory_image = "jeija_blinky_plant_off.png",
walkable = false,
groups = {dig_immediate=3, not_in_creative_inventory=1},
drop="mesecons_blinkyplant:blinky_plant_off 1",
description="Deactivated Blinky Plant",
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},
},
mesecons = {receptor = {
state = mesecon.state.off
}},
on_rightclick = function(pos, node, clicker)
minetest.set_node(pos, {name="mesecons_blinkyplant:blinky_plant_off"})
end
})
minetest.register_node("mesecons_blinkyplant:blinky_plant_off", {
drawtype = "plantlike",
visual_scale = 1,
tiles = {"jeija_blinky_plant_off.png"},
inventory_image = "jeija_blinky_plant_off.png",
paramtype = "light",
walkable = false,
groups = {dig_immediate=3, mesecon=2},
description="Blinky Plant",
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},
},
mesecons = {receptor = {
state = mesecon.state.off
}},
on_rightclick = function(pos, node, clicker)
minetest.set_node(pos, {name="mesecons_blinkyplant:blinky_plant"})
end
})
local toggle_timer = function (pos)
local timer = minetest.get_node_timer(pos)
if timer:is_started() then
timer:stop()
else
timer:start(mesecon.setting("blinky_plant_interval", 3))
end
end
minetest.register_node("mesecons_blinkyplant:blinky_plant_on", {
drawtype = "plantlike",
visual_scale = 1,
tiles = {"jeija_blinky_plant_on.png"},
inventory_image = "jeija_blinky_plant_off.png",
paramtype = "light",
walkable = false,
groups = {dig_immediate=3, not_in_creative_inventory=1, mesecon=2},
drop="mesecons_blinkyplant:blinky_plant_off 1",
light_source = LIGHT_MAX-7,
description = "Blinky Plant",
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},
},
mesecons = {receptor = {
state = mesecon.state.on
}},
on_rightclick = function(pos, node, clicker)
minetest.set_node(pos, {name = "mesecons_blinkyplant:blinky_plant"})
local on_timer = function (pos)
local node = minetest.get_node(pos)
if(mesecon.flipstate(pos, node) == "on") then
mesecon.receptor_on(pos)
else
mesecon.receptor_off(pos)
end
toggle_timer(pos)
end
mesecon.register_node("mesecons_blinkyplant:blinky_plant", {
description="Blinky Plant",
drawtype = "plantlike",
inventory_image = "jeija_blinky_plant_off.png",
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_rightclick = toggle_timer,
on_construct = toggle_timer
},{
tiles = {"jeija_blinky_plant_off.png"},
groups = {dig_immediate=3},
mesecons = {receptor = { state = mesecon.state.off }}
},{
tiles = {"jeija_blinky_plant_on.png"},
groups = {dig_immediate=3, not_in_creative_inventory=1},
mesecons = {receptor = { state = mesecon.state.on }}
})
minetest.register_craft({
output = "mesecons_blinkyplant:blinky_plant_off 1",
recipe = {
{"","group:mesecon_conductor_craftable",""},
{"","group:mesecon_conductor_craftable",""},
{"default:sapling","default:sapling","default:sapling"},
}
recipe = { {"","group:mesecon_conductor_craftable",""},
{"","group:mesecon_conductor_craftable",""},
{"default:sapling","default:sapling","default:sapling"}}
})
minetest.register_abm({
nodenames = {
"mesecons_blinkyplant:blinky_plant_off",
"mesecons_blinkyplant:blinky_plant_on"
},
interval = BLINKY_PLANT_INTERVAL,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
if node.name == "mesecons_blinkyplant:blinky_plant_off" then
minetest.add_node(pos, {name="mesecons_blinkyplant:blinky_plant_on"})
mesecon.receptor_on(pos)
else
minetest.add_node(pos, {name="mesecons_blinkyplant:blinky_plant_off"})
mesecon.receptor_off(pos)
end
nodeupdate(pos)
end,
})

@ -23,7 +23,7 @@ end
-- returns true if player was found, false if not
local object_detector_scan = function (pos)
local objs = minetest.get_objects_inside_radius(pos, OBJECT_DETECTOR_RADIUS)
local objs = minetest.get_objects_inside_radius(pos, mesecon.setting("detector_radius", 6))
for k, obj in pairs(objs) do
local isname = obj:get_player_name() -- "" is returned if it is not a player; "" ~= nil!
local scanname = minetest.get_meta(pos):get_string("scanname")

@ -201,7 +201,8 @@ local create_environment = function(pos, mem, event)
tostring = tostring,
tonumber = tonumber,
heat = minetest.get_meta(pos):get_int("heat"),
heat_max = OVERHEAT_MAX,
-- overheat_max Unit: actions per second, checks are every 1 second
heat_max = mesecon.setting("overheat_max", 20),
string = {
byte = string.byte,
char = string.char,

@ -91,13 +91,14 @@ minetest.register_entity("mesecons_movestones:movestone_entity", {
pos.x, pos.y, pos.z = math.floor(pos.x+0.5), math.floor(pos.y+0.5), math.floor(pos.z+0.5)
local direction = mesecon.get_movestone_direction(pos)
local maxpush = mesecon.setting("movestone_max_push", 50)
if not direction then -- no mesecon power
--push only solid nodes
local name = minetest.get_node(pos).name
if name ~= "air" and name ~= "ignore"
and ((not minetest.registered_nodes[name])
or minetest.registered_nodes[name].liquidtype == "none") then
mesecon.mvps_push(pos, self.lastdir, MOVESTONE_MAXIMUM_PUSH)
mesecon.mvps_push(pos, self.lastdir, maxpush)
end
minetest.add_node(pos, {name="mesecons_movestones:movestone"})
self.object:remove()
@ -105,7 +106,7 @@ minetest.register_entity("mesecons_movestones:movestone_entity", {
end
local success, stack, oldstack =
mesecon.mvps_push(pos, direction, MOVESTONE_MAXIMUM_PUSH)
mesecon.mvps_push(pos, direction, maxpush)
if not success then -- Too large stack/stopper in the way
minetest.add_node(pos, {name="mesecons_movestones:movestone"})
self.object:remove()

@ -79,7 +79,8 @@ local piston_on = function(pos, node)
local dir = piston_get_direction(pistonspec.dir, node)
local np = mesecon.addPosRule(pos, dir)
local success, stack, oldstack = mesecon.mvps_push(np, dir, PISTON_MAXIMUM_PUSH)
local maxpush = mesecon.setting("piston_max_push", 15)
local success, stack, oldstack = mesecon.mvps_push(np, dir, maxpush)
if success then
minetest.add_node(pos, {param2 = node.param2, name = pistonspec.onname})
minetest.add_node(np, {param2 = node.param2, name = pistonspec.pusher})

@ -59,7 +59,7 @@ function mesecon.register_pressure_plate(basename, description, textures_off, te
pressureplate_basename = basename,
on_timer = pp_on_timer,
on_construct = function(pos)
minetest.get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL)
minetest.get_node_timer(pos):start(mesecon.setting("pplate_interval", 0.1))
end,
},{
mesecons = {receptor = { state = mesecon.state.off, rules = mesecon.rules.pplate }},