pipe2 addded

This commit is contained in:
Joachim Stolberg 2020-01-31 19:55:10 +01:00
parent 859587713d
commit f049f7b18c
60 changed files with 1815 additions and 1419 deletions

View File

@ -1,62 +0,0 @@
-- for lazy programmers
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local P = minetest.string_to_pos
local M = minetest.get_meta
local CYCLE_TIME = 2
local PWR_CAPA = 15
local Cable = techage.ElectricCable
local power = techage.power
local function node_timer(pos, elapsed)
--print("node_timer source "..S(pos))
local mem = tubelib2.get_mem(pos)
if mem.generating then
local provided = power.generator_alive(pos, mem)
--print("provided", provided)
end
return mem.generating
end
local function on_rightclick(pos, node, clicker)
local mem = tubelib2.get_mem(pos)
if not mem.generating then
mem.generating = true
power.generator_start(pos, mem, PWR_CAPA)
minetest.get_node_timer(pos):start(CYCLE_TIME)
M(pos):set_string("infotext", "on")
else
mem.generating = false
power.generator_stop(pos, mem)
minetest.get_node_timer(pos):stop()
M(pos):set_string("infotext", "off")
end
end
minetest.register_node("techage:source", {
description = "Source",
tiles = {
-- up, down, right, left, back, front
'techage_electric_button.png^techage_appl_electronic_fab.png',
'techage_electric_button.png^techage_appl_electronic_fab.png',
'techage_electric_button.png^techage_appl_electronic_fab.png^techage_electric_plug.png',
'techage_electric_button.png^techage_appl_electronic_fab.png',
'techage_electric_button.png^techage_appl_electronic_fab.png',
'techage_electric_button.png^techage_appl_electronic_fab.png',
},
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2, not_in_creative_inventory=1},
is_ground_content = false,
on_rightclick = on_rightclick,
on_timer = node_timer,
})
techage.power.register_node({"techage:source"}, {
power_network = Cable,
after_place_node = function(pos)
local mem = tubelib2.init_mem(pos)
M(pos):set_string("infotext", "off")
end,
})

View File

@ -1,46 +0,0 @@
-- for lazy programmers
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local P = minetest.string_to_pos
local M = minetest.get_meta
local Cable = techage.ElectricCable
local power_switched = techage.power.power_switched
local function on_rightclick(pos, node, clicker)
local mem = tubelib2.get_mem(pos)
mem.interrupted_dirs = mem.interrupted_dirs or {}
mem.interrupted = not mem.interrupted
--print("switch", mem.interrupted)
if mem.interrupted then
mem.interrupted_dirs = {true, true, true, true, true, true}
for dir,_ in pairs(mem.connections) do
mem.interrupted_dirs[dir] = false
power_switched(pos)
mem.interrupted_dirs[dir] = true
end
else
mem.interrupted_dirs = {}
power_switched(pos)
end
end
minetest.register_node("techage:switch", {
description = "Switch",
tiles = {'techage_appl_switch_inv.png'},
--on_timer = node_timer,
on_rightclick = on_rightclick,
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {choppy=2, cracky=2, crumbly=2},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
techage.power2.register_node({"techage:switch"}, {
power_network = Cable,
})

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -51,7 +51,7 @@ local function build(pos, param2, AssemblyPlan, idx)
minetest.add_node(pos1, {name=node_name, param2=(param2 + fd_offs) % 4}) minetest.add_node(pos1, {name=node_name, param2=(param2 + fd_offs) % 4})
minetest.after(0.5, build, pos, param2, AssemblyPlan, idx+1) minetest.after(0.5, build, pos, param2, AssemblyPlan, idx+1)
else else
local mem = tubelib2.get_mem(pos) local mem = techage.get_mem(pos)
mem.assemble_locked = false mem.assemble_locked = false
end end
end end
@ -65,7 +65,7 @@ local function remove(pos, param2, AssemblyPlan, idx)
minetest.remove_node(pos1) minetest.remove_node(pos1)
minetest.after(0.5, remove, pos, param2, AssemblyPlan, idx-1) minetest.after(0.5, remove, pos, param2, AssemblyPlan, idx-1)
else else
local mem = tubelib2.get_mem(pos) local mem = techage.get_mem(pos)
mem.assemble_locked = false mem.assemble_locked = false
end end
end end
@ -98,7 +98,7 @@ function techage.assemble.build(pos, AssemblyPlan, player_name)
if minetest.is_protected(pos, player_name) then if minetest.is_protected(pos, player_name) then
return return
end end
local mem = tubelib2.get_mem(pos) local mem = techage.get_mem(pos)
if mem.assemble_locked then if mem.assemble_locked then
return return
end end
@ -115,7 +115,7 @@ function techage.assemble.remove(pos, AssemblyPlan, player_name)
if minetest.is_protected(pos, player_name) then if minetest.is_protected(pos, player_name) then
return return
end end
local mem = tubelib2.get_mem(pos) local mem = techage.get_mem(pos)
if mem.assemble_locked then if mem.assemble_locked then
return return
end end

View File

@ -18,22 +18,47 @@ local P = minetest.string_to_pos
local M = minetest.get_meta local M = minetest.get_meta
local function deserialize(s)
local tbl = {}
for line in s:gmatch("[^;]+") do
local num, spos = unpack(string.split(line, "="))
tbl[num] = {pos = minetest.string_to_pos(spos)}
end
return tbl
end
local function serialize(data)
local tbl = {}
for k,v in pairs(data) do
tbl[#tbl+1] = k.."="..minetest.pos_to_string(v.pos)
end
return table.concat(tbl, ";")
end
------------------------------------------------------------------ ------------------------------------------------------------------
-- Data base storage -- Data base storage
------------------------------------------------------------------- -------------------------------------------------------------------
local storage = minetest.get_mod_storage() local storage = minetest.get_mod_storage()
local NextNumber = minetest.deserialize(storage:get_string("NextNumber")) or 1 local NextNumber = minetest.deserialize(storage:get_string("NextNumber")) or 1
local Version = minetest.deserialize(storage:get_string("Version")) or 1 local Version = minetest.deserialize(storage:get_string("Version")) or 2
local Number2Pos = minetest.deserialize(storage:get_string("Number2Pos")) or {} local Number2Pos
if Version == 1 then
Version = 2
Number2Pos = minetest.deserialize(storage:get_string("Number2Pos")) or {}
else
Number2Pos = deserialize(storage:get_string("Number2Pos"))
end
local function update_mod_storage() local function update_mod_storage()
local t = minetest.get_us_time()
minetest.log("action", "[TechAge] Store data...") minetest.log("action", "[TechAge] Store data...")
storage:set_string("NextNumber", minetest.serialize(NextNumber)) storage:set_string("NextNumber", minetest.serialize(NextNumber))
storage:set_string("Version", minetest.serialize(Version)) storage:set_string("Version", minetest.serialize(Version))
storage:set_string("Number2Pos", minetest.serialize(Number2Pos)) storage:set_string("Number2Pos", serialize(Number2Pos))
-- store data each hour -- store data each hour
minetest.after(60*59, update_mod_storage) minetest.after(60*59, update_mod_storage)
minetest.log("action", "[TechAge] Data stored") t = minetest.get_us_time() - t
minetest.log("action", "[TechAge] Data stored. t="..t.."us")
end end
minetest.register_on_shutdown(function() minetest.register_on_shutdown(function()
@ -232,11 +257,7 @@ function techage.remove_node(pos)
local name local name
if Number2Pos[number] then if Number2Pos[number] then
name = Number2Pos[number].name name = Number2Pos[number].name
Number2Pos[number] = { Number2Pos[number].name = nil
pos = pos,
name = nil,
time = minetest.get_day_count() -- used for reservation timeout
}
end end
if item_handling_node(name) then if item_handling_node(name) then
Tube:after_dig_node(pos) Tube:after_dig_node(pos)
@ -485,18 +506,15 @@ end
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
local function data_maintenance() local function data_maintenance()
minetest.log("info", "[TechAge] Data maintenance started") minetest.log("info", "[TechAge] Data maintenance started")
-- Remove old unused positions -- Remove unused positions
local Tbl = table.copy(Number2Pos) local tbl = table.copy(Number2Pos)
Number2Pos = {} Number2Pos = {}
local day_cnt = minetest.get_day_count() for num,item in pairs(tbl) do
for num,item in pairs(Tbl) do local name = techage.get_node_lvm(item.pos).name
if item.name then if NodeDef[name] then
Number2Pos[num] = item Number2Pos[num] = item
-- data not older than 5 real days -- add node names which are not stored as file
elseif item.time and (item.time + (72*5)) > day_cnt then Number2Pos[num].name = name
Number2Pos[num] = item
else
minetest.log("info", "Position deleted", num)
end end
end end
minetest.log("info", "[TechAge] Data maintenance finished") minetest.log("info", "[TechAge] Data maintenance finished")
@ -504,8 +522,6 @@ end
generate_Key2Number() generate_Key2Number()
-- maintain data after 5 seconds minetest.after(2, data_maintenance)
-- (minetest.get_day_count() will not be valid at start time)
minetest.after(5, data_maintenance)

View File

@ -491,6 +491,7 @@ function NodeStates:on_node_load(pos, not_start_timer)
elseif not info.pos then elseif not info.pos then
minetest.log("warning", "[TA] Node at "..S(pos).." has no info.pos") minetest.log("warning", "[TA] Node at "..S(pos).." has no info.pos")
elseif not vector.equals(pos, info.pos) then elseif not vector.equals(pos, info.pos) then
print(S(pos), S(info.pos))
minetest.log("warning", "[TA] Node at "..S(pos).." is pos ~= info.pos") minetest.log("warning", "[TA] Node at "..S(pos).." is pos ~= info.pos")
end end
swap_node(pos, "techage:defect_dummy") swap_node(pos, "techage:defect_dummy")

View File

@ -45,10 +45,10 @@ local function input_string(recipe)
return table.concat(tbl, "") return table.concat(tbl, "")
end end
function techage.recipes.get(mem, rtype) function techage.recipes.get(nvm, rtype)
local recipes = Recipes[rtype] or {} local recipes = Recipes[rtype] or {}
local recipe_list = RecipeList[rtype] or {} local recipe_list = RecipeList[rtype] or {}
return recipes[recipe_list[mem.recipe_idx or 1]] return recipes[recipe_list[nvm.recipe_idx or 1]]
end end
-- Add 4 input/output/waste recipe -- Add 4 input/output/waste recipe
@ -95,11 +95,11 @@ function techage.recipes.add(rtype, recipe)
end end
end end
function techage.recipes.formspec(x, y, rtype, mem) function techage.recipes.formspec(x, y, rtype, nvm)
local recipes = Recipes[rtype] or {} local recipes = Recipes[rtype] or {}
local recipe_list = RecipeList[rtype] or {} local recipe_list = RecipeList[rtype] or {}
mem.recipe_idx = range(mem.recipe_idx or 1, 1, #recipe_list) nvm.recipe_idx = range(nvm.recipe_idx or 1, 1, #recipe_list)
local idx = mem.recipe_idx local idx = nvm.recipe_idx
local recipe = recipes[recipe_list[idx]] or RECIPE local recipe = recipes[recipe_list[idx]] or RECIPE
local output = recipe.output.name.." "..recipe.output.num local output = recipe.output.name.." "..recipe.output.num
local waste = recipe.waste.name.." "..recipe.waste.num local waste = recipe.waste.name.." "..recipe.waste.num
@ -119,14 +119,14 @@ function techage.recipes.on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then if minetest.is_protected(pos, player:get_player_name()) then
return return
end end
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.recipe_idx = mem.recipe_idx or 1 nvm.recipe_idx = nvm.recipe_idx or 1
if not mem.running then if not nvm.running then
if fields.next == ">>" then if fields.next == ">>" then
mem.recipe_idx = mem.recipe_idx + 1 nvm.recipe_idx = nvm.recipe_idx + 1
elseif fields.priv == "<<" then elseif fields.priv == "<<" then
mem.recipe_idx = mem.recipe_idx - 1 nvm.recipe_idx = nvm.recipe_idx - 1
end end
end end
end end

View File

@ -14,14 +14,46 @@
]]-- ]]--
local NUM_NODES_PER_MIN = 100 local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
-- Node data will be stored every NUM_SLOTS * CYCLE_TIME seconds
local NUM_SLOTS = 50
local CYCLE_TIME = 30
local NvmStore = {} local NvmStore = {}
local MemStore = {} local MemStore = {}
local NumNodes = 0 local NumNodes = 0
local StoredNodes = 0 local StoredNodes = 0
local NextNum = 0
local Timeslot = 0
local FNAME = minetest.get_worldpath()..DIR_DELIM.."techage_metadata.txt"
local function read_file()
local f = io.open(FNAME, "r")
if f ~= nil then
local s = f:read("*all")
io.close(f)
return minetest.deserialize(s) or {}
end
return {}
end
local function write_file(tbl)
local s = minetest.serialize(tbl)
local f = io.open(FNAME, "w")
f:write(s)
f:close()
end
NvmStore = read_file()
minetest.register_on_shutdown(function()
write_file(NvmStore)
end)
local function set_metadata(hash, tbl) local function set_metadata(hash, tbl)
local pos = minetest.get_position_from_hash(hash) local pos = minetest.get_position_from_hash(hash)
tbl.USED = nil
local data = minetest.serialize(tbl) local data = minetest.serialize(tbl)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_string("ta_data", data) meta:set_string("ta_data", data)
@ -37,68 +69,46 @@ local function get_metadata(hash)
end end
end end
local function storage_loop() local function nvm_storage()
local cnt = 0 local ToBeDeleted = {}
while true do for hash,tbl in pairs(NvmStore) do
NumNodes = 0 NumNodes = NumNodes + 1
StoredNodes = 0 if tbl.USED then
for hash,tbl in pairs(NvmStore) do if not tbl.SLOT then
NumNodes = NumNodes + 1 tbl.SLOT = NextNum % NUM_SLOTS
if tbl.__used__ then NextNum = NextNum + 1
tbl.__used__ = nil end
if tbl.SLOT == Timeslot then
set_metadata(hash, tbl) set_metadata(hash, tbl)
StoredNodes = StoredNodes + 1 StoredNodes = StoredNodes + 1
cnt = cnt + 1
if cnt > NUM_NODES_PER_MIN then
cnt = 0
coroutine.yield()
end
else
-- remove from memory if node is unloaded
local pos = minetest.get_position_from_hash(hash)
if minetest.get_node(pos).name == "ignore" then
NvmStore[hash] = nil
MemStore[hash] = nil
end
end end
else
ToBeDeleted[#ToBeDeleted+1] = hash
end end
coroutine.yield()
end end
for _,hash in ipairs(ToBeDeleted) do
NvmStore[hash] = nil
end
return #ToBeDeleted
end end
local co = coroutine.create(storage_loop)
local function cyclic_task() local function cyclic_task()
local t = minetest.get_us_time() local t = minetest.get_us_time()
coroutine.resume(co) Timeslot = (Timeslot + 1) % NUM_SLOTS
t = minetest.get_us_time() - t
print("[TA NVM Storage] duration="..t.."us, total="..NumNodes..", stored="..StoredNodes)
-- run every minutes
minetest.after(60, cyclic_task)
end
minetest.register_on_shutdown(function()
NumNodes = 0 NumNodes = 0
StoredNodes = 0 StoredNodes = 0
local t = minetest.get_us_time() local deleted = nvm_storage()
for k,v in pairs(NvmStore) do
NumNodes = NumNodes + 1
if v.__used__ then
v.__used__ = nil
set_metadata(k, v)
StoredNodes = StoredNodes + 1
end
end
t = minetest.get_us_time() - t t = minetest.get_us_time() - t
print("[TA NVM Storage] duration="..t.."us, total="..NumNodes..", stored="..StoredNodes) print("[TA NVM Storage] duration="..t.."us, total="..NumNodes..", stored="..StoredNodes..", deleted="..deleted)
end) minetest.after(CYCLE_TIME, cyclic_task)
end
minetest.after(CYCLE_TIME, cyclic_task)
minetest.after(60, cyclic_task)
-- To get the volatile node data as table -- To get the volatile node data as table
function techage.get_mem(pos, will_change) function techage.get_mem(pos)
local hash = minetest.hash_node_position(pos) local hash = minetest.hash_node_position(pos)
if not MemStore[hash] then if not MemStore[hash] then
MemStore[hash] = {} MemStore[hash] = {}
@ -112,10 +122,15 @@ function techage.get_nvm(pos)
if not NvmStore[hash] then if not NvmStore[hash] then
NvmStore[hash] = get_metadata(hash) or {} NvmStore[hash] = get_metadata(hash) or {}
end end
NvmStore[hash].__used__ = true NvmStore[hash].USED = true
return NvmStore[hash] return NvmStore[hash]
end end
function techage.peek_nvm(pos)
local hash = minetest.hash_node_position(pos)
return NvmStore[hash] or {}
end
-- To be called when a node is removed -- To be called when a node is removed
function techage.del_mem(pos) function techage.del_mem(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)

View File

@ -47,14 +47,14 @@ local function get_starter_name(pos)
end end
end end
local function formspec(self, pos, mem) local function formspec(self, pos, nvm)
return "size[8,7]".. return "size[8,7]"..
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
recipes.formspec(0, 0, "ta4_doser", mem).. recipes.formspec(0, 0, "ta4_doser", nvm)..
"image_button[6,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]".. "image_button[6,1;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"tooltip[6,1;1,1;"..self:get_state_tooltip(mem).."]".. "tooltip[6,1;1,1;"..self:get_state_tooltip(nvm).."]"..
"list[current_player;main;0,3.3;8,4;]" .. "list[current_player;main;0,3.3;8,4;]" ..
default.get_hotbar_bg(0, 3.5) default.get_hotbar_bg(0, 3.5)
end end
@ -92,7 +92,7 @@ local function reactor_cmnd(pos, cmnd, payload)
end end
local function can_start(pos, mem, state) local function can_start(pos, nvm, state)
-- check reactor -- check reactor
local res = reactor_cmnd(pos, "check") local res = reactor_cmnd(pos, "check")
if not res then if not res then
@ -105,15 +105,15 @@ local function can_start(pos, mem, state)
return true return true
end end
local function start_node(pos, mem, state) local function start_node(pos, nvm, state)
reactor_cmnd(pos, "start") reactor_cmnd(pos, "start")
del_liquids(pos) del_liquids(pos)
mem.running = true nvm.running = true
end end
local function stop_node(pos, mem, state) local function stop_node(pos, nvm, state)
reactor_cmnd(pos, "stop") reactor_cmnd(pos, "stop")
mem.running = false nvm.running = false
end end
local State = techage.NodeStates:new({ local State = techage.NodeStates:new({
@ -128,30 +128,30 @@ local State = techage.NodeStates:new({
stop_node = stop_node, stop_node = stop_node,
}) })
local function dosing(pos, mem, elapsed) local function dosing(pos, nvm, elapsed)
-- trigger reactor (power) -- trigger reactor (power)
if not reactor_cmnd(pos, "power") then if not reactor_cmnd(pos, "power") then
if not mem.techage_countdown or mem.techage_countdown < 3 then if not nvm.techage_countdown or nvm.techage_countdown < 3 then
reactor_cmnd(pos, "stop") reactor_cmnd(pos, "stop")
State:nopower(pos, mem, S("reactor has no power")) State:nopower(pos, nvm, S("reactor has no power"))
end end
State:idle(pos, mem) State:idle(pos, nvm)
return return
end end
-- check from time to time -- check from time to time
mem.check_cnt = (mem.check_cnt or 0) + 1 nvm.check_cnt = (nvm.check_cnt or 0) + 1
if mem.check_cnt >= 4 then if nvm.check_cnt >= 4 then
mem.check_cnt = 0 nvm.check_cnt = 0
local res = reactor_cmnd(pos, "check") local res = reactor_cmnd(pos, "check")
if not res then if not res then
State:fault(pos, mem, S("reactor defect")) State:fault(pos, nvm, S("reactor defect"))
reactor_cmnd(pos, "stop") reactor_cmnd(pos, "stop")
return return
end end
end end
-- available liquids -- available liquids
local liquids = get_liquids(pos) local liquids = get_liquids(pos)
local recipe = recipes.get(mem, "ta4_doser") local recipe = recipes.get(nvm, "ta4_doser")
if not liquids or not recipe then return end if not liquids or not recipe then return end
-- inputs -- inputs
local starter = get_starter_name(pos) local starter = get_starter_name(pos)
@ -159,12 +159,12 @@ local function dosing(pos, mem, elapsed)
if item.name ~= "" then if item.name ~= "" then
local outdir = liquids[item.name] local outdir = liquids[item.name]
if not outdir then if not outdir then
State:standby(pos, mem) State:standby(pos, nvm)
reactor_cmnd(pos, "stop") reactor_cmnd(pos, "stop")
return return
end end
if liquid.take(pos, outdir, item.name, item.num, starter) < item.num then if liquid.take(pos, outdir, item.name, item.num, starter) < item.num then
State:standby(pos, mem) State:standby(pos, nvm)
reactor_cmnd(pos, "stop") reactor_cmnd(pos, "stop")
return return
end end
@ -176,7 +176,7 @@ local function dosing(pos, mem, elapsed)
name = recipe.output.name, name = recipe.output.name,
amount = recipe.output.num}) amount = recipe.output.num})
if not leftover or (tonumber(leftover) or 1) > 0 then if not leftover or (tonumber(leftover) or 1) > 0 then
State:blocked(pos, mem) State:blocked(pos, nvm)
reactor_cmnd(pos, "stop") reactor_cmnd(pos, "stop")
return return
end end
@ -185,23 +185,23 @@ local function dosing(pos, mem, elapsed)
name = recipe.waste.name, name = recipe.waste.name,
amount = recipe.waste.num}) amount = recipe.waste.num})
if not leftover or (tonumber(leftover) or 1) > 0 then if not leftover or (tonumber(leftover) or 1) > 0 then
State:blocked(pos, mem) State:blocked(pos, nvm)
reactor_cmnd(pos, "stop") reactor_cmnd(pos, "stop")
return return
end end
end end
State:keep_running(pos, mem, COUNTDOWN_TICKS) State:keep_running(pos, nvm, COUNTDOWN_TICKS)
end end
local function node_timer(pos, elapsed) local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
dosing(pos, mem, elapsed) dosing(pos, nvm, elapsed)
return State:is_active(mem) return State:is_active(nvm)
end end
local function on_rightclick(pos) local function on_rightclick(pos)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(State, pos, mem)) M(pos):set_string("formspec", formspec(State, pos, nvm))
end end
local function on_receive_fields(pos, formname, fields, player) local function on_receive_fields(pos, formname, fields, player)
@ -209,17 +209,17 @@ local function on_receive_fields(pos, formname, fields, player)
return return
end end
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if not mem.running then if not nvm.running then
recipes.on_receive_fields(pos, formname, fields, player) recipes.on_receive_fields(pos, formname, fields, player)
end end
set_starter_name(pos, player) set_starter_name(pos, player)
State:state_button_event(pos, mem, fields) State:state_button_event(pos, nvm, fields)
M(pos):set_string("formspec", formspec(State, pos, mem)) M(pos):set_string("formspec", formspec(State, pos, nvm))
end end
local nworks = { local nworks = {
pipe = { pipe2 = {
sides = techage.networks.AllSides, -- Pipe connection sides sides = techage.networks.AllSides, -- Pipe connection sides
ntype = "pump", ntype = "pump",
}, },
@ -237,13 +237,13 @@ minetest.register_node("techage:ta4_doser", {
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local meta = M(pos) local meta = M(pos)
local mem = tubelib2.init_mem(pos) local nvm = techage.get_nvm(pos)
local number = techage.add_node(pos, "techage:ta4_doser") local number = techage.add_node(pos, "techage:ta4_doser")
meta:set_string("node_number", number) meta:set_string("node_number", number)
meta:set_string("owner", placer:get_player_name()) meta:set_string("owner", placer:get_player_name())
meta:set_string("formspec", formspec(State, pos, mem)) meta:set_string("formspec", formspec(State, pos, nvm))
meta:set_string("infotext", S("TA4 Doser").." "..number) meta:set_string("infotext", S("TA4 Doser").." "..number)
State:node_init(pos, mem, number) State:node_init(pos, nvm, number)
Pipe:after_place_node(pos) Pipe:after_place_node(pos)
end, end,
tubelib2_on_update2 = function(pos, dir, tlib2, node) tubelib2_on_update2 = function(pos, dir, tlib2, node)
@ -253,7 +253,7 @@ minetest.register_node("techage:ta4_doser", {
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos) techage.remove_node(pos)
Pipe:after_dig_node(pos) Pipe:after_dig_node(pos)
tubelib2.del_mem(pos) techage.del_mem(pos)
end, end,
on_receive_fields = on_receive_fields, on_receive_fields = on_receive_fields,
on_rightclick = on_rightclick, on_rightclick = on_rightclick,

View File

@ -66,7 +66,7 @@ minetest.register_node("techage:ta4_reactor_fillerpipe", {
sounds = default.node_sound_metal_defaults(), sounds = default.node_sound_metal_defaults(),
networks = { networks = {
pipe = { pipe2 = {
sides = {U=1}, -- Pipe connection sides sides = {U=1}, -- Pipe connection sides
ntype = "tank", ntype = "tank",
}, },

View File

@ -23,17 +23,17 @@ local liquid = techage.liquid
local PWR_NEEDED = 8 local PWR_NEEDED = 8
local CYCLE_TIME = 4 local CYCLE_TIME = 4
local function on_power(pos, mem) local function on_power(pos, nvm)
if mem.running then if nvm.running then
minetest.get_node_timer(pos):start(CYCLE_TIME) minetest.get_node_timer(pos):start(CYCLE_TIME)
M(pos):set_string("infotext", S("on")) M(pos):set_string("infotext", S("on"))
mem.has_power = true nvm.has_power = true
end end
end end
local function on_nopower(pos, mem) local function on_nopower(pos, nvm)
M(pos):set_string("infotext", S("no power")) M(pos):set_string("infotext", S("no power"))
mem.has_power = false nvm.has_power = false
end end
minetest.register_node("techage:ta4_reactor_stand", { minetest.register_node("techage:ta4_reactor_stand", {
@ -70,7 +70,7 @@ minetest.register_node("techage:ta4_reactor_stand", {
}, },
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local mem = tubelib2.init_mem(pos) local nvm = techage.get_nvm(pos)
techage.power.after_place_node(pos) techage.power.after_place_node(pos)
M(pos):set_string("infotext", S("off")) M(pos):set_string("infotext", S("off"))
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R")) M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
@ -83,18 +83,18 @@ minetest.register_node("techage:ta4_reactor_stand", {
techage.power.after_tube_update2(node, pos, out_dir, peer_pos, peer_in_dir) techage.power.after_tube_update2(node, pos, out_dir, peer_pos, peer_in_dir)
end, end,
on_timer = function(pos, elapsed) on_timer = function(pos, elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
power.consumer_alive(pos, mem) power.consumer_alive(pos, nvm)
minetest.sound_play("techage_reactor", { minetest.sound_play("techage_reactor", {
pos = pos, pos = pos,
gain = 0.5, gain = 0.5,
max_hear_distance = 10}) max_hear_distance = 10})
return mem.running return nvm.running
end, end,
after_dig_node = function(pos, oldnode) after_dig_node = function(pos, oldnode)
techage.power.after_dig_node(pos, oldnode) techage.power.after_dig_node(pos, oldnode)
Pipe:after_dig_node(pos) Pipe:after_dig_node(pos)
tubelib2.del_mem(pos) techage.del_mem(pos)
end, end,
paramtype = "light", paramtype = "light",
@ -105,7 +105,7 @@ minetest.register_node("techage:ta4_reactor_stand", {
sounds = default.node_sound_metal_defaults(), sounds = default.node_sound_metal_defaults(),
-- Pipe connection -- Pipe connection
networks = { networks = {
pipe = { pipe2 = {
sides = {R=1}, sides = {R=1},
ntype = "pump", ntype = "pump",
}, },
@ -124,25 +124,25 @@ techage.power.enrich_node({"techage:ta4_reactor_stand"}, {
techage.register_node({"techage:ta4_reactor_stand"}, { techage.register_node({"techage:ta4_reactor_stand"}, {
on_transfer = function(pos, in_dir, topic, payload) on_transfer = function(pos, in_dir, topic, payload)
--print(topic, dump(payload)) --print(topic, dump(payload))
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if topic == "power" then if topic == "power" then
--print("power", mem.has_power) --print("power", nvm.has_power)
return mem.has_power or power.power_available(pos, mem, 0) return nvm.has_power or power.power_available(pos, Cable)
elseif topic == "output" then elseif topic == "output" then
local outdir = M(pos):get_int("outdir") local outdir = M(pos):get_int("outdir")
return liquid.put(pos, outdir, payload.name, payload.amount, payload.player_name) return liquid.put(pos, outdir, payload.name, payload.amount, payload.player_name)
elseif topic == "can_start" then elseif topic == "can_start" then
return power.power_available(pos, mem, 0) return power.power_available(pos, Cable)
elseif topic == "start" and payload then elseif topic == "start" and payload then
mem.running = true nvm.running = true
mem.has_power = false nvm.has_power = false
power.consumer_start(pos, mem, CYCLE_TIME, PWR_NEEDED) power.consumer_start(pos, Cable, CYCLE_TIME)
M(pos):set_string("infotext", "...") M(pos):set_string("infotext", "...")
return true return true
elseif topic == "stop" then elseif topic == "stop" then
mem.running = false nvm.running = false
mem.has_power = false nvm.has_power = false
power.consumer_stop(pos, mem) power.consumer_stop(pos, Cable)
minetest.get_node_timer(pos):stop() minetest.get_node_timer(pos):stop()
M(pos):set_string("infotext", S("off")) M(pos):set_string("infotext", S("off"))
return true return true
@ -180,7 +180,7 @@ minetest.register_node("techage:ta4_reactor_base", {
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
networks = { networks = {
pipe = { pipe2 = {
sides = {R=1}, -- Pipe connection sides sides = {R=1}, -- Pipe connection sides
ntype = "pump", ntype = "pump",
}, },

View File

@ -220,9 +220,9 @@ techage.register_node({"techage:generator", "techage:generator_on"}, {
end end
end, end,
on_recv_message = function(pos, src, topic, payload) on_recv_message = function(pos, src, topic, payload)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if topic == "load" then if topic == "load" then
return techage.power.percent(PWR_CAPA, mem.provided) return techage.power.percent(PWR_CAPA, nvm.provided)
else else
return State:on_receive_message(pos, topic, payload) return State:on_receive_message(pos, topic, payload)
end end

View File

@ -38,28 +38,28 @@ local function firehole(pos, on)
end end
local function node_timer(pos, elapsed) local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if mem.running then if nvm.running then
-- trigger generator and provide power ratio 0..1 -- trigger generator and provide power ratio 0..1
local ratio = techage.transfer( local ratio = techage.transfer(
{x=pos.x, y=pos.y+2, z=pos.z}, {x=pos.x, y=pos.y+2, z=pos.z},
nil, -- outdir nil, -- outdir
"trigger", -- topic "trigger", -- topic
(mem.power_level or 4)/4.0, -- payload (nvm.power_level or 4)/4.0, -- payload
nil, -- network nil, -- network
{"techage:coalboiler_top"} -- nodenames {"techage:coalboiler_top"} -- nodenames
) )
ratio = math.max((ratio or 0.02), 0.02) ratio = math.max((ratio or 0.02), 0.02)
mem.burn_cycles = (mem.burn_cycles or 0) - ratio nvm.burn_cycles = (nvm.burn_cycles or 0) - ratio
if mem.burn_cycles <= 0 then if nvm.burn_cycles <= 0 then
local taken = firebox.get_fuel(pos) local taken = firebox.get_fuel(pos)
if taken then if taken then
mem.burn_cycles = (firebox.Burntime[taken:get_name()] or 1) * EFFICIENCY / CYCLE_TIME nvm.burn_cycles = (firebox.Burntime[taken:get_name()] or 1) * EFFICIENCY / CYCLE_TIME
mem.burn_cycles_total = mem.burn_cycles nvm.burn_cycles_total = nvm.burn_cycles
else else
mem.running = false nvm.running = false
firehole(pos, false) firehole(pos, false)
M(pos):set_string("formspec", firebox.formspec(mem)) M(pos):set_string("formspec", firebox.formspec(nvm))
return false return false
end end
end end
@ -67,9 +67,9 @@ local function node_timer(pos, elapsed)
end end
end end
local function start_firebox(pos, mem) local function start_firebox(pos, nvm)
if not mem.running then if not nvm.running then
mem.running = true nvm.running = true
node_timer(pos, 0) node_timer(pos, 0)
firehole(pos, true) firehole(pos, true)
minetest.get_node_timer(pos):start(CYCLE_TIME) minetest.get_node_timer(pos):start(CYCLE_TIME)
@ -102,13 +102,13 @@ minetest.register_node("techage:coalfirebox", {
on_rightclick = firebox.on_rightclick, on_rightclick = firebox.on_rightclick,
on_construct = function(pos) on_construct = function(pos)
local mem = tubelib2.init_mem(pos) local nvm = techage.get_nvm(pos)
techage.add_node(pos, "techage:coalfirebox") techage.add_node(pos, "techage:coalfirebox")
mem.running = false nvm.running = false
mem.burn_cycles = 0 nvm.burn_cycles = 0
mem.power_level = 4 nvm.power_level = 4
local meta = M(pos) local meta = M(pos)
meta:set_string("formspec", firebox.formspec(mem)) meta:set_string("formspec", firebox.formspec(nvm))
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size('fuel', 1) inv:set_size('fuel', 1)
firehole(pos, false) firehole(pos, false)
@ -119,9 +119,9 @@ minetest.register_node("techage:coalfirebox", {
end, end,
on_metadata_inventory_put = function(pos, listname, index, stack, player) on_metadata_inventory_put = function(pos, listname, index, stack, player)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
start_firebox(pos, mem) start_firebox(pos, nvm)
M(pos):set_string("formspec", firebox.formspec(mem)) M(pos):set_string("formspec", firebox.formspec(nvm))
end, end,
}) })
@ -189,32 +189,32 @@ minetest.register_node("techage:coalfirehole_on", {
}) })
local function on_timer2(pos, elapsed) local function on_timer2(pos, elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if mem.running then if nvm.running then
fuel.formspec_update(pos, mem) fuel.formspec_update(pos, nvm)
-- trigger generator and provide power ratio 0..1 -- trigger generator and provide power ratio 0..1
local ratio = techage.transfer( local ratio = techage.transfer(
{x=pos.x, y=pos.y+2, z=pos.z}, {x=pos.x, y=pos.y+2, z=pos.z},
nil, -- outdir nil, -- outdir
"trigger", -- topic "trigger", -- topic
(mem.power_level or 4)/4.0, -- payload (nvm.power_level or 4)/4.0, -- payload
nil, -- network nil, -- network
{"techage:coalboiler_top"} -- nodenames {"techage:coalboiler_top"} -- nodenames
) )
ratio = math.max((ratio or 0.02), 0.02) ratio = math.max((ratio or 0.02), 0.02)
mem.burn_cycles = (mem.burn_cycles or 0) - ratio nvm.burn_cycles = (nvm.burn_cycles or 0) - ratio
mem.liquid = mem.liquid or {} nvm.liquid = nvm.liquid or {}
mem.liquid.amount = mem.liquid.amount or 0 nvm.liquid.amount = nvm.liquid.amount or 0
if mem.burn_cycles <= 0 then if nvm.burn_cycles <= 0 then
if mem.liquid.amount > 0 then if nvm.liquid.amount > 0 then
mem.liquid.amount = mem.liquid.amount - 1 nvm.liquid.amount = nvm.liquid.amount - 1
mem.burn_cycles = fuel.burntime(mem.liquid.name) * EFFICIENCY / CYCLE_TIME nvm.burn_cycles = fuel.burntime(nvm.liquid.name) * EFFICIENCY / CYCLE_TIME
mem.burn_cycles_total = mem.burn_cycles nvm.burn_cycles_total = nvm.burn_cycles
else else
mem.running = false nvm.running = false
mem.liquid.name = nil nvm.liquid.name = nil
firehole(pos, false) firehole(pos, false)
M(pos):set_string("formspec", fuel.formspec(mem)) M(pos):set_string("formspec", fuel.formspec(nvm))
return false return false
end end
end end
@ -222,13 +222,13 @@ local function on_timer2(pos, elapsed)
end end
end end
local function start_firebox2(pos, mem) local function start_firebox2(pos, nvm)
if not mem.running and mem.liquid.amount > 0 then if not nvm.running and nvm.liquid.amount > 0 then
mem.running = true nvm.running = true
on_timer2(pos, 0) on_timer2(pos, 0)
firehole(pos, true) firehole(pos, true)
minetest.get_node_timer(pos):start(CYCLE_TIME) minetest.get_node_timer(pos):start(CYCLE_TIME)
M(pos):set_string("formspec", fuel.formspec(mem)) M(pos):set_string("formspec", fuel.formspec(nvm))
end end
end end
@ -258,14 +258,14 @@ minetest.register_node("techage:oilfirebox", {
on_rightclick = fuel.on_rightclick, on_rightclick = fuel.on_rightclick,
on_construct = function(pos) on_construct = function(pos)
local mem = tubelib2.init_mem(pos) local nvm = techage.get_nvm(pos)
techage.add_node(pos, "techage:oilfirebox") techage.add_node(pos, "techage:oilfirebox")
mem.running = false nvm.running = false
mem.burn_cycles = 0 nvm.burn_cycles = 0
mem.liquid = {} nvm.liquid = {}
mem.liquid.amount = 0 nvm.liquid.amount = 0
local meta = M(pos) local meta = M(pos)
meta:set_string("formspec", fuel.formspec(mem)) meta:set_string("formspec", fuel.formspec(nvm))
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size('fuel', 1) inv:set_size('fuel', 1)
firehole(pos, false) firehole(pos, false)
@ -276,10 +276,10 @@ minetest.register_node("techage:oilfirebox", {
end, end,
on_metadata_inventory_put = function(pos, listname, index, stack, player) on_metadata_inventory_put = function(pos, listname, index, stack, player)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.liquid = mem.liquid or {} nvm.liquid = nvm.liquid or {}
mem.liquid.amount = mem.liquid.amount or 0 nvm.liquid.amount = nvm.liquid.amount or 0
minetest.after(1, start_firebox2, pos, mem) minetest.after(1, start_firebox2, pos, nvm)
fuel.on_metadata_inventory_put(pos, listname, index, stack, player) fuel.on_metadata_inventory_put(pos, listname, index, stack, player)
end, end,
@ -290,10 +290,10 @@ minetest.register_node("techage:oilfirebox", {
put = function(pos, indir, name, amount) put = function(pos, indir, name, amount)
if fuel.valid_fuel(name, fuel.BT_BITUMEN) then if fuel.valid_fuel(name, fuel.BT_BITUMEN) then
local leftover = liquid.srv_put(pos, indir, name, amount) local leftover = liquid.srv_put(pos, indir, name, amount)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.liquid = mem.liquid or {} nvm.liquid = nvm.liquid or {}
mem.liquid.amount = mem.liquid.amount or 0 nvm.liquid.amount = nvm.liquid.amount or 0
start_firebox2(pos, mem) start_firebox2(pos, nvm)
return leftover return leftover
end end
return amount return amount
@ -321,8 +321,8 @@ techage.register_node({"techage:coalfirebox"}, {
if firebox.Burntime[stack:get_name()] then if firebox.Burntime[stack:get_name()] then
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
start_firebox(pos, mem) start_firebox(pos, nvm)
return techage.put_items(inv, "fuel", stack) return techage.put_items(inv, "fuel", stack)
end end
return false return false
@ -333,9 +333,9 @@ techage.register_node({"techage:coalfirebox"}, {
return techage.put_items(inv, "fuel", stack) return techage.put_items(inv, "fuel", stack)
end, end,
on_recv_message = function(pos, src, topic, payload) on_recv_message = function(pos, src, topic, payload)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if topic == "state" then if topic == "state" then
if mem.running then if nvm.running then
return "running" return "running"
else else
return "stopped" return "stopped"
@ -352,15 +352,15 @@ techage.register_node({"techage:coalfirebox"}, {
techage.register_node({"techage:oilfirebox"}, { techage.register_node({"techage:oilfirebox"}, {
on_recv_message = function(pos, src, topic, payload) on_recv_message = function(pos, src, topic, payload)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if topic == "state" then if topic == "state" then
if mem.running then if nvm.running then
return "running" return "running"
else else
return "stopped" return "stopped"
end end
elseif topic == "fuel" then elseif topic == "fuel" then
return mem.liquid and mem.liquid.amount and mem.liquid.amount return nvm.liquid and nvm.liquid.amount and nvm.liquid.amount
else else
return "unsupported" return "unsupported"
end end

View File

@ -32,11 +32,11 @@ end
-- to detect the missing turbine -- to detect the missing turbine
local function node_timer(pos, elapsed) local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.remote_trigger = (mem.remote_trigger or 0) - 1 nvm.remote_trigger = (nvm.remote_trigger or 0) - 1
if mem.remote_trigger <= 0 then if nvm.remote_trigger <= 0 then
swap_node(pos, "techage:ta4_generator") swap_node(pos, "techage:ta4_generator")
mem.running = false nvm.running = false
end end
return true return true
end end
@ -118,9 +118,9 @@ techage.power.register_node({"techage:ta4_generator", "techage:ta4_generator_on"
conn_sides = {"R"}, conn_sides = {"R"},
power_network = Cable, power_network = Cable,
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local mem = tubelib2.init_mem(pos) local nvm = techage.get_nvm(pos)
mem.running = false nvm.running = false
mem.remote_trigger = 0 nvm.remote_trigger = 0
end, end,
}) })
@ -128,24 +128,24 @@ techage.power.register_node({"techage:ta4_generator", "techage:ta4_generator_on"
-- controlled by the turbine -- controlled by the turbine
techage.register_node({"techage:ta4_generator", "techage:ta4_generator_on"}, { techage.register_node({"techage:ta4_generator", "techage:ta4_generator_on"}, {
on_transfer = function(pos, in_dir, topic, payload) on_transfer = function(pos, in_dir, topic, payload)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if topic == "power" then if topic == "power" then
mem.remote_trigger = 2 nvm.remote_trigger = 2
return techage.power.power_network_available(pos) return techage.power.power_network_available(pos)
elseif topic == "start" then elseif topic == "start" then
mem.remote_trigger = 2 nvm.remote_trigger = 2
swap_node(pos, "techage:ta4_generator_on") swap_node(pos, "techage:ta4_generator_on")
mem.running = true nvm.running = true
minetest.get_node_timer(pos):start(CYCLE_TIME) minetest.get_node_timer(pos):start(CYCLE_TIME)
return true return true
elseif topic == "stop" then elseif topic == "stop" then
swap_node(pos, "techage:ta4_generator") swap_node(pos, "techage:ta4_generator")
mem.running = false nvm.running = false
mem.remote_trigger = 0 nvm.remote_trigger = 0
minetest.get_node_timer(pos):stop() minetest.get_node_timer(pos):stop()
return true return true
elseif topic == "trigger" then elseif topic == "trigger" then
mem.remote_trigger = 2 nvm.remote_trigger = 2
return true return true
end end
end, end,

View File

@ -28,7 +28,7 @@ local PWR_CAPA = {
} }
local Cable = techage.ElectricCable local Cable = techage.ElectricCable
local Pipe = techage.BiogasPipe local Pipe = techage.LiquidPipe
local power = techage.power local power = techage.power
local function in_range(val, min, max) local function in_range(val, min, max)
@ -69,9 +69,9 @@ local function inlet_cmnd(pos, cmnd, payload)
end end
local function play_sound(pos) local function play_sound(pos)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if mem.running then if nvm.running then
mem.handle = minetest.sound_play("techage_booster", { nvm.handle = minetest.sound_play("techage_booster", {
pos = pos, pos = pos,
gain = 0.5, gain = 0.5,
max_hear_distance = 10}) max_hear_distance = 10})
@ -79,10 +79,10 @@ local function play_sound(pos)
end end
local function stop_sound(pos) local function stop_sound(pos)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if mem.running and mem.handle then if nvm.running and nvm.handle then
minetest.sound_stop(mem.handle) minetest.sound_stop(nvm.handle)
mem.handle = nil nvm.handle = nil
end end
end end
@ -95,12 +95,12 @@ local function swap_node(pos, name)
minetest.swap_node(pos, node) minetest.swap_node(pos, node)
end end
local function charging(pos, mem, is_charging) local function charging(pos, nvm, is_charging)
if mem.capa >= mem.capa_max then if nvm.capa >= nvm.capa_max then
return return
end end
if is_charging ~= mem.was_charging then if is_charging ~= nvm.was_charging then
mem.was_charging = is_charging nvm.was_charging = is_charging
if is_charging then if is_charging then
turbine_cmnd(pos, "stop") turbine_cmnd(pos, "stop")
play_sound(pos) play_sound(pos)
@ -113,12 +113,12 @@ local function charging(pos, mem, is_charging)
end end
end end
local function delivering(pos, mem, delivered) local function delivering(pos, nvm, delivered)
if mem.capa <= 0 then if nvm.capa <= 0 then
return return
end end
if delivered ~= mem.had_delivered then if delivered ~= nvm.had_delivered then
mem.had_delivered = delivered nvm.had_delivered = delivered
if delivered > 0 then if delivered > 0 then
turbine_cmnd(pos, "start") turbine_cmnd(pos, "start")
elseif delivered == 0 then elseif delivered == 0 then
@ -127,26 +127,26 @@ local function delivering(pos, mem, delivered)
end end
end end
local function glowing(pos, mem, should_glow) local function glowing(pos, nvm, should_glow)
if mem.win_pos then if nvm.win_pos then
if should_glow then if should_glow then
swap_node(mem.win_pos, "techage:glow_gravel") swap_node(nvm.win_pos, "techage:glow_gravel")
else else
swap_node(mem.win_pos, "default:gravel") swap_node(nvm.win_pos, "default:gravel")
end end
end end
end end
local function formspec(self, pos, mem) local function formspec(self, pos, nvm)
return "size[5,3]".. return "size[5,3]"..
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
"image[0,0.5;1,2;"..techage.power.formspec_power_bar(mem.capa_max, mem.capa).."]".. "image[0,0.5;1,2;"..techage.power.formspec_power_bar(nvm.capa_max, nvm.capa).."]"..
"label[0.2,2.5;Load]".. "label[0.2,2.5;Load]"..
"button[1.1,1;1.8,1;update;"..S("Update").."]".. "button[1.1,1;1.8,1;update;"..S("Update").."]"..
"image_button[3,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]".. "image_button[3,1;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"image[4,0.5;1,2;"..techage.power.formspec_load_bar(-(mem.delivered or 0), PWR_PERF).."]".. "image[4,0.5;1,2;"..techage.power.formspec_load_bar(-(nvm.delivered or 0), PWR_PERF).."]"..
"label[4.2,2.5;Flow]" "label[4.2,2.5;Flow]"
end end
@ -156,12 +156,12 @@ local function error_info(pos, err)
M(pos1):set_string("infotext", S("TA4 Heat Exchanger").." "..own_num.." : "..err) M(pos1):set_string("infotext", S("TA4 Heat Exchanger").." "..own_num.." : "..err)
end end
local function can_start(pos, mem, state) local function can_start(pos, nvm, state)
if turbine_cmnd(pos, "power") then if turbine_cmnd(pos, "power") then
local diameter = inlet_cmnd(pos, "diameter") local diameter = inlet_cmnd(pos, "diameter")
if diameter then if diameter then
mem.capa_max = PWR_CAPA[tonumber(diameter)] or 0 nvm.capa_max = PWR_CAPA[tonumber(diameter)] or 0
if mem.capa_max ~= 0 then if nvm.capa_max ~= 0 then
local owner = M(pos):get_string("owner") or "" local owner = M(pos):get_string("owner") or ""
if inlet_cmnd(pos, "volume", owner) then if inlet_cmnd(pos, "volume", owner) then
error_info(pos, "") error_info(pos, "")
@ -185,21 +185,21 @@ local function can_start(pos, mem, state)
return false return false
end end
local function start_node(pos, mem, state) local function start_node(pos, nvm, state)
mem.running = true nvm.running = true
mem.delivered = 0 nvm.delivered = 0
mem.was_charging = true nvm.was_charging = true
mem.had_delivered = nil nvm.had_delivered = nil
play_sound(pos) play_sound(pos)
mem.win_pos = inlet_cmnd(pos, "window") nvm.win_pos = inlet_cmnd(pos, "window")
power.secondary_start(pos, mem, PWR_PERF, PWR_PERF) power.secondary_start(pos, nvm, PWR_PERF, PWR_PERF)
end end
local function stop_node(pos, mem, state) local function stop_node(pos, nvm, state)
mem.running = false nvm.running = false
mem.delivered = 0 nvm.delivered = 0
turbine_cmnd(pos, "stop") turbine_cmnd(pos, "stop")
power.secondary_stop(pos, mem) power.secondary_stop(pos, nvm)
end end
local State = techage.NodeStates:new({ local State = techage.NodeStates:new({
@ -212,24 +212,24 @@ local State = techage.NodeStates:new({
}) })
local function node_timer(pos, elapsed) local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if mem.running and turbine_cmnd(pos, "power") then if nvm.running and turbine_cmnd(pos, "power") then
mem.capa = mem.capa or 0 nvm.capa = nvm.capa or 0
mem.capa_max = mem.capa_max or 0 nvm.capa_max = nvm.capa_max or 0
mem.delivered = mem.delivered or 0 nvm.delivered = nvm.delivered or 0
mem.delivered = power.secondary_alive(pos, mem, mem.capa, mem.capa_max) nvm.delivered = power.secondary_alive(pos, nvm, nvm.capa, nvm.capa_max)
mem.capa = mem.capa - mem.delivered nvm.capa = nvm.capa - nvm.delivered
mem.capa = in_range(mem.capa, 0, mem.capa_max) nvm.capa = in_range(nvm.capa, 0, nvm.capa_max)
glowing(pos, mem, mem.capa > mem.capa_max * 0.8) glowing(pos, nvm, nvm.capa > nvm.capa_max * 0.8)
charging(pos, mem, mem.delivered < 0) charging(pos, nvm, nvm.delivered < 0)
delivering(pos, mem, mem.delivered) delivering(pos, nvm, nvm.delivered)
end end
return mem.running return nvm.running
end end
local function can_dig(pos, player) local function can_dig(pos, player)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
return not mem.running return not nvm.running
end end
local function orientate_node(pos, name) local function orientate_node(pos, name)
@ -292,16 +292,16 @@ minetest.register_node("techage:heatexchanger2", {
return true return true
end end
local pos1 = {x = pos.x, y = pos.y - 1, z = pos.z} local pos1 = {x = pos.x, y = pos.y - 1, z = pos.z}
local mem = tubelib2.get_mem(pos1) local nvm = techage.get_nvm(pos1)
local own_num = M(pos1):get_string("node_number") local own_num = M(pos1):get_string("node_number")
M(pos):set_string("formspec", formspec(State, pos1, mem)) M(pos):set_string("formspec", formspec(State, pos1, nvm))
M(pos):set_string("infotext", S("TA4 Heat Exchanger").." "..own_num) M(pos):set_string("infotext", S("TA4 Heat Exchanger").." "..own_num)
end, end,
on_rightclick = function(pos) on_rightclick = function(pos)
local pos1 = {x = pos.x, y = pos.y - 1, z = pos.z} local pos1 = {x = pos.x, y = pos.y - 1, z = pos.z}
local mem = tubelib2.get_mem(pos1) local nvm = techage.get_nvm(pos1)
M(pos):set_string("formspec", formspec(State, pos1, mem)) M(pos):set_string("formspec", formspec(State, pos1, nvm))
end, end,
on_receive_fields = function(pos, formname, fields, player) on_receive_fields = function(pos, formname, fields, player)
@ -309,9 +309,9 @@ minetest.register_node("techage:heatexchanger2", {
return return
end end
local pos1 = {x = pos.x, y = pos.y - 1, z = pos.z} local pos1 = {x = pos.x, y = pos.y - 1, z = pos.z}
local mem = tubelib2.get_mem(pos1) local nvm = techage.get_nvm(pos1)
State:state_button_event(pos1, mem, fields) State:state_button_event(pos1, nvm, fields)
M(pos):set_string("formspec", formspec(State, pos1, mem)) M(pos):set_string("formspec", formspec(State, pos1, nvm))
end, end,
paramtype2 = "facedir", paramtype2 = "facedir",
@ -345,12 +345,12 @@ techage.power.register_node({"techage:heatexchanger1"}, {
conn_sides = {"F", "B"}, conn_sides = {"F", "B"},
power_network = Cable, power_network = Cable,
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local mem = tubelib2.init_mem(pos) local nvm = techage.get_nvm(pos)
local meta = M(pos) local meta = M(pos)
local own_num = techage.add_node(pos, "techage:heatexchanger1") local own_num = techage.add_node(pos, "techage:heatexchanger1")
meta:set_string("owner", placer:get_player_name()) meta:set_string("owner", placer:get_player_name())
State:node_init(pos, mem, own_num) State:node_init(pos, nvm, own_num)
mem.capa = 0 nvm.capa = 0
end, end,
}) })
@ -359,11 +359,11 @@ Pipe:add_secondary_node_names({"techage:heatexchanger1", "techage:heatexchanger3
-- for logical communication -- for logical communication
techage.register_node({"techage:heatexchanger1"}, { techage.register_node({"techage:heatexchanger1"}, {
on_recv_message = function(pos, src, topic, payload) on_recv_message = function(pos, src, topic, payload)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if topic == "load" then if topic == "load" then
return techage.power.percent(mem.capa_max, mem.capa) return techage.power.percent(nvm.capa_max, nvm.capa)
elseif topic == "size" then elseif topic == "size" then
return (mem.capa_max or 0) / GRVL_CAPA return (nvm.capa_max or 0) / GRVL_CAPA
else else
return State:on_receive_message(pos, topic, payload) return State:on_receive_message(pos, topic, payload)
end end

View File

@ -19,7 +19,7 @@ local D = techage.Debug
local M = minetest.get_meta local M = minetest.get_meta
local S = techage.S local S = techage.S
local Pipe = techage.BiogasPipe local Pipe = techage.LiquidPipe
minetest.register_node("techage:ta4_pipe_inlet", { minetest.register_node("techage:ta4_pipe_inlet", {
description = S("TA4 Pipe Inlet"), description = S("TA4 Pipe Inlet"),

View File

@ -18,7 +18,7 @@ local S = techage.S
local CYCLE_TIME = 2 local CYCLE_TIME = 2
local Pipe = techage.BiogasPipe local Pipe = techage.LiquidPipe
local function swap_node(pos, name) local function swap_node(pos, name)
local node = techage.get_node_lvm(pos) local node = techage.get_node_lvm(pos)
@ -30,9 +30,9 @@ local function swap_node(pos, name)
end end
local function play_sound(pos) local function play_sound(pos)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if mem.running then if nvm.running then
mem.handle = minetest.sound_play("techage_turbine", { nvm.handle = minetest.sound_play("techage_turbine", {
pos = pos, pos = pos,
gain = 0.5, gain = 0.5,
max_hear_distance = 10}) max_hear_distance = 10})
@ -40,10 +40,10 @@ local function play_sound(pos)
end end
local function stop_sound(pos) local function stop_sound(pos)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if mem.running and mem.handle then if nvm.running and nvm.handle then
minetest.sound_stop(mem.handle) minetest.sound_stop(nvm.handle)
mem.handle = nil nvm.handle = nil
end end
end end
@ -59,12 +59,12 @@ end
-- to detect the missing "steam pressure" -- to detect the missing "steam pressure"
local function node_timer(pos, elapsed) local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.remote_trigger = (mem.remote_trigger or 0) - 1 nvm.remote_trigger = (nvm.remote_trigger or 0) - 1
if mem.remote_trigger <= 0 then if nvm.remote_trigger <= 0 then
swap_node(pos, "techage:ta4_turbine") swap_node(pos, "techage:ta4_turbine")
stop_sound(pos) stop_sound(pos)
mem.running = false nvm.running = false
end end
play_sound(pos) play_sound(pos)
return true return true
@ -138,35 +138,35 @@ techage.power.register_node({"techage:ta4_turbine", "techage:ta4_turbine_on"}, {
conn_sides = {"L", "U"}, conn_sides = {"L", "U"},
power_network = Pipe, power_network = Pipe,
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local mem = tubelib2.init_mem(pos) local nvm = techage.get_nvm(pos)
mem.running = false nvm.running = false
mem.remote_trigger = 0 nvm.remote_trigger = 0
end, end,
}) })
-- for logical communication -- for logical communication
techage.register_node({"techage:ta4_turbine", "techage:ta4_turbine_on"}, { techage.register_node({"techage:ta4_turbine", "techage:ta4_turbine_on"}, {
on_transfer = function(pos, in_dir, topic, payload) on_transfer = function(pos, in_dir, topic, payload)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if topic == "power" then if topic == "power" then
mem.remote_trigger = 2 nvm.remote_trigger = 2
return generator_cmnd(pos, topic) return generator_cmnd(pos, topic)
elseif topic == "start" then elseif topic == "start" then
mem.remote_trigger = 2 nvm.remote_trigger = 2
swap_node(pos, "techage:ta4_turbine_on") swap_node(pos, "techage:ta4_turbine_on")
mem.running = true nvm.running = true
minetest.get_node_timer(pos):start(CYCLE_TIME) minetest.get_node_timer(pos):start(CYCLE_TIME)
play_sound(pos) play_sound(pos)
return generator_cmnd(pos, topic) return generator_cmnd(pos, topic)
elseif topic == "stop" then elseif topic == "stop" then
swap_node(pos, "techage:ta4_turbine") swap_node(pos, "techage:ta4_turbine")
mem.running = false nvm.running = false
mem.remote_trigger = 0 nvm.remote_trigger = 0
minetest.get_node_timer(pos):stop() minetest.get_node_timer(pos):stop()
stop_sound(pos) stop_sound(pos)
return generator_cmnd(pos, topic) return generator_cmnd(pos, topic)
elseif topic == "trigger" then elseif topic == "trigger" then
mem.remote_trigger = 2 nvm.remote_trigger = 2
return generator_cmnd(pos, topic) return generator_cmnd(pos, topic)
end end
end end

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -20,8 +20,9 @@ local D = techage.Debug
local PWR_NEEDED = 3 local PWR_NEEDED = 3
local CYCLE_TIME = 2 local CYCLE_TIME = 2
local Power = techage.ElectricCable local Cable = techage.ElectricCable
local power = techage.power local power = techage.power
--local networks = techage.networks
local function infotext(pos, state) local function infotext(pos, state)
M(pos):set_string("infotext", S("TA3 Booster")..": "..state) M(pos):set_string("infotext", S("TA3 Booster")..": "..state)
@ -36,36 +37,71 @@ local function swap_node(pos, name)
minetest.swap_node(pos, node) minetest.swap_node(pos, node)
end end
local function on_power(pos, mem) local function play_sound(pos)
if mem.running then local mem = techage.get_mem(pos)
swap_node(pos, "techage:ta3_booster_on") mem.handle = minetest.sound_play("techage_booster", {
infotext(pos, "running") pos = pos,
gain = 1,
max_hear_distance = 7,
loop = true})
if mem.handle == -1 then
minetest.after(1, play_sound, pos)
end end
if D.dbg2 then D.dbg("booster on_power") end
mem.is_powered = true
end end
local function on_nopower(pos, mem) local function stop_sound(pos)
local mem = techage.get_mem(pos)
if mem.handle then
minetest.sound_stop(mem.handle)
mem.handle = nil
end
end
local function on_power(pos)
swap_node(pos, "techage:ta3_booster_on")
infotext(pos, "running")
play_sound(pos)
end
local function on_nopower(pos)
swap_node(pos, "techage:ta3_booster") swap_node(pos, "techage:ta3_booster")
infotext(pos, "no power") infotext(pos, "no power")
if D.dbg2 then D.dbg("booster on_nopower") end stop_sound(pos)
mem.is_powered = false
end end
local function node_timer(pos, elapsed) local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos) power.consumer_alive(pos, Cable, CYCLE_TIME)
if mem.running and mem.is_powered then return true
minetest.sound_play("techage_booster", {
pos = pos,
gain = 1,
max_hear_distance = 7})
end
if mem.running then
power.consumer_alive(pos, mem)
end
return mem.running
end end
local function after_place_node(pos)
local nvm = techage.get_nvm(pos)
Cable:after_place_node(pos)
local node = minetest.get_node(pos)
local indir = techage.side_to_indir("R", node.param2)
M(pos):set_int("indir", indir)
infotext(pos, "stopped")
end
local function after_dig_node(pos, oldnode)
Cable:after_dig_node(pos)
techage.del_mem(pos)
end
local function tubelib2_on_update2(pos, outdir, tlib2, node)
power.update_network(pos, outdir, tlib2)
end
local net_def = {
ele1 = {
sides = {B = true, F = true, L = true, D = true, U = true},
ntype = "con1",
on_power = on_power,
on_nopower = on_nopower,
nominal = PWR_NEEDED,
},
}
minetest.register_node("techage:ta3_booster", { minetest.register_node("techage:ta3_booster", {
description = S("TA3 Booster"), description = S("TA3 Booster"),
tiles = { tiles = {
@ -77,7 +113,13 @@ minetest.register_node("techage:ta3_booster", {
"techage_filling_ta3.png^techage_appl_compressor.png^techage_frame_ta3.png", "techage_filling_ta3.png^techage_appl_compressor.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_appl_compressor.png^[transformFX^techage_frame_ta3.png", "techage_filling_ta3.png^techage_appl_compressor.png^[transformFX^techage_frame_ta3.png",
}, },
on_timer = node_timer, on_timer = node_timer,
after_place_node = after_place_node,
after_dig_node = after_dig_node,
tubelib2_on_update2 = tubelib2_on_update2,
networks = net_def,
paramtype2 = "facedir", paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2}, groups = {cracky=2, crumbly=2, choppy=2},
on_rotate = screwdriver.disallow, on_rotate = screwdriver.disallow,
@ -116,6 +158,11 @@ minetest.register_node("techage:ta3_booster_on", {
}, },
on_timer = node_timer, on_timer = node_timer,
after_place_node = after_place_node,
after_dig_node = after_dig_node,
tubelib2_on_update2 = tubelib2_on_update2,
networks = net_def,
paramtype2 = "facedir", paramtype2 = "facedir",
groups = {not_in_creative_inventory = 1}, groups = {not_in_creative_inventory = 1},
diggable = false, diggable = false,
@ -124,46 +171,30 @@ minetest.register_node("techage:ta3_booster_on", {
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
}) })
techage.power.register_node({"techage:ta3_booster", "techage:ta3_booster_on"}, { Cable:add_secondary_node_names({"techage:ta3_booster", "techage:ta3_booster_on"})
power_network = Power,
conn_sides = {"F", "B", "U", "D", "L"},
on_power = on_power,
on_nopower = on_nopower,
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)
infotext(pos, "stopped")
end,
})
-- for intra machine communication -- for intra machine communication
techage.register_node({"techage:ta3_booster", "techage:ta3_booster_on"}, { techage.register_node({"techage:ta3_booster", "techage:ta3_booster_on"}, {
on_transfer = function(pos, in_dir, topic, payload) on_transfer = function(pos, in_dir, topic, payload)
if M(pos):get_int("indir") == in_dir then if M(pos):get_int("indir") == in_dir then
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if topic == "power" then if topic == "power" then
if D.dbg2 then D.dbg("booster power") end return techage.get_node_lvm(pos).name == "techage:ta3_booster_on"
return power.power_available(pos, mem, 0) elseif topic == "start" and not nvm.running then
elseif topic == "start" and not mem.running then if power.power_available(pos, Cable) then
if D.dbg2 then D.dbg("booster try start", mem.pwr_master_pos, mem.pwr_power_provided_cnt) end nvm.running = true
if power.power_available(pos, mem, 0) then power.consumer_start(pos, Cable, CYCLE_TIME)
mem.running = true
if D.dbg2 then D.dbg("booster start") end
power.consumer_start(pos, mem, CYCLE_TIME, PWR_NEEDED)
minetest.get_node_timer(pos):start(CYCLE_TIME) minetest.get_node_timer(pos):start(CYCLE_TIME)
else else
if D.dbg2 then D.dbg("booster no power") end
infotext(pos, "no power") infotext(pos, "no power")
end end
elseif topic == "stop" then elseif topic == "stop" then
mem.running = false nvm.running = false
if D.dbg2 then D.dbg("booster stop") end
swap_node(pos, "techage:ta3_booster") swap_node(pos, "techage:ta3_booster")
power.consumer_stop(pos, mem) power.consumer_stop(pos, Cable)
minetest.get_node_timer(pos):stop() minetest.get_node_timer(pos):stop()
infotext(pos, "stopped") infotext(pos, "stopped")
stop_sound(pos)
end end
end end
end end

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -104,17 +104,17 @@ local function process(inv, recipe, output)
return techage.RUNNING return techage.RUNNING
end end
function techage.furnace.check_if_worth_to_wakeup(pos, mem) function techage.furnace.check_if_worth_to_wakeup(pos, nvm)
local inv = M(pos):get_inventory() local inv = M(pos):get_inventory()
if not mem.output or not mem.num_recipe then if not nvm.output or not nvm.num_recipe then
return false return false
end end
local recipe = Recipes[mem.output] and Recipes[mem.output][mem.num_recipe] local recipe = Recipes[nvm.output] and Recipes[nvm.output][nvm.num_recipe]
if not recipe then if not recipe then
return false return false
end end
-- check dst inv -- check dst inv
local stack = ItemStack(mem.output) local stack = ItemStack(nvm.output)
stack:set_count(recipe.number) stack:set_count(recipe.number)
if not inv:room_for_item("dst", stack) then if not inv:room_for_item("dst", stack) then
return false return false
@ -129,52 +129,52 @@ function techage.furnace.check_if_worth_to_wakeup(pos, mem)
return true return true
end end
function techage.furnace.smelting(pos, mem, elapsed) function techage.furnace.smelting(pos, nvm, elapsed)
local inv = M(pos):get_inventory() local inv = M(pos):get_inventory()
local state = techage.RUNNING local state = techage.RUNNING
if inv and not inv:is_empty("src") then if inv and not inv:is_empty("src") then
if not mem.output or not mem.num_recipe then if not nvm.output or not nvm.num_recipe then
return techage.FAULT, "recipe error" return techage.FAULT, "recipe error"
end end
local recipe = Recipes[mem.output] and Recipes[mem.output][mem.num_recipe] local recipe = Recipes[nvm.output] and Recipes[nvm.output][nvm.num_recipe]
if not recipe then if not recipe then
return techage.FAULT, "recipe error" return techage.FAULT, "recipe error"
end end
elapsed = elapsed + (mem.leftover or 0) elapsed = elapsed + (nvm.leftover or 0)
while elapsed >= recipe.time do while elapsed >= recipe.time do
state = process(inv, recipe, mem.output) state = process(inv, recipe, nvm.output)
if state ~= techage.RUNNING then if state ~= techage.RUNNING then
return state return state
end end
elapsed = elapsed - recipe.time elapsed = elapsed - recipe.time
end end
mem.leftover = elapsed nvm.leftover = elapsed
if recipe.time >= 10 then if recipe.time >= 10 then
mem.item_percent = math.min(math.floor((mem.leftover * 100.0) / recipe.time), 100) nvm.item_percent = math.min(math.floor((nvm.leftover * 100.0) / recipe.time), 100)
else else
mem.item_percent = 100 nvm.item_percent = 100
end end
return state return state
end end
return techage.STANDBY return techage.STANDBY
end end
function techage.furnace.get_output(mem, ingr, idx) function techage.furnace.get_output(nvm, ingr, idx)
local tbl = get_recipes(ingr) local tbl = get_recipes(ingr)
idx = range(idx, 1, #tbl) idx = range(idx, 1, #tbl)
mem.output = tbl[idx] or tbl[1] nvm.output = tbl[idx] or tbl[1]
mem.num_recipe = all_ingredients_available(mem.output, ingr) nvm.num_recipe = all_ingredients_available(nvm.output, ingr)
return mem.output return nvm.output
end end
function techage.furnace.get_num_recipes(ingr) function techage.furnace.get_num_recipes(ingr)
return #get_recipes(ingr) return #get_recipes(ingr)
end end
function techage.furnace.reset_cooking(mem) function techage.furnace.reset_cooking(nvm)
mem.leftover = 0 nvm.leftover = 0
mem.item_percent = 0 nvm.item_percent = 0
end end

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -25,32 +25,33 @@ local CYCLE_TIME = 2
local EFFICIENCY = 2 -- burn cycles local EFFICIENCY = 2 -- burn cycles
local CATEGORY = 3 local CATEGORY = 3
local function has_fuel(pos, mem) local function has_fuel(pos, nvm)
return mem.burn_cycles > 0 or (mem.liquid and mem.liquid.amount and mem.liquid.amount > 0) print("has_fuel", nvm.burn_cycles, topic, payload)
return nvm.burn_cycles > 0 or (nvm.liquid and nvm.liquid.amount and nvm.liquid.amount > 0)
end end
local function stop_firebox(pos, mem) local function stop_firebox(pos, nvm)
mem.running = false nvm.running = false
firebox.swap_node(pos, "techage:furnace_firebox") firebox.swap_node(pos, "techage:furnace_firebox")
minetest.get_node_timer(pos):stop() minetest.get_node_timer(pos):stop()
M(pos):set_string("formspec", fuel.formspec(mem)) M(pos):set_string("formspec", fuel.formspec(nvm))
end end
local function node_timer(pos, elapsed) local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.liquid = mem.liquid or {} nvm.liquid = nvm.liquid or {}
mem.liquid.amount = mem.liquid.amount or 0 nvm.liquid.amount = nvm.liquid.amount or 0
if mem.running then if nvm.running then
fuel.formspec_update(pos, mem) fuel.formspec_update(pos, nvm)
mem.burn_cycles = (mem.burn_cycles or 0) - 1 nvm.burn_cycles = (nvm.burn_cycles or 0) - 1
if mem.burn_cycles <= 0 then if nvm.burn_cycles <= 0 then
if mem.liquid.amount > 0 then if nvm.liquid.amount > 0 then
mem.liquid.amount = mem.liquid.amount - 1 nvm.liquid.amount = nvm.liquid.amount - 1
mem.burn_cycles = fuel.burntime(mem.liquid.name) * EFFICIENCY / CYCLE_TIME nvm.burn_cycles = fuel.burntime(nvm.liquid.name) * EFFICIENCY / CYCLE_TIME
mem.burn_cycles_total = mem.burn_cycles nvm.burn_cycles_total = nvm.burn_cycles
else else
mem.liquid.name = nil nvm.liquid.name = nil
stop_firebox(pos, mem) stop_firebox(pos, nvm)
return false return false
end end
end end
@ -58,13 +59,13 @@ local function node_timer(pos, elapsed)
end end
end end
local function start_firebox(pos, mem) local function start_firebox(pos, nvm)
if not mem.running then if not nvm.running then
mem.running = true nvm.running = true
node_timer(pos, 0) node_timer(pos, 0)
firebox.swap_node(pos, "techage:furnace_firebox_on") firebox.swap_node(pos, "techage:furnace_firebox_on")
minetest.get_node_timer(pos):start(CYCLE_TIME) minetest.get_node_timer(pos):start(CYCLE_TIME)
M(pos):set_string("formspec", fuel.formspec(mem)) M(pos):set_string("formspec", fuel.formspec(nvm))
end end
end end
@ -92,7 +93,7 @@ local _liquid = {
} }
local _networks = { local _networks = {
pipe = { pipe2 = {
sides = techage.networks.AllSides, -- Pipe connection sides sides = techage.networks.AllSides, -- Pipe connection sides
ntype = "tank", ntype = "tank",
}, },
@ -126,14 +127,14 @@ minetest.register_node("techage:furnace_firebox", {
networks = _networks, networks = _networks,
on_construct = function(pos) on_construct = function(pos)
local mem = tubelib2.init_mem(pos) local nvm = techage.get_nvm(pos)
techage.add_node(pos, "techage:furnace_firebox") techage.add_node(pos, "techage:furnace_firebox")
mem.running = false nvm.running = false
mem.burn_cycles = 0 nvm.burn_cycles = 0
mem.liquid = {} nvm.liquid = {}
mem.liquid.amount = 0 nvm.liquid.amount = 0
local meta = M(pos) local meta = M(pos)
meta:set_string("formspec", fuel.formspec(mem)) meta:set_string("formspec", fuel.formspec(nvm))
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size('fuel', 1) inv:set_size('fuel', 1)
end, end,
@ -178,10 +179,10 @@ minetest.register_node("techage:furnace_firebox_on", {
networks = _networks, networks = _networks,
on_metadata_inventory_put = function(pos, listname, index, stack, player) on_metadata_inventory_put = function(pos, listname, index, stack, player)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.liquid = mem.liquid or {} nvm.liquid = nvm.liquid or {}
mem.liquid.amount = mem.liquid.amount or 0 nvm.liquid.amount = nvm.liquid.amount or 0
start_firebox(pos, mem) start_firebox(pos, nvm)
fuel.on_metadata_inventory_put(pos, listname, index, stack, player) fuel.on_metadata_inventory_put(pos, listname, index, stack, player)
end, end,
}) })
@ -197,31 +198,32 @@ minetest.register_craft({
techage.register_node({"techage:furnace_firebox", "techage:furnace_firebox_on"}, { techage.register_node({"techage:furnace_firebox", "techage:furnace_firebox_on"}, {
on_recv_message = function(pos, src, topic, payload) on_recv_message = function(pos, src, topic, payload)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if topic == "state" then if topic == "state" then
if mem.running then if nvm.running then
return "running" return "running"
else else
return "stopped" return "stopped"
end end
elseif topic == "fuel" then elseif topic == "fuel" then
return mem.liquid and mem.liquid.amount and mem.liquid.amount return nvm.liquid and nvm.liquid.amount and nvm.liquid.amount
else else
return "unsupported" return "unsupported"
end end
end, end,
-- called from furnace_top -- called from furnace_top
on_transfer = function(pos, in_dir, topic, payload) on_transfer = function(pos, in_dir, topic, payload)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if topic == "fuel" then if topic == "fuel" then
return has_fuel(pos, mem) and booster_cmnd(pos, "power") print(dump(nvm))
return has_fuel(pos, nvm) and booster_cmnd(pos, "power")
elseif topic == "running" then elseif topic == "running" then
return mem.running and booster_cmnd(pos, "power") return nvm.running and booster_cmnd(pos, "power")
elseif topic == "start" then elseif topic == "start" then
start_firebox(pos, mem) start_firebox(pos, nvm)
booster_cmnd(pos, "start") booster_cmnd(pos, "start")
elseif topic == "stop" then elseif topic == "stop" then
stop_firebox(pos, mem) stop_firebox(pos, nvm)
booster_cmnd(pos, "stop") booster_cmnd(pos, "stop")
end end
end end

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -33,26 +33,26 @@ local check_if_worth_to_wakeup = techage.furnace.check_if_worth_to_wakeup
local range = techage.in_range local range = techage.in_range
local function update_recipe_menu(pos, mem) local function update_recipe_menu(pos, nvm)
local ingr = get_ingredients(pos) local ingr = get_ingredients(pos)
mem.rp_num = num_recipes(ingr) nvm.rp_num = num_recipes(ingr)
mem.rp_idx = range(mem.rp_idx or 1, 0, mem.rp_num) nvm.rp_idx = range(nvm.rp_idx or 1, 0, nvm.rp_num)
mem.rp_outp = get_output(mem, ingr, mem.rp_idx) nvm.rp_outp = get_output(nvm, ingr, nvm.rp_idx)
end end
local function formspec(self, pos, mem) local function formspec(self, pos, nvm)
local idx = mem.rp_idx or 1 local idx = nvm.rp_idx or 1
local num = mem.rp_num or 1 local num = nvm.rp_num or 1
local outp = mem.rp_outp or "" local outp = nvm.rp_outp or ""
return "size[8,7.2]".. return "size[8,7.2]"..
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
"list[context;src;0,0;2,2;]".. "list[context;src;0,0;2,2;]"..
"image[2,0.5;1,1;techage_form_arrow_bg.png^[lowpart:".. "image[2,0.5;1,1;techage_form_arrow_bg.png^[lowpart:"..
(mem.item_percent or 0)..":techage_form_arrow_fg.png^[transformR270]".. (nvm.item_percent or 0)..":techage_form_arrow_fg.png^[transformR270]"..
"image_button[2,2;1,1;".. self:get_state_button_image(mem) ..";state_button;]".. "image_button[2,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"tooltip[2,2;1,1;"..self:get_state_tooltip(mem).."]".. "tooltip[2,2;1,1;"..self:get_state_tooltip(nvm).."]"..
"list[context;dst;3,0;2,2;]".. "list[context;dst;3,0;2,2;]"..
@ -71,8 +71,8 @@ local function formspec(self, pos, mem)
end end
local function on_rightclick(pos, node, clicker) local function on_rightclick(pos, node, clicker)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, mem)) M(pos):set_string("formspec", formspec(CRD(pos).State, pos, nvm))
end end
local function firebox_cmnd(pos, cmnd) local function firebox_cmnd(pos, cmnd)
@ -86,34 +86,34 @@ local function firebox_cmnd(pos, cmnd)
"techage:furnace_heater", "techage:furnace_heater_on"}) "techage:furnace_heater", "techage:furnace_heater_on"})
end end
local function cooking(pos, crd, mem, elapsed) local function cooking(pos, crd, nvm, elapsed)
if mem.techage_state == techage.RUNNING or check_if_worth_to_wakeup(pos, mem) then if nvm.techage_state == techage.RUNNING or check_if_worth_to_wakeup(pos, nvm) then
if firebox_cmnd(pos, "fuel") then if firebox_cmnd(pos, "fuel") then
local state, err = smelting(pos, mem, elapsed) local state, err = smelting(pos, nvm, elapsed)
if state == techage.RUNNING then if state == techage.RUNNING then
crd.State:keep_running(pos, mem, COUNTDOWN_TICKS) crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
elseif state == techage.BLOCKED then elseif state == techage.BLOCKED then
crd.State:blocked(pos, mem) crd.State:blocked(pos, nvm)
elseif state == techage.FAULT then elseif state == techage.FAULT then
crd.State:fault(pos, mem, err) crd.State:fault(pos, nvm, err)
elseif state == techage.STANDBY then elseif state == techage.STANDBY then
crd.State:idle(pos, mem) crd.State:idle(pos, nvm)
end end
else else
crd.State:idle(pos, mem) crd.State:idle(pos, nvm)
end end
end end
end end
local function keep_running(pos, elapsed) local function keep_running(pos, elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
local crd = CRD(pos) local crd = CRD(pos)
cooking(pos, crd, mem, elapsed) cooking(pos, crd, nvm, elapsed)
mem.toggle = not mem.toggle nvm.toggle = not nvm.toggle
if mem.toggle then -- progress bar/arrow if nvm.toggle then -- progress bar/arrow
M(pos):set_string("formspec", formspec(crd.State, pos, mem)) M(pos):set_string("formspec", formspec(crd.State, pos, nvm))
end end
return crd.State:is_active(mem) return crd.State:is_active(nvm)
end end
local function allow_metadata_inventory_put(pos, listname, index, stack, player) local function allow_metadata_inventory_put(pos, listname, index, stack, player)
@ -121,7 +121,7 @@ local function allow_metadata_inventory_put(pos, listname, index, stack, player)
return 0 return 0
end end
if listname == "src" then if listname == "src" then
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
return stack:get_count() return stack:get_count()
elseif listname == "dst" then elseif listname == "dst" then
return 0 return 0
@ -143,31 +143,31 @@ local function allow_metadata_inventory_take(pos, listname, index, stack, player
end end
local function on_metadata_inventory(pos) local function on_metadata_inventory(pos)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
local crd = CRD(pos) local crd = CRD(pos)
M(pos):set_string("formspec", formspec(crd.State, pos, mem)) M(pos):set_string("formspec", formspec(crd.State, pos, nvm))
end end
local function on_receive_fields(pos, formname, fields, player) local function on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then if minetest.is_protected(pos, player:get_player_name()) then
return return
end end
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.rp_idx = mem.rp_idx or 1 nvm.rp_idx = nvm.rp_idx or 1
if fields.next == ">>" then if fields.next == ">>" then
local ingr = get_ingredients(pos) local ingr = get_ingredients(pos)
mem.rp_idx = math.min(mem.rp_idx + 1, num_recipes(ingr)) nvm.rp_idx = math.min(nvm.rp_idx + 1, num_recipes(ingr))
update_recipe_menu(pos, mem) update_recipe_menu(pos, nvm)
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, mem)) M(pos):set_string("formspec", formspec(CRD(pos).State, pos, nvm))
reset_cooking(mem) reset_cooking(nvm)
elseif fields.priv == "<<" then elseif fields.priv == "<<" then
local ingr = get_ingredients(pos) local ingr = get_ingredients(pos)
mem.rp_idx = range(mem.rp_idx - 1, 1, num_recipes(ingr)) nvm.rp_idx = range(nvm.rp_idx - 1, 1, num_recipes(ingr))
update_recipe_menu(pos, mem) update_recipe_menu(pos, nvm)
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, mem)) M(pos):set_string("formspec", formspec(CRD(pos).State, pos, nvm))
reset_cooking(mem) reset_cooking(nvm)
end end
CRD(pos).State:state_button_event(pos, mem, fields) CRD(pos).State:state_button_event(pos, nvm, fields)
end end
local function can_dig(pos, player) local function can_dig(pos, player)
@ -178,8 +178,7 @@ local function can_dig(pos, player)
return inv:is_empty("dst") and inv:is_empty("src") return inv:is_empty("dst") and inv:is_empty("src")
end end
local function can_start(pos, mem, state) local function can_start(pos, nvm, state)
if D.dbg2 then D.dbg("can_start", state, firebox_cmnd(pos, "fuel")) end
if not firebox_cmnd(pos, "fuel") then if not firebox_cmnd(pos, "fuel") then
return S("no fuel or no power") return S("no fuel or no power")
end end
@ -187,7 +186,6 @@ local function can_start(pos, mem, state)
end end
local function on_node_state_change(pos, old_state, new_state) local function on_node_state_change(pos, old_state, new_state)
if D.dbg2 then D.dbg("on_node_state_change", new_state) end
local pwr1 = techage.needs_power2(old_state) local pwr1 = techage.needs_power2(old_state)
local pwr2 = techage.needs_power2(new_state) local pwr2 = techage.needs_power2(new_state)
if pwr1 ~= pwr2 then if pwr1 ~= pwr2 then
@ -197,8 +195,8 @@ local function on_node_state_change(pos, old_state, new_state)
firebox_cmnd(pos, "stop") firebox_cmnd(pos, "stop")
end end
end end
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
reset_cooking(mem) reset_cooking(nvm)
end end
local tiles = {} local tiles = {}

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -24,7 +24,7 @@ local liquid = techage.liquid
local CYCLE_TIME = 2 local CYCLE_TIME = 2
local PWR_NEEDED = 14 local PWR_NEEDED = 14
local Power = techage.ElectricCable local Cable = techage.ElectricCable
local power = techage.power local power = techage.power
local function swap_node(pos, name) local function swap_node(pos, name)
@ -36,25 +36,42 @@ local function swap_node(pos, name)
minetest.swap_node(pos, node) minetest.swap_node(pos, node)
end end
local function on_power(pos, mem) local function on_power(pos)
if mem.running then swap_node(pos, "techage:furnace_heater_on")
swap_node(pos, "techage:furnace_heater_on")
minetest.get_node_timer(pos):start(CYCLE_TIME)
end
mem.has_power = true
end end
local function on_nopower(pos, mem) local function on_nopower(pos)
swap_node(pos, "techage:furnace_heater") swap_node(pos, "techage:furnace_heater")
mem.has_power = false
end end
local function node_timer(pos, elapsed) local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos) power.consumer_alive(pos, Cable, CYCLE_TIME)
power.consumer_alive(pos, mem) return true
return mem.running
end end
local function after_place_node(pos)
Cable:after_place_node(pos)
end
local function after_dig_node(pos, oldnode)
Cable:after_dig_node(pos)
techage.del_mem(pos)
end
local function tubelib2_on_update2(pos, outdir, tlib2, node)
power.update_network(pos, outdir, tlib2)
end
local net_def = {
ele1 = {
sides = {B = true, F = true, L = true, D = true, U = true},
ntype = "con1",
on_power = on_power,
on_nopower = on_nopower,
nominal = PWR_NEEDED,
},
}
minetest.register_node("techage:furnace_heater", { minetest.register_node("techage:furnace_heater", {
description = S("TA4 Furnace Heater"), description = S("TA4 Furnace Heater"),
tiles = { tiles = {
@ -66,7 +83,13 @@ minetest.register_node("techage:furnace_heater", {
"techage_concrete.png^techage_frame_ta3.png", "techage_concrete.png^techage_frame_ta3.png",
"techage_concrete.png^techage_appl_heater.png^techage_frame_ta3.png", "techage_concrete.png^techage_appl_heater.png^techage_frame_ta3.png",
}, },
on_timer = node_timer, on_timer = node_timer,
after_place_node = after_place_node,
after_dig_node = after_dig_node,
tubelib2_on_update2 = tubelib2_on_update2,
networks = net_def,
paramtype2 = "facedir", paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2}, groups = {cracky=2, crumbly=2, choppy=2},
on_rotate = screwdriver.disallow, on_rotate = screwdriver.disallow,
@ -86,8 +109,13 @@ minetest.register_node("techage:furnace_heater_on", {
"techage_concrete.png^techage_appl_heater_on.png^techage_frame_ta3.png", "techage_concrete.png^techage_appl_heater_on.png^techage_frame_ta3.png",
}, },
light_source = 8,
on_timer = node_timer, on_timer = node_timer,
after_place_node = after_place_node,
after_dig_node = after_dig_node,
tubelib2_on_update2 = tubelib2_on_update2,
networks = net_def,
light_source = 8,
paramtype2 = "facedir", paramtype2 = "facedir",
groups = {not_in_creative_inventory = 1}, groups = {not_in_creative_inventory = 1},
diggable = false, diggable = false,
@ -96,15 +124,7 @@ minetest.register_node("techage:furnace_heater_on", {
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
}) })
techage.power.register_node({"techage:furnace_heater", "techage:furnace_heater_on"}, { Cable:add_secondary_node_names({"techage:furnace_heater", "techage:furnace_heater_on"})
power_network = Power,
conn_sides = {"F", "B", "U", "D", "L"},
on_power = on_power,
on_nopower = on_nopower,
after_place_node = function(pos, placer)
local mem = tubelib2.init_mem(pos)
end,
})
minetest.register_craft({ minetest.register_craft({
output = "techage:furnace_heater", output = "techage:furnace_heater",
@ -118,22 +138,22 @@ minetest.register_craft({
techage.register_node({"techage:furnace_heater", "techage:furnace_heater_on"}, { techage.register_node({"techage:furnace_heater", "techage:furnace_heater_on"}, {
-- called from furnace_top -- called from furnace_top
on_transfer = function(pos, in_dir, topic, payload) on_transfer = function(pos, in_dir, topic, payload)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if topic == "fuel" then if topic == "fuel" then
return mem.has_power or power.power_available(pos, mem, 0) return power.power_available(pos, Cable)
elseif topic == "running" then elseif topic == "running" then
return mem.running and (mem.has_power or power.power_available(pos, mem, 0)) return techage.get_node_lvm(pos).name == "techage:furnace_heater_on"
elseif topic == "start" and not mem.running then elseif topic == "start" and not nvm.running then
if power.power_available(pos, mem, 0) then if power.power_available(pos, Cable) then
mem.running = true nvm.running = true
mem.has_power = false power.consumer_start(pos, Cable, CYCLE_TIME)
power.consumer_start(pos, mem, CYCLE_TIME, PWR_NEEDED) minetest.get_node_timer(pos):start(CYCLE_TIME)
return true return true
end end
elseif topic == "stop" and mem.running then elseif topic == "stop" and nvm.running then
mem.running = false nvm.running = false
swap_node(pos, "techage:furnace_heater") swap_node(pos, "techage:furnace_heater")
power.consumer_stop(pos, mem) power.consumer_stop(pos, Cable)
minetest.get_node_timer(pos):stop() minetest.get_node_timer(pos):stop()
return true return true
end end

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information

View File

@ -27,33 +27,33 @@ local PWR_NEEDED = 40
local PWR_UNITS_PER_HYDROGEN_ITEM = 320 local PWR_UNITS_PER_HYDROGEN_ITEM = 320
local CAPACITY = 400 local CAPACITY = 400
local function formspec(self, pos, mem) local function formspec(self, pos, nvm)
local update = ((mem.countdown or 0) > 0 and mem.countdown) or S("Update") local update = ((nvm.countdown or 0) > 0 and nvm.countdown) or S("Update")
return "size[8,6.6]".. return "size[8,6.6]"..
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
"image[0.0,0;1,2;"..power.formspec_power_bar(PWR_NEEDED, mem.consumed).."]".. "image[0.0,0;1,2;"..power.formspec_power_bar(PWR_NEEDED, nvm.consumed).."]"..
"label[0.2,1.9;"..S("\\[ku\\]").."]".. "label[0.2,1.9;"..S("\\[ku\\]").."]"..
"image[2.5,0;1,1;techage_form_arrow_fg.png^[transformR270]".. "image[2.5,0;1,1;techage_form_arrow_fg.png^[transformR270]"..
"image_button[3.5,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]".. "image_button[3.5,1;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"tooltip[3.5,1;1,1;"..self:get_state_tooltip(mem).."]".. "tooltip[3.5,1;1,1;"..self:get_state_tooltip(nvm).."]"..
"button[1.6,1;1.8,1;update;"..update.."]".. "button[1.6,1;1.8,1;update;"..update.."]"..
"list[current_player;main;0,2.8;8,4;]" .. "list[current_player;main;0,2.8;8,4;]" ..
liquid.formspec_liquid(5, 0, mem).. liquid.formspec_liquid(5, 0, nvm)..
default.get_hotbar_bg(0, 2.8) default.get_hotbar_bg(0, 2.8)
end end
local function start_node(pos, mem, state) local function start_node(pos, nvm, state)
mem.running = true nvm.running = true
mem.consumed = 0 nvm.consumed = 0
power.secondary_start(pos, mem, PWR_NEEDED, PWR_NEEDED) power.secondary_start(pos, nvm, PWR_NEEDED, PWR_NEEDED)
end end
local function stop_node(pos, mem, state) local function stop_node(pos, nvm, state)
mem.running = false nvm.running = false
mem.consumed = 0 nvm.consumed = 0
power.secondary_stop(pos, mem) power.secondary_stop(pos, nvm)
end end
local State = techage.NodeStates:new({ local State = techage.NodeStates:new({
@ -69,54 +69,54 @@ local State = techage.NodeStates:new({
-- converts power into hydrogen -- converts power into hydrogen
local function node_timer(pos, elapsed) local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.num_pwr_units = mem.num_pwr_units or 0 nvm.num_pwr_units = nvm.num_pwr_units or 0
mem.countdown = mem.countdown or 0 nvm.countdown = nvm.countdown or 0
mem.liquid = mem.liquid or {} nvm.liquid = nvm.liquid or {}
mem.liquid.amount = mem.liquid.amount or 0 nvm.liquid.amount = nvm.liquid.amount or 0
print("electrolyzer", mem.running, mem.consumed, mem.num_pwr_units, mem.liquid.amount) print("electrolyzer", nvm.running, nvm.consumed, nvm.num_pwr_units, nvm.liquid.amount)
if mem.running then if nvm.running then
if techage.needs_power(mem) then if techage.needs_power(nvm) then
mem.consumed = -power.secondary_alive(pos, mem, 0, 1) nvm.consumed = -power.secondary_alive(pos, nvm, 0, 1)
--print("mem.consumed", mem.consumed) --print("nvm.consumed", nvm.consumed)
if mem.consumed > 0 then if nvm.consumed > 0 then
if mem.liquid.amount < CAPACITY then if nvm.liquid.amount < CAPACITY then
mem.num_pwr_units = mem.num_pwr_units + mem.consumed nvm.num_pwr_units = nvm.num_pwr_units + nvm.consumed
if mem.num_pwr_units >= PWR_UNITS_PER_HYDROGEN_ITEM then if nvm.num_pwr_units >= PWR_UNITS_PER_HYDROGEN_ITEM then
mem.liquid.amount = mem.liquid.amount + 1 nvm.liquid.amount = nvm.liquid.amount + 1
mem.liquid.name = "techage:hydrogen" nvm.liquid.name = "techage:hydrogen"
mem.num_pwr_units = mem.num_pwr_units - PWR_UNITS_PER_HYDROGEN_ITEM nvm.num_pwr_units = nvm.num_pwr_units - PWR_UNITS_PER_HYDROGEN_ITEM
State:keep_running(pos, mem, 1, 0) -- count items State:keep_running(pos, nvm, 1, 0) -- count items
end end
else else
State:blocked(pos, mem) State:blocked(pos, nvm)
power.secondary_stop(pos, mem) power.secondary_stop(pos, nvm)
end end
end end
else else
mem.consumed = -power.secondary_alive(pos, mem, 1, 1) nvm.consumed = -power.secondary_alive(pos, nvm, 1, 1)
if mem.liquid.amount < CAPACITY then if nvm.liquid.amount < CAPACITY then
State:start(pos, mem) State:start(pos, nvm)
power.secondary_start(pos, mem, PWR_NEEDED, PWR_NEEDED) power.secondary_start(pos, nvm, PWR_NEEDED, PWR_NEEDED)
end end
end end
end end
if mem.countdown > 0 then if nvm.countdown > 0 then
mem.countdown = mem.countdown - 1 nvm.countdown = nvm.countdown - 1
M(pos):set_string("formspec", formspec(State, pos, mem)) M(pos):set_string("formspec", formspec(State, pos, nvm))
end end
return mem.running or mem.countdown > 0 return nvm.running or nvm.countdown > 0
end end
local function on_receive_fields(pos, formname, fields, player) local function on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then if minetest.is_protected(pos, player:get_player_name()) then
return return
end end
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
State:state_button_event(pos, mem, fields) State:state_button_event(pos, nvm, fields)
mem.countdown = 10 nvm.countdown = 10
M(pos):set_string("formspec", formspec(State, pos, mem)) M(pos):set_string("formspec", formspec(State, pos, nvm))
minetest.get_node_timer(pos):start(CYCLE_TIME) minetest.get_node_timer(pos):start(CYCLE_TIME)
end end
@ -131,9 +131,9 @@ local function allow_metadata_inventory(pos, listname, index, stack, player)
end end
local function on_rightclick(pos) local function on_rightclick(pos)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.countdown = 10 nvm.countdown = 10
M(pos):set_string("formspec", formspec(State, pos, mem)) M(pos):set_string("formspec", formspec(State, pos, nvm))
minetest.get_node_timer(pos):start(CYCLE_TIME) minetest.get_node_timer(pos):start(CYCLE_TIME)
end end
@ -150,13 +150,13 @@ minetest.register_node("techage:ta4_electrolyzer2", {
}, },
on_construct = function(pos) on_construct = function(pos)
local mem = tubelib2.init_mem(pos) local nvm = techage.get_nvm(pos)
local number = techage.add_node(pos, "techage:ta4_electrolyzer2") local number = techage.add_node(pos, "techage:ta4_electrolyzer2")
mem.running = false nvm.running = false
mem.num_pwr_units = 0 nvm.num_pwr_units = 0
State:node_init(pos, mem, number) State:node_init(pos, nvm, number)
local meta = M(pos) local meta = M(pos)
meta:set_string("formspec", formspec(State, pos, mem)) meta:set_string("formspec", formspec(State, pos, nvm))
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size('src', 1) inv:set_size('src', 1)
inv:set_size('dst', 1) inv:set_size('dst', 1)
@ -185,7 +185,7 @@ minetest.register_node("techage:ta4_electrolyzer2", {
take = liquid.srv_take, take = liquid.srv_take,
}, },
networks = { networks = {
pipe = { pipe2 = {
sides = {R = 1}, -- Pipe connection sides sides = {R = 1}, -- Pipe connection sides
ntype = "tank", ntype = "tank",
}, },
@ -251,7 +251,7 @@ minetest.register_node("techage:ta4_electrolyzer2_on", {
take = liquid.srv_take, take = liquid.srv_take,
}, },
networks = { networks = {
pipe = { pipe2 = {
sides = {R = 1}, -- Pipe connection sides sides = {R = 1}, -- Pipe connection sides
ntype = "tank", ntype = "tank",
}, },

View File

@ -24,16 +24,16 @@ local STANDBY_TICKS = 5
local PWR_CAPA = 40 local PWR_CAPA = 40
local PWR_UNITS_PER_HYDROGEN_ITEM = 240 local PWR_UNITS_PER_HYDROGEN_ITEM = 240
local function formspec(self, pos, mem) local function formspec(self, pos, nvm)
return "size[8,6.6]".. return "size[8,6.6]"..
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
"list[context;src;0.5,0;2,2;]".. "list[context;src;0.5,0;2,2;]"..
"image[4,0;1,1;techage_form_arrow_fg.png^[transformR270]".. "image[4,0;1,1;techage_form_arrow_fg.png^[transformR270]"..
"image_button[5,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]".. "image_button[5,1;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"button[3.1,1;1.8,1;update;"..S("Update").."]".. "button[3.1,1;1.8,1;update;"..S("Update").."]"..
"image[6.5,0;1,2;"..power.formspec_power_bar(PWR_CAPA, mem.provided).."]".. "image[6.5,0;1,2;"..power.formspec_power_bar(PWR_CAPA, nvm.provided).."]"..
"label[6.7,1.9;"..S("\\[ku\\]").."]".. "label[6.7,1.9;"..S("\\[ku\\]").."]"..
"list[current_player;main;0,2.8;8,4;]" .. "list[current_player;main;0,2.8;8,4;]" ..
"listring[current_player;main]".. "listring[current_player;main]"..
@ -42,16 +42,16 @@ local function formspec(self, pos, mem)
default.get_hotbar_bg(0, 2.8) default.get_hotbar_bg(0, 2.8)
end end
local function start_node(pos, mem, state) local function start_node(pos, nvm, state)
mem.running = true nvm.running = true
mem.provided = 0 nvm.provided = 0
power.generator_start(pos, mem, PWR_CAPA) power.generator_start(pos, nvm, PWR_CAPA)
end end
local function stop_node(pos, mem, state) local function stop_node(pos, nvm, state)
mem.running = false nvm.running = false
mem.provided = 0 nvm.provided = 0
power.generator_stop(pos, mem) power.generator_stop(pos, nvm)
end end
local State = techage.NodeStates:new({ local State = techage.NodeStates:new({
@ -78,46 +78,46 @@ end
-- converts hydrogen into power -- converts hydrogen into power
local function node_timer(pos, elapsed) local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.num_pwr_units = mem.num_pwr_units or 0 nvm.num_pwr_units = nvm.num_pwr_units or 0
--print("fuelcell", mem.running, mem.provided, mem.num_pwr_units, techage.get_state_string(mem)) --print("fuelcell", nvm.running, nvm.provided, nvm.num_pwr_units, techage.get_state_string(nvm))
if mem.running then if nvm.running then
if techage.needs_power(mem) then if techage.needs_power(nvm) then
if mem.num_pwr_units <= 0 then if nvm.num_pwr_units <= 0 then
if get_hydrogen(pos) then if get_hydrogen(pos) then
State:keep_running(pos, mem, 1, 0) -- count items State:keep_running(pos, nvm, 1, 0) -- count items
mem.num_pwr_units = mem.num_pwr_units + PWR_UNITS_PER_HYDROGEN_ITEM nvm.num_pwr_units = nvm.num_pwr_units + PWR_UNITS_PER_HYDROGEN_ITEM
else else
State:standby(pos, mem) State:standby(pos, nvm)
mem.provided = 0 nvm.provided = 0
power.generator_stop(pos, mem) power.generator_stop(pos, nvm)
M(pos):set_string("formspec", formspec(State, pos, mem)) M(pos):set_string("formspec", formspec(State, pos, nvm))
return true return true
end end
end end
mem.provided = power.generator_alive(pos, mem) nvm.provided = power.generator_alive(pos, nvm)
mem.num_pwr_units = mem.num_pwr_units - mem.provided nvm.num_pwr_units = nvm.num_pwr_units - nvm.provided
else else
if contains_hydrogen(pos) then if contains_hydrogen(pos) then
State:start(pos, mem) State:start(pos, nvm)
mem.provided = 0 nvm.provided = 0
power.generator_start(pos, mem, PWR_CAPA) power.generator_start(pos, nvm, PWR_CAPA)
M(pos):set_string("formspec", formspec(State, pos, mem)) M(pos):set_string("formspec", formspec(State, pos, nvm))
end end
end end
end end
return mem.running return nvm.running
end end
local function on_receive_fields(pos, formname, fields, player) local function on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then if minetest.is_protected(pos, player:get_player_name()) then
return return
end end
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
State:state_button_event(pos, mem, fields) State:state_button_event(pos, nvm, fields)
if fields.update then if fields.update then
M(pos):set_string("formspec", formspec(State, pos, mem)) M(pos):set_string("formspec", formspec(State, pos, nvm))
end end
end end
@ -132,8 +132,8 @@ local function allow_metadata_inventory(pos, listname, index, stack, player)
end end
local function on_rightclick(pos) local function on_rightclick(pos)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(State, pos, mem)) M(pos):set_string("formspec", formspec(State, pos, nvm))
end end
minetest.register_node("techage:ta4_fuelcell", { minetest.register_node("techage:ta4_fuelcell", {
@ -149,13 +149,13 @@ minetest.register_node("techage:ta4_fuelcell", {
}, },
on_construct = function(pos) on_construct = function(pos)
local mem = tubelib2.init_mem(pos) local nvm = techage.get_nvm(pos)
local number = techage.add_node(pos, "techage:ta4_fuelcell") local number = techage.add_node(pos, "techage:ta4_fuelcell")
mem.running = false nvm.running = false
mem.num_pwr_units = 0 nvm.num_pwr_units = 0
State:node_init(pos, mem, number) State:node_init(pos, nvm, number)
local meta = M(pos) local meta = M(pos)
meta:set_string("formspec", formspec(State, pos, mem)) meta:set_string("formspec", formspec(State, pos, nvm))
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size('src', 4) inv:set_size('src', 4)
end, end,

View File

@ -60,15 +60,7 @@ else
dofile(MP.."/power/powerswitch.lua") dofile(MP.."/power/powerswitch.lua")
dofile(MP.."/power/protection.lua") dofile(MP.."/power/protection.lua")
dofile(MP.."/power/power_line.lua") dofile(MP.."/power/power_line.lua")
dofile(MP.."/power/ta4_cable.lua")
--dofile(MP.."/power/test.lua")
--dofile(MP.."/power/power.lua")
--dofile(MP.."/power/power2.lua")
--dofile(MP.."/power/junction.lua")
--dofile(MP.."/power/junctionbox.lua")
--dofile(MP.."/power/ta4_cable.lua")
-- Iron Age -- Iron Age
dofile(MP.."/iron_age/main.lua") dofile(MP.."/iron_age/main.lua")
@ -109,13 +101,13 @@ else
dofile(MP.."/basic_machines/liquidsampler.lua") dofile(MP.."/basic_machines/liquidsampler.lua")
-- -- Liquids -- -- Liquids
-- dofile(MP.."/liquids/liquid_pipe.lua") dofile(MP.."/liquids/liquid_pipe.lua")
-- dofile(MP.."/liquids/liquid.lua") dofile(MP.."/liquids/liquid.lua")
-- dofile(MP.."/liquids/liquid_lib.lua") dofile(MP.."/liquids/liquid_lib.lua")
-- dofile(MP.."/liquids/tank.lua") dofile(MP.."/liquids/tank.lua")
-- dofile(MP.."/liquids/silo.lua") dofile(MP.."/liquids/silo.lua")
-- dofile(MP.."/liquids/pump.lua") dofile(MP.."/liquids/pump.lua")
-- dofile(MP.."/liquids/fuel_lib.lua") dofile(MP.."/liquids/fuel_lib.lua")
-- Coal power station -- Coal power station
dofile(MP.."/coal_power_station/firebox.lua") dofile(MP.."/coal_power_station/firebox.lua")
@ -126,12 +118,12 @@ else
dofile(MP.."/coal_power_station/cooler.lua") dofile(MP.."/coal_power_station/cooler.lua")
-- -- Industrial Furnace -- -- Industrial Furnace
-- dofile(MP.."/furnace/firebox.lua") dofile(MP.."/furnace/firebox.lua")
-- dofile(MP.."/furnace/cooking.lua") dofile(MP.."/furnace/cooking.lua")
-- dofile(MP.."/furnace/furnace_top.lua") dofile(MP.."/furnace/furnace_top.lua")
-- dofile(MP.."/furnace/booster.lua") dofile(MP.."/furnace/booster.lua")
-- dofile(MP.."/furnace/heater.lua") dofile(MP.."/furnace/heater.lua")
-- dofile(MP.."/furnace/recipes.lua") dofile(MP.."/furnace/recipes.lua")
-- Tools -- Tools
dofile(MP.."/tools/trowel.lua") dofile(MP.."/tools/trowel.lua")
@ -139,14 +131,14 @@ else
dofile(MP.."/basic_machines/blackhole.lua") dofile(MP.."/basic_machines/blackhole.lua")
dofile(MP.."/basic_machines/forceload.lua") dofile(MP.."/basic_machines/forceload.lua")
-- -- Lamps -- Lamps
-- dofile(MP.."/lamps/lib.lua") dofile(MP.."/lamps/lib.lua")
-- dofile(MP.."/lamps/simplelamp.lua") dofile(MP.."/lamps/simplelamp.lua")
-- dofile(MP.."/lamps/streetlamp.lua") dofile(MP.."/lamps/streetlamp.lua")
-- dofile(MP.."/lamps/ceilinglamp.lua") dofile(MP.."/lamps/ceilinglamp.lua")
-- dofile(MP.."/lamps/industriallamp1.lua") dofile(MP.."/lamps/industriallamp1.lua")
-- dofile(MP.."/lamps/industriallamp2.lua") dofile(MP.."/lamps/industriallamp2.lua")
-- dofile(MP.."/lamps/industriallamp3.lua") dofile(MP.."/lamps/industriallamp3.lua")
-- -- Oil -- -- Oil
-- dofile(MP.."/oil/explore.lua") -- dofile(MP.."/oil/explore.lua")
@ -181,6 +173,7 @@ else
-- Test -- Test
dofile(MP.."/recipe_checker.lua") dofile(MP.."/recipe_checker.lua")
dofile(MP.."/.test/sink.lua") dofile(MP.."/.test/sink.lua")
dofile(MP.."/.test/meta_node.lua")
--dofile(MP.."/.test/source.lua") --dofile(MP.."/.test/source.lua")
--dofile(MP.."/.test/accu.lua") --dofile(MP.."/.test/accu.lua")
@ -213,24 +206,24 @@ else
-- dofile(MP.."/hydrogen/legacy.lua") -- dofile(MP.."/hydrogen/legacy.lua")
-- Items -- Items
-- dofile(MP.."/items/barrel.lua") dofile(MP.."/items/barrel.lua")
dofile(MP.."/items/baborium.lua") dofile(MP.."/items/baborium.lua")
dofile(MP.."/items/usmium.lua") dofile(MP.."/items/usmium.lua")
-- dofile(MP.."/items/lye.lua") dofile(MP.."/items/lye.lua")
-- dofile(MP.."/items/oil.lua") dofile(MP.."/items/oil.lua")
-- dofile(MP.."/items/petroleum.lua") dofile(MP.."/items/petroleum.lua")
-- dofile(MP.."/items/bauxit.lua") dofile(MP.."/items/bauxit.lua")
-- dofile(MP.."/items/silicon.lua") dofile(MP.."/items/silicon.lua")
-- dofile(MP.."/items/steelmat.lua") dofile(MP.."/items/steelmat.lua")
-- dofile(MP.."/items/powder.lua") dofile(MP.."/items/powder.lua")
-- dofile(MP.."/items/epoxy.lua") dofile(MP.."/items/epoxy.lua")
-- dofile(MP.."/items/aluminium.lua") dofile(MP.."/items/aluminium.lua")
-- dofile(MP.."/items/plastic.lua") dofile(MP.."/items/plastic.lua")
-- dofile(MP.."/items/hydrogen.lua") dofile(MP.."/items/hydrogen.lua")
-- if techage.basalt_stone_enabled then if techage.basalt_stone_enabled then
-- dofile(MP.."/items/basalt.lua") dofile(MP.."/items/basalt.lua")
-- end end
-- dofile(MP.."/power3/electric_cable.lua") -- dofile(MP.."/power3/electric_cable.lua")
-- dofile(MP.."/power3/node_api.lua") -- dofile(MP.."/power3/node_api.lua")

View File

@ -18,7 +18,7 @@ local P = minetest.string_to_pos
local M = minetest.get_meta local M = minetest.get_meta
local PWR_NEEDED = 0.5 local PWR_NEEDED = 0.5
local CYCLE_TIME = 4 local CYCLE_TIME = 2
local Cable = techage.ElectricCable local Cable = techage.ElectricCable
local power = techage.power local power = techage.power
@ -33,22 +33,17 @@ local function swap_node(pos, postfix)
minetest.swap_node(pos, node) minetest.swap_node(pos, node)
end end
local function on_power(pos, mem) local function on_power(pos)
if mem.turned_on then swap_node(pos, "on")
swap_node(pos, "on")
end
end end
local function on_nopower(pos, mem) local function on_nopower(pos)
swap_node(pos, "off") swap_node(pos, "off")
end end
local function node_timer(pos, elapsed) local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos) power.consumer_alive(pos, Cable, CYCLE_TIME)
if mem.turned_on then return true
power.consumer_alive(pos, mem)
end
return mem.turned_on
end end
local function lamp_on_rightclick(pos, node, clicker) local function lamp_on_rightclick(pos, node, clicker)
@ -56,16 +51,16 @@ local function lamp_on_rightclick(pos, node, clicker)
return return
end end
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
minetest.get_node_timer(pos):start(CYCLE_TIME) if not nvm.turned_on and power.power_available(pos, Cable) then
nvm.turned_on = true
if not mem.turned_on and power.power_available(pos, mem, PWR_NEEDED) then power.consumer_start(pos, Cable, CYCLE_TIME)
mem.turned_on = true minetest.get_node_timer(pos):start(CYCLE_TIME)
power.consumer_start(pos, mem, CYCLE_TIME, PWR_NEEDED)
swap_node(pos, "on") swap_node(pos, "on")
else else
mem.turned_on = false nvm.turned_on = false
power.consumer_stop(pos, mem) power.consumer_stop(pos, Cable)
minetest.get_node_timer(pos):stop()
swap_node(pos, "off") swap_node(pos, "off")
end end
end end
@ -86,12 +81,35 @@ local function on_place(itemstack, placer, pointed_thing)
return minetest.rotate_and_place(itemstack, placer, pointed_thing) return minetest.rotate_and_place(itemstack, placer, pointed_thing)
end end
local function determine_power_side(pos, node) local function after_place_node(pos)
return {techage.determine_node_bottom_as_dir(node)} local nvm = techage.get_nvm(pos)
Cable:after_place_node(pos)
end end
local function after_dig_node(pos, oldnode)
Cable:after_dig_node(pos)
techage.del_mem(pos)
end
local function tubelib2_on_update2(pos, outdir, tlib2, node)
power.update_network(pos, outdir, tlib2)
end
local net_def = {
ele1 = {
sides = {U=1, D=1}, -- Cable connection sides
ntype = "con1",
on_power = on_power,
on_nopower = on_nopower,
nominal = PWR_NEEDED,
},
}
function techage.register_lamp(basename, ndef_off, ndef_on) function techage.register_lamp(basename, ndef_off, ndef_on)
ndef_off.on_construct = tubelib2.init_mem ndef_off.after_place_node = after_place_node
ndef_off.after_dig_node = after_dig_node
ndef_off.tubelib2_on_update2 = tubelib2_on_update2
ndef_off.networks = net_def
ndef_off.on_rightclick = lamp_on_rightclick ndef_off.on_rightclick = lamp_on_rightclick
if not ndef_off.on_rotate then if not ndef_off.on_rotate then
ndef_off.on_place = on_place ndef_off.on_place = on_place
@ -106,7 +124,10 @@ function techage.register_lamp(basename, ndef_off, ndef_on)
ndef_off.is_ground_content = false ndef_off.is_ground_content = false
ndef_off.sounds = default.node_sound_glass_defaults() ndef_off.sounds = default.node_sound_glass_defaults()
ndef_on.on_construct = tubelib2.init_mem ndef_on.after_place_node = after_place_node
ndef_on.after_dig_node = after_dig_node
ndef_on.tubelib2_on_update2 = tubelib2_on_update2
ndef_on.networks = net_def
ndef_on.on_rightclick = lamp_on_rightclick ndef_on.on_rightclick = lamp_on_rightclick
ndef_on.on_rotate = ndef_on.on_rotate or on_rotate ndef_on.on_rotate = ndef_on.on_rotate or on_rotate
ndef_on.on_timer = node_timer ndef_on.on_timer = node_timer
@ -121,23 +142,7 @@ function techage.register_lamp(basename, ndef_off, ndef_on)
minetest.register_node(basename.."_off", ndef_off) minetest.register_node(basename.."_off", ndef_off)
minetest.register_node(basename.."_on", ndef_on) minetest.register_node(basename.."_on", ndef_on)
techage.power.register_node({basename.."_off", basename.."_on"}, { Cable:add_secondary_node_names({basename.."_off", basename.."_on"})
power_network = Cable,
conn_sides = ndef_off.conn_sides or determine_power_side, -- will be handled by clbk function
on_power = on_power,
on_nopower = on_nopower,
})
minetest.register_lbm({
label = "[techage] Start lamp",
name = "techage:start_lamp",
nodenames = {basename.."_on"},
run_at_every_load = true,
action = function(pos, node)
local mem = tubelib2.get_mem(pos)
minetest.get_node_timer(pos):start(CYCLE_TIME)
power.consumer_start(pos, mem, CYCLE_TIME, PWR_NEEDED)
end
})
end end

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -35,14 +35,14 @@ techage.fuel.BT_FUELOIL = 2
techage.fuel.BT_NAPHTHA = 1 techage.fuel.BT_NAPHTHA = 1
local function formspec_fuel(x, y, mem) local function formspec_fuel(x, y, nvm)
local itemname = "" local itemname = ""
if mem.liquid and mem.liquid.name and mem.liquid.amount and mem.liquid.amount > 0 then if nvm.liquid and nvm.liquid.name and nvm.liquid.amount and nvm.liquid.amount > 0 then
itemname = mem.liquid.name.." "..mem.liquid.amount itemname = nvm.liquid.name.." "..nvm.liquid.amount
end end
local fuel_percent = 0 local fuel_percent = 0
if mem.running then if nvm.running then
fuel_percent = ((mem.burn_cycles or 1) * 100) / (mem.burn_cycles_total or 1) fuel_percent = ((nvm.burn_cycles or 1) * 100) / (nvm.burn_cycles_total or 1)
end end
return "container["..x..","..y.."]".. return "container["..x..","..y.."]"..
"background[0,0;3,1.05;techage_form_grey.png]".. "background[0,0;3,1.05;techage_form_grey.png]"..
@ -56,48 +56,48 @@ end
techage.fuel.formspec_fuel = formspec_fuel techage.fuel.formspec_fuel = formspec_fuel
function techage.fuel.formspec(mem) function techage.fuel.formspec(nvm)
local update = ((mem.countdown or 0) > 0 and mem.countdown) or S("Update") local update = ((nvm.countdown or 0) > 0 and nvm.countdown) or S("Update")
return "size[8,5]".. return "size[8,5]"..
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
formspec_fuel(1, 0, mem).. formspec_fuel(1, 0, nvm)..
"button[5,0;2,1;update;"..update.."]".. "button[5,0;2,1;update;"..update.."]"..
"list[current_player;main;0,1.3;8,4;]" "list[current_player;main;0,1.3;8,4;]"
end end
local function fill_container(pos, inv, mem) local function fill_container(pos, inv, nvm)
mem.liquid = mem.liquid or {} nvm.liquid = nvm.liquid or {}
mem.liquid.amount = mem.liquid.amount or 0 nvm.liquid.amount = nvm.liquid.amount or 0
local empty_container = inv:get_stack("fuel", 1):get_name() local empty_container = inv:get_stack("fuel", 1):get_name()
local full_container = liquid.get_full_container(empty_container, mem.liquid.name) local full_container = liquid.get_full_container(empty_container, nvm.liquid.name)
if empty_container and full_container then if empty_container and full_container then
local ldef = liquid.get_liquid_def(full_container) local ldef = liquid.get_liquid_def(full_container)
if ldef and mem.liquid.amount - ldef.size >= 0 then if ldef and nvm.liquid.amount - ldef.size >= 0 then
inv:remove_item("fuel", ItemStack(empty_container)) inv:remove_item("fuel", ItemStack(empty_container))
inv:add_item("fuel", ItemStack(full_container)) inv:add_item("fuel", ItemStack(full_container))
mem.liquid.amount = mem.liquid.amount - ldef.size nvm.liquid.amount = nvm.liquid.amount - ldef.size
if mem.liquid.amount == 0 then if nvm.liquid.amount == 0 then
mem.liquid.name = nil nvm.liquid.name = nil
end end
end end
end end
end end
local function empty_container(pos, inv, mem) local function empty_container(pos, inv, nvm)
mem.liquid = mem.liquid or {} nvm.liquid = nvm.liquid or {}
mem.liquid.amount = mem.liquid.amount or 0 nvm.liquid.amount = nvm.liquid.amount or 0
local stack = inv:get_stack("fuel", 1) local stack = inv:get_stack("fuel", 1)
if stack:get_count() == 1 then if stack:get_count() == 1 then
local ldef = liquid.get_liquid_def(stack:get_name()) local ldef = liquid.get_liquid_def(stack:get_name())
if ldef and ValidOilFuels[ldef.inv_item] then if ldef and ValidOilFuels[ldef.inv_item] then
if not mem.liquid.name or ldef.inv_item == mem.liquid.name then if not nvm.liquid.name or ldef.inv_item == nvm.liquid.name then
if mem.liquid.amount + ldef.size <= CAPACITY then if nvm.liquid.amount + ldef.size <= CAPACITY then
inv:remove_item("fuel", stack) inv:remove_item("fuel", stack)
inv:add_item("fuel", ItemStack(ldef.container)) inv:add_item("fuel", ItemStack(ldef.container))
mem.liquid.amount = mem.liquid.amount + ldef.size nvm.liquid.amount = nvm.liquid.amount + ldef.size
mem.liquid.name = ldef.inv_item nvm.liquid.name = ldef.inv_item
end end
end end
end end
@ -105,25 +105,25 @@ local function empty_container(pos, inv, mem)
end end
local function move_item(pos, stack) local function move_item(pos, stack)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
local inv = M(pos):get_inventory() local inv = M(pos):get_inventory()
if liquid.is_container_empty(stack:get_name()) then if liquid.is_container_empty(stack:get_name()) then
fill_container(pos, inv, mem) fill_container(pos, inv, nvm)
else else
empty_container(pos, inv, mem) empty_container(pos, inv, nvm)
end end
M(pos):set_string("formspec", techage.fuel.formspec(mem)) M(pos):set_string("formspec", techage.fuel.formspec(nvm))
end end
function techage.fuel.move_item(pos, stack, formspec) function techage.fuel.move_item(pos, stack, formspec)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
local inv = M(pos):get_inventory() local inv = M(pos):get_inventory()
if liquid.is_container_empty(stack:get_name()) then if liquid.is_container_empty(stack:get_name()) then
fill_container(pos, inv, mem) fill_container(pos, inv, nvm)
else else
empty_container(pos, inv, mem) empty_container(pos, inv, nvm)
end end
M(pos):set_string("formspec", formspec(pos, mem)) M(pos):set_string("formspec", formspec(pos, nvm))
end end
function techage.fuel.allow_metadata_inventory_put(pos, listname, index, stack, player) function techage.fuel.allow_metadata_inventory_put(pos, listname, index, stack, player)
@ -156,32 +156,32 @@ function techage.fuel.can_dig(pos, player)
if minetest.is_protected(pos, player:get_player_name()) then if minetest.is_protected(pos, player:get_player_name()) then
return false return false
end end
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.liquid = mem.liquid or {} nvm.liquid = nvm.liquid or {}
mem.liquid.amount = mem.liquid.amount or 0 nvm.liquid.amount = nvm.liquid.amount or 0
local inv = M(pos):get_inventory() local inv = M(pos):get_inventory()
return inv:is_empty("fuel") and mem.liquid.amount == 0 return inv:is_empty("fuel") and nvm.liquid.amount == 0
end end
function techage.fuel.on_rightclick(pos) function techage.fuel.on_rightclick(pos)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.countdown = 10 nvm.countdown = 10
M(pos):set_string("formspec", techage.fuel.formspec(mem)) M(pos):set_string("formspec", techage.fuel.formspec(nvm))
end end
function techage.fuel.on_receive_fields(pos, formname, fields, player) function techage.fuel.on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then if minetest.is_protected(pos, player:get_player_name()) then
return return
end end
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.countdown = 10 nvm.countdown = 10
M(pos):set_string("formspec", techage.fuel.formspec(mem)) M(pos):set_string("formspec", techage.fuel.formspec(nvm))
end end
function techage.fuel.formspec_update(pos, mem) function techage.fuel.formspec_update(pos, nvm)
if mem.countdown and mem.countdown > 0 then if nvm.countdown and nvm.countdown > 0 then
mem.countdown = mem.countdown - 1 nvm.countdown = nvm.countdown - 1
M(pos):set_string("formspec", techage.fuel.formspec(mem)) M(pos):set_string("formspec", techage.fuel.formspec(nvm))
end end
end end

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -35,7 +35,7 @@ local ContainerDef = {}
local function determine_netID(pos, outdir) local function determine_netID(pos, outdir)
local netID = 0 local netID = 0
networks.connection_walk(pos, outdir, Pipe, function(pos, indir, node) networks.connection_walk(pos, outdir, Pipe, function(pos, indir, node)
local ntype = net_def(pos, "pipe").ntype local ntype = net_def(pos, "pipe2").ntype
if ntype and ntype == "pump" then if ntype and ntype == "pump" then
local new = minetest.hash_node_position(pos) * 8 + outdir local new = minetest.hash_node_position(pos) * 8 + outdir
if netID <= new then if netID <= new then
@ -49,13 +49,13 @@ end
-- store network ID on each pump like node -- store network ID on each pump like node
local function store_netID(pos, outdir, netID) local function store_netID(pos, outdir, netID)
networks.connection_walk(pos, outdir, Pipe, function(pos, indir, node) networks.connection_walk(pos, outdir, Pipe, function(pos, indir, node)
local ntype = net_def(pos, "pipe").ntype local ntype = net_def(pos, "pipe2").ntype
if ntype and ntype == "pump" then if ntype and ntype == "pump" then
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
local outdir = networks.Flip[indir] local outdir = networks.Flip[indir]
mem.pipe = mem.pipe or {} nvm.pipe2 = nvm.pipe2 or {}
mem.pipe.netIDs = mem.pipe.netIDs or {} nvm.pipe2.netIDs = nvm.pipe2.netIDs or {}
mem.pipe.netIDs[outdir] = netID nvm.pipe2.netIDs[outdir] = netID
end end
end) end)
end end
@ -64,13 +64,13 @@ end
local function delete_netID(pos, outdir) local function delete_netID(pos, outdir)
local netID = 0 local netID = 0
networks.connection_walk(pos, outdir, Pipe, function(pos, indir, node) networks.connection_walk(pos, outdir, Pipe, function(pos, indir, node)
local ntype = net_def(pos, "pipe").ntype local ntype = net_def(pos, "pipe2").ntype
if ntype and ntype == "pump" then if ntype and ntype == "pump" then
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
local outdir = networks.Flip[indir] local outdir = networks.Flip[indir]
if mem.pipe and mem.pipe.netIDs and mem.pipe.netIDs[outdir] then if nvm.pipe2 and nvm.pipe2.netIDs and nvm.pipe2.netIDs[outdir] then
netID = mem.pipe.netIDs[outdir] netID = nvm.pipe2.netIDs[outdir]
mem.pipe.netIDs[outdir] = nil nvm.pipe2.netIDs[outdir] = nil
end end
end end
end) end)
@ -78,21 +78,21 @@ local function delete_netID(pos, outdir)
end end
local function get_netID(pos, outdir) local function get_netID(pos, outdir)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if not mem.pipe or not mem.pipe.netIDs or not mem.pipe.netIDs[outdir] then if not nvm.pipe2 or not nvm.pipe2.netIDs or not nvm.pipe2.netIDs[outdir] then
local netID = determine_netID(pos, outdir) local netID = determine_netID(pos, outdir)
store_netID(pos, outdir, netID) store_netID(pos, outdir, netID)
end end
return mem.pipe and mem.pipe.netIDs and mem.pipe.netIDs[outdir] return nvm.pipe2 and nvm.pipe2.netIDs and nvm.pipe2.netIDs[outdir]
end end
local function get_network_table(pos, outdir, ntype) local function get_network_table(pos, outdir, ntype)
local netID = get_netID(pos, outdir) local netID = get_netID(pos, outdir)
if netID then if netID then
local netw = networks.get_network("pipe", netID) local netw = networks.get_network("pipe2", netID)
if not netw then if not netw then
netw = networks.collect_network_nodes(pos, outdir, Pipe) netw = networks.collect_network_nodes(pos, outdir, Pipe)
networks.set_network("pipe", netID, netw) networks.set_network("pipe2", netID, netw)
end end
local s = minetest.pos_to_string(minetest.get_position_from_hash(netID)) local s = minetest.pos_to_string(minetest.get_position_from_hash(netID))
--print("netw", string.format("%012X", netID), s, dump(netw)) --print("netw", string.format("%012X", netID), s, dump(netw))
@ -165,28 +165,28 @@ end
-- --
function techage.liquid.srv_peek(pos, indir) function techage.liquid.srv_peek(pos, indir)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.liquid = mem.liquid or {} nvm.liquid = nvm.liquid or {}
return mem.liquid.name return nvm.liquid.name
end end
function techage.liquid.srv_put(pos, indir, name, amount) function techage.liquid.srv_put(pos, indir, name, amount)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.liquid = mem.liquid or {} nvm.liquid = nvm.liquid or {}
amount = amount or 0 amount = amount or 0
if not mem.liquid.name then if not nvm.liquid.name then
mem.liquid.name = name nvm.liquid.name = name
mem.liquid.amount = amount nvm.liquid.amount = amount
return 0 return 0
elseif mem.liquid.name == name then elseif nvm.liquid.name == name then
mem.liquid.amount = mem.liquid.amount or 0 nvm.liquid.amount = nvm.liquid.amount or 0
local capa = LQD(pos).capa local capa = LQD(pos).capa
if mem.liquid.amount + amount <= capa then if nvm.liquid.amount + amount <= capa then
mem.liquid.amount = mem.liquid.amount + amount nvm.liquid.amount = nvm.liquid.amount + amount
return 0 return 0
else else
local rest = mem.liquid.amount + amount - capa local rest = nvm.liquid.amount + amount - capa
mem.liquid.amount = capa nvm.liquid.amount = capa
return rest return rest
end end
end end
@ -194,20 +194,20 @@ function techage.liquid.srv_put(pos, indir, name, amount)
end end
function techage.liquid.srv_take(pos, indir, name, amount) function techage.liquid.srv_take(pos, indir, name, amount)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.liquid = mem.liquid or {} nvm.liquid = nvm.liquid or {}
amount = amount or 0 amount = amount or 0
if not name or mem.liquid.name == name then if not name or nvm.liquid.name == name then
name = mem.liquid.name name = nvm.liquid.name
mem.liquid.amount = mem.liquid.amount or 0 nvm.liquid.amount = nvm.liquid.amount or 0
if mem.liquid.amount > amount then if nvm.liquid.amount > amount then
mem.liquid.amount = mem.liquid.amount - amount nvm.liquid.amount = nvm.liquid.amount - amount
return amount, name return amount, name
else else
local rest = mem.liquid.amount local rest = nvm.liquid.amount
local name = mem.liquid.name local name = nvm.liquid.name
mem.liquid.amount = 0 nvm.liquid.amount = 0
mem.liquid.name = nil nvm.liquid.name = nil
return rest, name return rest, name
end end
end end

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -18,10 +18,10 @@ local liquid = techage.liquid
local LQD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).liquid end local LQD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).liquid end
function techage.liquid.formspec_liquid(x, y, mem) function techage.liquid.formspec_liquid(x, y, nvm)
local itemname = "techage:liquid" local itemname = "techage:liquid"
if mem.liquid and mem.liquid.amount and mem.liquid.amount > 0 and mem.liquid.name then if nvm.liquid and nvm.liquid.amount and nvm.liquid.amount > 0 and nvm.liquid.name then
itemname = mem.liquid.name.." "..mem.liquid.amount itemname = nvm.liquid.name.." "..nvm.liquid.amount
end end
return "container["..x..","..y.."]".. return "container["..x..","..y.."]"..
"background[0,0;3,2.05;techage_form_grey.png]".. "background[0,0;3,2.05;techage_form_grey.png]"..
@ -40,20 +40,20 @@ function techage.liquid.formspec_liquid(x, y, mem)
end end
local function fill_container(pos, inv) local function fill_container(pos, inv)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.liquid = mem.liquid or {} nvm.liquid = nvm.liquid or {}
mem.liquid.amount = mem.liquid.amount or 0 nvm.liquid.amount = nvm.liquid.amount or 0
local empty_container = inv:get_stack("src", 1):get_name() local empty_container = inv:get_stack("src", 1):get_name()
local full_container = liquid.get_full_container(empty_container, mem.liquid.name) local full_container = liquid.get_full_container(empty_container, nvm.liquid.name)
if empty_container and full_container then if empty_container and full_container then
local ldef = liquid.get_liquid_def(full_container) local ldef = liquid.get_liquid_def(full_container)
if ldef and mem.liquid.amount - ldef.size >= 0 then if ldef and nvm.liquid.amount - ldef.size >= 0 then
if inv:room_for_item("dst", ItemStack(full_container)) then if inv:room_for_item("dst", ItemStack(full_container)) then
inv:remove_item("src", ItemStack(empty_container)) inv:remove_item("src", ItemStack(empty_container))
inv:add_item("dst", ItemStack(full_container)) inv:add_item("dst", ItemStack(full_container))
mem.liquid.amount = mem.liquid.amount - ldef.size nvm.liquid.amount = nvm.liquid.amount - ldef.size
if mem.liquid.amount == 0 then if nvm.liquid.amount == 0 then
mem.liquid.name = nil nvm.liquid.name = nil
end end
end end
end end
@ -61,39 +61,39 @@ local function fill_container(pos, inv)
end end
local function empty_container(pos, inv, size) local function empty_container(pos, inv, size)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.liquid = mem.liquid or {} nvm.liquid = nvm.liquid or {}
mem.liquid.amount = mem.liquid.amount or 0 nvm.liquid.amount = nvm.liquid.amount or 0
local stack = inv:get_stack("src", 1) local stack = inv:get_stack("src", 1)
local ldef = liquid.get_liquid_def(stack:get_name()) local ldef = liquid.get_liquid_def(stack:get_name())
if ldef and (not mem.liquid.name or ldef.inv_item == mem.liquid.name) then if ldef and (not nvm.liquid.name or ldef.inv_item == nvm.liquid.name) then
local amount = stack:get_count() * ldef.size local amount = stack:get_count() * ldef.size
if mem.liquid.amount + amount <= size then if nvm.liquid.amount + amount <= size then
if inv:room_for_item("dst", ItemStack(ldef.container)) then if inv:room_for_item("dst", ItemStack(ldef.container)) then
inv:remove_item("src", stack) inv:remove_item("src", stack)
inv:add_item("dst", ItemStack(ldef.container)) inv:add_item("dst", ItemStack(ldef.container))
mem.liquid.amount = mem.liquid.amount + amount nvm.liquid.amount = nvm.liquid.amount + amount
mem.liquid.name = ldef.inv_item nvm.liquid.name = ldef.inv_item
end end
end end
end end
end end
function techage.liquid.move_item(pos, stack, size, formspec) function techage.liquid.move_item(pos, stack, size, formspec)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
local inv = M(pos):get_inventory() local inv = M(pos):get_inventory()
if liquid.is_container_empty(stack:get_name()) then if liquid.is_container_empty(stack:get_name()) then
fill_container(pos, inv) fill_container(pos, inv)
else else
empty_container(pos, inv, size) empty_container(pos, inv, size)
end end
M(pos):set_string("formspec", formspec(pos, mem)) M(pos):set_string("formspec", formspec(pos, nvm))
end end
function techage.liquid.is_empty(pos) function techage.liquid.is_empty(pos)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
local inv = minetest.get_meta(pos):get_inventory() local inv = minetest.get_meta(pos):get_inventory()
return inv:is_empty("src") and inv:is_empty("dst") and (not mem.liquid or (mem.liquid.amount or 0) == 0) return inv:is_empty("src") and inv:is_empty("dst") and (not nvm.liquid or (nvm.liquid.amount or 0) == 0)
end end
techage.liquid.tubing = { techage.liquid.tubing = {
@ -127,8 +127,8 @@ techage.liquid.tubing = {
end, end,
on_recv_message = function(pos, src, topic, payload) on_recv_message = function(pos, src, topic, payload)
if topic == "load" then if topic == "load" then
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
return techage.power.percent(LQD(pos).capa, (mem.liquid and mem.liquid.amount) or 0) return techage.power.percent(LQD(pos).capa, (nvm.liquid and nvm.liquid.amount) or 0)
elseif topic == "size" then elseif topic == "size" then
return LQD(pos).capa return LQD(pos).capa
else else

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -26,7 +26,7 @@ local Pipe = tubelib2.Tube:new({
max_tube_length = MAX_PIPE_LENGHT, max_tube_length = MAX_PIPE_LENGHT,
show_infotext = false, show_infotext = false,
force_to_use_tubes = true, force_to_use_tubes = true,
tube_type = "pipe", tube_type = "pipe2",
primary_node_names = {"techage:ta3_pipeS", "techage:ta3_pipeA"}, primary_node_names = {"techage:ta3_pipeS", "techage:ta3_pipeA"},
secondary_node_names = {}, secondary_node_names = {},
after_place_tube = function(pos, param2, tube_type, num_tubes) after_place_tube = function(pos, param2, tube_type, num_tubes)
@ -54,7 +54,7 @@ minetest.register_node("techage:ta3_pipeS", {
end, end,
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
Pipe:after_dig_tube(pos, oldnode) Pipe:after_dig_tube(pos, oldnode, oldmetadata)
end, end,
paramtype2 = "facedir", -- important! paramtype2 = "facedir", -- important!
@ -85,7 +85,7 @@ minetest.register_node("techage:ta3_pipeA", {
}, },
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
Pipe:after_dig_tube(pos, oldnode) Pipe:after_dig_tube(pos, oldnode, oldmetadata)
end, end,
paramtype2 = "facedir", -- important! paramtype2 = "facedir", -- important!
@ -138,7 +138,7 @@ local Boxes = {
} }
} }
techage.register_junction("techage:ta3_junctionpipe", 1/8, Boxes, nil, { techage.register_junction("techage:ta3_junctionpipe", 1/8, Boxes, Pipe, {
description = S("TA Junction Pipe"), description = S("TA Junction Pipe"),
tiles = {"techage_gaspipe_junction.png"}, tiles = {"techage_gaspipe_junction.png"},
groups = {crumbly = 2, cracky = 2, snappy = 2, techage_trowel = 1}, groups = {crumbly = 2, cracky = 2, snappy = 2, techage_trowel = 1},
@ -158,18 +158,13 @@ techage.register_junction("techage:ta3_junctionpipe", 1/8, Boxes, nil, {
Pipe:after_dig_node(pos) Pipe:after_dig_node(pos)
end, end,
networks = { networks = {
pipe = { pipe2 = {
sides = networks.AllSides, -- connection sides for pipes sides = networks.AllSides, -- connection sides for pipes
ntype = "junc", ntype = "junc",
}, },
}, },
}, 25) }, 25)
-- register by hand, as there is no power support
for idx = 0,63 do
Pipe:add_secondary_node_names({"techage:ta3_junctionpipe"..idx})
end
minetest.register_craft({ minetest.register_craft({
output = "techage:ta3_junctionpipe25 2", output = "techage:ta3_junctionpipe25 2",
recipe = { recipe = {
@ -191,6 +186,5 @@ minetest.register_craft({
minetest.register_alias("techage:ta4_pipeA", "techage:ta3_pipeA") minetest.register_alias("techage:ta4_pipeA", "techage:ta3_pipeA")
minetest.register_alias("techage:ta4_pipeS", "techage:ta3_pipeS") minetest.register_alias("techage:ta4_pipeS", "techage:ta3_pipeS")
techage.BiogasPipe = Pipe
techage.LiquidPipe = Pipe techage.LiquidPipe = Pipe

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -62,7 +62,7 @@ local State4 = techage.NodeStates:new({
standby_ticks = STANDBY_TICKS, standby_ticks = STANDBY_TICKS,
}) })
local function pumping(pos, mem, state, capa) local function pumping(pos, nvm, state, capa)
local outdir = M(pos):get_int("outdir") local outdir = M(pos):get_int("outdir")
local starter = get_starter_name(pos) local starter = get_starter_name(pos)
local taken, name = liquid.take(pos, Flip[outdir], nil, capa, starter) local taken, name = liquid.take(pos, Flip[outdir], nil, capa, starter)
@ -70,55 +70,55 @@ local function pumping(pos, mem, state, capa)
local leftover = liquid.put(pos, outdir, name, taken, starter) local leftover = liquid.put(pos, outdir, name, taken, starter)
if leftover and leftover > 0 then if leftover and leftover > 0 then
liquid.put(pos, Flip[outdir], name, leftover) liquid.put(pos, Flip[outdir], name, leftover)
state:blocked(pos, mem) state:blocked(pos, nvm)
return return
end end
state:keep_running(pos, mem, COUNTDOWN_TICKS) state:keep_running(pos, nvm, COUNTDOWN_TICKS)
return return
end end
state:idle(pos, mem) state:idle(pos, nvm)
end end
local function after_place_node3(pos, placer) local function after_place_node3(pos, placer)
local mem = tubelib2.init_mem(pos) local nvm = techage.get_nvm(pos)
local number = techage.add_node(pos, "techage:t3_pump") local number = techage.add_node(pos, "techage:t3_pump")
State3:node_init(pos, mem, number) State3:node_init(pos, nvm, number)
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R")) M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
Pipe:after_place_node(pos) Pipe:after_place_node(pos)
end end
local function after_place_node4(pos, placer) local function after_place_node4(pos, placer)
local mem = tubelib2.init_mem(pos) local nvm = techage.get_nvm(pos)
local number = techage.add_node(pos, "techage:t4_pump") local number = techage.add_node(pos, "techage:t4_pump")
State4:node_init(pos, mem, number) State4:node_init(pos, nvm, number)
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R")) M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
Pipe:after_place_node(pos) Pipe:after_place_node(pos)
end end
local function node_timer3(pos, elapsed) local function node_timer3(pos, elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
pumping(pos, mem, State3, CAPA) pumping(pos, nvm, State3, CAPA)
return State3:is_active(mem) return State3:is_active(nvm)
end end
local function node_timer4(pos, elapsed) local function node_timer4(pos, elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
pumping(pos, mem, State4, CAPA * 2) pumping(pos, nvm, State4, CAPA * 2)
return State4:is_active(mem) return State4:is_active(nvm)
end end
local function on_rightclick(pos, node, clicker) local function on_rightclick(pos, node, clicker)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if node.name == "techage:t3_pump" then if node.name == "techage:t3_pump" then
set_starter_name(pos, clicker) set_starter_name(pos, clicker)
State3:start(pos, mem) State3:start(pos, nvm)
elseif node.name == "techage:t3_pump_on" then elseif node.name == "techage:t3_pump_on" then
State3:stop(pos, mem) State3:stop(pos, nvm)
elseif node.name == "techage:t4_pump" then elseif node.name == "techage:t4_pump" then
set_starter_name(pos, clicker) set_starter_name(pos, clicker)
State4:start(pos, mem) State4:start(pos, nvm)
elseif node.name == "techage:t4_pump_on" then elseif node.name == "techage:t4_pump_on" then
State4:stop(pos, mem) State4:stop(pos, nvm)
end end
end end
@ -128,7 +128,7 @@ end
local function after_dig_node(pos, oldnode, oldmetadata, digger) local function after_dig_node(pos, oldnode, oldmetadata, digger)
Pipe:after_dig_node(pos) Pipe:after_dig_node(pos)
tubelib2.del_mem(pos) techage.del_mem(pos)
end end
local ta3_tiles_pas = { local ta3_tiles_pas = {
@ -208,7 +208,7 @@ local ta4_tiles_act = {
} }
local nworks = { local nworks = {
pipe = { pipe2 = {
sides = {L = 1, R = 1}, -- Pipe connection side sides = {L = 1, R = 1}, -- Pipe connection side
ntype = "pump", ntype = "pump",
}, },

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -26,8 +26,8 @@ local function allow_metadata_inventory_put(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then if minetest.is_protected(pos, player:get_player_name()) then
return 0 return 0
end end
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.item_name = nil nvm.item_name = nil
local inv = minetest.get_meta(pos):get_inventory() local inv = minetest.get_meta(pos):get_inventory()
if inv:is_empty(listname) then if inv:is_empty(listname) then
return stack:get_count() return stack:get_count()
@ -42,8 +42,8 @@ local function allow_metadata_inventory_take(pos, listname, index, stack, player
if minetest.is_protected(pos, player:get_player_name()) then if minetest.is_protected(pos, player:get_player_name()) then
return 0 return 0
end end
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.item_name = nil nvm.item_name = nil
return stack:get_count() return stack:get_count()
end end
@ -55,12 +55,12 @@ local function can_dig(pos, player)
return inv:is_empty("main") return inv:is_empty("main")
end end
local function get_item_name(mem, inv) local function get_item_name(nvm, inv)
for idx = 1, inv:get_size("main") do for idx = 1, inv:get_size("main") do
local stack = inv:get_stack("main", idx) local stack = inv:get_stack("main", idx)
if stack:get_count() > 0 then if stack:get_count() > 0 then
mem.item_name = stack:get_name() nvm.item_name = stack:get_name()
return mem.item_name return nvm.item_name
end end
end end
end end
@ -90,10 +90,10 @@ end
local tLiquid = { local tLiquid = {
capa = 0, capa = 0,
peek = function(pos, indir) peek = function(pos, indir)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
local inv = M(pos):get_inventory() local inv = M(pos):get_inventory()
if not inv:is_empty("main") then if not inv:is_empty("main") then
return mem.item_name or get_item_name(mem, inv) return nvm.item_name or get_item_name(nvm, inv)
end end
end, end,
put = function(pos, indir, name, amount) put = function(pos, indir, name, amount)
@ -106,10 +106,10 @@ local tLiquid = {
return amount return amount
end, end,
take = function(pos, indir, name, amount) take = function(pos, indir, name, amount)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
local inv = M(pos):get_inventory() local inv = M(pos):get_inventory()
if not name then if not name then
name = mem.item_name or get_item_name(mem, inv) name = nvm.item_name or get_item_name(nvm, inv)
end end
if name then if name then
local stack = ItemStack(name.." "..amount) local stack = ItemStack(name.." "..amount)
@ -120,7 +120,7 @@ local tLiquid = {
} }
local tNetworks = { local tNetworks = {
pipe = { pipe2 = {
sides = techage.networks.AllSides, -- Pipe connection sides sides = techage.networks.AllSides, -- Pipe connection sides
ntype = "tank", ntype = "tank",
}, },
@ -143,12 +143,12 @@ minetest.register_node("techage:ta3_silo", {
end, end,
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local meta = M(pos) local meta = M(pos)
local mem = tubelib2.init_mem(pos) local nvm = techage.get_nvm(pos)
mem.liquid = {} nvm.liquid = {}
local number = techage.add_node(pos, "techage:ta3_silo") local number = techage.add_node(pos, "techage:ta3_silo")
meta:set_string("node_number", number) meta:set_string("node_number", number)
meta:set_string("owner", placer:get_player_name()) meta:set_string("owner", placer:get_player_name())
meta:set_string("formspec", formspec3(mem)) meta:set_string("formspec", formspec3(nvm))
meta:set_string("infotext", S("TA3 Silo").." "..number) meta:set_string("infotext", S("TA3 Silo").." "..number)
Pipe:after_place_node(pos) Pipe:after_place_node(pos)
end, end,
@ -188,12 +188,12 @@ minetest.register_node("techage:ta4_silo", {
end, end,
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local meta = M(pos) local meta = M(pos)
local mem = tubelib2.init_mem(pos) local nvm = techage.get_nvm(pos)
mem.liquid = {} nvm.liquid = {}
local number = techage.add_node(pos, "techage:ta4_silo") local number = techage.add_node(pos, "techage:ta4_silo")
meta:set_string("node_number", number) meta:set_string("node_number", number)
meta:set_string("owner", placer:get_player_name()) meta:set_string("owner", placer:get_player_name())
meta:set_string("formspec", formspec4(mem)) meta:set_string("formspec", formspec4(nvm))
meta:set_string("infotext", S("TA4 Silo").." "..number) meta:set_string("infotext", S("TA4 Silo").." "..number)
Pipe:after_place_node(pos) Pipe:after_place_node(pos)
end, end,

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -21,13 +21,13 @@ local liquid = techage.liquid
local CAPACITY = 500 local CAPACITY = 500
local function formspec(pos, mem) local function formspec(pos, nvm)
local update = ((mem.countdown or 0) > 0 and mem.countdown) or S("Update") local update = ((nvm.countdown or 0) > 0 and nvm.countdown) or S("Update")
return "size[8,6]".. return "size[8,6]"..
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
liquid.formspec_liquid(2, 0, mem).. liquid.formspec_liquid(2, 0, nvm)..
"button[5.5,0.5;2,1;update;"..update.."]".. "button[5.5,0.5;2,1;update;"..update.."]"..
"list[current_player;main;0,2.3;8,4;]" "list[current_player;main;0,2.3;8,4;]"
end end
@ -55,9 +55,9 @@ local function on_metadata_inventory_put(pos, listname, index, stack, player)
end end
local function on_rightclick(pos) local function on_rightclick(pos)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.countdown = 10 nvm.countdown = 10
M(pos):set_string("formspec", formspec(pos, mem)) M(pos):set_string("formspec", formspec(pos, nvm))
minetest.get_node_timer(pos):start(2) minetest.get_node_timer(pos):start(2)
end end
@ -65,9 +65,9 @@ local function on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then if minetest.is_protected(pos, player:get_player_name()) then
return return
end end
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.countdown = 10 nvm.countdown = 10
M(pos):set_string("formspec", formspec(pos, mem)) M(pos):set_string("formspec", formspec(pos, nvm))
minetest.get_node_timer(pos):start(2) minetest.get_node_timer(pos):start(2)
end end
@ -98,12 +98,12 @@ minetest.register_node("techage:ta3_tank", {
end, end,
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local meta = M(pos) local meta = M(pos)
local mem = tubelib2.init_mem(pos) local nvm = techage.get_nvm(pos)
mem.liquid = {} nvm.liquid = {}
local number = techage.add_node(pos, "techage:ta3_tank") local number = techage.add_node(pos, "techage:ta3_tank")
meta:set_string("node_number", number) meta:set_string("node_number", number)
meta:set_string("owner", placer:get_player_name()) meta:set_string("owner", placer:get_player_name())
meta:set_string("formspec", formspec(pos, mem)) meta:set_string("formspec", formspec(pos, nvm))
meta:set_string("infotext", S("TA3 Tank").." "..number) meta:set_string("infotext", S("TA3 Tank").." "..number)
Pipe:after_place_node(pos) Pipe:after_place_node(pos)
end, end,
@ -111,11 +111,11 @@ minetest.register_node("techage:ta3_tank", {
liquid.update_network(pos, outdir) liquid.update_network(pos, outdir)
end, end,
on_timer = function(pos, elapsed) on_timer = function(pos, elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if mem.countdown then if nvm.countdown then
mem.countdown = mem.countdown - 1 nvm.countdown = nvm.countdown - 1
M(pos):set_string("formspec", formspec(pos, mem)) M(pos):set_string("formspec", formspec(pos, nvm))
return mem.countdown > 0 return nvm.countdown > 0
end end
end, end,
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
@ -136,7 +136,7 @@ minetest.register_node("techage:ta3_tank", {
take = liquid.srv_take, take = liquid.srv_take,
}, },
networks = { networks = {
pipe = { pipe2 = {
sides = techage.networks.AllSides, -- Pipe connection sides sides = techage.networks.AllSides, -- Pipe connection sides
ntype = "tank", ntype = "tank",
}, },
@ -185,12 +185,12 @@ minetest.register_node("techage:oiltank", {
end, end,
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local meta = M(pos) local meta = M(pos)
local mem = tubelib2.init_mem(pos) local nvm = techage.get_nvm(pos)
mem.liquid = {} nvm.liquid = {}
local number = techage.add_node(pos, "techage:oiltank") local number = techage.add_node(pos, "techage:oiltank")
meta:set_string("node_number", number) meta:set_string("node_number", number)
meta:set_string("owner", placer:get_player_name()) meta:set_string("owner", placer:get_player_name())
meta:set_string("formspec", formspec(pos, mem)) meta:set_string("formspec", formspec(pos, nvm))
meta:set_string("infotext", S("Oil Tank").." "..number) meta:set_string("infotext", S("Oil Tank").." "..number)
Pipe:after_place_node(pos) Pipe:after_place_node(pos)
end, end,
@ -198,11 +198,11 @@ minetest.register_node("techage:oiltank", {
liquid.update_network(pos, outdir) liquid.update_network(pos, outdir)
end, end,
on_timer = function(pos, elapsed) on_timer = function(pos, elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if mem.countdown then if nvm.countdown then
mem.countdown = mem.countdown - 1 nvm.countdown = nvm.countdown - 1
M(pos):set_string("formspec", formspec(pos, mem)) M(pos):set_string("formspec", formspec(pos, nvm))
return mem.countdown > 0 return nvm.countdown > 0
end end
end, end,
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
@ -223,7 +223,7 @@ minetest.register_node("techage:oiltank", {
take = liquid.srv_take, take = liquid.srv_take,
}, },
networks = { networks = {
pipe = { pipe2 = {
sides = techage.networks.AllSides, -- Pipe connection sides sides = techage.networks.AllSides, -- Pipe connection sides
ntype = "tank", ntype = "tank",
}, },
@ -262,12 +262,12 @@ minetest.register_node("techage:ta4_tank", {
end, end,
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local meta = M(pos) local meta = M(pos)
local mem = tubelib2.init_mem(pos) local nvm = techage.get_nvm(pos)
mem.liquid = {} nvm.liquid = {}
local number = techage.add_node(pos, "techage:ta4_tank") local number = techage.add_node(pos, "techage:ta4_tank")
meta:set_string("node_number", number) meta:set_string("node_number", number)
meta:set_string("owner", placer:get_player_name()) meta:set_string("owner", placer:get_player_name())
meta:set_string("formspec", formspec(pos, mem)) meta:set_string("formspec", formspec(pos, nvm))
meta:set_string("infotext", S("TA4 Tank").." "..number) meta:set_string("infotext", S("TA4 Tank").." "..number)
Pipe:after_place_node(pos) Pipe:after_place_node(pos)
end, end,
@ -275,11 +275,11 @@ minetest.register_node("techage:ta4_tank", {
liquid.update_network(pos, outdir) liquid.update_network(pos, outdir)
end, end,
on_timer = function(pos, elapsed) on_timer = function(pos, elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if mem.countdown then if nvm.countdown then
mem.countdown = mem.countdown - 1 nvm.countdown = nvm.countdown - 1
M(pos):set_string("formspec", formspec(pos, mem)) M(pos):set_string("formspec", formspec(pos, nvm))
return mem.countdown > 0 return nvm.countdown > 0
end end
end, end,
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
@ -300,7 +300,7 @@ minetest.register_node("techage:ta4_tank", {
take = liquid.srv_take, take = liquid.srv_take,
}, },
networks = { networks = {
pipe = { pipe2 = {
sides = techage.networks.AllSides, -- Pipe connection sides sides = techage.networks.AllSides, -- Pipe connection sides
ntype = "tank", ntype = "tank",
}, },

View File

@ -278,7 +278,7 @@ Water Barrel=Wasserfass
[TechAge Programmer] Error: programmer not supported!=[TechAge Programmer] Fehler: Programmer wird nicht unterstützt! [TechAge Programmer] Error: programmer not supported!=[TechAge Programmer] Fehler: Programmer wird nicht unterstützt!
[TechAge Programmer] Unknown node on=[TechAge Programmer] Unbekannter Block bei [TechAge Programmer] Unknown node on=[TechAge Programmer] Unbekannter Block bei
[TechAge Programmer] foreign or unknown node!=[TechAge Programmer] Fremder oder unbekannter Block! [TechAge Programmer] foreign or unknown node!=[TechAge Programmer] Fremder oder unbekannter Block!
[TechAge Programmer] node programmed!=[TechAge Programmer] Nicht programmiert! [TechAge Programmer] node programmed!=[TechAge Programmer] Nummer(n) programmiert!
[TechAge Programmer] number=[TechAge Programmer] Nummer= [TechAge Programmer] number=[TechAge Programmer] Nummer=
[TechAge Programmer] programmer reset=[TechAge Programmer] Programmer zurück gesetzt [TechAge Programmer] programmer reset=[TechAge Programmer] Programmer zurück gesetzt
\\[ku\\]=\\[ku\\] \\[ku\\]=\\[ku\\]

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2017-2019 Joachim Stolberg Copyright (C) 2017-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -140,7 +140,6 @@ minetest.register_node("techage:ta3_button_off", {
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos) techage.remove_node(pos)
tubelib2.del_mem(pos)
end, end,
on_rotate = screwdriver.disallow, on_rotate = screwdriver.disallow,
@ -186,7 +185,6 @@ minetest.register_node("techage:ta3_button_on", {
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos) techage.remove_node(pos)
tubelib2.del_mem(pos)
end, end,
paramtype2 = "facedir", paramtype2 = "facedir",

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -95,7 +95,6 @@ end
local function after_dig_node(pos, oldnode, oldmetadata, digger) local function after_dig_node(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos) techage.remove_node(pos)
tubelib2.del_mem(pos)
end end
minetest.register_node("techage:ta3_cartdetector_off", { minetest.register_node("techage:ta3_cartdetector_off", {

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2017-2019 Joachim Stolberg Copyright (C) 2017-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -20,7 +20,7 @@ local logic = techage.logic
local BLOCKING_TIME = 8 -- seconds local BLOCKING_TIME = 8 -- seconds
local function switch_on(pos) local function switch_on(pos)
local mem = tubelib2.get_mem(pos) local mem = techage.get_mem(pos)
local t = minetest.get_gametime() local t = minetest.get_gametime()
if t > (mem.time or 0) then if t > (mem.time or 0) then
logic.swap_node(pos, "techage:ta3_detector_on") logic.swap_node(pos, "techage:ta3_detector_on")
@ -55,7 +55,6 @@ minetest.register_node("techage:ta3_detector_off", {
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local meta = M(pos) local meta = M(pos)
local mem = tubelib2.init_mem(pos)
logic.after_place_node(pos, placer, "techage:ta3_detector_off", S("TA3 Detector")) logic.after_place_node(pos, placer, "techage:ta3_detector_off", S("TA3 Detector"))
logic.infotext(meta, S("TA3 Detector")) logic.infotext(meta, S("TA3 Detector"))
meta:set_string("formspec", formspec(meta)) meta:set_string("formspec", formspec(meta))
@ -79,7 +78,7 @@ minetest.register_node("techage:ta3_detector_off", {
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos) techage.remove_node(pos)
tubelib2.del_mem(pos) techage.del_mem(pos)
end, end,
on_rotate = screwdriver.disallow, on_rotate = screwdriver.disallow,
@ -116,7 +115,7 @@ minetest.register_node("techage:ta3_detector_on", {
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos) techage.remove_node(pos)
tubelib2.del_mem(pos) techage.del_mem(pos)
end, end,
paramtype2 = "facedir", paramtype2 = "facedir",

View File

@ -57,11 +57,11 @@ for idx,pgn in ipairs(tPgns) do
}, },
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local mem = tubelib2.init_mem(pos) local nvm = techage.get_nvm(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
local number = techage.add_node(pos, "techage:doorblock"..idx) local number = techage.add_node(pos, "techage:doorblock"..idx)
mem.facedir = node.param2 nvm.facedir = node.param2
meta:set_string("node_number", number) meta:set_string("node_number", number)
meta:set_string("infotext", S("TechAge Door Block").." "..number) meta:set_string("infotext", S("TechAge Door Block").." "..number)
meta:set_string("formspec", "size[3,2]".. meta:set_string("formspec", "size[3,2]"..
@ -73,11 +73,11 @@ for idx,pgn in ipairs(tPgns) do
on_receive_fields = function(pos, formname, fields, player) on_receive_fields = function(pos, formname, fields, player)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if fields.type then if fields.type then
node.name = "techage:doorblock"..tTextures[fields.type] node.name = "techage:doorblock"..tTextures[fields.type]
minetest.swap_node(pos, node) minetest.swap_node(pos, node)
mem.name = node.name nvm.name = node.name
end end
if fields.exit then if fields.exit then
meta:set_string("formspec", nil) meta:set_string("formspec", nil)
@ -86,7 +86,7 @@ for idx,pgn in ipairs(tPgns) do
after_dig_node = function(pos, oldnode, oldmetadata) after_dig_node = function(pos, oldnode, oldmetadata)
techage.remove_node(pos) techage.remove_node(pos)
tubelib2.del_mem(pos) techage.del_mem(pos)
end, end,
--drawtype = "glasslike", --drawtype = "glasslike",
@ -104,10 +104,10 @@ for idx,pgn in ipairs(tPgns) do
if topic == "on" then if topic == "on" then
minetest.remove_node(pos) minetest.remove_node(pos)
elseif topic == "off" then elseif topic == "off" then
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.facedir = mem.facedir or 0 nvm.facedir = nvm.facedir or 0
mem.name = mem.name or "techage:doorblock"..NUM_TEXTURES nvm.name = nvm.name or "techage:doorblock"..NUM_TEXTURES
minetest.add_node(pos, {name = mem.name, paramtype2 = "facedir", param2 = mem.facedir}) minetest.add_node(pos, {name = nvm.name, paramtype2 = "facedir", param2 = nvm.facedir})
end end
end, end,
}) })

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2017-2019 Joachim Stolberg Copyright (C) 2017-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -52,56 +52,56 @@ local function check(expression)
return true, "ok" return true, "ok"
end end
local function compile(mem, expression) local function compile(nvm, expression)
local res, err = check(expression) local res, err = check(expression)
if res then if res then
local code, err = loadstring(expression, "") local code, err = loadstring(expression, "")
if code then if code then
mem.code = code nvm.code = code
mem.error = "ok" nvm.error = "ok"
else else
mem.code = nil nvm.code = nil
mem.error = err nvm.error = err
end end
else else
mem.code = nil nvm.code = nil
mem.error = err nvm.error = err
end end
end end
local function get_code(pos, mem) local function get_code(pos, nvm)
local meta = M(pos) local meta = M(pos)
local if_expr = meta:get_string("if_expr") or "" local if_expr = meta:get_string("if_expr") or ""
local then_expr = meta:get_string("then_expr") or "" local then_expr = meta:get_string("then_expr") or ""
local else_expr = meta:get_string("else_expr") or "" local else_expr = meta:get_string("else_expr") or ""
local expr = "if "..if_expr.." then return "..then_expr.." else return "..else_expr.." end" local expr = "if "..if_expr.." then return "..then_expr.." else return "..else_expr.." end"
compile(mem, expr) compile(nvm, expr)
return mem.code return nvm.code
end end
local function eval(pos, mem) local function eval(pos, nvm)
mem.code = mem.code or get_code(pos, mem) nvm.code = nvm.code or get_code(pos, nvm)
if mem.code then if nvm.code then
setfenv(mem.code, mem.inp_tbl) setfenv(nvm.code, nvm.inp_tbl)
local res, sts = pcall(mem.code) local res, sts = pcall(nvm.code)
if res then if res then
mem.error = "ok" nvm.error = "ok"
if sts == true and mem.inp_tbl.outp ~= true then if sts == true and nvm.inp_tbl.outp ~= true then
mem.inp_tbl.outp = sts nvm.inp_tbl.outp = sts
return "on" return "on"
elseif sts == false and mem.inp_tbl.outp ~= false then elseif sts == false and nvm.inp_tbl.outp ~= false then
mem.inp_tbl.outp = sts nvm.inp_tbl.outp = sts
return "off" return "off"
end end
else else
mem.error = "Error: "..sts nvm.error = "Error: "..sts
end end
end end
end end
local function data(mem) local function data(nvm)
local tbl = {"inp = "..dump(mem.inp_tbl.inp), "outp = "..dump(mem.inp_tbl.outp)} local tbl = {"inp = "..dump(nvm.inp_tbl.inp), "outp = "..dump(nvm.inp_tbl.outp)}
for k,v in pairs(mem.inp_tbl) do for k,v in pairs(nvm.inp_tbl) do
if k ~= "inp" and k ~= "outp" then if k ~= "inp" and k ~= "outp" then
tbl[#tbl+1] = k.." = "..dump(v) tbl[#tbl+1] = k.." = "..dump(v)
end end
@ -110,18 +110,18 @@ local function data(mem)
end end
local function formspec(pos, meta) local function formspec(pos, meta)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
local numbers = meta:get_string("numbers") or "" local numbers = meta:get_string("numbers") or ""
local if_expr = meta:get_string("if_expr") or "" local if_expr = meta:get_string("if_expr") or ""
local then_expr = meta:get_string("then_expr") or "" local then_expr = meta:get_string("then_expr") or ""
local else_expr = meta:get_string("else_expr") or "" local else_expr = meta:get_string("else_expr") or ""
local err = mem.error or "ok" local err = nvm.error or "ok"
if err ~= "ok" then if err ~= "ok" then
err = string.sub(err, 15) err = string.sub(err, 15)
end end
err = minetest.formspec_escape(err) err = minetest.formspec_escape(err)
mem.inp_tbl = mem.inp_tbl or {inp = false, outp = false} nvm.inp_tbl = nvm.inp_tbl or {inp = false, outp = false}
local data = data(mem) local data = data(nvm)
return "size[9,8]".. return "size[9,8]"..
"background[0,0;9,1.3;techage_formspec_bg.png]".. "background[0,0;9,1.3;techage_formspec_bg.png]"..
"field[0.5,0.2;8.5,2;numbers;"..S("Insert destination node number(s)")..";"..numbers.."]" .. "field[0.5,0.2;8.5,2;numbers;"..S("Insert destination node number(s)")..";"..numbers.."]" ..
@ -153,8 +153,8 @@ minetest.register_node("techage:ta3_logic", {
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local meta = M(pos) local meta = M(pos)
local mem = tubelib2.init_mem(pos) local nvm = techage.get_nvm(pos)
mem.inp_tbl = {inp = false, outp = false} nvm.inp_tbl = {inp = false, outp = false}
logic.after_place_node(pos, placer, "techage:ta3_logic", S("TA3 Logic Block")) logic.after_place_node(pos, placer, "techage:ta3_logic", S("TA3 Logic Block"))
logic.infotext(meta, S("TA3 Logic Block")) logic.infotext(meta, S("TA3 Logic Block"))
meta:set_string("formspec", formspec(pos, meta)) meta:set_string("formspec", formspec(pos, meta))
@ -166,7 +166,7 @@ minetest.register_node("techage:ta3_logic", {
end end
local meta = M(pos) local meta = M(pos)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if fields.numbers and fields.numbers ~= "" then if fields.numbers and fields.numbers ~= "" then
if techage.check_numbers(fields.numbers, player:get_player_name()) then if techage.check_numbers(fields.numbers, player:get_player_name()) then
meta:set_string("numbers", fields.numbers) meta:set_string("numbers", fields.numbers)
@ -183,14 +183,14 @@ minetest.register_node("techage:ta3_logic", {
meta:set_string("else_expr", fields.else_expr) meta:set_string("else_expr", fields.else_expr)
end end
if fields.store then if fields.store then
get_code(pos, mem) get_code(pos, nvm)
end end
meta:set_string("formspec", formspec(pos, meta)) meta:set_string("formspec", formspec(pos, meta))
end, end,
on_timer = function(pos,elapsed) on_timer = function(pos,elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
local topic = eval(pos, mem) local topic = eval(pos, nvm)
if topic then if topic then
local meta = M(pos) local meta = M(pos)
local own_num = meta:get_string("node_number") or "" local own_num = meta:get_string("node_number") or ""
@ -209,7 +209,7 @@ minetest.register_node("techage:ta3_logic", {
after_dig_node = function(pos) after_dig_node = function(pos)
techage.remove_node(pos) techage.remove_node(pos)
tubelib2.del_mem(pos) techage.del_mem(pos)
end, end,
paramtype2 = "facedir", paramtype2 = "facedir",
@ -230,15 +230,15 @@ minetest.register_craft({
techage.register_node({"techage:ta3_logic"}, { techage.register_node({"techage:ta3_logic"}, {
on_recv_message = function(pos, src, topic, payload) on_recv_message = function(pos, src, topic, payload)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.inp_tbl = mem.inp_tbl or {outp = false} nvm.inp_tbl = nvm.inp_tbl or {outp = false}
if topic == "on" then if topic == "on" then
mem.inp_tbl.inp = true nvm.inp_tbl.inp = true
mem.inp_tbl["n"..src] = true nvm.inp_tbl["n"..src] = true
elseif topic == "off" then elseif topic == "off" then
mem.inp_tbl.inp = false nvm.inp_tbl.inp = false
mem.inp_tbl["n"..src] = false nvm.inp_tbl["n"..src] = false
else else
return "unsupported" return "unsupported"
end end

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2017-2019 Joachim Stolberg Copyright (C) 2017-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -37,7 +37,7 @@ local DropdownValues = {
[S("added or removed")] = 3, [S("added or removed")] = 3,
} }
local function formspec(meta, mem) local function formspec(meta, nvm)
local numbers = meta:get_string("numbers") or "" local numbers = meta:get_string("numbers") or ""
local label = S("added")..","..S("removed")..","..S("added or removed") local label = S("added")..","..S("removed")..","..S("added or removed")
return "size[7.5,4]".. return "size[7.5,4]"..
@ -46,34 +46,34 @@ local function formspec(meta, mem)
default.gui_slots.. default.gui_slots..
"field[0.5,0.6;7,1;numbers;"..S("Insert destination node number(s)")..";"..numbers.."]" .. "field[0.5,0.6;7,1;numbers;"..S("Insert destination node number(s)")..";"..numbers.."]" ..
"label[0.2,1.6;"..S("Send signal if nodes have been:").."]".. "label[0.2,1.6;"..S("Send signal if nodes have been:").."]"..
"dropdown[0.2,2.1;7.3,1;mode;"..label..";"..(mem.mode or 3).."]".. "dropdown[0.2,2.1;7.3,1;mode;"..label..";"..(nvm.mode or 3).."]"..
"button_exit[2,3.2;3,1;accept;"..S("accept").."]" "button_exit[2,3.2;3,1;accept;"..S("accept").."]"
end end
local function any_node_changed(pos) local function any_node_changed(pos)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if not mem.pos1 or not mem.pos2 or not mem.num then if not nvm.pos1 or not nvm.pos2 or not nvm.num then
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
local param2 = (node.param2 + 2) % 4 local param2 = (node.param2 + 2) % 4
mem.pos1 = logic.dest_pos(pos, param2, {0}) nvm.pos1 = logic.dest_pos(pos, param2, {0})
mem.pos2 = logic.dest_pos(pos, param2, {0,0,0}) nvm.pos2 = logic.dest_pos(pos, param2, {0,0,0})
mem.num = #minetest.find_nodes_in_area(mem.pos1, mem.pos2, {"air"}) nvm.num = #minetest.find_nodes_in_area(nvm.pos1, nvm.pos2, {"air"})
return false return false
end end
local num = #minetest.find_nodes_in_area(mem.pos1, mem.pos2, {"air"}) local num = #minetest.find_nodes_in_area(nvm.pos1, nvm.pos2, {"air"})
if mem.num ~= num then if nvm.num ~= num then
if mem.mode == 1 and num < mem.num then if nvm.mode == 1 and num < nvm.num then
mem.num = num nvm.num = num
return true return true
elseif mem.mode == 2 and num > mem.num then elseif nvm.mode == 2 and num > nvm.num then
mem.num = num nvm.num = num
return true return true
elseif mem.mode == 3 then elseif nvm.mode == 3 then
mem.num = num nvm.num = num
return true return true
end end
mem.num = num nvm.num = num
end end
return false return false
end end
@ -83,16 +83,16 @@ local function on_receive_fields(pos, formname, fields, player)
return return
end end
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
local meta = M(pos) local meta = M(pos)
if fields.accept then if fields.accept then
mem.mode = DropdownValues[fields.mode] or 3 nvm.mode = DropdownValues[fields.mode] or 3
if techage.check_numbers(fields.numbers, player:get_player_name()) then if techage.check_numbers(fields.numbers, player:get_player_name()) then
meta:set_string("numbers", fields.numbers) meta:set_string("numbers", fields.numbers)
logic.infotext(M(pos), S("TA3 Node Detector")) logic.infotext(M(pos), S("TA3 Node Detector"))
end end
end end
meta:set_string("formspec", formspec(meta, mem)) meta:set_string("formspec", formspec(meta, nvm))
end end
local function node_timer(pos) local function node_timer(pos)
@ -115,11 +115,11 @@ minetest.register_node("techage:ta3_nodedetector_off", {
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local meta = M(pos) local meta = M(pos)
local mem = tubelib2.init_mem(pos) local nvm = techage.get_nvm(pos)
logic.after_place_node(pos, placer, "techage:ta3_repeater", S("TA3 Node Detector")) logic.after_place_node(pos, placer, "techage:ta3_repeater", S("TA3 Node Detector"))
logic.infotext(meta, S("TA3 Node Detector")) logic.infotext(meta, S("TA3 Node Detector"))
mem.mode = 3 -- default mode nvm.mode = 3 -- default mode
meta:set_string("formspec", formspec(meta, mem)) meta:set_string("formspec", formspec(meta, nvm))
minetest.get_node_timer(pos):start(CYCLE_TIME) minetest.get_node_timer(pos):start(CYCLE_TIME)
any_node_changed(pos) any_node_changed(pos)
end, end,
@ -130,13 +130,13 @@ minetest.register_node("techage:ta3_nodedetector_off", {
techage_set_numbers = function(pos, numbers, player_name) techage_set_numbers = function(pos, numbers, player_name)
local meta = M(pos) local meta = M(pos)
local res = logic.set_numbers(pos, numbers, player_name, S("TA3 Node Detector")) local res = logic.set_numbers(pos, numbers, player_name, S("TA3 Node Detector"))
meta:set_string("formspec", formspec(meta, tubelib2.get_mem(pos))) meta:set_string("formspec", formspec(meta, techage.get_nvm(pos)))
return res return res
end, end,
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos) techage.remove_node(pos)
tubelib2.del_mem(pos) techage.del_mem(pos)
end, end,
on_rotate = screwdriver.disallow, on_rotate = screwdriver.disallow,
@ -160,13 +160,13 @@ minetest.register_node("techage:ta3_nodedetector_on", {
techage_set_numbers = function(pos, numbers, player_name) techage_set_numbers = function(pos, numbers, player_name)
local meta = M(pos) local meta = M(pos)
local res = logic.set_numbers(pos, numbers, player_name, S("TA3 Node Detector")) local res = logic.set_numbers(pos, numbers, player_name, S("TA3 Node Detector"))
meta:set_string("formspec", formspec(meta, tubelib2.get_mem(pos))) meta:set_string("formspec", formspec(meta, techage.get_nvm(pos)))
return res return res
end, end,
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos) techage.remove_node(pos)
tubelib2.del_mem(pos) techage.del_mem(pos)
end, end,
on_rotate = screwdriver.disallow, on_rotate = screwdriver.disallow,

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2017-2019 Joachim Stolberg Copyright (C) 2017-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -32,24 +32,24 @@ local function switch_off(pos)
end end
local function scan_for_player(pos) local function scan_for_player(pos)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local names = meta:get_string("names") or "" local names = meta:get_string("names") or ""
for _, object in pairs(minetest.get_objects_inside_radius(pos, 4)) do for _, object in pairs(minetest.get_objects_inside_radius(pos, 4)) do
if object:is_player() then if object:is_player() then
if names == "" then if names == "" then
mem.player_name = object:get_player_name() nvm.player_name = object:get_player_name()
return true return true
end end
for _,name in ipairs(string.split(names, " ")) do for _,name in ipairs(string.split(names, " ")) do
if object:get_player_name() == name then if object:get_player_name() == name then
mem.player_name = name nvm.player_name = name
return true return true
end end
end end
end end
end end
mem.player_name = nil nvm.player_name = nil
return false return false
end end
@ -133,7 +133,7 @@ minetest.register_node("techage:ta3_playerdetector_off", {
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos) techage.remove_node(pos)
tubelib2.del_mem(pos) techage.del_mem(pos)
end, end,
paramtype2 = "facedir", paramtype2 = "facedir",
@ -168,7 +168,7 @@ minetest.register_node("techage:ta3_playerdetector_on", {
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos) techage.remove_node(pos)
tubelib2.del_mem(pos) techage.del_mem(pos)
end, end,
paramtype2 = "facedir", paramtype2 = "facedir",
@ -190,8 +190,8 @@ minetest.register_craft({
techage.register_node({"techage:ta3_playerdetector_off", "techage:ta3_playerdetector_on"}, { techage.register_node({"techage:ta3_playerdetector_off", "techage:ta3_playerdetector_on"}, {
on_recv_message = function(pos, topic, payload) on_recv_message = function(pos, topic, payload)
if topic == "name" then if topic == "name" then
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
return mem.player_name or "" return nvm.player_name or ""
else else
return "unsupported" return "unsupported"
end end

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2017-2019 Joachim Stolberg Copyright (C) 2017-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2017-2019 Joachim Stolberg Copyright (C) 2017-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -38,7 +38,7 @@ minetest.register_node("techage:ta3_repeater", {
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local meta = M(pos) local meta = M(pos)
local mem = tubelib2.init_mem(pos) local mem = techage.get_mem(pos)
logic.after_place_node(pos, placer, "techage:ta3_repeater", S("TA3 Repeater")) logic.after_place_node(pos, placer, "techage:ta3_repeater", S("TA3 Repeater"))
logic.infotext(meta, S("TA3 Repeater")) logic.infotext(meta, S("TA3 Repeater"))
meta:set_string("formspec", formspec(meta)) meta:set_string("formspec", formspec(meta))
@ -60,7 +60,7 @@ minetest.register_node("techage:ta3_repeater", {
end, end,
on_timer = function(pos,elapsed) on_timer = function(pos,elapsed)
local mem = tubelib2.get_mem(pos) local mem = techage.get_mem(pos)
mem.overload_cnt = 0 mem.overload_cnt = 0
return true return true
end, end,
@ -74,7 +74,7 @@ minetest.register_node("techage:ta3_repeater", {
after_dig_node = function(pos) after_dig_node = function(pos)
techage.remove_node(pos) techage.remove_node(pos)
tubelib2.del_mem(pos) techage.del_mem(pos)
end, end,
paramtype2 = "facedir", paramtype2 = "facedir",
@ -95,7 +95,7 @@ minetest.register_craft({
techage.register_node({"techage:ta3_repeater"}, { techage.register_node({"techage:ta3_repeater"}, {
on_recv_message = function(pos, src, topic, payload) on_recv_message = function(pos, src, topic, payload)
local mem = tubelib2.get_mem(pos) local mem = techage.get_mem(pos)
mem.overload_cnt = (mem.overload_cnt or 0) + 1 mem.overload_cnt = (mem.overload_cnt or 0) + 1
if mem.overload_cnt > OVER_LOAD_MAX then if mem.overload_cnt > OVER_LOAD_MAX then
logic.infotext(M(pos), S("TA3 Repeater"), "fault (overloaded)") logic.infotext(M(pos), S("TA3 Repeater"), "fault (overloaded)")

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2017-2019 Joachim Stolberg Copyright (C) 2017-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -66,13 +66,13 @@ local function formspec_help()
end end
local function stop_the_sequencer(pos) local function stop_the_sequencer(pos)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
local meta = M(pos) local meta = M(pos)
mem.running = false nvm.running = false
mem.endless = mem.endless or false nvm.endless = nvm.endless or false
mem.rules = mem.rules or new_rules() nvm.rules = nvm.rules or new_rules()
logic.infotext(meta, S("TA3 Sequencer"), "stopped") logic.infotext(meta, S("TA3 Sequencer"), "stopped")
meta:set_string("formspec", formspec(techage.STOPPED, mem.rules, mem.endless)) meta:set_string("formspec", formspec(techage.STOPPED, nvm.rules, nvm.endless))
minetest.get_node_timer(pos):stop() minetest.get_node_timer(pos):stop()
return false return false
end end
@ -98,20 +98,20 @@ local function restart_timer(pos, time)
end end
local function check_rules(pos, elapsed) local function check_rules(pos, elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
local own_num = M(pos):get_string("node_number") local own_num = M(pos):get_string("node_number")
mem.rules = mem.rules or new_rules() nvm.rules = nvm.rules or new_rules()
mem.running = mem.running or false nvm.running = nvm.running or false
mem.index = mem.index or 1 nvm.index = nvm.index or 1
mem.endless = mem.endless or false nvm.endless = nvm.endless or false
while true do -- process all rules as long as offs == 0 while true do -- process all rules as long as offs == 0
local rule = mem.rules[mem.index] local rule = nvm.rules[nvm.index]
local offs = tonumber(mem.rules[mem.index].offs or 1) local offs = tonumber(nvm.rules[nvm.index].offs or 1)
techage.send_multi(own_num, rule.num, tAction[rule.act]) techage.send_multi(own_num, rule.num, tAction[rule.act])
mem.index = get_next_slot(mem.index, mem.rules, mem.endless) nvm.index = get_next_slot(nvm.index, nvm.rules, nvm.endless)
if mem.index ~= nil and offs ~= nil and mem.running then if nvm.index ~= nil and offs ~= nil and nvm.running then
-- after the last rule a pause with 1 or more sec is required -- after the last rule a pause with 1 or more sec is required
if mem.index == 1 and offs < 1 then if nvm.index == 1 and offs < 1 then
offs = 1 offs = 1
end end
if offs > 0 then if offs > 0 then
@ -126,13 +126,13 @@ local function check_rules(pos, elapsed)
end end
local function start_the_sequencer(pos) local function start_the_sequencer(pos)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
local meta = M(pos) local meta = M(pos)
mem.running = true nvm.running = true
mem.endless = mem.endless or false nvm.endless = nvm.endless or false
mem.rules = mem.rules or new_rules() nvm.rules = nvm.rules or new_rules()
logic.infotext(meta, S("TA3 Sequencer"), "running") logic.infotext(meta, S("TA3 Sequencer"), "running")
meta:set_string("formspec", formspec(techage.RUNNING, mem.rules, mem.endless)) meta:set_string("formspec", formspec(techage.RUNNING, nvm.rules, nvm.endless))
minetest.get_node_timer(pos):start(0.1) minetest.get_node_timer(pos):start(0.1)
return false return false
end end
@ -143,10 +143,10 @@ local function on_receive_fields(pos, formname, fields, player)
end end
local meta = M(pos) local meta = M(pos)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.running = mem.running or false nvm.running = nvm.running or false
mem.endless = mem.endless or false nvm.endless = nvm.endless or false
mem.rules = mem.rules or new_rules() nvm.rules = nvm.rules or new_rules()
if fields.help ~= nil then if fields.help ~= nil then
meta:set_string("formspec", formspec_help()) meta:set_string("formspec", formspec_help())
@ -154,34 +154,34 @@ local function on_receive_fields(pos, formname, fields, player)
end end
if fields.endless ~= nil then if fields.endless ~= nil then
mem.endless = fields.endless == "true" nvm.endless = fields.endless == "true"
mem.index = 1 nvm.index = 1
end end
if fields.exit ~= nil then if fields.exit ~= nil then
if mem.running then if nvm.running then
meta:set_string("formspec", formspec(techage.RUNNING, mem.rules, mem.endless)) meta:set_string("formspec", formspec(techage.RUNNING, nvm.rules, nvm.endless))
else else
meta:set_string("formspec", formspec(techage.STOPPED, mem.rules, mem.endless)) meta:set_string("formspec", formspec(techage.STOPPED, nvm.rules, nvm.endless))
end end
return return
end end
for idx = 1,NUM_SLOTS do for idx = 1,NUM_SLOTS do
if fields["offs"..idx] ~= nil then if fields["offs"..idx] ~= nil then
mem.rules[idx].offs = tonumber(fields["offs"..idx]) or "" nvm.rules[idx].offs = tonumber(fields["offs"..idx]) or ""
end end
if fields["num"..idx] ~= nil and if fields["num"..idx] ~= nil and
techage.check_numbers(fields["num"..idx], player:get_player_name()) then techage.check_numbers(fields["num"..idx], player:get_player_name()) then
mem.rules[idx].num = fields["num"..idx] nvm.rules[idx].num = fields["num"..idx]
end end
if fields["act"..idx] ~= nil then if fields["act"..idx] ~= nil then
mem.rules[idx].act = kvAction[fields["act"..idx]] nvm.rules[idx].act = kvAction[fields["act"..idx]]
end end
end end
if fields.button ~= nil then if fields.button ~= nil then
if mem.running then if nvm.running then
stop_the_sequencer(pos) stop_the_sequencer(pos)
else else
start_the_sequencer(pos) start_the_sequencer(pos)
@ -189,10 +189,10 @@ local function on_receive_fields(pos, formname, fields, player)
elseif fields.num1 ~= nil then -- any other change? elseif fields.num1 ~= nil then -- any other change?
stop_the_sequencer(pos) stop_the_sequencer(pos)
else else
if mem.running then if nvm.running then
meta:set_string("formspec", formspec(techage.RUNNING, mem.rules, mem.endless)) meta:set_string("formspec", formspec(techage.RUNNING, nvm.rules, nvm.endless))
else else
meta:set_string("formspec", formspec(techage.STOPPED, mem.rules, mem.endless)) meta:set_string("formspec", formspec(techage.STOPPED, nvm.rules, nvm.endless))
end end
end end
end end
@ -208,14 +208,14 @@ minetest.register_node("techage:ta3_sequencer", {
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local meta = M(pos) local meta = M(pos)
local mem = tubelib2.init_mem(pos) local nvm = techage.get_nvm(pos)
logic.after_place_node(pos, placer, "techage:ta3_sequencer", S("TA3 Sequencer")) logic.after_place_node(pos, placer, "techage:ta3_sequencer", S("TA3 Sequencer"))
logic.infotext(meta, S("TA3 Sequencer"), S("stopped")) logic.infotext(meta, S("TA3 Sequencer"), S("stopped"))
mem.rules = new_rules() nvm.rules = new_rules()
mem.index = 1 nvm.index = 1
mem.running = false nvm.running = false
mem.endless = false nvm.endless = false
meta:set_string("formspec", formspec(techage.STOPPED, mem.rules, mem.endless)) meta:set_string("formspec", formspec(techage.STOPPED, nvm.rules, nvm.endless))
end, end,
on_receive_fields = on_receive_fields, on_receive_fields = on_receive_fields,
@ -224,11 +224,11 @@ minetest.register_node("techage:ta3_sequencer", {
if minetest.is_protected(pos, puncher:get_player_name()) then if minetest.is_protected(pos, puncher:get_player_name()) then
return return
end end
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if not mem.running then if not nvm.running then
minetest.node_dig(pos, node, puncher, pointed_thing) minetest.node_dig(pos, node, puncher, pointed_thing)
techage.remove_node(pos) techage.remove_node(pos)
tubelib2.del_mem(pos) techage.del_mem(pos)
end end
end, end,
@ -256,15 +256,15 @@ techage.register_node({"techage:ta3_sequencer"}, {
start_the_sequencer(pos) start_the_sequencer(pos)
elseif topic == "off" then elseif topic == "off" then
-- do not stop immediately -- do not stop immediately
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.endless = false nvm.endless = false
else else
return "unsupported" return "unsupported"
end end
end, end,
on_node_load = function(pos) on_node_load = function(pos)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if mem.running then if nvm.running then
minetest.get_node_timer(pos):start(1) minetest.get_node_timer(pos):start(1)
end end
end, end,

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -55,7 +55,6 @@ minetest.register_node("techage:signal_lamp_off", {
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos) techage.remove_node(pos)
tubelib2.del_mem(pos)
if COLORED then if COLORED then
unifieddyes.after_dig_node(pos, oldnode, oldmetadata, digger) unifieddyes.after_dig_node(pos, oldnode, oldmetadata, digger)
end end
@ -99,7 +98,6 @@ minetest.register_node("techage:signal_lamp_on", {
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos) techage.remove_node(pos)
tubelib2.del_mem(pos)
if COLORED then if COLORED then
unifieddyes.after_dig_node(pos, oldnode, oldmetadata, digger) unifieddyes.after_dig_node(pos, oldnode, oldmetadata, digger)
end end

View File

@ -3,7 +3,7 @@
Terminal Terminal
======== ========
Copyright (C) 2018-2019 Joachim Stolberg Copyright (C) 2018-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -167,7 +167,7 @@ local function command(pos, command, player)
"B", -- outdir "B", -- outdir
cmnd, -- topic cmnd, -- topic
payload, -- payload payload, -- payload
techage.BiogasPipe, -- network techage.LiquidPipe, -- network
nil) -- valid nodes nil) -- valid nodes
output(pos, dump(resp)) output(pos, dump(resp))
return return
@ -228,7 +228,6 @@ local function register_terminal(num, tiles, node_box, selection_box)
after_dig_node = function(pos) after_dig_node = function(pos)
techage.remove_node(pos) techage.remove_node(pos)
tubelib2.del_mem(pos)
end, end,
paramtype = "light", paramtype = "light",

View File

@ -79,8 +79,8 @@ end
local function check_rules(pos,elapsed) local function check_rules(pos,elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.done = mem.done or {false,false,false,false,false,false} nvm.done = nvm.done or {false,false,false,false,false,false}
local hour = math.floor(minetest.get_timeofday() * 24) local hour = math.floor(minetest.get_timeofday() * 24)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local events = deserialize(meta, "events") local events = deserialize(meta, "events")
@ -94,19 +94,19 @@ local function check_rules(pos,elapsed)
if act ~= "" and numbers[idx] ~= "" then if act ~= "" and numbers[idx] ~= "" then
local hr = (events[idx] - 1) * 2 local hr = (events[idx] - 1) * 2
if ((hour - hr) % 24) <= 4 then -- last 4 hours? if ((hour - hr) % 24) <= 4 then -- last 4 hours?
if mem.done[idx] == false then -- not already executed? if nvm.done[idx] == false then -- not already executed?
techage.send_multi(number, numbers[idx], act) techage.send_multi(number, numbers[idx], act)
mem.done[idx] = true nvm.done[idx] = true
end end
else else
mem.done[idx] = false nvm.done[idx] = false
end end
end end
end end
-- prepare for the next day -- prepare for the next day
if hour == 23 then if hour == 23 then
mem.done = {false,false,false,false,false,false} nvm.done = {false,false,false,false,false,false}
end end
return true return true
end end
@ -125,13 +125,13 @@ minetest.register_node("techage:ta3_timer", {
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local meta = M(pos) local meta = M(pos)
local mem = tubelib2.init_mem(pos) local nvm = techage.get_nvm(pos)
logic.after_place_node(pos, placer, "techage:ta3_timer", S("TA3 Timer")) logic.after_place_node(pos, placer, "techage:ta3_timer", S("TA3 Timer"))
logic.infotext(meta, S("TA3 Timer")) logic.infotext(meta, S("TA3 Timer"))
local events = {1,1,1,1,1,1} local events = {1,1,1,1,1,1}
local numbers = {"0000","","","","",""} local numbers = {"0000","","","","",""}
local actions = {"","","","","",""} local actions = {"","","","","",""}
mem.done = {false,false,false,false,false,false} nvm.done = {false,false,false,false,false,false}
meta:set_string("events", minetest.serialize(events)) meta:set_string("events", minetest.serialize(events))
meta:set_string("numbers", minetest.serialize(numbers)) meta:set_string("numbers", minetest.serialize(numbers))
meta:set_string("actions", minetest.serialize(actions)) meta:set_string("actions", minetest.serialize(actions))
@ -169,15 +169,15 @@ minetest.register_node("techage:ta3_timer", {
end end
meta:set_string("actions", minetest.serialize(actions)) meta:set_string("actions", minetest.serialize(actions))
meta:set_string("formspec", formspec(events, numbers, actions)) meta:set_string("formspec", formspec(events, numbers, actions))
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.done = {false,false,false,false,false,false} nvm.done = {false,false,false,false,false,false}
end, end,
on_timer = check_rules, on_timer = check_rules,
after_dig_node = function(pos) after_dig_node = function(pos)
techage.remove_node(pos) techage.remove_node(pos)
tubelib2.del_mem(pos) techage.del_mem(pos)
end, end,
paramtype = "light", paramtype = "light",
@ -202,8 +202,8 @@ techage.register_node({"techage:ta3_timer"}, {
on_node_load = function(pos) on_node_load = function(pos)
minetest.get_node_timer(pos):start(CYCLE_TIME) minetest.get_node_timer(pos):start(CYCLE_TIME)
-- check rules for just loaded areas -- check rules for just loaded areas
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.done = {false,false,false,false,false,false} nvm.done = {false,false,false,false,false,false}
check_rules(pos,0) check_rules(pos,0)
end, end,
}) })

View File

@ -85,7 +85,7 @@ minetest.register_node("techage:ta3_distiller_base", {
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
networks = { networks = {
pipe = { pipe2 = {
sides = {B=1}, -- Pipe connection sides sides = {B=1}, -- Pipe connection sides
ntype = "pump", ntype = "pump",
}, },
@ -124,7 +124,7 @@ minetest.register_node("techage:ta3_distiller1", {
sounds = default.node_sound_metal_defaults(), sounds = default.node_sound_metal_defaults(),
networks = { networks = {
pipe = { pipe2 = {
sides = {F=1}, -- Pipe connection sides sides = {F=1}, -- Pipe connection sides
ntype = "tank", ntype = "tank",
}, },
@ -187,7 +187,7 @@ minetest.register_node("techage:ta3_distiller3", {
sounds = default.node_sound_metal_defaults(), sounds = default.node_sound_metal_defaults(),
networks = { networks = {
pipe = { pipe2 = {
sides = {B=1}, -- Pipe connection sides sides = {B=1}, -- Pipe connection sides
ntype = "pump", ntype = "pump",
}, },
@ -225,7 +225,7 @@ minetest.register_node("techage:ta3_distiller4", {
sounds = default.node_sound_metal_defaults(), sounds = default.node_sound_metal_defaults(),
networks = { networks = {
pipe = { pipe2 = {
sides = {U=1}, -- Pipe connection sides sides = {U=1}, -- Pipe connection sides
ntype = "pump", ntype = "pump",
}, },

View File

@ -31,9 +31,9 @@ local formspec0 = "size[5,4]"..
"button_exit[1,3.2;3,1;build;"..S("Build derrick").."]" "button_exit[1,3.2;3,1;build;"..S("Build derrick").."]"
local function play_sound(pos) local function play_sound(pos)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if mem.techage_state == techage.RUNNING then if nvm.techage_state == techage.RUNNING then
mem.handle = minetest.sound_play("techage_oildrill", { nvm.handle = minetest.sound_play("techage_oildrill", {
pos = pos, pos = pos,
gain = 1, gain = 1,
max_hear_distance = 15}) max_hear_distance = 15})
@ -42,19 +42,19 @@ local function play_sound(pos)
end end
local function stop_sound(pos) local function stop_sound(pos)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if mem.handle then if nvm.handle then
minetest.sound_stop(mem.handle) minetest.sound_stop(nvm.handle)
mem.handle = nil nvm.handle = nil
end end
end end
local function formspec(self, pos, mem) local function formspec(self, pos, nvm)
if not mem.assemble_build then if not nvm.assemble_build then
return formspec0 return formspec0
end end
local depth = M(pos):get_int("depth") local depth = M(pos):get_int("depth")
local curr_depth = pos.y - (mem.drill_pos or pos).y local curr_depth = pos.y - (nvm.drill_pos or pos).y
return "size[8,8]".. return "size[8,8]"..
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
@ -64,9 +64,9 @@ local function formspec(self, pos, mem)
"item_image[1,1;1,1;techage:oil_drillbit]".. "item_image[1,1;1,1;techage:oil_drillbit]"..
"label[1,2;"..S("Drill Bit").."]".. "label[1,2;"..S("Drill Bit").."]"..
"label[0.5,3;"..S("Depth")..": "..curr_depth.."/"..depth.."]".. "label[0.5,3;"..S("Depth")..": "..curr_depth.."/"..depth.."]"..
"image[3.5,0;1,1;"..techage.get_power_image(pos, mem).."]".. "image[3.5,0;1,1;"..techage.get_power_image(pos, nvm).."]"..
"image[3.5,1;1,1;techage_form_arrow.png]".. "image[3.5,1;1,1;techage_form_arrow.png]"..
"image_button[3.5,2;1,1;".. self:get_state_button_image(mem) ..";state_button;]".. "image_button[3.5,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"label[6.2,0.5;OUT]".. "label[6.2,0.5;OUT]"..
"list[context;dst;6,1;1,1;]".. "list[context;dst;6,1;1,1;]"..
"button_exit[5,3;3,1;remove;"..S("Remove derrick").."]".. "button_exit[5,3;3,1;remove;"..S("Remove derrick").."]"..
@ -105,8 +105,8 @@ local function allow_metadata_inventory_take(pos, listname, index, stack, player
end end
local function on_rightclick(pos) local function on_rightclick(pos)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, mem)) M(pos):set_string("formspec", formspec(CRD(pos).State, pos, nvm))
end end
local function on_node_state_change(pos, old_state, new_state) local function on_node_state_change(pos, old_state, new_state)
@ -117,65 +117,65 @@ local function on_node_state_change(pos, old_state, new_state)
end end
end end
local function drilling(pos, crd, mem, inv) local function drilling(pos, crd, nvm, inv)
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, mem)) M(pos):set_string("formspec", formspec(CRD(pos).State, pos, nvm))
mem.drill_pos = mem.drill_pos or {x=pos.x, y=pos.y-1, z=pos.z} nvm.drill_pos = nvm.drill_pos or {x=pos.x, y=pos.y-1, z=pos.z}
local owner = M(pos):get_string("owner") local owner = M(pos):get_string("owner")
local depth = M(pos):get_int("depth") local depth = M(pos):get_int("depth")
local curr_depth = pos.y - (mem.drill_pos or pos).y local curr_depth = pos.y - (nvm.drill_pos or pos).y
local node = techage.get_node_lvm(mem.drill_pos) local node = techage.get_node_lvm(nvm.drill_pos)
local ndef = minetest.registered_nodes[node.name] local ndef = minetest.registered_nodes[node.name]
if not inv:contains_item("src", ItemStack("techage:oil_drillbit")) then if not inv:contains_item("src", ItemStack("techage:oil_drillbit")) then
crd.State:idle(pos, mem) crd.State:idle(pos, nvm)
elseif curr_depth >= depth then elseif curr_depth >= depth then
M(pos):set_string("oil_found", "true") M(pos):set_string("oil_found", "true")
crd.State:stop(pos, mem) crd.State:stop(pos, nvm)
elseif minetest.is_protected(mem.drill_pos, owner) then elseif minetest.is_protected(nvm.drill_pos, owner) then
crd.State:fault(pos, mem) crd.State:fault(pos, nvm)
elseif node.name == "techage:oil_drillbit2" then elseif node.name == "techage:oil_drillbit2" then
mem.drill_pos.y = mem.drill_pos.y-1 nvm.drill_pos.y = nvm.drill_pos.y-1
crd.State:keep_running(pos, mem, COUNTDOWN_TICKS) crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
elseif minetest.get_item_group(node.name, "lava") >= 1 then elseif minetest.get_item_group(node.name, "lava") >= 1 then
minetest.swap_node(mem.drill_pos, {name = "techage:oil_drillbit2"}) minetest.swap_node(nvm.drill_pos, {name = "techage:oil_drillbit2"})
inv:remove_item("src", ItemStack("techage:oil_drillbit")) inv:remove_item("src", ItemStack("techage:oil_drillbit"))
mem.drill_pos.y = mem.drill_pos.y-1 nvm.drill_pos.y = nvm.drill_pos.y-1
crd.State:keep_running(pos, mem, COUNTDOWN_TICKS) crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
elseif techage.can_node_dig(node, ndef) then elseif techage.can_node_dig(node, ndef) then
local drop_name = techage.dropped_node(node, ndef) local drop_name = techage.dropped_node(node, ndef)
if drop_name then if drop_name then
local item = ItemStack(drop_name) local item = ItemStack(drop_name)
if not inv:room_for_item("dst", item) then if not inv:room_for_item("dst", item) then
crd.State:blocked(pos, mem) crd.State:blocked(pos, nvm)
return return
end end
inv:add_item("dst", item) inv:add_item("dst", item)
end end
minetest.swap_node(mem.drill_pos, {name = "techage:oil_drillbit2"}) minetest.swap_node(nvm.drill_pos, {name = "techage:oil_drillbit2"})
inv:remove_item("src", ItemStack("techage:oil_drillbit")) inv:remove_item("src", ItemStack("techage:oil_drillbit"))
mem.drill_pos.y = mem.drill_pos.y-1 nvm.drill_pos.y = nvm.drill_pos.y-1
crd.State:keep_running(pos, mem, COUNTDOWN_TICKS) crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
else else
crd.State:fault(pos, mem) crd.State:fault(pos, nvm)
end end
end end
local function keep_running(pos, elapsed) local function keep_running(pos, elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
local crd = CRD(pos) local crd = CRD(pos)
local inv = M(pos):get_inventory() local inv = M(pos):get_inventory()
if inv then if inv then
drilling(pos, crd, mem, inv) drilling(pos, crd, nvm, inv)
end end
return crd.State:is_active(mem) return crd.State:is_active(nvm)
end end
local function can_dig(pos, player) local function can_dig(pos, player)
if minetest.is_protected(pos, player:get_player_name()) then if minetest.is_protected(pos, player:get_player_name()) then
return false return false
end end
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if mem.assemble_locked or mem.assemble_build then if nvm.assemble_locked or nvm.assemble_build then
return false return false
end end
local inv = M(pos):get_inventory() local inv = M(pos):get_inventory()
@ -194,9 +194,9 @@ local function on_receive_fields(pos, formname, fields, player)
techage.oiltower.remove(pos, player:get_player_name()) techage.oiltower.remove(pos, player:get_player_name())
end end
else else
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if not mem.assemble_locked and M(pos):get_string("oil_found") ~= "true" then if not nvm.assemble_locked and M(pos):get_string("oil_found") ~= "true" then
CRD(pos).State:state_button_event(pos, mem, fields) CRD(pos).State:state_button_event(pos, nvm, fields)
end end
end end
end end
@ -302,9 +302,9 @@ minetest.register_lbm({
nodenames = {"techage:ta3_drillbox_pas", "techage:ta3_drillbox_act"}, nodenames = {"techage:ta3_drillbox_pas", "techage:ta3_drillbox_act"},
run_at_every_load = true, run_at_every_load = true,
action = function(pos, node) action = function(pos, node)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.assemble_locked = false nvm.assemble_locked = false
if mem.techage_state == techage.RUNNING then if nvm.techage_state == techage.RUNNING then
play_sound(pos) play_sound(pos)
end end
end end

View File

@ -45,7 +45,7 @@ local function dec_oil_item(pos, meta)
end end
end end
local function formspec(self, pos, mem) local function formspec(self, pos, nvm)
local amount = 0 local amount = 0
local storage_pos = M(pos):get_string("storage_pos") local storage_pos = M(pos):get_string("storage_pos")
if storage_pos ~= "" then if storage_pos ~= "" then
@ -56,36 +56,36 @@ local function formspec(self, pos, mem)
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
"image[0.5,0;1,1;techage_liquid2_inv.png^[colorize:#000000^techage_liquid1_inv.png]".. "image[0.5,0;1,1;techage_liquid2_inv.png^[colorize:#000000^techage_liquid1_inv.png]"..
"image[2,0;1,1;"..techage.get_power_image(pos, mem).."]".. "image[2,0;1,1;"..techage.get_power_image(pos, nvm).."]"..
"label[0,1.3;"..S("Oil amount:")..": "..amount.."]".. "label[0,1.3;"..S("Oil amount:")..": "..amount.."]"..
"button[3,1.1;2,1;update;"..S("Update").."]".. "button[3,1.1;2,1;update;"..S("Update").."]"..
"image_button[2,2.2;1,1;".. self:get_state_button_image(mem) ..";state_button;]" "image_button[2,2.2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"
end end
local function on_rightclick(pos, node, clicker) local function on_rightclick(pos, node, clicker)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, mem)) M(pos):set_string("formspec", formspec(CRD(pos).State, pos, nvm))
end end
local function pumping(pos, crd, meta, mem) local function pumping(pos, crd, meta, nvm)
if has_oil(pos, meta) then if has_oil(pos, meta) then
local leftover = liquid.put(pos, 6, "techage:oil_source", 1) local leftover = liquid.put(pos, 6, "techage:oil_source", 1)
if leftover and leftover > 0 then if leftover and leftover > 0 then
crd.State:blocked(pos, mem) crd.State:blocked(pos, nvm)
return return
end end
dec_oil_item(pos, meta) dec_oil_item(pos, meta)
crd.State:keep_running(pos, mem, COUNTDOWN_TICKS) crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
return return
end end
crd.State:fault(pos, mem) crd.State:fault(pos, nvm)
end end
local function keep_running(pos, elapsed) local function keep_running(pos, elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
local crd = CRD(pos) local crd = CRD(pos)
pumping(pos, crd, M(pos), mem) pumping(pos, crd, M(pos), nvm)
return crd.State:is_active(mem) return crd.State:is_active(nvm)
end end
local function on_receive_fields(pos, formname, fields, player) local function on_receive_fields(pos, formname, fields, player)
@ -93,11 +93,11 @@ local function on_receive_fields(pos, formname, fields, player)
return return
end end
if fields.update then if fields.update then
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, mem)) M(pos):set_string("formspec", formspec(CRD(pos).State, pos, nvm))
else else
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
CRD(pos).State:state_button_event(pos, mem, fields) CRD(pos).State:state_button_event(pos, nvm, fields)
end end
end end
@ -171,7 +171,7 @@ local _, node_name_ta3, _ =
Pipe:after_place_node(pos) Pipe:after_place_node(pos)
end, end,
networks = { networks = {
pipe = { pipe2 = {
sides = {U = 1}, -- Pipe connection side sides = {U = 1}, -- Pipe connection side
ntype = "pump", ntype = "pump",
}, },

View File

@ -28,7 +28,7 @@ local CAPA = 12
local PWR_NEEDED = 14 local PWR_NEEDED = 14
local function swap_node(pos, on) local function swap_node(pos, on)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if on then if on then
local node = techage.get_node_lvm(pos) local node = techage.get_node_lvm(pos)
node.name = "techage:ta3_reboiler_on" node.name = "techage:ta3_reboiler_on"
@ -38,23 +38,23 @@ local function swap_node(pos, on)
pos = pos, pos = pos,
gain = 1, gain = 1,
max_hear_distance = 10}) max_hear_distance = 10})
elseif not on and mem.running then elseif not on and nvm.running then
local node = techage.get_node_lvm(pos) local node = techage.get_node_lvm(pos)
node.name = "techage:ta3_reboiler" node.name = "techage:ta3_reboiler"
minetest.swap_node(pos, node) minetest.swap_node(pos, node)
minetest.get_node_timer(pos):stop() minetest.get_node_timer(pos):stop()
mem.running = false nvm.running = false
power.consumer_stop(pos, mem) power.consumer_stop(pos, Cable)
end end
end end
local function on_power(pos, mem) local function on_power(pos, nvm)
if mem.running then if nvm.running then
swap_node(pos, true) swap_node(pos, true)
end end
end end
local function on_nopower(pos, mem) local function on_nopower(pos, nvm)
swap_node(pos, false) swap_node(pos, false)
end end
@ -69,32 +69,32 @@ local function pump_cmnd(pos, cmnd, payload)
end end
local function start_node(pos) local function start_node(pos)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if mem.running then return end if nvm.running then return end
mem.liquid = mem.liquid or {} nvm.liquid = nvm.liquid or {}
mem.liquid.amount = mem.liquid.amount or 0 nvm.liquid.amount = nvm.liquid.amount or 0
if mem.liquid.amount >= 5 and mem.liquid.name == "techage:oil_source" then if nvm.liquid.amount >= 5 and nvm.liquid.name == "techage:oil_source" then
if power.power_available(pos, mem, PWR_NEEDED) then if power.power_available(pos, Cable) then
mem.running = true nvm.running = true
power.consumer_start(pos, mem, CYCLE_TIME, PWR_NEEDED) power.consumer_start(pos, Cable, CYCLE_TIME)
end end
end end
end end
local function node_timer(pos, elapsed) local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.liquid = mem.liquid or {} nvm.liquid = nvm.liquid or {}
mem.liquid.amount = mem.liquid.amount or 0 nvm.liquid.amount = nvm.liquid.amount or 0
power.consumer_alive(pos, mem) power.consumer_alive(pos, nvm)
if mem.liquid.amount >= 5 and mem.liquid.name == "techage:oil_source" then if nvm.liquid.amount >= 5 and nvm.liquid.name == "techage:oil_source" then
mem.liquid.amount = mem.liquid.amount - 5 nvm.liquid.amount = nvm.liquid.amount - 5
local leftover = pump_cmnd(pos, "put") local leftover = pump_cmnd(pos, "put")
if (tonumber(leftover) or 1) > 0 then if (tonumber(leftover) or 1) > 0 then
mem.liquid.amount = mem.liquid.amount + 5 nvm.liquid.amount = nvm.liquid.amount + 5
mem.error = 25 -- = 5 pump cycles nvm.error = 25 -- = 5 pump cycles
M(pos):set_string("infotext", S("TA3 Oil Reboiler: blocked")) M(pos):set_string("infotext", S("TA3 Oil Reboiler: blocked"))
swap_node(pos, false) swap_node(pos, false)
return false return false
@ -123,17 +123,17 @@ end
local function after_dig_node(pos, oldnode, oldmetadata, digger) local function after_dig_node(pos, oldnode, oldmetadata, digger)
Pipe:after_dig_node(pos) Pipe:after_dig_node(pos)
power.after_dig_node(pos, oldnode) power.after_dig_node(pos, oldnode)
tubelib2.del_mem(pos) techage.del_mem(pos)
end end
local _liquid = { local _liquid = {
capa = CAPA, capa = CAPA,
peek = liquid.srv_peek, peek = liquid.srv_peek,
put = function(pos, indir, name, amount) put = function(pos, indir, name, amount)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if mem.error and mem.error > 0 then if nvm.error and nvm.error > 0 then
mem.error = mem.error - 1 nvm.error = nvm.error - 1
if mem.error <= 0 then if nvm.error <= 0 then
M(pos):set_string("infotext", S("TA3 Oil Reboiler")) M(pos):set_string("infotext", S("TA3 Oil Reboiler"))
start_node(pos) start_node(pos)
return liquid.srv_put(pos, indir, name, amount) return liquid.srv_put(pos, indir, name, amount)
@ -149,7 +149,7 @@ local _liquid = {
} }
local _networks = { local _networks = {
pipe = { pipe2 = {
sides = {L = true, R = true}, -- Pipe connection sides sides = {L = true, R = true}, -- Pipe connection sides
ntype = "tank", ntype = "tank",
}, },
@ -168,8 +168,8 @@ minetest.register_node("techage:ta3_reboiler", {
}, },
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local mem = tubelib2.init_mem(pos) local nvm = techage.get_nvm(pos)
mem.liquid = {} nvm.liquid = {}
local meta = M(pos) local meta = M(pos)
meta:set_string("infotext", S("TA3 Oil Reboiler")) meta:set_string("infotext", S("TA3 Oil Reboiler"))
meta:set_int("outdir", networks.side_to_outdir(pos, "R")) meta:set_int("outdir", networks.side_to_outdir(pos, "R"))

View File

@ -54,8 +54,6 @@ local Cable = tubelib2.Tube:new({
end, end,
}) })
techage.ElectricCable = Cable
-- Overridden method of tubelib2! -- Overridden method of tubelib2!
function Cable:get_primary_node_param2(pos, dir) function Cable:get_primary_node_param2(pos, dir)

246
power/powerswitch.lua Normal file
View File

@ -0,0 +1,246 @@
--[[
TechAge
=======
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
TA3 Power Switch (large and small)
]]--
-- for lazy programmers
local P = minetest.string_to_pos
local M = minetest.get_meta
local S = techage.S
local Cable = techage.ElectricCable
local Param2ToDir = {
[0] = 6,
[1] = 5,
[2] = 2,
[3] = 4,
[4] = 1,
[5] = 3,
}
local function switch_on(pos, node, clicker, name)
if clicker and minetest.is_protected(pos, clicker:get_player_name()) then
return
end
node.name = name
minetest.swap_node(pos, node)
minetest.sound_play("techage_button", {
pos = pos,
gain = 0.5,
max_hear_distance = 5,
})
local dir = Param2ToDir[node.param2]
local pos2 = tubelib2.get_pos(pos, dir)
M(pos2):set_int("tl2_param2", M(pos2):get_int("techage_hidden_param2"))
Cable:after_place_tube(pos2, clicker)
end
local function switch_off(pos, node, clicker, name)
if clicker and minetest.is_protected(pos, clicker:get_player_name()) then
return
end
node.name = name
minetest.swap_node(pos, node)
minetest.get_node_timer(pos):stop()
minetest.sound_play("techage_button", {
pos = pos,
gain = 0.5,
max_hear_distance = 5,
})
local dir = Param2ToDir[node.param2]
local pos2 = tubelib2.get_pos(pos, dir)
local node2 = techage.get_node_lvm(pos2)
node2.param2 = Cable:get_primary_node_param2(pos2)
M(pos2):set_int("tl2_param2", 0)
Cable:after_dig_tube(pos2, node2)
end
minetest.register_node("techage:powerswitch", {
description = S("TA Power Switch"),
inventory_image = "techage_appl_switch_inv.png",
tiles = {
'techage_appl_switch_off.png',
},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{ -1/4, -8/16, -1/4, 1/4, -7/16, 1/4},
{ -1/6, -12/16, -1/6, 1/6, -8/16, 1/6},
},
},
after_place_node = function(pos, placer)
local meta = M(pos)
local number = techage.add_node(pos, "techage:powerswitch")
meta:set_string("node_number", number)
meta:set_string("owner", placer:get_player_name())
meta:set_string("infotext", S("TA Power Switch").." "..number)
end,
on_rightclick = function(pos, node, clicker)
switch_on(pos, node, clicker, "techage:powerswitch_on")
end,
on_rotate = screwdriver.disallow,
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "wallmounted",
groups = {choppy=2, cracky=2, crumbly=2},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
minetest.register_node("techage:powerswitch_on", {
description = S("TA Power Switch"),
inventory_image = "techage_appl_switch_inv.png",
tiles = {
'techage_appl_switch_on.png',
},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{ -1/4, -8/16, -1/4, 1/4, -7/16, 1/4},
{ -1/6, -12/16, -1/6, 1/6, -8/16, 1/6},
},
},
on_rightclick = function(pos, node, clicker)
switch_off(pos, node, clicker, "techage:powerswitch")
end,
drop = "techage:powerswitch",
on_rotate = screwdriver.disallow,
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "wallmounted",
groups = {choppy=2, cracky=2, crumbly=2, not_in_creative_inventory = 1},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
minetest.register_node("techage:powerswitchsmall", {
description = S("TA Power Switch Small"),
inventory_image = "techage_smart_button_inventory.png",
tiles = {
'techage_smart_button_off.png',
},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{ -5/32, -16/32, -5/32, 5/32, -15/32, 5/32},
{ -2/16, -12/16, -2/16, 2/16, -8/16, 2/16},
},
},
after_place_node = function(pos, placer)
local meta = M(pos)
local number = techage.add_node(pos, "techage:powerswitchsmall")
meta:set_string("node_number", number)
meta:set_string("owner", placer:get_player_name())
meta:set_string("infotext", S("TA Power Switch Small").." "..number)
end,
on_rightclick = function(pos, node, clicker)
switch_on(pos, node, clicker, "techage:powerswitchsmall_on")
end,
on_rotate = screwdriver.disallow,
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "wallmounted",
groups = {choppy=2, cracky=2, crumbly=2},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
minetest.register_node("techage:powerswitchsmall_on", {
description = S("TA Power Switch Small"),
inventory_image = "techage_appl_switch_inv.png",
tiles = {
'techage_smart_button_on.png',
},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{ -5/32, -16/32, -5/32, 5/32, -15/32, 5/32},
{ -2/16, -12/16, -2/16, 2/16, -8/16, 2/16},
},
},
on_rightclick = function(pos, node, clicker)
switch_off(pos, node, clicker, "techage:powerswitchsmall")
end,
drop = "techage:powerswitchsmall",
on_rotate = screwdriver.disallow,
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "wallmounted",
groups = {choppy=2, cracky=2, crumbly=2, not_in_creative_inventory = 1},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
techage.register_node({"techage:powerswitch", "techage:powerswitch_on"}, {
on_recv_message = function(pos, src, topic, payload)
local node = techage.get_node_lvm(pos)
if topic == "on" and node.name == "techage:powerswitch" then
switch_on(pos, node, nil, "techage:powerswitch_on")
return true
elseif topic == "on" and node.name == "techage:powerswitchsmall" then
switch_on(pos, node, nil, "techage:powerswitchsmall_on")
return true
elseif topic == "off" and node.name == "techage:powerswitch_on" then
switch_off(pos, node, nil, "techage:powerswitch")
return true
elseif topic == "off" and node.name == "techage:powerswitchsmall_on" then
switch_off(pos, node, nil, "techage:powerswitchsmall")
return true
elseif topic == "state" then
if node.name == "techage:powerswitch_on" or
node.name == "techage:powerswitchsmall_on" then
return "on"
end
return "off"
else
return "unsupported"
end
end,
})
minetest.register_craft({
output = "techage:powerswitch 2",
recipe = {
{"", "", ""},
{"dye:yellow", "dye:red", "dye:yellow"},
{"basic_materials:plastic_sheet", "basic_materials:copper_wire", "basic_materials:plastic_sheet"},
},
})
minetest.register_craft({
type = "shapeless",
output = "techage:powerswitchsmall",
recipe = {"techage:powerswitch"},
})

189
power/ta4_cable.lua Normal file
View File

@ -0,0 +1,189 @@
--[[
TechAge
=======
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
TA4 Low Power Cable for solar plants
]]--
-- for lazy programmers
local S2P = minetest.string_to_pos
local P2S = minetest.pos_to_string
local M = minetest.get_meta
local S = techage.S
local power = techage.power
local ELE2_MAX_CABLE_LENGHT = 200
local Cable = tubelib2.Tube:new({
dirs_to_check = {1,2,3,4,5,6},
max_tube_length = ELE2_MAX_CABLE_LENGHT,
show_infotext = false,
tube_type = "ele2",
primary_node_names = {"techage:ta4_power_cableS", "techage:ta4_power_cableA"},
secondary_node_names = {},
after_place_tube = function(pos, param2, tube_type, num_tubes)
minetest.swap_node(pos, {name = "techage:ta4_power_cable"..tube_type, param2 = param2})
end,
})
--Cable:register_on_tube_update(function(node, pos, out_dir, peer_pos, peer_in_dir)
-- local ndef = minetest.registered_nodes[node.name]
-- if ndef and ndef.after_tube_update then
-- minetest.registered_nodes[node.name].after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir)
-- end
--end)
minetest.register_node("techage:ta4_power_cableS", {
description = S("TA4 Low Power Cable"),
tiles = {
-- up, down, right, left, back, front
"techage_ta4_cable.png",
"techage_ta4_cable.png",
"techage_ta4_cable.png",
"techage_ta4_cable.png",
"techage_ta4_cable_end.png",
"techage_ta4_cable_end.png",
},
after_place_node = function(pos, placer, itemstack, pointed_thing)
if not Cable:after_place_tube(pos, placer, pointed_thing) then
minetest.remove_node(pos)
return true
end
return false
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
Cable:after_dig_tube(pos, oldnode)
end,
paramtype2 = "facedir", -- important!
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-1/16, -1/16, -4/8, 1/16, 1/16, 4/8},
},
},
on_rotate = screwdriver.disallow, -- important!
paramtype = "light",
sunlight_propagates = true,
is_ground_content = false,
groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 3},
sounds = default.node_sound_defaults(),
})
minetest.register_node("techage:ta4_power_cableA", {
description = S("TA4 Low Power Cable"),
tiles = {
-- up, down, right, left, back, front
"techage_ta4_cable.png",
"techage_ta4_cable_end.png",
"techage_ta4_cable.png",
"techage_ta4_cable.png",
"techage_ta4_cable.png",
"techage_ta4_cable_end.png",
},
after_dig_node = function(pos, oldnode, oldmetadata, digger)
Cable:after_dig_tube(pos, oldnode)
end,
paramtype2 = "facedir", -- important!
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-1/16, -4/8, -1/16, 1/16, 1/16, 1/16},
{-1/16, -1/16, -4/8, 1/16, 1/16, -1/16},
},
},
on_rotate = screwdriver.disallow, -- important!
paramtype = "light",
sunlight_propagates = true,
is_ground_content = false,
groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 3, not_in_creative_inventory = 1},
sounds = default.node_sound_defaults(),
drop = "techage:ta4_power_cableS",
})
minetest.register_node("techage:ta4_power_box", {
description = S("TA4 Low Power Box"),
tiles = {
"techage_ta4_junctionbox_top.png",
"techage_ta4_junctionbox_top.png",
"techage_ta4_junctionbox_side.png^techage_appl_ta4_cable.png",
},
paramtype2 = "facedir", -- important!
drawtype = "nodebox",
node_box = {
type = "connected",
fixed = {
{ -3/16, -3/16, -3/16, 3/16, 3/16, 3/16}, -- box
{ -1/16, -7/16, -1/16, 1/16, -4/16, 1/16}, -- post
{ -3/16, -8/16, -3/16, 3/16, -7/16, 3/16}, -- base
},
connect_left = {{ -1/2, -1/16, -1/16, 0, 1/16, 1/16}},
connect_right = {{ 0, -1/16, -1/16, 1/2, 1/16, 1/16}},
connect_back = {{-1/16, -1/16, 0, 1/16, 1/16, 1/2}},
connect_front = {{-1/16, -1/16, -1/2, 1/16, 1/16, 0}},
},
connects_to = {"techage:ta4_power_cableA", "techage:ta4_power_cableS"},
after_place_node = function(pos, placer, itemstack, pointed_thing)
Cable:after_place_node(pos)
end,
tubelib2_on_update2 = function(pos, dir1, tlib2, node)
power.update_network(pos, nil, tlib2)
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
Cable:after_dig_node(pos)
end,
networks = {
ele2 = {
sides = {L=1, R=1, F=1, B=1},
ntype = "junc",
},
},
on_rotate = screwdriver.disallow, -- important!
paramtype = "light",
sunlight_propagates = true,
is_ground_content = false,
groups = {cracky=2, crumbly=2, choppy=2},
sounds = default.node_sound_defaults(),
})
Cable:add_secondary_node_names({"techage:ta4_power_box"})
minetest.register_craft({
output = "techage:ta4_power_cableS 8",
recipe = {
{"basic_materials:plastic_sheet", "dye:red", ""},
{"", "default:copper_ingot", ""},
{"", "dye:red", "basic_materials:plastic_sheet"},
},
})
minetest.register_craft({
output = "techage:ta4_power_box 2",
recipe = {
{"techage:ta4_power_cableS", "basic_materials:plastic_sheet", "techage:ta4_power_cableS"},
{"basic_materials:plastic_sheet", "default:copper_ingot", "basic_materials:plastic_sheet"},
{"techage:ta4_power_cableS", "basic_materials:plastic_sheet", "techage:ta4_power_cableS"},
},})
techage.TA4_Cable = Cable

View File

@ -25,41 +25,41 @@ local power = techage.power
local CYCLE_TIME = 2 local CYCLE_TIME = 2
local PWR_PERF = 100 local PWR_PERF = 100
local function determine_power(pos, mem) local function determine_power(pos, nvm)
-- determine DC node position -- determine DC node position
local dir = M(pos):get_int("left_dir") local dir = M(pos):get_int("left_dir")
local pos1 = tubelib2.get_pos(pos, dir) local pos1 = techage.get_pos(pos, dir)
local max_power, num_inverter = power.get_power(pos1, "techage:ta4_solar_inverterDC") local max_power, num_inverter = power.get_power(pos1, "techage:ta4_solar_inverterDC")
if num_inverter == 1 then if num_inverter == 1 then
mem.max_power = math.min(PWR_PERF, max_power) nvm.max_power = math.min(PWR_PERF, max_power)
else else
mem.max_power = 0 nvm.max_power = 0
end end
return max_power, num_inverter return max_power, num_inverter
end end
local function determine_power_from_time_to_time(pos, mem) local function determine_power_from_time_to_time(pos, nvm)
local time = minetest.get_timeofday() or 0 local time = minetest.get_timeofday() or 0
if time < 6.00/24.00 or time > 18.00/24.00 then if time < 6.00/24.00 or time > 18.00/24.00 then
mem.ticks = 0 nvm.ticks = 0
mem.max_power = 0 nvm.max_power = 0
power.generator_update(pos, mem, mem.max_power) power.generator_update(pos, nvm, nvm.max_power)
return return
end end
mem.ticks = mem.ticks or 0 nvm.ticks = nvm.ticks or 0
if (mem.ticks % 10) == 0 then -- calculate max_power not to often if (nvm.ticks % 10) == 0 then -- calculate max_power not to often
determine_power(pos, mem) determine_power(pos, nvm)
power.generator_update(pos, mem, mem.max_power) power.generator_update(pos, nvm, nvm.max_power)
else else
mem.max_power = mem.max_power or 0 nvm.max_power = nvm.max_power or 0
end end
mem.ticks = mem.ticks + 1 nvm.ticks = nvm.ticks + 1
end end
local function formspec(self, pos, mem) local function formspec(self, pos, nvm)
determine_power(pos, mem) determine_power(pos, nvm)
local max_power = mem.max_power or 0 local max_power = nvm.max_power or 0
local delivered = mem.delivered or 0 local delivered = nvm.delivered or 0
local bar_in = techage.power.formspec_power_bar(max_power, max_power) local bar_in = techage.power.formspec_power_bar(max_power, max_power)
local bar_out = techage.power.formspec_power_bar(max_power, delivered) local bar_out = techage.power.formspec_power_bar(max_power, delivered)
return "size[5,3]".. return "size[5,3]"..
@ -70,30 +70,30 @@ local function formspec(self, pos, mem)
"image[0,0.5;1,2;"..bar_in.."]".. "image[0,0.5;1,2;"..bar_in.."]"..
"label[0,2.5;"..max_power.." ku]".. "label[0,2.5;"..max_power.." ku]"..
"button[1.1,1;1.8,1;update;"..S("Update").."]".. "button[1.1,1;1.8,1;update;"..S("Update").."]"..
"image_button[3,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]".. "image_button[3,1;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"label[4.2,0;AC]".. "label[4.2,0;AC]"..
"image[4,0.5;1,2;"..bar_out.."]".. "image[4,0.5;1,2;"..bar_out.."]"..
"label[4,2.5;"..delivered.." ku]" "label[4,2.5;"..delivered.." ku]"
end end
local function can_start(pos, mem, state) local function can_start(pos, nvm, state)
local max_power, num_inverter = determine_power(pos, mem) local max_power, num_inverter = determine_power(pos, nvm)
if num_inverter > 1 then return "solar network error" end if num_inverter > 1 then return "solar network error" end
if max_power == 0 then return "no solar power" end if max_power == 0 then return "no solar power" end
return true return true
end end
local function start_node(pos, mem, state) local function start_node(pos, nvm, state)
mem.running = true nvm.running = true
mem.delivered = 0 nvm.delivered = 0
mem.ticks = 0 nvm.ticks = 0
power.generator_start(pos, mem, mem.max_power) power.generator_start(pos, nvm, nvm.max_power)
end end
local function stop_node(pos, mem, state) local function stop_node(pos, nvm, state)
mem.running = false nvm.running = false
mem.delivered = 0 nvm.delivered = 0
power.generator_stop(pos, mem) power.generator_stop(pos, nvm)
end end
local State = techage.NodeStates:new({ local State = techage.NodeStates:new({
@ -108,33 +108,33 @@ local State = techage.NodeStates:new({
}) })
local function node_timer(pos, elapsed) local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if mem.running then if nvm.running then
determine_power(pos, mem) determine_power(pos, nvm)
if mem.max_power > 0 then if nvm.max_power > 0 then
mem.delivered = power.generator_alive(pos, mem) nvm.delivered = power.generator_alive(pos, nvm)
else else
mem.delivered = 0 nvm.delivered = 0
end end
end end
return mem.running return nvm.running
end end
local function on_receive_fields(pos, formname, fields, player) local function on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then if minetest.is_protected(pos, player:get_player_name()) then
return return
end end
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
State:state_button_event(pos, mem, fields) State:state_button_event(pos, nvm, fields)
if fields.update then if fields.update then
M(pos):set_string("formspec", formspec(State, pos, mem)) M(pos):set_string("formspec", formspec(State, pos, nvm))
end end
end end
local function on_rightclick(pos) local function on_rightclick(pos)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(State, pos, mem)) M(pos):set_string("formspec", formspec(State, pos, nvm))
end end
minetest.register_node("techage:ta4_solar_inverter", { minetest.register_node("techage:ta4_solar_inverter", {
@ -182,9 +182,9 @@ techage.power.register_node({"techage:ta4_solar_inverter"}, {
-- DC block direction -- DC block direction
M(pos):set_int("left_dir", techage.power.side_to_outdir(pos, "L")) M(pos):set_int("left_dir", techage.power.side_to_outdir(pos, "L"))
local number = techage.add_node(pos, "techage:ta4_solar_inverter") local number = techage.add_node(pos, "techage:ta4_solar_inverter")
local mem = tubelib2.init_mem(pos) local nvm = techage.get_nvm(pos)
State:node_init(pos, mem, number) State:node_init(pos, nvm, number)
M(pos):set_string("formspec", formspec(State, pos, mem)) M(pos):set_string("formspec", formspec(State, pos, nvm))
end, end,
}) })

View File

@ -30,32 +30,32 @@ local Cable = techage.ElectricCable
local power = techage.power local power = techage.power
local function node_timer(pos, elapsed) local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.capa = mem.capa or 0 nvm.capa = nvm.capa or 0
pos.y = pos.y + 1 pos.y = pos.y + 1
local light = minetest.get_node_light(pos) or 0 local light = minetest.get_node_light(pos) or 0
pos.y = pos.y - 1 pos.y = pos.y - 1
if light >= (minetest.LIGHT_MAX - 1) then if light >= (minetest.LIGHT_MAX - 1) then
if mem.providing then if nvm.providing then
power.generator_stop(pos, mem) power.generator_stop(pos, nvm)
mem.providing = false nvm.providing = false
mem.provided = 0 nvm.provided = 0
end end
mem.capa = math.min(mem.capa + PWR_PERF * 1.2, PWR_CAPA) nvm.capa = math.min(nvm.capa + PWR_PERF * 1.2, PWR_CAPA)
else else
if mem.capa > 0 then if nvm.capa > 0 then
if not mem.providing then if not nvm.providing then
power.generator_start(pos, mem, PWR_PERF) power.generator_start(pos, nvm, PWR_PERF)
mem.providing = true nvm.providing = true
end end
mem.provided = power.generator_alive(pos, mem) nvm.provided = power.generator_alive(pos, nvm)
mem.capa = mem.capa - mem.provided nvm.capa = nvm.capa - nvm.provided
else else
power.generator_stop(pos, mem) power.generator_stop(pos, nvm)
mem.providing = false nvm.providing = false
mem.provided = 0 nvm.provided = 0
mem.capa = 0 nvm.capa = 0
end end
end end
return true return true
@ -91,25 +91,25 @@ techage.power.register_node({"techage:ta4_solar_minicell"}, {
local number = techage.add_node(pos, "techage:ta4_solar_minicell") local number = techage.add_node(pos, "techage:ta4_solar_minicell")
meta:set_string("node_number", number) meta:set_string("node_number", number)
meta:set_string("infotext", S("TA4 Streetlamp Solar Cell").." "..number) meta:set_string("infotext", S("TA4 Streetlamp Solar Cell").." "..number)
local mem = tubelib2.init_mem(pos) local nvm = techage.get_nvm(pos)
mem.capa = 0 nvm.capa = 0
mem.providing = false nvm.providing = false
minetest.get_node_timer(pos):start(CYCLE_TIME) minetest.get_node_timer(pos):start(CYCLE_TIME)
end, end,
after_dig_node = function(pos) after_dig_node = function(pos)
techage.remove_node(pos) techage.remove_node(pos)
tubelib2.del_mem(pos) techage.del_mem(pos)
end, end,
}) })
techage.register_node({"techage:ta4_solar_minicell"}, { techage.register_node({"techage:ta4_solar_minicell"}, {
on_recv_message = function(pos, src, topic, payload) on_recv_message = function(pos, src, topic, payload)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if topic == "state" then if topic == "state" then
if mem.providing then if nvm.providing then
return "discharging" return "discharging"
elseif (mem.capa or 0) > 0 then elseif (nvm.capa or 0) > 0 then
return "charging" return "charging"
else else
return "unused" return "unused"

View File

@ -49,7 +49,7 @@ local function start_node(pos, nvm, state)
nvm.needed = 0 nvm.needed = 0
local outdir = M(pos):get_int("outdir") local outdir = M(pos):get_int("outdir")
power.generator_start(pos, Cable, CYCLE_TIME, outdir) power.generator_start(pos, Cable, CYCLE_TIME, outdir)
power.consumer_start(pos, Cable, CYCLE_TIME, outdir) power.consumer_start(pos, Cable, CYCLE_TIME)
end end
local function stop_node(pos, nvm, state) local function stop_node(pos, nvm, state)
@ -57,7 +57,7 @@ local function stop_node(pos, nvm, state)
nvm.needed = 0 nvm.needed = 0
local outdir = M(pos):get_int("outdir") local outdir = M(pos):get_int("outdir")
power.generator_stop(pos, Cable, outdir) power.generator_stop(pos, Cable, outdir)
power.consumer_stop(pos, Cable, outdir) power.consumer_stop(pos, Cable)
end end
local State = techage.NodeStates:new({ local State = techage.NodeStates:new({

View File

@ -16,54 +16,58 @@
local M = minetest.get_meta local M = minetest.get_meta
local S = techage.S local S = techage.S
local Power = techage.ElectricCable local Cable = techage.ElectricCable
local firebox = techage.firebox local firebox = techage.firebox
local power = techage.power local power = techage.power
local fuel = techage.fuel local fuel = techage.fuel
local Pipe = techage.LiquidPipe local Pipe = techage.LiquidPipe
local liquid = techage.liquid local liquid = techage.liquid
local networks = techage.networks
local CYCLE_TIME = 2 local CYCLE_TIME = 2
local PWR_CAPA = 12 local PWR_CAPA = 12
local EFFICIENCY = 2.5 local EFFICIENCY = 2.5
local function formspec(self, pos, mem) local function formspec(self, pos, nvm)
local fuel_percent = 0 local fuel_percent = 0
if mem.running then if nvm.running then
fuel_percent = ((mem.burn_cycles or 1) * 100) / (mem.burn_cycles_total or 1) fuel_percent = ((nvm.burn_cycles or 1) * 100) / (nvm.burn_cycles_total or 1)
end end
return "size[8,6]".. return "size[8,6]"..
--"box[0,-0.1;3.8,0.5;#c6e8ff]"..
--"label[1,-0.1;"..minetest.colorize( "#000000", S("Tiny Generator")).."]"..
--power.formspec_label_bar(0, 0.8, S("power"), PWR_CAPA, nvm.provided)..
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
fuel.formspec_fuel(1, 0, mem).. fuel.formspec_fuel(1, 0, nvm)..
"button[1.6,1;1.8,1;update;"..S("Update").."]".. "button[1.6,1;1.8,1;update;"..S("Update").."]"..
"image_button[5.5,0.5;1,1;".. self:get_state_button_image(mem) ..";state_button;]".. "image_button[5.5,0.5;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"image[6.5,0;1,2;"..power.formspec_power_bar(PWR_CAPA, mem.provided).."]".. "image[6.5,0;1,2;"..power.formspec_power_bar(PWR_CAPA, nvm.provided).."]"..
"list[current_player;main;0,2.3;8,4;]".. "list[current_player;main;0,2.3;8,4;]"..
default.get_hotbar_bg(0, 3) default.get_hotbar_bg(0, 3)
end end
local function can_start(pos, mem, state) local function can_start(pos, nvm, state)
if mem.burn_cycles > 0 or (mem.liquid and mem.liquid.amount and mem.liquid.amount > 0) then if nvm.burn_cycles > 0 or (nvm.liquid and nvm.liquid.amount and nvm.liquid.amount > 0) then
return true return true
end end
return false return false
end end
local function start_node(pos, mem, state) local function start_node(pos, nvm, state)
mem.running = true nvm.running = true
power.generator_start(pos, mem, PWR_CAPA) power.generator_start(pos, nvm, PWR_CAPA)
minetest.sound_play("techage_generator", { minetest.sound_play("techage_generator", {
pos = pos, pos = pos,
gain = 1, gain = 1,
max_hear_distance = 10}) max_hear_distance = 10})
end end
local function stop_node(pos, mem, state) local function stop_node(pos, nvm, state)
mem.running = false nvm.running = false
mem.provided = 0 nvm.provided = 0
power.generator_stop(pos, mem) power.generator_stop(pos, nvm)
end end
local State = techage.NodeStates:new({ local State = techage.NodeStates:new({
@ -72,27 +76,27 @@ local State = techage.NodeStates:new({
cycle_time = CYCLE_TIME, cycle_time = CYCLE_TIME,
standby_ticks = 0, standby_ticks = 0,
formspec_func = formspec, formspec_func = formspec,
infotext_name = "TA3 Tiny Power Generator", infotext_name = S("TA3 Tiny Power Generator"),
can_start = can_start, can_start = can_start,
start_node = start_node, start_node = start_node,
stop_node = stop_node, stop_node = stop_node,
}) })
local function burning(pos, mem) local function burning(pos, nvm)
local ratio = math.max((mem.provided or PWR_CAPA) / PWR_CAPA, 0.02) local ratio = math.max((nvm.provided or PWR_CAPA) / PWR_CAPA, 0.02)
mem.liquid = mem.liquid or {} nvm.liquid = nvm.liquid or {}
mem.liquid.amount = mem.liquid.amount or 0 nvm.liquid.amount = nvm.liquid.amount or 0
mem.burn_cycles = (mem.burn_cycles or 0) - ratio nvm.burn_cycles = (nvm.burn_cycles or 0) - ratio
if mem.burn_cycles <= 0 then if nvm.burn_cycles <= 0 then
if mem.liquid.amount > 0 then if nvm.liquid.amount > 0 then
mem.liquid.amount = mem.liquid.amount - 1 nvm.liquid.amount = nvm.liquid.amount - 1
mem.burn_cycles = fuel.burntime(mem.liquid.name) * EFFICIENCY / CYCLE_TIME nvm.burn_cycles = fuel.burntime(nvm.liquid.name) * EFFICIENCY / CYCLE_TIME
mem.burn_cycles_total = mem.burn_cycles nvm.burn_cycles_total = nvm.burn_cycles
return true return true
else else
mem.liquid.name = nil nvm.liquid.name = nil
State:fault(pos, mem) State:fault(pos, nvm)
return false return false
end end
else else
@ -101,16 +105,16 @@ local function burning(pos, mem)
end end
local function node_timer(pos, elapsed) local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if mem.running and burning(pos, mem) then if nvm.running and burning(pos, nvm) then
mem.provided = power.generator_alive(pos, mem) nvm.provided = power.generator_alive(pos, nvm)
minetest.sound_play("techage_generator", { minetest.sound_play("techage_generator", {
pos = pos, pos = pos,
gain = 1, gain = 1,
max_hear_distance = 10}) max_hear_distance = 10})
return true return true
else else
mem.provided = 0 nvm.provided = 0
end end
return false return false
end end
@ -119,15 +123,15 @@ local function on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then if minetest.is_protected(pos, player:get_player_name()) then
return return
end end
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
State:state_button_event(pos, mem, fields) State:state_button_event(pos, nvm, fields)
M(pos):set_string("formspec", formspec(State, pos, mem)) M(pos):set_string("formspec", formspec(State, pos, nvm))
end end
local function formspec_clbk(pos, mem) local function formspec_clbk(pos, nvm)
return formspec(State, pos, mem) return formspec(State, pos, nvm)
end end
local function on_metadata_inventory_put(pos, listname, index, stack, player) local function on_metadata_inventory_put(pos, listname, index, stack, player)
@ -135,8 +139,8 @@ local function on_metadata_inventory_put(pos, listname, index, stack, player)
end end
local function on_rightclick(pos) local function on_rightclick(pos)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(State, pos, mem)) M(pos):set_string("formspec", formspec(State, pos, nvm))
end end
local _liquid = { local _liquid = {
@ -176,13 +180,13 @@ minetest.register_node("techage:tiny_generator", {
is_ground_content = false, is_ground_content = false,
on_construct = function(pos) on_construct = function(pos)
local mem = tubelib2.init_mem(pos) local nvm = techage.get_nvm(pos)
local number = techage.add_node(pos, "techage:tiny_generator") local number = techage.add_node(pos, "techage:tiny_generator")
mem.running = false nvm.running = false
mem.burn_cycles = 0 nvm.burn_cycles = 0
State:node_init(pos, mem, number) State:node_init(pos, nvm, number)
local meta = M(pos) local meta = M(pos)
meta:set_string("formspec", formspec(State, pos, mem)) meta:set_string("formspec", formspec(State, pos, nvm))
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size('fuel', 1) inv:set_size('fuel', 1)
end, end,
@ -257,9 +261,9 @@ techage.power.register_node({"techage:tiny_generator", "techage:tiny_generator_o
techage.register_node({"techage:tiny_generator", "techage:tiny_generator_on"}, { techage.register_node({"techage:tiny_generator", "techage:tiny_generator_on"}, {
on_recv_message = function(pos, src, topic, payload) on_recv_message = function(pos, src, topic, payload)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if topic == "load" then if topic == "load" then
return power.percent(PWR_CAPA, mem.provided) return power.percent(PWR_CAPA, nvm.provided)
else else
return State:on_receive_message(pos, topic, payload) return State:on_receive_message(pos, topic, payload)
end end

View File

@ -100,7 +100,6 @@ minetest.register_on_dignode(function(pos, oldnode, digger)
if other_hidden_nodes(pos, "techage_hidden_nodename") then if other_hidden_nodes(pos, "techage_hidden_nodename") then
-- test both hidden networks -- test both hidden networks
techage.ElectricCable:after_dig_node(pos, oldnode, digger) techage.ElectricCable:after_dig_node(pos, oldnode, digger)
--techage.BiogasPipe:after_dig_node(pos, oldnode, digger)
-- probably a hidden node with mem data -- probably a hidden node with mem data
techage.del_mem(pos) techage.del_mem(pos)
else else

View File

@ -48,8 +48,8 @@ local function pos_and_yaw(pos, param2)
return pos, {x=0, y=yaw, z=0} return pos, {x=0, y=yaw, z=0}
end end
local function add_rotor(pos, mem, player_name) local function add_rotor(pos, nvm, player_name)
mem.error = false nvm.error = false
-- Check for next wind turbine -- Check for next wind turbine
local pos1 = {x=pos.x-13, y=pos.y-9, z=pos.z-13} local pos1 = {x=pos.x-13, y=pos.y-9, z=pos.z-13}
@ -62,7 +62,7 @@ local function add_rotor(pos, mem, player_name)
" "..S("The wind turbines are too close together!")) " "..S("The wind turbines are too close together!"))
end end
M(pos):set_string("infotext", S("TA4 Wind Turbine").." "..S("Error")) M(pos):set_string("infotext", S("TA4 Wind Turbine").." "..S("Error"))
mem.error = true nvm.error = true
return return
end end
@ -77,7 +77,7 @@ local function add_rotor(pos, mem, player_name)
" "..S("More water expected (2 m deep)!")) " "..S("More water expected (2 m deep)!"))
end end
M(pos):set_string("infotext", S("TA4 Wind Turbine").." "..S("Error")) M(pos):set_string("infotext", S("TA4 Wind Turbine").." "..S("Error"))
mem.error = true nvm.error = true
return return
end end
@ -90,7 +90,7 @@ local function add_rotor(pos, mem, player_name)
" "..S("No wind at this altitude!")) " "..S("No wind at this altitude!"))
end end
M(pos):set_string("infotext", S("TA4 Wind Turbine").." "..S("Error")) M(pos):set_string("infotext", S("TA4 Wind Turbine").." "..S("Error"))
mem.error = true nvm.error = true
return return
end end
@ -108,28 +108,28 @@ local function add_rotor(pos, mem, player_name)
M(pos):set_string("infotext", S("TA4 Wind Turbine").." "..own_num) M(pos):set_string("infotext", S("TA4 Wind Turbine").." "..own_num)
end end
local function start_rotor(pos, mem) local function start_rotor(pos, nvm)
local npos = techage.get_pos(pos, "F") local npos = techage.get_pos(pos, "F")
local node = minetest.get_node(npos) local node = minetest.get_node(npos)
if node.name ~= "techage:ta4_wind_turbine_nacelle" then if node.name ~= "techage:ta4_wind_turbine_nacelle" then
M(pos):set_string("infotext", S("TA4 Wind Turbine").." "..S("Error")) M(pos):set_string("infotext", S("TA4 Wind Turbine").." "..S("Error"))
mem.error = true nvm.error = true
return return
end end
mem.providing = true nvm.providing = true
mem.delivered = 0 nvm.delivered = 0
power.generator_start(pos, mem, PWR_PERF) power.generator_start(pos, nvm, PWR_PERF)
local hash = minetest.hash_node_position(pos) local hash = minetest.hash_node_position(pos)
if Rotors[hash] then if Rotors[hash] then
Rotors[hash]:set_animation_frame_speed(50) Rotors[hash]:set_animation_frame_speed(50)
end end
end end
local function stop_rotor(pos, mem) local function stop_rotor(pos, nvm)
mem.providing = false nvm.providing = false
mem.delivered = 0 nvm.delivered = 0
power.generator_stop(pos, mem) power.generator_stop(pos, nvm)
local hash = minetest.hash_node_position(pos) local hash = minetest.hash_node_position(pos)
if Rotors[hash] then if Rotors[hash] then
Rotors[hash]:set_animation_frame_speed(0) Rotors[hash]:set_animation_frame_speed(0)
@ -137,24 +137,24 @@ local function stop_rotor(pos, mem)
end end
local function node_timer(pos, elapsed) local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if not mem.running then if not nvm.running then
return false return false
end end
local time = minetest.get_timeofday() or 0 local time = minetest.get_timeofday() or 0
if (time >= 5.00/24.00 and time <= 9.00/24.00) or (time >= 17.00/24.00 and time <= 21.00/24.00) then if (time >= 5.00/24.00 and time <= 9.00/24.00) or (time >= 17.00/24.00 and time <= 21.00/24.00) then
if not mem.providing then if not nvm.providing then
start_rotor(pos, mem) start_rotor(pos, nvm)
end end
else else
if mem.providing then if nvm.providing then
stop_rotor(pos, mem) stop_rotor(pos, nvm)
end end
end end
if mem.providing then if nvm.providing then
mem.delivered = power.generator_alive(pos, mem) nvm.delivered = power.generator_alive(pos, nvm)
end end
return true return true
end end
@ -212,14 +212,14 @@ techage.power.register_node({"techage:ta4_wind_turbine"}, {
conn_sides = {"D"}, conn_sides = {"D"},
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local meta = M(pos) local meta = M(pos)
local mem = tubelib2.init_mem(pos) local nvm = techage.get_nvm(pos)
local own_num = techage.add_node(pos, "techage:ta4_wind_turbine") local own_num = techage.add_node(pos, "techage:ta4_wind_turbine")
meta:set_string("node_number", own_num) meta:set_string("node_number", own_num)
meta:set_string("owner", placer:get_player_name()) meta:set_string("owner", placer:get_player_name())
meta:set_string("infotext", S("TA4 Wind Turbine").." "..own_num) meta:set_string("infotext", S("TA4 Wind Turbine").." "..own_num)
mem.providing = false nvm.providing = false
mem.running = true nvm.running = true
add_rotor(pos, mem, placer:get_player_name()) add_rotor(pos, nvm, placer:get_player_name())
minetest.get_node_timer(pos):start(CYCLE_TIME) minetest.get_node_timer(pos):start(CYCLE_TIME)
end, end,
@ -230,37 +230,37 @@ techage.power.register_node({"techage:ta4_wind_turbine"}, {
end end
Rotors[hash] = nil Rotors[hash] = nil
techage.remove_node(pos) techage.remove_node(pos)
tubelib2.del_mem(pos) techage.del_mem(pos)
end, end,
}) })
techage.register_node({"techage:ta4_wind_turbine"}, { techage.register_node({"techage:ta4_wind_turbine"}, {
on_recv_message = function(pos, src, topic, payload) on_recv_message = function(pos, src, topic, payload)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if topic == "state" then if topic == "state" then
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
if node.name == "ignore" then -- unloaded node? if node.name == "ignore" then -- unloaded node?
return "unloaded" return "unloaded"
end end
if mem.error then if nvm.error then
return "error" return "error"
elseif mem.running and mem.providing then elseif nvm.running and nvm.providing then
return "running" return "running"
else else
return "stopped" return "stopped"
end end
elseif topic == "on" then elseif topic == "on" then
mem.running = true nvm.running = true
elseif topic == "off" then elseif topic == "off" then
mem.running = false nvm.running = false
else else
return "unsupported" return "unsupported"
end end
end, end,
on_node_load = function(pos) on_node_load = function(pos)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
add_rotor(pos, mem) add_rotor(pos, nvm)
mem.providing = false -- to force the rotor start nvm.providing = false -- to force the rotor start
minetest.get_node_timer(pos):start(CYCLE_TIME) minetest.get_node_timer(pos):start(CYCLE_TIME)
end, end,
}) })