From a7a6b50492eb199780461c597d56fe22a7c5cd0c Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Tue, 23 Apr 2019 21:46:08 +0200 Subject: [PATCH] V2.03, Piston/WorldEdit/replacer detection added, farming and grinder recipes added --- README.md | 1 + releasenotes.md | 16 +++ sl_controller/server.lua | 13 ++- smartline/button.lua | 76 ++++++------- smartline/collector.lua | 43 ++++---- smartline/controller.lua | 21 ++-- smartline/display.lua | 7 +- smartline/playerdetector.lua | 13 ++- smartline/repeater.lua | 9 +- smartline/sequencer.lua | 59 +++++----- smartline/timer.lua | 61 ++++++----- techpack_warehouse/common.lua | 59 +++++----- tubelib/button.lua | 76 ++++++------- tubelib/defect.lua | 48 +++++++++ tubelib/distributor.lua | 9 +- tubelib/init.lua | 1 + tubelib/legacy_nodes.lua | 28 +++++ tubelib/node_states.lua | 14 +-- tubelib/pusher.lua | 9 +- tubelib_addons1/README.md | 6 ++ tubelib_addons1/autocrafter.lua | 15 +-- tubelib_addons1/detector.lua | 38 ++++--- tubelib_addons1/fermenter.lua | 9 +- tubelib_addons1/grinder.lua | 11 +- tubelib_addons1/harvester.lua | 39 +++---- tubelib_addons1/liquidsampler.lua | 9 +- tubelib_addons1/nodes.lua | 60 +++++++++++ tubelib_addons1/pusher_fast.lua | 9 +- tubelib_addons1/quarry.lua | 9 +- tubelib_addons1/reformer.lua | 9 +- tubelib_addons2/accesscontrol.lua | 44 ++++---- tubelib_addons2/logic_not.lua | 28 ++--- tubelib_addons2/mesecons_converter.lua | 9 +- tubelib_addons2/repeater.lua | 9 +- tubelib_addons2/sequencer.lua | 143 +++++++++++++------------ tubelib_addons2/timer.lua | 57 +++++----- tubelib_addons3/distributor.lua | 9 +- tubelib_addons3/pusher.lua | 9 +- tubelib_addons3/pushing_chest.lua | 49 +++++---- 39 files changed, 692 insertions(+), 442 deletions(-) create mode 100644 tubelib/defect.lua diff --git a/README.md b/README.md index 2d76c5b..eeaad8e 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,7 @@ tubelib_addons1 optional: unified_inventory - 2019-01-12 V2.00 * release - 2019-01-27 V2.01 * SaferLua Controller Terminal added - 2019-01-28 V2.02 * Logic Not added, output reduction on Harvester, Fermenter, and Gravel Sieve +- 2019-04-23 V2.03 * Piston/WorldEdit/replacer detection added, farming and grinder recipes added ## New in v2 (from players point of view) diff --git a/releasenotes.md b/releasenotes.md index 6d143e0..e1feebe 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -1,5 +1,21 @@ # Release Notes for ModPack TechPack [techpack] +2019-04-23 V2.03 * , + +## V2.03 (2019-04-23) + +### Additions +- Farming and Grinder recipes added (thanks to obl3pplifp) +- Support for Signs Bot chest and Box added + +### Removals + +### Changes + +### Fixes +- Piston/WorldEdit/Replacer tool detection added. If node is replaced/removed/copied, + it will switch to a "defect" dummy node. + ## V2.02.06 (2019-03-23) diff --git a/sl_controller/server.lua b/sl_controller/server.lua index 02b15df..01178a9 100644 --- a/sl_controller/server.lua +++ b/sl_controller/server.lua @@ -33,11 +33,14 @@ end local function on_time(pos, elasped) - local meta = minetest.get_meta(pos) - local number = meta:get_string("number") - local mem = tubelib.get_data(number, "memory") or table.copy(DEFAULT_MEM) - meta:set_string("infotext", "Server "..number..": ("..(mem.size or 0).."/"..SERVER_CAPA..")") - return true + if tubelib.data_not_corrupted(pos) then + local meta = minetest.get_meta(pos) + local number = meta:get_string("number") + local mem = tubelib.get_data(number, "memory") or table.copy(DEFAULT_MEM) + meta:set_string("infotext", "Server "..number..": ("..(mem.size or 0).."/"..SERVER_CAPA..")") + return true + end + return false end minetest.register_node("sl_controller:server", { diff --git a/smartline/button.lua b/smartline/button.lua index 1b55e69..6b2b087 100644 --- a/smartline/button.lua +++ b/smartline/button.lua @@ -15,47 +15,51 @@ local function switch_on(pos, node) - node.name = "smartline:button_active" - minetest.swap_node(pos, node) - minetest.sound_play("button", { - pos = pos, - gain = 0.5, - max_hear_distance = 5, - }) - local meta = minetest.get_meta(pos) - local own_num = meta:get_string("own_num") - local numbers = meta:get_string("numbers") - local cycle_time = meta:get_int("cycle_time") - if cycle_time > 0 then -- button mode? - minetest.get_node_timer(pos):start(cycle_time) + if tubelib.data_not_corrupted(pos) then + node.name = "smartline:button_active" + minetest.swap_node(pos, node) + minetest.sound_play("button", { + pos = pos, + gain = 0.5, + max_hear_distance = 5, + }) + local meta = minetest.get_meta(pos) + local own_num = meta:get_string("own_num") + local numbers = meta:get_string("numbers") + local cycle_time = meta:get_int("cycle_time") + if cycle_time > 0 then -- button mode? + minetest.get_node_timer(pos):start(cycle_time) + end + local placer_name = meta:get_string("placer_name") + local clicker_name = nil + if meta:get_string("public") == "false" then + clicker_name = meta:get_string("clicker_name") + end + tubelib.send_message(numbers, placer_name, clicker_name, "on", own_num) end - local placer_name = meta:get_string("placer_name") - local clicker_name = nil - if meta:get_string("public") == "false" then - clicker_name = meta:get_string("clicker_name") - end - tubelib.send_message(numbers, placer_name, clicker_name, "on", own_num) end local function switch_off(pos) - local node = minetest.get_node(pos) - node.name = "smartline:button" - minetest.swap_node(pos, node) - minetest.get_node_timer(pos):stop() - minetest.sound_play("button", { - pos = pos, - gain = 0.5, - max_hear_distance = 5, - }) - local meta = minetest.get_meta(pos) - local own_num = meta:get_string("own_num") - local numbers = meta:get_string("numbers") - local placer_name = meta:get_string("placer_name") - local clicker_name = nil - if meta:get_string("public") == "false" then - clicker_name = meta:get_string("clicker_name") + if tubelib.data_not_corrupted(pos) then + local node = minetest.get_node(pos) + node.name = "smartline:button" + minetest.swap_node(pos, node) + minetest.get_node_timer(pos):stop() + minetest.sound_play("button", { + pos = pos, + gain = 0.5, + max_hear_distance = 5, + }) + local meta = minetest.get_meta(pos) + local own_num = meta:get_string("own_num") + local numbers = meta:get_string("numbers") + local placer_name = meta:get_string("placer_name") + local clicker_name = nil + if meta:get_string("public") == "false" then + clicker_name = meta:get_string("clicker_name") + end + tubelib.send_message(numbers, placer_name, clicker_name, "off", own_num) end - tubelib.send_message(numbers, placer_name, clicker_name, "off", own_num) end diff --git a/smartline/collector.lua b/smartline/collector.lua index 0c31bf5..d307d0d 100644 --- a/smartline/collector.lua +++ b/smartline/collector.lua @@ -67,27 +67,30 @@ end local function on_timer(pos,elapsed) - local meta = minetest.get_meta(pos) - local poll_numbers = meta:get_string("poll_numbers") - local idx = meta:get_int("index") + 1 - - if poll_numbers == "" then - local own_number = meta:get_string("own_number") - meta:set_string("infotext", "SmartLine State Collector "..own_number..": stopped") - meta:set_int("state", 0) - meta:set_int("stored_state", 0) - return false + if tubelib.data_not_corrupted(pos) then + local meta = minetest.get_meta(pos) + local poll_numbers = meta:get_string("poll_numbers") + local idx = meta:get_int("index") + 1 + + if poll_numbers == "" then + local own_number = meta:get_string("own_number") + meta:set_string("infotext", "SmartLine State Collector "..own_number..": stopped") + meta:set_int("state", 0) + meta:set_int("stored_state", 0) + return false + end + + if idx > meta:get_int("num_numbers") then + idx = 1 + send_event(meta) + end + meta:set_int("index", idx) + + request_state(meta, poll_numbers, idx) + + return true end - - if idx > meta:get_int("num_numbers") then - idx = 1 - send_event(meta) - end - meta:set_int("index", idx) - - request_state(meta, poll_numbers, idx) - - return true + return false end minetest.register_node("smartline:collector", { diff --git a/smartline/controller.lua b/smartline/controller.lua index 22b40f8..1d4b6da 100644 --- a/smartline/controller.lua +++ b/smartline/controller.lua @@ -578,16 +578,19 @@ local function execute(meta, number, debug) end local function check_rules(pos, elapsed) - --local t = minetest.get_us_time() - local meta = minetest.get_meta(pos) - meta:set_int("runtime", (meta:get_int("runtime") or 1) + 1) - local number = meta:get_string("number") - local state = meta:get_int("state") - if state == tubelib.RUNNING and number then - execute(meta, number, debug) + if tubelib.data_not_corrupted(pos) then + --local t = minetest.get_us_time() + local meta = minetest.get_meta(pos) + meta:set_int("runtime", (meta:get_int("runtime") or 1) + 1) + local number = meta:get_string("number") + local state = meta:get_int("state") + if state == tubelib.RUNNING and number then + execute(meta, number, debug) + end + --print("time", minetest.get_us_time() - t) + return true end - --print("time", minetest.get_us_time() - t) - return true + return false end local function switch_state(pos, state, fs_data) diff --git a/smartline/display.lua b/smartline/display.lua index 752862c..62d8b26 100644 --- a/smartline/display.lua +++ b/smartline/display.lua @@ -28,8 +28,11 @@ local function display_update(pos, objref) end local function on_timer(pos) - local meta = minetest.get_meta(pos) - lcdlib.update_entities(pos) + if tubelib.data_not_corrupted(pos) then + local meta = minetest.get_meta(pos) + lcdlib.update_entities(pos) + return false + end return false end diff --git a/smartline/playerdetector.lua b/smartline/playerdetector.lua index 8c3f751..eca6707 100644 --- a/smartline/playerdetector.lua +++ b/smartline/playerdetector.lua @@ -139,12 +139,15 @@ minetest.register_node("smartline:playerdetector", { end, on_timer = function (pos, elapsed) - if scan_for_player(pos) then - switch_on(pos) - minetest.get_node_timer(pos):start(1) - return false + if tubelib.data_not_corrupted(pos) then + if scan_for_player(pos) then + switch_on(pos) + minetest.get_node_timer(pos):start(1) + return false + end + return true end - return true + return false end, paramtype = "light", diff --git a/smartline/repeater.lua b/smartline/repeater.lua index 3868f4b..a942bd2 100644 --- a/smartline/repeater.lua +++ b/smartline/repeater.lua @@ -75,9 +75,12 @@ minetest.register_node("smartline:repeater", { end, on_timer = function(pos,elapsed) - local meta = minetest.get_meta(pos) - meta:set_int("overload_cnt", 0) - return true + if tubelib.data_not_corrupted(pos) then + local meta = minetest.get_meta(pos) + meta:set_int("overload_cnt", 0) + return true + end + return false end, after_dig_node = function(pos) diff --git a/smartline/sequencer.lua b/smartline/sequencer.lua index 440b624..8758c38 100644 --- a/smartline/sequencer.lua +++ b/smartline/sequencer.lua @@ -98,37 +98,40 @@ local function restart_timer(pos, time) end local function check_rules(pos, elapsed) - local meta = minetest.get_meta(pos) - local rules = minetest.deserialize(meta:get_string("rules")) - if rules then - local running = meta:get_int("running") - local index = meta:get_int("index") or 1 - local number = meta:get_string("number") - local endless = meta:get_int("endless") or 0 - local placer_name = meta:get_string("placer_name") - while true do -- process all rules as long as offs == 0 - local rule = rules[index] - local offs = rules[index].offs - if type(offs) == "string" then - offs = 0 - end - tubelib.send_message(rule.num, placer_name, nil, tAction[rule.act], number) - index = get_next_slot(index, rules, endless) - if index ~= nil and offs ~= nil and running == 1 then - -- after the last rule a pause with 2 or more sec is required - if index == 1 and offs < 1 then - offs = 2 + if tubelib.data_not_corrupted(pos) then + local meta = minetest.get_meta(pos) + local rules = minetest.deserialize(meta:get_string("rules")) + if rules then + local running = meta:get_int("running") + local index = meta:get_int("index") or 1 + local number = meta:get_string("number") + local endless = meta:get_int("endless") or 0 + local placer_name = meta:get_string("placer_name") + while true do -- process all rules as long as offs == 0 + local rule = rules[index] + local offs = rules[index].offs + if type(offs) == "string" then + offs = 0 end - meta:set_string("infotext", "SmartLine Sequencer "..number..": running ("..index.."/"..NUM_SLOTS..")") - meta:set_int("index", index) - if offs > 0 then - minetest.after(0, restart_timer, pos, offs) - return false + tubelib.send_message(rule.num, placer_name, nil, tAction[rule.act], number) + index = get_next_slot(index, rules, endless) + if index ~= nil and offs ~= nil and running == 1 then + -- after the last rule a pause with 2 or more sec is required + if index == 1 and offs < 1 then + offs = 2 + end + meta:set_string("infotext", "SmartLine Sequencer "..number..": running ("..index.."/"..NUM_SLOTS..")") + meta:set_int("index", index) + if offs > 0 then + minetest.after(0, restart_timer, pos, offs) + return false + end + else + return stop_the_sequencer(pos) end - else - return stop_the_sequencer(pos) end end + return false end return false end @@ -147,7 +150,7 @@ local function start_the_sequencer(pos) return false end -local function on_receive_fields(pos, formname, fields, player) +local function on_receive_fields(pos, formname, fields, player) local meta = minetest.get_meta(pos) local running = meta:get_int("running") if minetest.is_protected(pos, player:get_player_name()) then diff --git a/smartline/timer.lua b/smartline/timer.lua index 5315676..9367973 100644 --- a/smartline/timer.lua +++ b/smartline/timer.lua @@ -86,41 +86,44 @@ local function formspec_help() end local function check_rules(pos,elapsed) - local hour = math.floor(minetest.get_timeofday() * 24) - local meta = minetest.get_meta(pos) - local events = minetest.deserialize(meta:get_string("events")) - local numbers = minetest.deserialize(meta:get_string("numbers")) - local actions = minetest.deserialize(meta:get_string("actions")) - local done = minetest.deserialize(meta:get_string("done")) - local placer_name = meta:get_string("placer_name") - local own_num = meta:get_string("own_num") - - -- check all rules - for idx,act in ipairs(actions) do - if act ~= "" and numbers[idx] ~= "" then - local hr = (events[idx] - 1) * 2 - if ((hour - hr) % 24) <= 4 then -- last 4 hours? - if done[idx] == false then -- not already executed? + if tubelib.data_not_corrupted(pos) then + local hour = math.floor(minetest.get_timeofday() * 24) + local meta = minetest.get_meta(pos) + local events = minetest.deserialize(meta:get_string("events")) + local numbers = minetest.deserialize(meta:get_string("numbers")) + local actions = minetest.deserialize(meta:get_string("actions")) + local done = minetest.deserialize(meta:get_string("done")) + local placer_name = meta:get_string("placer_name") + local own_num = meta:get_string("own_num") + + -- check all rules + for idx,act in ipairs(actions) do + if act ~= "" and numbers[idx] ~= "" then + 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 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 - tubelib.send_message(numbers[idx], placer_name, nil, act, own_num) - done[idx] = true end end + + -- prepare for the next day + if hour == 23 then + done = {false,false,false,false,false,false} + end + meta:set_string("done", minetest.serialize(done)) + meta:set_string("infotext","SmartLine Timer ("..own_num..")"..hour..":00") + return true end - - -- prepare for the next day - if hour == 23 then - done = {false,false,false,false,false,false} - end - meta:set_string("done", minetest.serialize(done)) - meta:set_string("infotext","SmartLine Timer ("..own_num..")"..hour..":00") - return true + return false end diff --git a/techpack_warehouse/common.lua b/techpack_warehouse/common.lua index 84d5d00..1c217c4 100644 --- a/techpack_warehouse/common.lua +++ b/techpack_warehouse/common.lua @@ -268,38 +268,41 @@ function techpack_warehouse.after_place_node(self, pos, placer, itemstack) end function techpack_warehouse.on_timer(self, pos, elapsed) - local meta = M(pos) - local inv = meta:get_inventory() - if not inv:is_empty("shift") then - --local number = meta:get_string("tubelib_number") - local player_name = meta:get_string("player_name") - local offs = meta:get_int("offs") - local push_dir = meta:get_string("push_dir") - if push_dir == "" then push_dir = "L" end - meta:set_int("offs", offs + 1) - for i = 0,7 do - local idx = ((i + offs) % 8) + 1 - local stack = inv:get_stack("shift", idx) - if stack:get_count() > 0 then - if tubelib.push_items(pos, push_dir, stack, player_name) then - -- The effort is needed here for the case the - -- pusher pushes into its own chest. - local num = stack:get_count() - stack = inv:get_stack("shift", idx) - stack:take_item(num) - inv:set_stack("shift", idx, stack) - self.State:keep_running(pos, meta, COUNTDOWN_TICKS) - break - else - self.State:blocked(pos, meta) + if tubelib.data_not_corrupted(pos) then + local meta = M(pos) + local inv = meta:get_inventory() + if not inv:is_empty("shift") then + --local number = meta:get_string("tubelib_number") + local player_name = meta:get_string("player_name") + local offs = meta:get_int("offs") + local push_dir = meta:get_string("push_dir") + if push_dir == "" then push_dir = "L" end + meta:set_int("offs", offs + 1) + for i = 0,7 do + local idx = ((i + offs) % 8) + 1 + local stack = inv:get_stack("shift", idx) + if stack:get_count() > 0 then + if tubelib.push_items(pos, push_dir, stack, player_name) then + -- The effort is needed here for the case the + -- pusher pushes into its own chest. + local num = stack:get_count() + stack = inv:get_stack("shift", idx) + stack:take_item(num) + inv:set_stack("shift", idx, stack) + self.State:keep_running(pos, meta, COUNTDOWN_TICKS) + break + else + self.State:blocked(pos, meta) + end end end + else + self.State:idle(pos, meta) end - else - self.State:idle(pos, meta) + + return self.State:is_active(meta) end - - return self.State:is_active(meta) + return false end function techpack_warehouse.can_dig(self, pos) diff --git a/tubelib/button.lua b/tubelib/button.lua index ba561d1..1d5225b 100644 --- a/tubelib/button.lua +++ b/tubelib/button.lua @@ -16,47 +16,51 @@ local function switch_on(pos, node) - node.name = "tubelib:button_active" - minetest.swap_node(pos, node) - minetest.sound_play("button", { - pos = pos, - gain = 0.5, - max_hear_distance = 5, - }) - local meta = minetest.get_meta(pos) - local own_num = meta:get_string("own_num") - local numbers = meta:get_string("numbers") - local cycle_time = meta:get_int("cycle_time") - if cycle_time > 0 then -- button mode? - minetest.get_node_timer(pos):start(cycle_time) + if tubelib.data_not_corrupted(pos) then + node.name = "tubelib:button_active" + minetest.swap_node(pos, node) + minetest.sound_play("button", { + pos = pos, + gain = 0.5, + max_hear_distance = 5, + }) + local meta = minetest.get_meta(pos) + local own_num = meta:get_string("own_num") + local numbers = meta:get_string("numbers") + local cycle_time = meta:get_int("cycle_time") + if cycle_time > 0 then -- button mode? + minetest.get_node_timer(pos):start(cycle_time) + end + local placer_name = meta:get_string("placer_name") + local clicker_name = nil + if meta:get_string("public") == "false" then + clicker_name = meta:get_string("clicker_name") + end + tubelib.send_message(numbers, placer_name, clicker_name, "on", own_num) -- <<=== tubelib end - local placer_name = meta:get_string("placer_name") - local clicker_name = nil - if meta:get_string("public") == "false" then - clicker_name = meta:get_string("clicker_name") - end - tubelib.send_message(numbers, placer_name, clicker_name, "on", own_num) -- <<=== tubelib end local function switch_off(pos) - local node = minetest.get_node(pos) - node.name = "tubelib:button" - minetest.swap_node(pos, node) - minetest.get_node_timer(pos):stop() - minetest.sound_play("button", { - pos = pos, - gain = 0.5, - max_hear_distance = 5, - }) - local meta = minetest.get_meta(pos) - local own_num = meta:get_string("own_num") - local numbers = meta:get_string("numbers") - local placer_name = meta:get_string("placer_name") - local clicker_name = nil - if meta:get_string("public") == "false" then - clicker_name = meta:get_string("clicker_name") + if tubelib.data_not_corrupted(pos) then + local node = minetest.get_node(pos) + node.name = "tubelib:button" + minetest.swap_node(pos, node) + minetest.get_node_timer(pos):stop() + minetest.sound_play("button", { + pos = pos, + gain = 0.5, + max_hear_distance = 5, + }) + local meta = minetest.get_meta(pos) + local own_num = meta:get_string("own_num") + local numbers = meta:get_string("numbers") + local placer_name = meta:get_string("placer_name") + local clicker_name = nil + if meta:get_string("public") == "false" then + clicker_name = meta:get_string("clicker_name") + end + tubelib.send_message(numbers, placer_name, clicker_name, "off", own_num) -- <<=== tubelib end - tubelib.send_message(numbers, placer_name, clicker_name, "off", own_num) -- <<=== tubelib end diff --git a/tubelib/defect.lua b/tubelib/defect.lua new file mode 100644 index 0000000..d0e5981 --- /dev/null +++ b/tubelib/defect.lua @@ -0,0 +1,48 @@ +minetest.register_node("tubelib:defect_dummy", { + description = "Corrupted Tubelib Node", + tiles = { + "tubelib_front.png", + "tubelib_front.png", + "tubelib_front.png^tubelib_defect.png", + "tubelib_front.png^tubelib_defect.png", + "tubelib_front.png^tubelib_defect.png", + "tubelib_front.png^tubelib_defect.png", + }, + drop = "", + groups = {cracky=3, crumbly=3, choppy=3, not_in_creative_inventory=1}, + is_ground_content = false, +}) + + +function tubelib.data_not_corrupted(pos) + if minetest.pos_to_string(pos) ~= minetest.get_meta(pos):get_string("my_pos") then + -- node number corrupt? + local meta = minetest.get_meta(pos) + local number = meta:get_string("tubelib_number") + if number == "" then + number = meta:get_string("number") + end + if number == "" then + number = meta:get_string("own_num") + end + if number == "" then + number = meta:get_string("own_number") + end + if number == "" then + tubelib.remove_node(pos) + minetest.set_node(pos, {name = "tubelib:defect_dummy"}) + meta:from_table(nil) + return false + end + -- node moved? + local info = tubelib.get_node_info(number) + if not info or not vector.equals(info.pos, pos) then + tubelib.remove_node(pos) + minetest.set_node(pos, {name = "tubelib:defect_dummy"}) + meta:from_table(nil) + return false + end + minetest.get_meta(pos):get_string("my_pos", minetest.pos_to_string(pos)) + end + return true +end \ No newline at end of file diff --git a/tubelib/distributor.lua b/tubelib/distributor.lua index 958ccf6..3de6dc7 100644 --- a/tubelib/distributor.lua +++ b/tubelib/distributor.lua @@ -270,9 +270,12 @@ end -- move items to the output slots local function keep_running(pos, elapsed) - local meta = M(pos) - distributing(pos, meta) - return State:is_active(meta) + if tubelib.data_not_corrupted(pos) then + local meta = M(pos) + distributing(pos, meta) + return State:is_active(meta) + end + return false end local function on_receive_fields(pos, formname, fields, player) diff --git a/tubelib/init.lua b/tubelib/init.lua index 3d8a8de..fb803c2 100644 --- a/tubelib/init.lua +++ b/tubelib/init.lua @@ -101,6 +101,7 @@ else -- conversion from v1.16 to v2.00 dofile(minetest.get_modpath("tubelib") .. "/migrate.lua") dofile(minetest.get_modpath("tubelib") .. "/states.lua") + dofile(minetest.get_modpath("tubelib") .. "/defect.lua") dofile(minetest.get_modpath("tubelib") .. "/node_states.lua") dofile(minetest.get_modpath("tubelib") .. "/pusher.lua") dofile(minetest.get_modpath("tubelib") .. "/blackhole.lua") diff --git a/tubelib/legacy_nodes.lua b/tubelib/legacy_nodes.lua index e67a48a..8b814a0 100644 --- a/tubelib/legacy_nodes.lua +++ b/tubelib/legacy_nodes.lua @@ -104,4 +104,32 @@ tubelib.register_node("shop:shop", {}, { end, }) +tubelib.register_node("signs_bot:box", {}, { + on_pull_item = function(pos, side) + local meta = minetest.get_meta(pos) + return tubelib.get_item(meta, "main") + end, + on_push_item = function(pos, side, item) + local meta = minetest.get_meta(pos) + return tubelib.put_item(meta, "main", item) + end, + on_unpull_item = function(pos, side, item) + local meta = minetest.get_meta(pos) + return tubelib.put_item(meta, "main", item) + end, +}) +tubelib.register_node("signs_bot:chest", {}, { + on_pull_item = function(pos, side) + local meta = minetest.get_meta(pos) + return tubelib.get_item(meta, "main") + end, + on_push_item = function(pos, side, item) + local meta = minetest.get_meta(pos) + return tubelib.put_item(meta, "main", item) + end, + on_unpull_item = function(pos, side, item) + local meta = minetest.get_meta(pos) + return tubelib.put_item(meta, "main", item) + end, +}) diff --git a/tubelib/node_states.lua b/tubelib/node_states.lua index a3a72b7..bd8f7b6 100644 --- a/tubelib/node_states.lua +++ b/tubelib/node_states.lua @@ -376,17 +376,9 @@ function NodeStates:on_node_load(pos, not_start_timer) meta:set_int("counter", 0) end - -- node number corrupt? - number = meta:get_string("tubelib_number") - if number == "" then - number = tubelib.get_new_number(pos, self.node_name_passive) - meta:set_string("tubelib_number", number) - else - local info = tubelib.get_node_info(number) - if not info or info.pos ~= pos then - number = tubelib.get_new_number(pos, self.node_name_passive) - meta:set_string("tubelib_number", number) - end + -- node corrupt? + if not tubelib.data_not_corrupted(pos) then + return end -- state corrupt? diff --git a/tubelib/pusher.lua b/tubelib/pusher.lua index 56ac1a3..8e6e878 100644 --- a/tubelib/pusher.lua +++ b/tubelib/pusher.lua @@ -66,9 +66,12 @@ local function pushing(pos, meta) end local function keep_running(pos, elapsed) - local meta = M(pos) - pushing(pos, meta) - return State:is_active(meta) + if tubelib.data_not_corrupted(pos) then + local meta = M(pos) + pushing(pos, meta) + return State:is_active(meta) + end + return false end minetest.register_node("tubelib:pusher", { diff --git a/tubelib_addons1/README.md b/tubelib_addons1/README.md index 05c0e77..499481e 100644 --- a/tubelib_addons1/README.md +++ b/tubelib_addons1/README.md @@ -6,6 +6,12 @@ the automated mining, farming, and crafting. A Tutorial to this Mod is available as ![Wiki](https://github.com/joe7575/techpack/wiki) +With contributions from: +* obl3pplifp, https://github.com/obl3pplifp/techpack_compat and as pull requests +* realmicu, as pull requests +* theFox6, as pull request + + ## Dependencies tubelib, default opt. unified_inventory diff --git a/tubelib_addons1/autocrafter.lua b/tubelib_addons1/autocrafter.lua index ce6c305..5a06e63 100644 --- a/tubelib_addons1/autocrafter.lua +++ b/tubelib_addons1/autocrafter.lua @@ -127,12 +127,15 @@ end local function keep_running(pos, elapsed) - local meta = M(pos) - local inv = meta:get_inventory() - local craft = get_craft(pos, inv) - local output_item = craft.output.item - autocraft(pos, meta, inv, craft) - return State:is_active(meta) + if tubelib.data_not_corrupted(pos) then + local meta = M(pos) + local inv = meta:get_inventory() + local craft = get_craft(pos, inv) + local output_item = craft.output.item + autocraft(pos, meta, inv, craft) + return State:is_active(meta) + end + return false end -- note, that this function assumes allready being updated to virtual items diff --git a/tubelib_addons1/detector.lua b/tubelib_addons1/detector.lua index 40817ee..f7c5ad9 100644 --- a/tubelib_addons1/detector.lua +++ b/tubelib_addons1/detector.lua @@ -14,26 +14,30 @@ local function switch_on(pos) - local node = minetest.get_node(pos) - node.name = "tubelib_addons1:detector_active" - minetest.swap_node(pos, node) - minetest.get_node_timer(pos):start(1) - local meta = minetest.get_meta(pos) - local own_num = meta:get_string("own_num") - local numbers = meta:get_string("numbers") - local placer_name = meta:get_string("placer_name") - tubelib.send_message(numbers, placer_name, nil, "on", own_num) + if tubelib.data_not_corrupted(pos) then + local node = minetest.get_node(pos) + node.name = "tubelib_addons1:detector_active" + minetest.swap_node(pos, node) + minetest.get_node_timer(pos):start(1) + local meta = minetest.get_meta(pos) + local own_num = meta:get_string("own_num") + local numbers = meta:get_string("numbers") + local placer_name = meta:get_string("placer_name") + tubelib.send_message(numbers, placer_name, nil, "on", own_num) + end end local function switch_off(pos) - local node = minetest.get_node(pos) - node.name = "tubelib_addons1:detector" - minetest.swap_node(pos, node) - local meta = minetest.get_meta(pos) - local own_num = meta:get_string("own_num") - local numbers = meta:get_string("numbers") - local placer_name = meta:get_string("placer_name") - tubelib.send_message(numbers, placer_name, nil, "off", own_num) + if tubelib.data_not_corrupted(pos) then + local node = minetest.get_node(pos) + node.name = "tubelib_addons1:detector" + minetest.swap_node(pos, node) + local meta = minetest.get_meta(pos) + local own_num = meta:get_string("own_num") + local numbers = meta:get_string("numbers") + local placer_name = meta:get_string("placer_name") + tubelib.send_message(numbers, placer_name, nil, "off", own_num) + end end diff --git a/tubelib_addons1/fermenter.lua b/tubelib_addons1/fermenter.lua index a5e9a9a..0af9868 100644 --- a/tubelib_addons1/fermenter.lua +++ b/tubelib_addons1/fermenter.lua @@ -144,9 +144,12 @@ local function convert_leaves_to_biogas(pos, meta) end local function keep_running(pos, elapsed) - local meta = M(pos) - convert_leaves_to_biogas(pos, meta) - return State:is_active(meta) + if tubelib.data_not_corrupted(pos) then + local meta = M(pos) + convert_leaves_to_biogas(pos, meta) + return State:is_active(meta) + end + return false end local function on_receive_fields(pos, formname, fields, player) diff --git a/tubelib_addons1/grinder.lua b/tubelib_addons1/grinder.lua index 1807a9c..653aac3 100644 --- a/tubelib_addons1/grinder.lua +++ b/tubelib_addons1/grinder.lua @@ -103,10 +103,13 @@ local function grinding(pos, meta, inv) end local function keep_running(pos, elapsed) - local meta = M(pos) - local inv = meta:get_inventory() - grinding(pos, meta, inv) - return State:is_active(meta) + if tubelib.data_not_corrupted(pos) then + local meta = M(pos) + local inv = meta:get_inventory() + grinding(pos, meta, inv) + return State:is_active(meta) + end + return false end local function on_receive_fields(pos, formname, fields, player) diff --git a/tubelib_addons1/harvester.lua b/tubelib_addons1/harvester.lua index 47ed578..7ad040e 100644 --- a/tubelib_addons1/harvester.lua +++ b/tubelib_addons1/harvester.lua @@ -243,30 +243,33 @@ end -- move the "harvesting copter" to the next pos and harvest the field below local function keep_running(pos, elapsed) - local meta = M(pos) - local this = minetest.deserialize(meta:get_string("this")) - this.num_items = 0 - - if not_blocked(pos, this, meta) then - if check_fuel(pos, this, meta) then - if calc_new_pos(pos, this, meta) then - if harvest_field(this, meta) then - meta:set_string("this", minetest.serialize(this)) - meta:set_string("infotext", - "Tubelib Harvester "..this.number.. - ": running ("..this.idx.."/"..this.max..")") - State:keep_running(pos, meta, COUNTDOWN_TICKS, this.num_items) + if tubelib.data_not_corrupted(pos) then + local meta = M(pos) + local this = minetest.deserialize(meta:get_string("this")) + this.num_items = 0 + + if not_blocked(pos, this, meta) then + if check_fuel(pos, this, meta) then + if calc_new_pos(pos, this, meta) then + if harvest_field(this, meta) then + meta:set_string("this", minetest.serialize(this)) + meta:set_string("infotext", + "Tubelib Harvester "..this.number.. + ": running ("..this.idx.."/"..this.max..")") + State:keep_running(pos, meta, COUNTDOWN_TICKS, this.num_items) + else + State:blocked(pos, meta) + end else - State:blocked(pos, meta) + State:stop(pos, meta) end else - State:stop(pos, meta) + State:fault(pos, meta) end - else - State:fault(pos, meta) end + return State:is_active(meta) end - return State:is_active(meta) + return false end diff --git a/tubelib_addons1/liquidsampler.lua b/tubelib_addons1/liquidsampler.lua index c717746..d6b1812 100644 --- a/tubelib_addons1/liquidsampler.lua +++ b/tubelib_addons1/liquidsampler.lua @@ -112,9 +112,12 @@ local function allow_metadata_inventory_take(pos, listname, index, stack, player end local function keep_running(pos, elapsed) - local meta = M(pos) - sample_liquid(pos, meta) - return State:is_active(meta) + if tubelib.data_not_corrupted(pos) then + local meta = M(pos) + sample_liquid(pos, meta) + return State:is_active(meta) + end + return false end local function on_receive_fields(pos, formname, fields, player) diff --git a/tubelib_addons1/nodes.lua b/tubelib_addons1/nodes.lua index b543f6c..469c9fc 100644 --- a/tubelib_addons1/nodes.lua +++ b/tubelib_addons1/nodes.lua @@ -48,6 +48,7 @@ local tn = tubelib_addons1.register_tree_node local dn = tubelib_addons1.register_default_farming_node local fn = tubelib_addons1.register_farming_node local gn = tubelib_addons1.register_ground_node +local gr = tubelib.add_grinder_recipe ------------------------------------------------------------------------------- -- Default Farming @@ -103,6 +104,13 @@ if farming.mod == "redo" then fn("farming:oat_8", "farming:oat", "farming:oat_1") fn("farming:rye_8", "farming:rye", "farming:rye_1") fn("farming:rice_8", "farming:rice", "farming:rice_1") + fn('farming:beetroot_5', 'farming:beetroot 2', 'farming:beetroot_1') + fn('farming:cocoa_4', 'farming:cocoa_beans 2', 'farming:cocoa_1') + fn('farming:garlic_5', 'farming:garlic 2', 'farming:garlic_1') + fn('farming:onion_5', 'farming:onion 2', 'farming:onion_1') + fn('farming:pea_5', 'farming:pea_pod 3', 'farming:pea_1') + fn('farming:pepper_5', 'farming:pepper 2', 'farming:pepper_1') + fn('farming:pineapple_8', 'farming:pineapple 1', 'farming:pineapple_1') end ------------------------------------------------------------------------------- @@ -246,3 +254,55 @@ end minetest.after(10, register_flowers) +------------------------------------------------------------------------------- +-- moretrees +------------------------------------------------------------------------------- + +if minetest.global_exists("moretrees") then + local function register_tree(treename) + local trunk_name = 'moretrees:' .. treename .. '_trunk' + local sappling_name = 'moretrees:' .. treename .. '_sapling' + local leaves_name = 'moretrees:' .. treename .. '_leaves' + + tn(trunk_name, trunk_name, sappling_name) + fn(leaves_name) + gr({input=trunk_name, output=leaves_name .. ' 8'}) + end + + -- "ordinary" moretrees blocks + for i in ipairs(moretrees.treelist) do + local treename = moretrees.treelist[i][1] + + if treename ~= 'jungletree' then + register_tree(treename) + end + end + + -- "weird" moretrees trunks + tn('moretrees:date_palm_fruit_trunk', 'moretrees:date_palm_trunk', 'moretrees:date_palm_sapling') + gr({input='moretrees:date_palm_fruit_trunk', output='moretrees:date_palm_leaves 8'}) + tn('moretrees:date_palm_ffruit_trunk', 'moretrees:date_palm_trunk', 'moretrees:date_palm_sapling') + gr({input='moretrees:date_palm_ffruit_trunk', output='moretrees:date_palm_leaves 8'}) + tn('moretrees:date_palm_mfruit_trunk', 'moretrees:date_palm_trunk', 'moretrees:date_palm_sapling') + gr({input='moretrees:date_palm_mfruit_trunk', output='moretrees:date_palm_leaves 8'}) + tn('moretrees:jungletree_trunk', 'default:jungletree', 'default:junglesapling') + gr({input='moretrees:jungletree_trunk', output='default:jungleleaves 8'}) + tn('moretrees:palm_fruit_trunk', 'moretrees:palm_trunk', 'moretrees:palm_sapling') + gr({input='moretrees:palm_fruit_trunk', output='moretrees:palm_leaves 8'}) + tn('moretrees:palm_fruit_trunk_gen', 'moretrees:palm_trunk', 'moretrees:palm_sapling') + gr({input='moretrees:palm_fruit_trunk_gen', output='moretrees:palm_leaves 8'}) + tn('moretrees:rubber_tree_trunk_empty', 'moretrees:rubber_tree_trunk_empty', 'moretrees:rubber_tree_sapling') + gr({input='moretrees:rubber_tree_trunk_empty', output='moretrees:rubber_tree_leaves 8'}) + + -- moretrees fruit and leaves + fn('moretrees:acorn') + fn('moretrees:cedar_cone') + fn('moretrees:coconut_3', 'moretrees:coconut') + fn('moretrees:dates_f4', 'moretrees:date 16') + fn('moretrees:fir_cone') + fn('moretrees:fir_leaves_bright') + fn('moretrees:jungletree_leaves_red') + fn('moretrees:jungletree_leaves_yellow') + fn('moretrees:spruce_cone') +end + diff --git a/tubelib_addons1/pusher_fast.lua b/tubelib_addons1/pusher_fast.lua index 31a68fe..8789028 100644 --- a/tubelib_addons1/pusher_fast.lua +++ b/tubelib_addons1/pusher_fast.lua @@ -66,9 +66,12 @@ local function pushing(pos, meta) end local function keep_running(pos, elapsed) - local meta = M(pos) - pushing(pos, meta) - return State:is_active(meta) + if tubelib.data_not_corrupted(pos) then + local meta = M(pos) + pushing(pos, meta) + return State:is_active(meta) + end + return false end minetest.register_node("tubelib_addons1:pusher_fast", { diff --git a/tubelib_addons1/quarry.lua b/tubelib_addons1/quarry.lua index 8861bf4..6bfbaa5 100644 --- a/tubelib_addons1/quarry.lua +++ b/tubelib_addons1/quarry.lua @@ -238,9 +238,12 @@ local function quarry_next_node(pos, meta) end local function keep_running(pos, elapsed) - local meta = M(pos) - quarry_next_node(pos, meta) - return State:is_active(meta) + if tubelib.data_not_corrupted(pos) then + local meta = M(pos) + quarry_next_node(pos, meta) + return State:is_active(meta) + end + return false end local function on_receive_fields(pos, formname, fields, player) diff --git a/tubelib_addons1/reformer.lua b/tubelib_addons1/reformer.lua index 0f02ab6..595e54d 100644 --- a/tubelib_addons1/reformer.lua +++ b/tubelib_addons1/reformer.lua @@ -139,9 +139,12 @@ end local function keep_running(pos, elapsed) - local meta = M(pos) - convert_biogas_to_biofuel(pos, meta) - return State:is_active(meta) + if tubelib.data_not_corrupted(pos) then + local meta = M(pos) + convert_biogas_to_biofuel(pos, meta) + return State:is_active(meta) + end + return false end local function on_receive_fields(pos, formname, fields, player) diff --git a/tubelib_addons2/accesscontrol.lua b/tubelib_addons2/accesscontrol.lua index f0568b8..bfe8d73 100644 --- a/tubelib_addons2/accesscontrol.lua +++ b/tubelib_addons2/accesscontrol.lua @@ -13,29 +13,33 @@ ]]-- local function switch_on(pos, meta) - minetest.sound_play("tubelib_addons2_door", { - pos = pos, - gain = 0.5, - max_hear_distance = 5, - }) - local numbers = meta:get_string("numbers") - local number = meta:get_string("number") - local placer_name = meta:get_string("placer_name") - tubelib.send_message(numbers, placer_name, nil, "on", number) - minetest.get_node_timer(pos):start(4) + if tubelib.data_not_corrupted(pos) then + minetest.sound_play("tubelib_addons2_door", { + pos = pos, + gain = 0.5, + max_hear_distance = 5, + }) + local numbers = meta:get_string("numbers") + local number = meta:get_string("number") + local placer_name = meta:get_string("placer_name") + tubelib.send_message(numbers, placer_name, nil, "on", number) + minetest.get_node_timer(pos):start(4) + end end local function switch_off(pos) - minetest.sound_play("tubelib_addons2_door", { - pos = pos, - gain = 0.5, - max_hear_distance = 5, - }) - local meta = minetest.get_meta(pos) - local numbers = meta:get_string("numbers") - local number = meta:get_string("number") - local placer_name = meta:get_string("placer_name") - tubelib.send_message(numbers, placer_name, nil, "off", number) + if tubelib.data_not_corrupted(pos) then + minetest.sound_play("tubelib_addons2_door", { + pos = pos, + gain = 0.5, + max_hear_distance = 5, + }) + local meta = minetest.get_meta(pos) + local numbers = meta:get_string("numbers") + local number = meta:get_string("number") + local placer_name = meta:get_string("placer_name") + tubelib.send_message(numbers, placer_name, nil, "off", number) + end end local function formspec1(numbers) diff --git a/tubelib_addons2/logic_not.lua b/tubelib_addons2/logic_not.lua index 1071341..3003447 100644 --- a/tubelib_addons2/logic_not.lua +++ b/tubelib_addons2/logic_not.lua @@ -76,19 +76,21 @@ minetest.register_craft({ tubelib.register_node("tubelib_addons2:logic_not", {}, { on_recv_message = function(pos, topic, payload) - local meta = minetest.get_meta(pos) - local owner = meta:get_string("owner") - local numbers = meta:get_string("numbers") - local own_number = meta:get_string("own_number") - if topic == "set_numbers" then - meta:set_string("infotext", "Tubelib Logic Not "..own_number..": connected with "..payload) - meta:set_string("numbers", payload) - meta:set_string("formspec", formspec(meta)) - return true - elseif topic == "on" then - return tubelib.send_message(numbers, owner, nil, "off", payload) - elseif topic == "off" then - return tubelib.send_message(numbers, owner, nil, "on", payload) + if tubelib.data_not_corrupted(pos) then + local meta = minetest.get_meta(pos) + local owner = meta:get_string("owner") + local numbers = meta:get_string("numbers") + local own_number = meta:get_string("own_number") + if topic == "set_numbers" then + meta:set_string("infotext", "Tubelib Logic Not "..own_number..": connected with "..payload) + meta:set_string("numbers", payload) + meta:set_string("formspec", formspec(meta)) + return true + elseif topic == "on" then + return tubelib.send_message(numbers, owner, nil, "off", payload) + elseif topic == "off" then + return tubelib.send_message(numbers, owner, nil, "on", payload) + end end end, }) diff --git a/tubelib_addons2/mesecons_converter.lua b/tubelib_addons2/mesecons_converter.lua index b78768e..f64d0c5 100644 --- a/tubelib_addons2/mesecons_converter.lua +++ b/tubelib_addons2/mesecons_converter.lua @@ -108,9 +108,12 @@ minetest.register_node("tubelib_addons2:mesecons_converter", { }, on_timer = function(pos,elapsed) - local meta = minetest.get_meta(pos) - meta:set_int("overload_cnt", 0) - return true + if tubelib.data_not_corrupted(pos) then + local meta = minetest.get_meta(pos) + meta:set_int("overload_cnt", 0) + return true + end + return false end, after_dig_node = function(pos) diff --git a/tubelib_addons2/repeater.lua b/tubelib_addons2/repeater.lua index bbe0d87..313996f 100644 --- a/tubelib_addons2/repeater.lua +++ b/tubelib_addons2/repeater.lua @@ -62,9 +62,12 @@ minetest.register_node("tubelib_addons2:repeater", { end, on_timer = function(pos,elapsed) - local meta = minetest.get_meta(pos) - meta:set_int("overload_cnt", 0) - return true + if tubelib.data_not_corrupted(pos) then + local meta = minetest.get_meta(pos) + meta:set_int("overload_cnt", 0) + return true + end + return false end, after_dig_node = function(pos) diff --git a/tubelib_addons2/sequencer.lua b/tubelib_addons2/sequencer.lua index 70464d0..9c7fec1 100644 --- a/tubelib_addons2/sequencer.lua +++ b/tubelib_addons2/sequencer.lua @@ -89,37 +89,40 @@ local function restart_timer(pos, time) end local function check_rules(pos, elapsed) - local meta = minetest.get_meta(pos) - local rules = minetest.deserialize(meta:get_string("rules")) - if rules then - local running = meta:get_int("running") - local index = meta:get_int("index") or 1 - local number = meta:get_string("number") - local endless = meta:get_int("endless") or 0 - local placer_name = meta:get_string("placer_name") - while true do -- process all rules as long as offs == 0 - local rule = rules[index] - local offs = rules[index].offs - if type(offs) == "string" then - offs = 0 - end - tubelib.send_message(rule.num, placer_name, nil, tAction[rule.act], number) - index = get_next_slot(index, rules, endless) - if index ~= nil and offs ~= nil and running == 1 then - -- after the last rule a pause with 1 or more sec is required - if index == 1 and offs < 1 then - offs = 1 + if tubelib.data_not_corrupted(pos) then + local meta = minetest.get_meta(pos) + local rules = minetest.deserialize(meta:get_string("rules")) + if rules then + local running = meta:get_int("running") + local index = meta:get_int("index") or 1 + local number = meta:get_string("number") + local endless = meta:get_int("endless") or 0 + local placer_name = meta:get_string("placer_name") + while true do -- process all rules as long as offs == 0 + local rule = rules[index] + local offs = rules[index].offs + if type(offs) == "string" then + offs = 0 end - meta:set_string("infotext", "Tubelib Sequencer "..number..": running ("..index.."/"..NUM_SLOTS..")") - meta:set_int("index", index) - if offs > 0 then - minetest.after(0, restart_timer, pos, offs) - return false + tubelib.send_message(rule.num, placer_name, nil, tAction[rule.act], number) + index = get_next_slot(index, rules, endless) + if index ~= nil and offs ~= nil and running == 1 then + -- after the last rule a pause with 1 or more sec is required + if index == 1 and offs < 1 then + offs = 1 + end + meta:set_string("infotext", "Tubelib Sequencer "..number..": running ("..index.."/"..NUM_SLOTS..")") + meta:set_int("index", index) + if offs > 0 then + minetest.after(0, restart_timer, pos, offs) + return false + end + else + return stop_the_sequencer(pos) end - else - return stop_the_sequencer(pos) end end + return false end return false end @@ -139,54 +142,56 @@ local function start_the_sequencer(pos) end local function on_receive_fields(pos, formname, fields, player) - local meta = minetest.get_meta(pos) - local running = meta:get_int("running") - if minetest.is_protected(pos, player:get_player_name()) then - return - end - - if fields.help ~= nil then - meta:set_string("formspec", formspec_help()) - return - end - - local endless = meta:get_int("endless") or 0 - if fields.endless ~= nil then - endless = fields.endless == "true" and 1 or 0 - meta:set_int("index", 1) - end - meta:set_int("endless", endless) - - local rules = minetest.deserialize(meta:get_string("rules")) - if fields.exit ~= nil then - meta:set_string("formspec", formspec(tubelib.state(running), rules, endless)) - return - end + if tubelib.data_not_corrupted(pos) then + local meta = minetest.get_meta(pos) + local running = meta:get_int("running") + if minetest.is_protected(pos, player:get_player_name()) then + return + end + + if fields.help ~= nil then + meta:set_string("formspec", formspec_help()) + return + end + + local endless = meta:get_int("endless") or 0 + if fields.endless ~= nil then + endless = fields.endless == "true" and 1 or 0 + meta:set_int("index", 1) + end + meta:set_int("endless", endless) + + local rules = minetest.deserialize(meta:get_string("rules")) + if fields.exit ~= nil then + meta:set_string("formspec", formspec(tubelib.state(running), rules, endless)) + return + end - for idx = 1,NUM_SLOTS do - if fields["offs"..idx] ~= nil then - rules[idx].offs = tonumber(fields["offs"..idx]) or "" + for idx = 1,NUM_SLOTS do + if fields["offs"..idx] ~= nil then + rules[idx].offs = tonumber(fields["offs"..idx]) or "" + end + if fields["num"..idx] ~= nil and tubelib.check_numbers(fields["num"..idx]) then + rules[idx].num = fields["num"..idx] + end + if fields["act"..idx] ~= nil then + rules[idx].act = kvAction[fields["act"..idx]] + end end - if fields["num"..idx] ~= nil and tubelib.check_numbers(fields["num"..idx]) then - rules[idx].num = fields["num"..idx] - end - if fields["act"..idx] ~= nil then - rules[idx].act = kvAction[fields["act"..idx]] - end - end - meta:set_string("rules", minetest.serialize(rules)) + meta:set_string("rules", minetest.serialize(rules)) - if fields.button ~= nil then - if running > STOP_STATE then + if fields.button ~= nil then + if running > STOP_STATE then + stop_the_sequencer(pos) + else + start_the_sequencer(pos) + end + elseif fields.num1 ~= nil then -- any other change? stop_the_sequencer(pos) else - start_the_sequencer(pos) + local endless = meta:get_int("endless") or 0 + meta:set_string("formspec", formspec(tubelib.state(running), rules, endless)) end - elseif fields.num1 ~= nil then -- any other change? - stop_the_sequencer(pos) - else - local endless = meta:get_int("endless") or 0 - meta:set_string("formspec", formspec(tubelib.state(running), rules, endless)) end end diff --git a/tubelib_addons2/timer.lua b/tubelib_addons2/timer.lua index f4e89f2..588e059 100644 --- a/tubelib_addons2/timer.lua +++ b/tubelib_addons2/timer.lua @@ -67,37 +67,40 @@ end local function check_rules(pos,elapsed) - local hour = math.floor(minetest.get_timeofday() * 24) - local meta = minetest.get_meta(pos) - local events = minetest.deserialize(meta:get_string("events")) - local numbers = minetest.deserialize(meta:get_string("numbers")) - local actions = minetest.deserialize(meta:get_string("actions")) - local done = minetest.deserialize(meta:get_string("done")) - local placer_name = meta:get_string("placer_name") - local number = meta:get_string("number") - - -- check all rules - for idx,act in ipairs(actions) do - if act ~= "" and numbers[idx] ~= "" then - 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, number) - done[idx] = true + if tubelib.data_not_corrupted(pos) then + local hour = math.floor(minetest.get_timeofday() * 24) + local meta = minetest.get_meta(pos) + local events = minetest.deserialize(meta:get_string("events")) + local numbers = minetest.deserialize(meta:get_string("numbers")) + local actions = minetest.deserialize(meta:get_string("actions")) + local done = minetest.deserialize(meta:get_string("done")) + local placer_name = meta:get_string("placer_name") + local number = meta:get_string("number") + + -- check all rules + for idx,act in ipairs(actions) do + if act ~= "" and numbers[idx] ~= "" then + 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, number) + done[idx] = true + end + else + done[idx] = false end - else - done[idx] = false end end + + -- prepare for the next day + if hour == 23 then + done = {false,false,false,false,false,false} + end + meta:set_string("done", minetest.serialize(done)) + meta:set_string("infotext","Tubelib Timer "..hour..":00") + return true end - - -- prepare for the next day - if hour == 23 then - done = {false,false,false,false,false,false} - end - meta:set_string("done", minetest.serialize(done)) - meta:set_string("infotext","Tubelib Timer "..hour..":00") - return true + return false end diff --git a/tubelib_addons3/distributor.lua b/tubelib_addons3/distributor.lua index bc77499..f664117 100644 --- a/tubelib_addons3/distributor.lua +++ b/tubelib_addons3/distributor.lua @@ -254,9 +254,12 @@ end -- move items to the output slots local function keep_running(pos, elapsed) - local meta = M(pos) - distributing(pos, meta) - return State:is_active(meta) + if tubelib.data_not_corrupted(pos) then + local meta = M(pos) + distributing(pos, meta) + return State:is_active(meta) + end + return false end local function on_receive_fields(pos, formname, fields, player) diff --git a/tubelib_addons3/pusher.lua b/tubelib_addons3/pusher.lua index 7f18514..0074d85 100644 --- a/tubelib_addons3/pusher.lua +++ b/tubelib_addons3/pusher.lua @@ -51,9 +51,12 @@ local function pushing(pos, meta) end local function keep_running(pos, elapsed) - local meta = M(pos) - pushing(pos, meta) - return State:is_active(meta) + if tubelib.data_not_corrupted(pos) then + local meta = M(pos) + pushing(pos, meta) + return State:is_active(meta) + end + return false end minetest.register_node("tubelib_addons3:pusher", { diff --git a/tubelib_addons3/pushing_chest.lua b/tubelib_addons3/pushing_chest.lua index 01c4b4a..53baa91 100644 --- a/tubelib_addons3/pushing_chest.lua +++ b/tubelib_addons3/pushing_chest.lua @@ -90,33 +90,36 @@ local function configured(pos, item) end local function shift_items(pos, elapsed) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - if not inv:is_empty("shift") then - local number = meta:get_string("number") - local player_name = meta:get_string("player_name") - local offs = meta:get_int("offs") - meta:set_int("offs", offs + 1) - for i = 0,7 do - local idx = ((i + offs) % 8) + 1 - local stack = inv:get_stack("shift", idx) - if stack:get_count() > 0 then - if tubelib.push_items(pos, "R", stack, player_name) then - -- The effort is needed here for the case the - -- pusher pushes into its own chest. - local num = stack:get_count() - stack = inv:get_stack("shift", idx) - stack:take_item(num) - inv:set_stack("shift", idx, stack) - aging(pos, meta) - return true - else - set_state(meta, "blocked") + if tubelib.data_not_corrupted(pos) then + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + if not inv:is_empty("shift") then + local number = meta:get_string("number") + local player_name = meta:get_string("player_name") + local offs = meta:get_int("offs") + meta:set_int("offs", offs + 1) + for i = 0,7 do + local idx = ((i + offs) % 8) + 1 + local stack = inv:get_stack("shift", idx) + if stack:get_count() > 0 then + if tubelib.push_items(pos, "R", stack, player_name) then + -- The effort is needed here for the case the + -- pusher pushes into its own chest. + local num = stack:get_count() + stack = inv:get_stack("shift", idx) + stack:take_item(num) + inv:set_stack("shift", idx, stack) + aging(pos, meta) + return true + else + set_state(meta, "blocked") + end end end end + return true end - return true + return false end local function formspec()