sequencer and timer added

further code improvements
This commit is contained in:
Joachim Stolberg 2019-08-24 14:12:33 +02:00
parent 90c21db8c0
commit 266195db74
28 changed files with 528 additions and 15 deletions

View File

@ -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)

View File

@ -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,

View File

@ -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,

View File

@ -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))

View File

@ -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)

View File

@ -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,

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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")

View File

@ -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,

View File

@ -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",

View File

@ -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",

View File

@ -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",

278
logic/sequencer.lua Normal file
View File

@ -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")

View File

@ -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

View File

@ -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",

215
logic/timer.lua Normal file
View File

@ -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")

View File

@ -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)

View File

@ -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",

View File

@ -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

View File

@ -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,

View File

@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 254 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 272 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 B

View File

@ -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).." ")