V1.02 Timer improvements for unloaded areas

This commit is contained in:
Joachim Stolberg 2018-03-27 19:43:06 +02:00
parent 3b815f8031
commit c60ed39ed4
3 changed files with 29 additions and 22 deletions

@ -1,4 +1,4 @@
# TechPack V1.01 # TechPack V1.02
TechPack, a Mining, Crafting, & Farming Modpack for Minetest. TechPack, a Mining, Crafting, & Farming Modpack for Minetest.
@ -73,4 +73,4 @@ Gravelsieve optional: moreores, hopper, pipeworks
### History ### History
- 2018-03-18 V1.00 * Tubelib, tubelib_addons1, tubelib_addons2, smartline, and gravelsieve combined to one modpack. - 2018-03-18 V1.00 * Tubelib, tubelib_addons1, tubelib_addons2, smartline, and gravelsieve combined to one modpack.
- 2018-03-24 V1.01 * Support for Ethereal added - 2018-03-24 V1.01 * Support for Ethereal added
- 2018-03-27 V1.02 * Timer improvements for unloaded areas

@ -99,6 +99,14 @@ local function check_rules(pos,elapsed)
for idx,act in ipairs(actions) do for idx,act in ipairs(actions) do
if act ~= "" and numbers[idx] ~= "" then if act ~= "" and numbers[idx] ~= "" then
local hr = (events[idx] - 1) * 2 local hr = (events[idx] - 1) * 2
if ((hour - hr) % 24) <= 4 then -- last 4 hours?
if done[idx] == false then -- not already executed?
tubelib.send_message(numbers[idx], placer_name, nil, act, own_num)
done[idx] = true
end
else
done[idx] = false
end
if hour == hr and done[idx] == false then if hour == hr and done[idx] == false then
tubelib.send_message(numbers[idx], placer_name, nil, act, own_num) tubelib.send_message(numbers[idx], placer_name, nil, act, own_num)
done[idx] = true done[idx] = true
@ -218,26 +226,16 @@ minetest.register_craft({
}) })
minetest.register_lbm({ minetest.register_lbm({
label = "[Tubelib] Timer update", label = "[SmartLine] Timer update",
name = "smartline:update", name = "smartline:update",
nodenames = {"smartline:timer"}, nodenames = {"smartline:timer"},
run_at_every_load = false, run_at_every_load = true,
action = function(pos, node) action = function(pos, node)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local events = minetest.deserialize(meta:get_string("events")) -- check rules for just loaded areas
local numbers = minetest.deserialize(meta:get_string("numbers")) local done = {false,false,false,false,false,false}
local actions = {} meta:set_string("done", minetest.serialize(done))
for _,a in ipairs(minetest.deserialize(meta:get_string("actions"))) do check_rules(pos,0)
if a == "start" then
actions[#actions+1] = "on"
elseif a == "stop" then
actions[#actions+1] = "off"
else
actions[#actions+1] = a
end
end
meta:set_string("actions", minetest.serialize(actions))
meta:set_string("formspec", formspec(events, numbers, actions))
end end
}) })

@ -80,9 +80,13 @@ local function check_rules(pos,elapsed)
for idx,act in ipairs(actions) do for idx,act in ipairs(actions) do
if act ~= "" and numbers[idx] ~= "" then if act ~= "" and numbers[idx] ~= "" then
local hr = (events[idx] - 1) * 2 local hr = (events[idx] - 1) * 2
if hour == hr and done[idx] == false then if ((hour - hr) % 24) <= 4 then -- last 4 hours?
tubelib.send_message(numbers[idx], placer_name, nil, act, number) if done[idx] == false then -- not already executed?
done[idx] = true tubelib.send_message(numbers[idx], placer_name, nil, act, number)
done[idx] = true
end
else
done[idx] = false
end end
end end
end end
@ -186,9 +190,14 @@ minetest.register_lbm({
label = "[Tubelib] Timer update", label = "[Tubelib] Timer update",
name = "tubelib_addons2:update", name = "tubelib_addons2:update",
nodenames = {"tubelib_addons2:timer"}, nodenames = {"tubelib_addons2:timer"},
run_at_every_load = false, run_at_every_load = true,
action = function(pos, node) action = function(pos, node)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
-- check rules for just loaded areas
local done = {false,false,false,false,false,false}
meta:set_string("done", minetest.serialize(done))
check_rules(pos,0)
local events = minetest.deserialize(meta:get_string("events")) local events = minetest.deserialize(meta:get_string("events"))
local numbers = minetest.deserialize(meta:get_string("numbers")) local numbers = minetest.deserialize(meta:get_string("numbers"))
local actions = {} local actions = {}