diff --git a/.test/akku.lua b/.test/akku.lua index 02a714f..bc3da8f 100644 --- a/.test/akku.lua +++ b/.test/akku.lua @@ -55,7 +55,7 @@ local function on_receive_fields(pos, formname, fields, player) end local function after_place_node(pos, placer) - local mem = tubelib2.get_mem(pos) + local mem = tubelib2.init_mem(pos) mem.running = true mem.capa = 0 minetest.get_node_timer(pos):start(CYCLE_TIME) diff --git a/.test/sink.lua b/.test/sink.lua index bf30ffe..65711d7 100644 --- a/.test/sink.lua +++ b/.test/sink.lua @@ -65,6 +65,7 @@ minetest.register_node("techage:sink", { tiles = {'techage_electric_button.png'}, after_place_node = function(pos) + local mem = tubelib2.init_mem(pos) M(pos):set_string("infotext", "off") end, diff --git a/.test/source.lua b/.test/source.lua index 2cdbc31..b6cf457 100644 --- a/.test/source.lua +++ b/.test/source.lua @@ -46,6 +46,7 @@ minetest.register_node("techage:source", { 'techage_electric_button.png^techage_appl_electronic_fab.png', }, after_place_node = function(pos) + local mem = tubelib2.init_mem(pos) M(pos):set_string("infotext", "off") end, diff --git a/basic_machines/pusher.lua b/basic_machines/pusher.lua index f11d80d..7a27276 100644 --- a/basic_machines/pusher.lua +++ b/basic_machines/pusher.lua @@ -129,7 +129,6 @@ local node_name_ta2, node_name_ta3, node_name_ta4 = standby_ticks = STANDBY_TICKS, tubing = tubing, after_place_node = function(pos, placer) - local mem = tubelib2.get_mem(pos) local meta = M(pos) local node = minetest.get_node(pos) meta:set_int("pull_dir", techage.side_to_outdir("L", node.param2)) diff --git a/basic_machines/source.lua b/basic_machines/source.lua index ea0a28b..1961a69 100644 --- a/basic_machines/source.lua +++ b/basic_machines/source.lua @@ -126,7 +126,7 @@ minetest.register_node("techage:t2_source", { on_construct = tubelib2.init_mem, after_place_node = function(pos, placer) - local mem = tubelib2.get_mem(pos) + local mem = tubelib2.init_mem(pos) State2:node_init(pos, mem, "") mem.state_num = 2 on_rightclick(pos) diff --git a/basis/consumer.lua b/basis/consumer.lua index c995352..209b08c 100644 --- a/basis/consumer.lua +++ b/basis/consumer.lua @@ -157,7 +157,7 @@ function techage.register_consumer(base_name, inv_name, tiles, tNode, validState after_place_node = function(pos, placer, itemstack, pointed_thing) local meta = M(pos) - local mem = tubelib2.get_mem(pos) + local mem = tubelib2.init_mem(pos) local node = minetest.get_node(pos) meta:set_int("push_dir", techage.side_to_indir("L", node.param2)) meta:set_int("pull_dir", techage.side_to_indir("R", node.param2)) @@ -176,6 +176,7 @@ function techage.register_consumer(base_name, inv_name, tiles, tNode, validState tNode.after_dig_node(pos, oldnode, oldmetadata, digger) end techage.remove_node(pos) + tubelib2.del_mem(pos) end, can_dig = tNode.can_dig, diff --git a/coal_power_station/akkubox.lua b/coal_power_station/akkubox.lua index 65cda57..5d16813 100644 --- a/coal_power_station/akkubox.lua +++ b/coal_power_station/akkubox.lua @@ -130,7 +130,7 @@ minetest.register_node("techage:ta3_akku", { on_construct = tubelib2.init_mem, after_place_node = function(pos, placer, itemstack) - local mem = tubelib2.get_mem(pos) + local mem = tubelib2.init_mem(pos) State:node_init(pos, mem, "") mem.capa = get_capa(itemstack) on_rightclick(pos) diff --git a/coal_power_station/boiler_top.lua b/coal_power_station/boiler_top.lua index 9b52e12..a11646b 100644 --- a/coal_power_station/boiler_top.lua +++ b/coal_power_station/boiler_top.lua @@ -245,7 +245,7 @@ minetest.register_node("techage:coalboiler_top", { end, after_place_node = function(pos, placer) - local mem = tubelib2.get_mem(pos) + local mem = tubelib2.init_mem(pos) State:node_init(pos, mem, "") local node = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}) if node.name == "techage:coalboiler_base" then diff --git a/coal_power_station/generator.lua b/coal_power_station/generator.lua index 4d9b2a5..c4acede 100644 --- a/coal_power_station/generator.lua +++ b/coal_power_station/generator.lua @@ -115,7 +115,7 @@ minetest.register_node("techage:generator", { on_construct = tubelib2.init_mem, after_place_node = function(pos, placer) - local mem = tubelib2.get_mem(pos) + local mem = tubelib2.init_mem(pos) local number = techage.add_node(pos, "techage:generator") State:node_init(pos, mem, number) on_rightclick(pos) diff --git a/furnace/booster.lua b/furnace/booster.lua index c3a32b1..539817a 100644 --- a/furnace/booster.lua +++ b/furnace/booster.lua @@ -78,6 +78,7 @@ minetest.register_node("techage:ta3_booster", { on_construct = tubelib2.init_mem, after_place_node = function(pos, placer) + local mem = tubelib2.init_mem(pos) local node = minetest.get_node(pos) local indir = techage.side_to_indir("R", node.param2) M(pos):set_int("indir", indir) diff --git a/init.lua b/init.lua index 88314a4..b3d8d67 100644 --- a/init.lua +++ b/init.lua @@ -156,6 +156,8 @@ else dofile(MP.."/logic/repeater.lua") dofile(MP.."/logic/programmer.lua") dofile(MP.."/logic/signallamp.lua") + dofile(MP.."/logic/sequencer.lua") + dofile(MP.."/logic/timer.lua") -- Test dofile(MP.."/recipe_checker.lua") diff --git a/iron_age/hopper.lua b/iron_age/hopper.lua index 81ef87d..64ae3c1 100644 --- a/iron_age/hopper.lua +++ b/iron_age/hopper.lua @@ -117,6 +117,7 @@ minetest.register_node("techage:hopper_ta1", { after_dig_node = function(pos, oldnode, oldmetadata, digger) techage.remove_node(pos) + tubelib2.del_mem(pos) end, on_rotate = screwdriver.disallow, diff --git a/logic/button.lua b/logic/button.lua index 30af6ac..0674b7b 100644 --- a/logic/button.lua +++ b/logic/button.lua @@ -131,6 +131,7 @@ minetest.register_node("techage:ta3_button_off", { after_dig_node = function(pos, oldnode, oldmetadata, digger) techage.remove_node(pos) + tubelib2.del_mem(pos) end, on_rotate = screwdriver.disallow, @@ -176,6 +177,7 @@ minetest.register_node("techage:ta3_button_on", { after_dig_node = function(pos, oldnode, oldmetadata, digger) techage.remove_node(pos) + tubelib2.del_mem(pos) end, paramtype2 = "facedir", diff --git a/logic/detector.lua b/logic/detector.lua index b395a5c..0d4bad1 100644 --- a/logic/detector.lua +++ b/logic/detector.lua @@ -55,6 +55,7 @@ minetest.register_node("techage:ta3_detector_off", { after_place_node = function(pos, placer) local meta = M(pos) + local mem = tubelib2.init_mem(pos) logic.after_place_node(pos, placer, "techage:ta3_detector_off", S("TA3 Detector")) logic.infotext(meta, S("TA3 Detector")) meta:set_string("formspec", formspec(meta)) @@ -78,6 +79,7 @@ minetest.register_node("techage:ta3_detector_off", { after_dig_node = function(pos, oldnode, oldmetadata, digger) techage.remove_node(pos) + tubelib2.del_mem(pos) end, on_rotate = screwdriver.disallow, @@ -114,6 +116,7 @@ minetest.register_node("techage:ta3_detector_on", { after_dig_node = function(pos, oldnode, oldmetadata, digger) techage.remove_node(pos) + tubelib2.del_mem(pos) end, paramtype2 = "facedir", diff --git a/logic/repeater.lua b/logic/repeater.lua index 424966e..2b04c39 100644 --- a/logic/repeater.lua +++ b/logic/repeater.lua @@ -38,7 +38,7 @@ minetest.register_node("techage:ta3_repeater", { after_place_node = function(pos, placer) local meta = M(pos) - local mem = tubelib2.get_mem(pos) + local mem = tubelib2.init_mem(pos) logic.after_place_node(pos, placer, "techage:ta3_repeater", S("TA3 Repeater")) logic.infotext(meta, S("TA3 Repeater")) meta:set_string("formspec", formspec(meta)) @@ -70,6 +70,7 @@ minetest.register_node("techage:ta3_repeater", { after_dig_node = function(pos) techage.remove_node(pos) + tubelib2.del_mem(pos) end, paramtype = "light", diff --git a/logic/sequencer.lua b/logic/sequencer.lua new file mode 100644 index 0000000..3c7c728 --- /dev/null +++ b/logic/sequencer.lua @@ -0,0 +1,278 @@ +--[[ + + TechAge + ======= + + Copyright (C) 2017-2019 Joachim Stolberg + + GPL v3 + See LICENSE.txt for more information + + TA3 Sequencer + +]]-- + +-- for lazy programmers +local M = minetest.get_meta +local S = techage.S + +local logic = techage.logic +local NUM_SLOTS = 8 + +local sAction = ",on,off" +local kvAction = {[""]=1, ["on"]=2, ["off"]=3} +local tAction = {nil, "on", "off"} + +local function new_rules() + local tbl = {} + for idx = 1,NUM_SLOTS do + tbl[idx] = {offs = "", num = "", act = 1} + end + return tbl +end + +local function formspec(state, rules, endless) + local tbl = {"size[8,9.2]".. + default.gui_bg.. + default.gui_bg_img.. + default.gui_slots.. + "label[0,0;Number(s)]label[2.1,0;Command]label[6.4,0;Offset/s]"} + + for idx, rule in ipairs(rules or {}) do + tbl[#tbl+1] = "field[0.2,"..(-0.2+idx)..";2,1;num"..idx..";;"..(rule.num or "").."]" + tbl[#tbl+1] = "dropdown[2,"..(-0.4+idx)..";3.9,1;act"..idx..";"..sAction..";"..(rule.act or "").."]" + tbl[#tbl+1] = "field[6.2,"..(-0.2+idx)..";2,1;offs"..idx..";;"..(rule.offs or "").."]" + end + tbl[#tbl+1] = "checkbox[0,8.5;endless;Run endless;"..dump(endless).."]" + tbl[#tbl+1] = "image_button[5,8.5;1,1;".. techage.state_button(state) ..";button;]" + tbl[#tbl+1] = "button[6.2,8.5;1.5,1;help;help]" + + return table.concat(tbl) +end + +local function formspec_help() + return "size[8,9.2]".. + default.gui_bg.. + default.gui_bg_img.. + default.gui_slots.. + "label[2,0;TA3 Sequencer Help]".. + "label[0,1;Define a sequence of commands\nto control other machines.]".. + "label[0,2.2;Numbers(s) are the node numbers,\nthe command shall sent to.]".. + "label[0,3.4;The commands 'on'/'off' are used\n for machines and other nodes.]".. + "label[0,4.6;Offset is the time to the\nnext line in seconds (1..999).]".. + "label[0,5.8;If endless is set, the Sequencer\nrestarts again and again.]".. + "label[0,7;The command ' ' does nothing,\nonly consuming the offset time.]".. + "button[3,8;2,1;exit;close]" +end + +local function stop_the_sequencer(pos) + local mem = tubelib2.get_mem(pos) + local meta = M(pos) + mem.running = false + mem.endless = mem.endless or false + mem.rules = mem.rules or new_rules() + logic.infotext(meta, S("TA3 Sequencer"), "stopped") + meta:set_string("formspec", formspec(techage.STOPPED, mem.rules, mem.endless)) + minetest.get_node_timer(pos):stop() + return false +end + +local function get_next_slot(idx, rules, endless) + idx = idx + 1 + if idx <= #rules and rules[idx].offs ~= "" and rules[idx].num ~= "" then + return idx + elseif endless then + return 1 + end + return nil +end + +local function restart_timer(pos, time) + local timer = minetest.get_node_timer(pos) + if timer:is_started() then + timer:stop() + end + if type(time) == "number" then + timer:start(time) + end +end + +local function check_rules(pos, elapsed) + local mem = tubelib2.get_mem(pos) + local own_num = M(pos):get_string("node_number") + mem.rules = mem.rules or new_rules() + mem.running = mem.running or false + mem.index = mem.index or 1 + mem.endless = mem.endless or false + while true do -- process all rules as long as offs == 0 + local rule = mem.rules[mem.index] + local offs = tonumber(mem.rules[mem.index].offs or 1) + techage.send_multi(rule.num, tAction[rule.act], own_num) + mem.index = get_next_slot(mem.index, mem.rules, mem.endless) + if mem.index ~= nil and offs ~= nil and mem.running then + -- after the last rule a pause with 1 or more sec is required + if mem.index == 1 and offs < 1 then + offs = 1 + end + if offs > 0 then + minetest.after(0, restart_timer, pos, offs) + return false + end + else + return stop_the_sequencer(pos) + end + end + return false +end + +local function start_the_sequencer(pos) + local mem = tubelib2.get_mem(pos) + local meta = M(pos) + mem.running = true + mem.endless = mem.endless or false + mem.rules = mem.rules or new_rules() + logic.infotext(meta, S("TA3 Sequencer"), "running") + meta:set_string("formspec", formspec(techage.RUNNING, mem.rules, mem.endless)) + minetest.get_node_timer(pos):start(0.1) + return false +end + +local function on_receive_fields(pos, formname, fields, player) + if minetest.is_protected(pos, player:get_player_name()) then + return + end + + local meta = M(pos) + local mem = tubelib2.get_mem(pos) + mem.running = mem.running or false + mem.endless = mem.endless or false + mem.rules = mem.rules or new_rules() + + if fields.help ~= nil then + meta:set_string("formspec", formspec_help()) + return + end + + if fields.endless ~= nil then + mem.endless = fields.endless == "true" + mem.index = 1 + end + + if fields.exit ~= nil then + if mem.running then + meta:set_string("formspec", formspec(techage.RUNNING, mem.rules, mem.endless)) + else + meta:set_string("formspec", formspec(techage.STOPPED, mem.rules, mem.endless)) + end + return + end + + for idx = 1,NUM_SLOTS do + if fields["offs"..idx] ~= nil then + mem.rules[idx].offs = tonumber(fields["offs"..idx]) or "" + end + if fields["num"..idx] ~= nil and + techage.check_numbers(fields["num"..idx], player:get_player_name()) then + mem.rules[idx].num = fields["num"..idx] + end + if fields["act"..idx] ~= nil then + mem.rules[idx].act = kvAction[fields["act"..idx]] + end + end + + if fields.button ~= nil then + if mem.running then + stop_the_sequencer(pos) + else + start_the_sequencer(pos) + end + elseif fields.num1 ~= nil then -- any other change? + stop_the_sequencer(pos) + else + if mem.running then + meta:set_string("formspec", formspec(techage.RUNNING, mem.rules, mem.endless)) + else + meta:set_string("formspec", formspec(techage.STOPPED, mem.rules, mem.endless)) + end + end +end + +minetest.register_node("techage:ta3_sequencer", { + description = S("TA3 Sequencer"), + tiles = { + -- up, down, right, left, back, front + "techage_filling_ta3.png^techage_frame_ta3_top.png", + "techage_filling_ta3.png^techage_frame_ta3_top.png", + "techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_sequencer.png", + }, + + after_place_node = function(pos, placer) + local meta = M(pos) + local mem = tubelib2.init_mem(pos) + logic.after_place_node(pos, placer, "techage:ta3_sequencer", S("TA3 Sequencer")) + logic.infotext(meta, S("TA3 Sequencer", "stopped")) + mem.rules = new_rules() + mem.index = 1 + mem.running = false + mem.endless = false + meta:set_string("formspec", formspec(techage.STOPPED, mem.rules, mem.endless)) + end, + + on_receive_fields = on_receive_fields, + + on_dig = function(pos, node, puncher, pointed_thing) + if minetest.is_protected(pos, puncher:get_player_name()) then + return + end + local mem = tubelib2.get_mem(pos) + if not mem.running then + minetest.node_dig(pos, node, puncher, pointed_thing) + techage.remove_node(pos) + tubelib2.del_mem(pos) + end + end, + + on_timer = check_rules, + + paramtype2 = "facedir", + groups = {choppy=2, cracky=2, crumbly=2}, + is_ground_content = false, + sounds = default.node_sound_stone_defaults(), +}) + + +minetest.register_craft({ + output = "techage:ta3_sequencer", + recipe = { + {"group:wood", "group:wood", ""}, + {"default:mese_crystal", "techage:vacuum_tube", ""}, + {"group:wood", "group:wood", ""}, + }, +}) + +techage.register_node({"techage:ta3_sequencer"}, { + on_recv_message = function(pos, topic, payload) + if topic == "on" then + start_the_sequencer(pos) + elseif topic == "off" then + -- do not stop immediately + local mem = tubelib2.get_mem(pos) + mem.endless = false + end + end, + on_node_load = function(pos) + local mem = tubelib2.get_mem(pos) + if mem.running then + minetest.get_node_timer(pos):start(1) + end + end, +}) + +techage.register_entry_page("ta3l", "sequencer", + S("TA3 Sequencer"), + S("The Sequencer block allows to define sequences of on/off commands@n".. + "with time delays in between. A sequence of up to 8 steps@n".. + "can be programmed, each with destination block numbers, on/off command,@n".. + "and time gap to the next step in seconds. The Sequencer can run endless@n".. + "or only once and can be switches on/off by other blocks."), + "techage:ta3_sequencer") diff --git a/logic/signallamp.lua b/logic/signallamp.lua index 2dbc9e5..4f33dbc 100644 --- a/logic/signallamp.lua +++ b/logic/signallamp.lua @@ -55,6 +55,7 @@ minetest.register_node("techage:signal_lamp_off", { after_dig_node = function(pos, oldnode, oldmetadata, digger) techage.remove_node(pos) + tubelib2.del_mem(pos) if COLORED then unifieddyes.after_dig_node(pos, oldnode, oldmetadata, digger) end @@ -65,7 +66,7 @@ minetest.register_node("techage:signal_lamp_off", { paramtype = "light", paramtype2 = "color", - palette = "unifieddyes_palette_extended.png", + palette = COLORED and "unifieddyes_palette_extended.png" or 'techage_color16.png', place_param2 = 241, sunlight_propagates = true, sounds = default.node_sound_stone_defaults(), @@ -90,7 +91,7 @@ minetest.register_node("techage:signal_lamp_on", { paramtype = "light", paramtype2 = "color", - palette = "unifieddyes_palette_extended.png", + palette = COLORED and "unifieddyes_palette_extended.png" or 'techage_color16.png', groups = {choppy=2, cracky=1, not_in_creative_inventory=1, ud_param2_colorable = 1}, on_construct = COLORED and unifieddyes.on_construct, @@ -98,6 +99,7 @@ minetest.register_node("techage:signal_lamp_on", { after_dig_node = function(pos, oldnode, oldmetadata, digger) techage.remove_node(pos) + tubelib2.del_mem(pos) if COLORED then unifieddyes.after_dig_node(pos, oldnode, oldmetadata, digger) end diff --git a/logic/terminal.lua b/logic/terminal.lua index f184697..83fd877 100644 --- a/logic/terminal.lua +++ b/logic/terminal.lua @@ -208,6 +208,7 @@ local function register_terminal(num, tiles, node_box, selection_box) after_dig_node = function(pos) techage.remove_node(pos) + tubelib2.del_mem(pos) end, paramtype = "light", diff --git a/logic/timer.lua b/logic/timer.lua new file mode 100644 index 0000000..aac4505 --- /dev/null +++ b/logic/timer.lua @@ -0,0 +1,215 @@ +--[[ + + TechAge + ======= + + Copyright (C) 2017-2019 Joachim Stolberg + + GPL v3 + See LICENSE.txt for more information + + TA3 Sequencer + +]]-- + +-- for lazy programmers +local M = minetest.get_meta +local S = techage.S + +local logic = techage.logic +local CYCLE_TIME = 8 + +local tTime = { + ["00:00"] = 1, ["02:00"] = 2, ["04:00"] = 3, + ["06:00"] = 4, ["08:00"] = 5, ["10:00"] = 6, + ["12:00"] = 7, ["14:00"] = 8, ["16:00"] = 9, + ["18:00"] =10, ["20:00"] =11, ["22:00"] =12, +} + +local sTime = "00:00,02:00,04:00,06:00,08:00,10:00,12:00,14:00,16:00,18:00,20:00,22:00" + +local tAction = { + [""] = 1, + ["on"] = 2, + ["off"] = 3, +} + +local sAction = ",on,off" + +local function deserialize(meta, name) + local s = meta:get_string(name) or "" + if s ~= "" then + return minetest.deserialize(s) + end +end + +local function formspec(events, numbers, actions) + return "size[8,8]".. + default.gui_bg.. + default.gui_bg_img.. + default.gui_slots.. + + "label[0,0;Time]label[2.3,0;Number(s)]label[4.5,0;Command]".. + "dropdown[0,1;2,1;e1;"..sTime..";"..events[1].."]".. + "field[2.3,1.2;2,1;n1;;"..numbers[1].."]" .. + "dropdown[4.5,1;3,1;a1;"..sAction..";"..tAction[actions[1]].."]".. + + "dropdown[0,2;2,1;e2;"..sTime..";"..events[2].."]".. + "field[2.3,2.2;2,1;n2;;"..numbers[2].."]" .. + "dropdown[4.5,2;3,1;a2;"..sAction..";"..tAction[actions[2]].."]".. + + "dropdown[0,3;2,1;e3;"..sTime..";"..events[3].."]".. + "field[2.3,3.2;2,1;n3;;"..numbers[3].."]" .. + "dropdown[4.5,3;3,1;a3;"..sAction..";"..tAction[actions[3]].."]".. + + "dropdown[0,4;2,1;e4;"..sTime..";"..events[4].."]".. + "field[2.3,4.2;2,1;n4;;"..numbers[4].."]" .. + "dropdown[4.5,4;3,1;a4;"..sAction..";"..tAction[actions[4]].."]".. + + "dropdown[0,5;2,1;e5;"..sTime..";"..events[5].."]".. + "field[2.3,5.2;2,1;n5;;"..numbers[5].."]" .. + "dropdown[4.5,5;3,1;a5;"..sAction..";"..tAction[actions[5]].."]".. + + "dropdown[0,6;2,1;e6;"..sTime..";"..events[6].."]".. + "field[2.3,6.2;2,1;n6;;"..numbers[6].."]" .. + "dropdown[4.5,6;3,1;a6;"..sAction..";"..tAction[actions[6]].."]".. + + "button_exit[3,7;2,1;exit;close]" +end + + +local function check_rules(pos,elapsed) + local mem = tubelib2.get_mem(pos) + mem.done = mem.done or {false,false,false,false,false,false} + local hour = math.floor(minetest.get_timeofday() * 24) + local meta = minetest.get_meta(pos) + local events = deserialize(meta, "events") + local numbers = deserialize(meta, "numbers") + local actions = deserialize(meta, "actions") + local number = meta:get_string("node_number") + + if events and numbers and actions then + -- 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 mem.done[idx] == false then -- not already executed? + techage.send_multi(numbers[idx], act, number) + mem.done[idx] = true + end + else + mem.done[idx] = false + end + end + end + + -- prepare for the next day + if hour == 23 then + mem.done = {false,false,false,false,false,false} + end + return true + end + return false +end + + +minetest.register_node("techage:ta3_timer", { + description = S("TA3 Timer"), + tiles = { + -- up, down, right, left, back, front + "techage_filling_ta3.png^techage_frame_ta3_top.png", + "techage_filling_ta3.png^techage_frame_ta3_top.png", + "techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_timer.png", + }, + + after_place_node = function(pos, placer) + local meta = M(pos) + local mem = tubelib2.init_mem(pos) + logic.after_place_node(pos, placer, "techage:ta3_timer", S("TA3 Timer")) + logic.infotext(meta, S("TA3 Timer")) + local events = {1,1,1,1,1,1} + local numbers = {"0000","","","","",""} + local actions = {"","","","","",""} + mem.done = {false,false,false,false,false,false} + meta:set_string("events", minetest.serialize(events)) + meta:set_string("numbers", minetest.serialize(numbers)) + meta:set_string("actions", minetest.serialize(actions)) + meta:set_string("formspec", formspec(events, numbers, actions)) + minetest.get_node_timer(pos):start(CYCLE_TIME) + end, + + on_receive_fields = function(pos, formname, fields, player) + local meta = minetest.get_meta(pos) + if minetest.is_protected(pos, player:get_player_name()) then + return + end + + local events = minetest.deserialize(meta:get_string("events")) + for idx, evt in ipairs({fields.e1, fields.e2, fields.e3, fields.e4, fields.e5, fields.e6}) do + if evt ~= nil then + events[idx] = tTime[evt] + end + end + meta:set_string("events", minetest.serialize(events)) + + local numbers = minetest.deserialize(meta:get_string("numbers")) + for idx, num in ipairs({fields.n1, fields.n2, fields.n3, fields.n4, fields.n5, fields.n6}) do + if num ~= nil and techage.check_numbers(num, player:get_player_name()) then + numbers[idx] = num + end + end + meta:set_string("numbers", minetest.serialize(numbers)) + + local actions = minetest.deserialize(meta:get_string("actions")) + for idx, act in ipairs({fields.a1, fields.a2, fields.a3, fields.a4, fields.a5, fields.a6}) do + if act ~= nil then + actions[idx] = act + end + end + meta:set_string("actions", minetest.serialize(actions)) + meta:set_string("formspec", formspec(events, numbers, actions)) + local mem = tubelib2.get_mem(pos) + mem.done = {false,false,false,false,false,false} + end, + + on_timer = check_rules, + + after_dig_node = function(pos) + techage.remove_node(pos) + tubelib2.del_mem(pos) + end, + + paramtype = "light", + paramtype2 = "facedir", + sunlight_propagates = true, + sounds = default.node_sound_stone_defaults(), + groups = {choppy=2, cracky=2, crumbly=2}, + is_ground_content = false, +}) + + +minetest.register_craft({ + output = "techage:ta3_timer", + recipe = { + {"group:wood", "group:wood", ""}, + {"default:gold_ingot", "techage:vacuum_tube", ""}, + {"group:wood", "group:wood", ""}, + }, +}) + +techage.register_node({"techage:ta3_timer"}, { + on_node_load = function(pos) + minetest.get_node_timer(pos):start(CYCLE_TIME) + -- check rules for just loaded areas + local mem = tubelib2.get_mem(pos) + mem.done = {false,false,false,false,false,false} + check_rules(pos,0) + end, +}) + +techage.register_entry_page("ta3l", "timer", + S("TA3 Timer"), + S("The Timer block allows to turn machines/nodes on and off@n".. + "based on the day time."), + "techage:ta3_timer") diff --git a/power/powerswitch.lua b/power/powerswitch.lua index e7d7d71..02dc4d5 100644 --- a/power/powerswitch.lua +++ b/power/powerswitch.lua @@ -195,7 +195,6 @@ techage.power.register_node({"techage:powerswitch_box"}, { techage.register_node({"techage:powerswitch", "techage:powerswitch_on"}, { on_recv_message = function(pos, topic, payload) - local mem = tubelib2.get_mem(pos) local node = minetest.get_node(pos) if topic == "on" and node.name == "techage:powerswitch" then switch_on(pos, node) diff --git a/solar/minicell.lua b/solar/minicell.lua index 65b375d..fa9c6dc 100644 --- a/solar/minicell.lua +++ b/solar/minicell.lua @@ -85,7 +85,7 @@ minetest.register_node("techage:ta4_solar_minicell", { local number = techage.add_node(pos, "techage:ta4_solar_minicell") meta:set_string("node_number", number) meta:set_string("infotext", S("TA4 Streetlamp Solar Cell").." "..number) - local mem = tubelib2.get_mem(pos) + local mem = tubelib2.init_mem(pos) mem.capa = 0 mem.providing = false minetest.get_node_timer(pos):start(CYCLE_TIME) @@ -93,6 +93,7 @@ minetest.register_node("techage:ta4_solar_minicell", { after_dig_node = function(pos) techage.remove_node(pos) + tubelib2.del_mem(pos) end, paramtype2 = "facedir", diff --git a/steam_engine/boiler.lua b/steam_engine/boiler.lua index 7ed712c..6eb486d 100644 --- a/steam_engine/boiler.lua +++ b/steam_engine/boiler.lua @@ -253,7 +253,7 @@ minetest.register_node("techage:boiler2", { end, after_place_node = function(pos, placer) - local mem = tubelib2.get_mem(pos) + local mem = tubelib2.init_mem(pos) State:node_init(pos, mem, "") local node = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}) if node.name == "techage:boiler1" then diff --git a/steam_engine/flywheel.lua b/steam_engine/flywheel.lua index 212b7a1..3d831e2 100644 --- a/steam_engine/flywheel.lua +++ b/steam_engine/flywheel.lua @@ -131,7 +131,7 @@ minetest.register_node("techage:flywheel", { on_construct = tubelib2.init_mem, after_place_node = function(pos, placer) - local mem = tubelib2.get_mem(pos) + local mem = tubelib2.init_mem(pos) State:node_init(pos, mem, "") on_rightclick(pos) end, diff --git a/steam_engine/gearbox.lua b/steam_engine/gearbox.lua index 52c7912..281101b 100644 --- a/steam_engine/gearbox.lua +++ b/steam_engine/gearbox.lua @@ -56,7 +56,7 @@ local function on_rightclick(pos, node, clicker) end local function after_place_node(pos, placer, itemstack, pointed_thing) - local mem = tubelib2.get_mem(pos) + local mem = tubelib2.init_mem(pos) minetest.get_node_timer(pos):start(CYCLE_TIME) power.consumer_start(pos, mem, CYCLE_TIME, PWR_NEEDED) end diff --git a/textures/techage_appl_sequencer.png b/textures/techage_appl_sequencer.png new file mode 100644 index 0000000..6d028a8 Binary files /dev/null and b/textures/techage_appl_sequencer.png differ diff --git a/textures/techage_appl_timer.png b/textures/techage_appl_timer.png new file mode 100644 index 0000000..960376d Binary files /dev/null and b/textures/techage_appl_timer.png differ diff --git a/textures/techage_color16.png b/textures/techage_color16.png new file mode 100644 index 0000000..115dfd6 Binary files /dev/null and b/textures/techage_color16.png differ diff --git a/tools/repairkit.lua b/tools/repairkit.lua index a9a8b55..272642f 100644 --- a/tools/repairkit.lua +++ b/tools/repairkit.lua @@ -26,6 +26,11 @@ local Nodes2Convert = { local function read_state(itemstack, user, pointed_thing) local pos = pointed_thing.under if pos and user then + local time = math.floor(minetest.get_timeofday() * 24 * 6) + local hours = math.floor(time / 6) + local mins = (time % 6) * 10 + if mins < 10 then mins = "00" end + minetest.chat_send_player(user:get_player_name(), S("Time")..": "..hours..":"..mins.." ") local data = minetest.get_biome_data(pos) if data then minetest.chat_send_player(user:get_player_name(), S("Biome")..": "..data.biome..", "..S("Position temperature")..": "..math.floor(data.heat).." ")