Skip to content

Commit f977ac8

Browse files
author
Jeija
committedNov 22, 2014
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
1 parent 80d1361 commit f977ac8

File tree

9 files changed

+57
-102
lines changed

9 files changed

+57
-102
lines changed
 

Diff for: ‎mesecons/actionqueue.lua

+4-1
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,12 @@ local get_highest_priority = function (actions)
5757
end
5858

5959
local m_time = 0
60+
local resumetime = mesecon.setting("resumetime", 4)
6061
minetest.register_globalstep(function (dtime)
6162
m_time = m_time + dtime
62-
if (m_time < MESECONS_RESUMETIME) then return end -- don't even try if server has not been running for XY seconds
63+
-- don't even try if server has not been running for XY seconds; resumetime = time to wait
64+
-- after starting the server before processing the ActionQueue, don't set this too low
65+
if (m_time < resumetime) then return end
6366
local actions = mesecon.tablecopy(mesecon.queue.actions)
6467
local actions_now={}
6568

Diff for: ‎mesecons/services.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ mesecon.do_overheat = function(pos)
6161
heat = heat + 1
6262
meta:set_int("heat", heat)
6363

64-
if heat < OVERHEAT_MAX then
64+
if heat < mesecon.setting("overheat_max", 20) then
6565
mesecon.queue:add_action(pos, "cooldown", {}, 1, nil, 0)
6666
else
6767
return true

Diff for: ‎mesecons/settings.lua

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

Diff for: ‎mesecons_blinkyplant/init.lua

+34-81
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,51 @@
11
-- The BLINKY_PLANT
2-
minetest.register_node("mesecons_blinkyplant:blinky_plant", {
3-
drawtype = "plantlike",
4-
visual_scale = 1,
5-
tiles = {"jeija_blinky_plant_off.png"},
6-
inventory_image = "jeija_blinky_plant_off.png",
7-
walkable = false,
8-
groups = {dig_immediate=3, not_in_creative_inventory=1},
9-
drop="mesecons_blinkyplant:blinky_plant_off 1",
10-
description="Deactivated Blinky Plant",
11-
sounds = default.node_sound_leaves_defaults(),
12-
selection_box = {
13-
type = "fixed",
14-
fixed = {-0.3, -0.5, -0.3, 0.3, -0.5+0.7, 0.3},
15-
},
16-
mesecons = {receptor = {
17-
state = mesecon.state.off
18-
}},
19-
on_rightclick = function(pos, node, clicker)
20-
minetest.set_node(pos, {name="mesecons_blinkyplant:blinky_plant_off"})
21-
end
22-
})
232

24-
minetest.register_node("mesecons_blinkyplant:blinky_plant_off", {
25-
drawtype = "plantlike",
26-
visual_scale = 1,
27-
tiles = {"jeija_blinky_plant_off.png"},
28-
inventory_image = "jeija_blinky_plant_off.png",
29-
paramtype = "light",
30-
walkable = false,
31-
groups = {dig_immediate=3, mesecon=2},
32-
description="Blinky Plant",
33-
sounds = default.node_sound_leaves_defaults(),
34-
selection_box = {
35-
type = "fixed",
36-
fixed = {-0.3, -0.5, -0.3, 0.3, -0.5+0.7, 0.3},
37-
},
38-
mesecons = {receptor = {
39-
state = mesecon.state.off
40-
}},
41-
on_rightclick = function(pos, node, clicker)
42-
minetest.set_node(pos, {name="mesecons_blinkyplant:blinky_plant"})
43-
end
44-
})
3+
local toggle_timer = function (pos)
4+
local timer = minetest.get_node_timer(pos)
5+
if timer:is_started() then
6+
timer:stop()
7+
else
8+
timer:start(mesecon.setting("blinky_plant_interval", 3))
9+
end
10+
end
4511

46-
minetest.register_node("mesecons_blinkyplant:blinky_plant_on", {
12+
local on_timer = function (pos)
13+
local node = minetest.get_node(pos)
14+
if(mesecon.flipstate(pos, node) == "on") then
15+
mesecon.receptor_on(pos)
16+
else
17+
mesecon.receptor_off(pos)
18+
end
19+
toggle_timer(pos)
20+
end
21+
22+
mesecon.register_node("mesecons_blinkyplant:blinky_plant", {
23+
description="Blinky Plant",
4724
drawtype = "plantlike",
48-
visual_scale = 1,
49-
tiles = {"jeija_blinky_plant_on.png"},
5025
inventory_image = "jeija_blinky_plant_off.png",
5126
paramtype = "light",
5227
walkable = false,
53-
groups = {dig_immediate=3, not_in_creative_inventory=1, mesecon=2},
54-
drop="mesecons_blinkyplant:blinky_plant_off 1",
55-
light_source = LIGHT_MAX-7,
56-
description = "Blinky Plant",
5728
sounds = default.node_sound_leaves_defaults(),
5829
selection_box = {
5930
type = "fixed",
6031
fixed = {-0.3, -0.5, -0.3, 0.3, -0.5+0.7, 0.3},
6132
},
62-
mesecons = {receptor = {
63-
state = mesecon.state.on
64-
}},
65-
on_rightclick = function(pos, node, clicker)
66-
minetest.set_node(pos, {name = "mesecons_blinkyplant:blinky_plant"})
67-
mesecon.receptor_off(pos)
68-
end
33+
on_timer = on_timer,
34+
on_rightclick = toggle_timer,
35+
on_construct = toggle_timer
36+
},{
37+
tiles = {"jeija_blinky_plant_off.png"},
38+
groups = {dig_immediate=3},
39+
mesecons = {receptor = { state = mesecon.state.off }}
40+
},{
41+
tiles = {"jeija_blinky_plant_on.png"},
42+
groups = {dig_immediate=3, not_in_creative_inventory=1},
43+
mesecons = {receptor = { state = mesecon.state.on }}
6944
})
7045

7146
minetest.register_craft({
7247
output = "mesecons_blinkyplant:blinky_plant_off 1",
73-
recipe = {
74-
{"","group:mesecon_conductor_craftable",""},
75-
{"","group:mesecon_conductor_craftable",""},
76-
{"default:sapling","default:sapling","default:sapling"},
77-
}
48+
recipe = { {"","group:mesecon_conductor_craftable",""},
49+
{"","group:mesecon_conductor_craftable",""},
50+
{"default:sapling","default:sapling","default:sapling"}}
7851
})
79-
80-
minetest.register_abm({
81-
nodenames = {
82-
"mesecons_blinkyplant:blinky_plant_off",
83-
"mesecons_blinkyplant:blinky_plant_on"
84-
},
85-
interval = BLINKY_PLANT_INTERVAL,
86-
chance = 1,
87-
action = function(pos, node, active_object_count, active_object_count_wider)
88-
if node.name == "mesecons_blinkyplant:blinky_plant_off" then
89-
minetest.add_node(pos, {name="mesecons_blinkyplant:blinky_plant_on"})
90-
mesecon.receptor_on(pos)
91-
else
92-
minetest.add_node(pos, {name="mesecons_blinkyplant:blinky_plant_off"})
93-
mesecon.receptor_off(pos)
94-
end
95-
nodeupdate(pos)
96-
end,
97-
})
98-

Diff for: ‎mesecons_detector/init.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ end
2323

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

Diff for: ‎mesecons_luacontroller/init.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ local create_environment = function(pos, mem, event)
201201
tostring = tostring,
202202
tonumber = tonumber,
203203
heat = minetest.get_meta(pos):get_int("heat"),
204-
heat_max = OVERHEAT_MAX,
204+
-- overheat_max Unit: actions per second, checks are every 1 second
205+
heat_max = mesecon.setting("overheat_max", 20),
205206
string = {
206207
byte = string.byte,
207208
char = string.char,

Diff for: ‎mesecons_movestones/init.lua

+3-2
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,22 @@ minetest.register_entity("mesecons_movestones:movestone_entity", {
9191
pos.x, pos.y, pos.z = math.floor(pos.x+0.5), math.floor(pos.y+0.5), math.floor(pos.z+0.5)
9292
local direction = mesecon.get_movestone_direction(pos)
9393

94+
local maxpush = mesecon.setting("movestone_max_push", 50)
9495
if not direction then -- no mesecon power
9596
--push only solid nodes
9697
local name = minetest.get_node(pos).name
9798
if name ~= "air" and name ~= "ignore"
9899
and ((not minetest.registered_nodes[name])
99100
or minetest.registered_nodes[name].liquidtype == "none") then
100-
mesecon.mvps_push(pos, self.lastdir, MOVESTONE_MAXIMUM_PUSH)
101+
mesecon.mvps_push(pos, self.lastdir, maxpush)
101102
end
102103
minetest.add_node(pos, {name="mesecons_movestones:movestone"})
103104
self.object:remove()
104105
return
105106
end
106107

107108
local success, stack, oldstack =
108-
mesecon.mvps_push(pos, direction, MOVESTONE_MAXIMUM_PUSH)
109+
mesecon.mvps_push(pos, direction, maxpush)
109110
if not success then -- Too large stack/stopper in the way
110111
minetest.add_node(pos, {name="mesecons_movestones:movestone"})
111112
self.object:remove()

Diff for: ‎mesecons_pistons/init.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ local piston_on = function(pos, node)
7979

8080
local dir = piston_get_direction(pistonspec.dir, node)
8181
local np = mesecon.addPosRule(pos, dir)
82-
local success, stack, oldstack = mesecon.mvps_push(np, dir, PISTON_MAXIMUM_PUSH)
82+
local maxpush = mesecon.setting("piston_max_push", 15)
83+
local success, stack, oldstack = mesecon.mvps_push(np, dir, maxpush)
8384
if success then
8485
minetest.add_node(pos, {param2 = node.param2, name = pistonspec.onname})
8586
minetest.add_node(np, {param2 = node.param2, name = pistonspec.pusher})

Diff for: ‎mesecons_pressureplates/init.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function mesecon.register_pressure_plate(basename, description, textures_off, te
5959
pressureplate_basename = basename,
6060
on_timer = pp_on_timer,
6161
on_construct = function(pos)
62-
minetest.get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL)
62+
minetest.get_node_timer(pos):start(mesecon.setting("pplate_interval", 0.1))
6363
end,
6464
},{
6565
mesecons = {receptor = { state = mesecon.state.off, rules = mesecon.rules.pplate }},

0 commit comments

Comments
 (0)
Please sign in to comment.