Prepare for lib 'networks'
This commit is contained in:
parent
d80304b449
commit
ef9d904917
@ -3,7 +3,7 @@
|
|||||||
TechAge
|
TechAge
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Copyright (C) 2019-2020 Joachim Stolberg
|
Copyright (C) 2019-2021 Joachim Stolberg
|
||||||
|
|
||||||
GPL v3
|
GPL v3
|
||||||
See LICENSE.txt for more information
|
See LICENSE.txt for more information
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
local M = minetest.get_meta
|
local M = minetest.get_meta
|
||||||
local S = techage.S
|
local S = techage.S
|
||||||
|
|
||||||
local networks = techage.networks
|
|
||||||
local Tube = techage.Tube
|
local Tube = techage.Tube
|
||||||
|
|
||||||
local size = 2/8
|
local size = 2/8
|
||||||
@ -29,7 +28,7 @@ local Boxes = {
|
|||||||
{{-size, -size, -size, size, 0.5, size}}, -- y+
|
{{-size, -size, -size, size, 0.5, size}}, -- y+
|
||||||
}
|
}
|
||||||
|
|
||||||
local names = techage.register_junction("techage:concentrator", 2/8, Boxes, Tube, {
|
local names = networks.register_junction("techage:concentrator", 2/8, Boxes, Tube, {
|
||||||
description = S("Tube Concentrator"),
|
description = S("Tube Concentrator"),
|
||||||
tiles = {
|
tiles = {
|
||||||
"techage_tube_junction.png^techage_appl_arrow2.png^[transformR270",
|
"techage_tube_junction.png^techage_appl_arrow2.png^[transformR270",
|
||||||
@ -45,13 +44,13 @@ local names = techage.register_junction("techage:concentrator", 2/8, Boxes, Tube
|
|||||||
|
|
||||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
local name = "techage:concentrator"..techage.junction_type(pos, Tube, "R", node.param2)
|
local name = "techage:concentrator"..networks.junction_type(pos, Tube, "R", node.param2)
|
||||||
minetest.swap_node(pos, {name = name, param2 = node.param2})
|
minetest.swap_node(pos, {name = name, param2 = node.param2})
|
||||||
M(pos):set_int("push_dir", techage.side_to_outdir("R", node.param2))
|
M(pos):set_int("push_dir", techage.side_to_outdir("R", node.param2))
|
||||||
Tube:after_place_node(pos)
|
Tube:after_place_node(pos)
|
||||||
end,
|
end,
|
||||||
tubelib2_on_update2 = function(pos, dir1, tlib2, node)
|
tubelib2_on_update2 = function(pos, dir1, tlib2, node)
|
||||||
local name = "techage:concentrator"..techage.junction_type(pos, Tube, "R", node.param2)
|
local name = "techage:concentrator"..networks.junction_type(pos, Tube, "R", node.param2)
|
||||||
minetest.swap_node(pos, {name = name, param2 = node.param2})
|
minetest.swap_node(pos, {name = name, param2 = node.param2})
|
||||||
end,
|
end,
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
@ -67,7 +66,7 @@ techage.register_node(names, {
|
|||||||
is_pusher = true, -- is a pulling/pushing node
|
is_pusher = true, -- is a pulling/pushing node
|
||||||
})
|
})
|
||||||
|
|
||||||
names = techage.register_junction("techage:ta4_concentrator", 2/8, Boxes, Tube, {
|
names = networks.register_junction("techage:ta4_concentrator", 2/8, Boxes, Tube, {
|
||||||
description = S("TA4 Tube Concentrator"),
|
description = S("TA4 Tube Concentrator"),
|
||||||
tiles = {
|
tiles = {
|
||||||
"techage_tubeta4_junction.png^techage_appl_arrow2.png^[transformR270",
|
"techage_tubeta4_junction.png^techage_appl_arrow2.png^[transformR270",
|
||||||
@ -83,13 +82,13 @@ names = techage.register_junction("techage:ta4_concentrator", 2/8, Boxes, Tube,
|
|||||||
|
|
||||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
local name = "techage:ta4_concentrator"..techage.junction_type(pos, Tube, "R", node.param2)
|
local name = "techage:ta4_concentrator"..networks.junction_type(pos, Tube, "R", node.param2)
|
||||||
minetest.swap_node(pos, {name = name, param2 = node.param2})
|
minetest.swap_node(pos, {name = name, param2 = node.param2})
|
||||||
M(pos):set_int("push_dir", techage.side_to_outdir("R", node.param2))
|
M(pos):set_int("push_dir", techage.side_to_outdir("R", node.param2))
|
||||||
Tube:after_place_node(pos)
|
Tube:after_place_node(pos)
|
||||||
end,
|
end,
|
||||||
tubelib2_on_update2 = function(pos, dir1, tlib2, node)
|
tubelib2_on_update2 = function(pos, dir1, tlib2, node)
|
||||||
local name = "techage:ta4_concentrator"..techage.junction_type(pos, Tube, "R", node.param2)
|
local name = "techage:ta4_concentrator"..networks.junction_type(pos, Tube, "R", node.param2)
|
||||||
minetest.swap_node(pos, {name = name, param2 = node.param2})
|
minetest.swap_node(pos, {name = name, param2 = node.param2})
|
||||||
end,
|
end,
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
|
@ -28,8 +28,7 @@ local CYCLE_TIME = 2
|
|||||||
local PWR_PERF = 100
|
local PWR_PERF = 100
|
||||||
|
|
||||||
local function formspec(self, pos, nvm)
|
local function formspec(self, pos, nvm)
|
||||||
return techage.generator_formspec(self, pos, nvm, S("Power Source"),
|
return techage.generator_formspec(self, pos, nvm, S("Power Source"), nvm.provided, PWR_PERF)
|
||||||
nvm.provided, PWR_PERF, nvm.generating)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Axles texture animation
|
-- Axles texture animation
|
||||||
@ -39,7 +38,7 @@ local function switch_axles(pos, on)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function start_node2(pos, nvm, state)
|
local function start_node2(pos, nvm, state)
|
||||||
nvm.generating = true
|
nvm.running = true
|
||||||
nvm.provided = 0
|
nvm.provided = 0
|
||||||
local outdir = M(pos):get_int("outdir")
|
local outdir = M(pos):get_int("outdir")
|
||||||
switch_axles(pos, true)
|
switch_axles(pos, true)
|
||||||
@ -47,7 +46,7 @@ local function start_node2(pos, nvm, state)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function stop_node2(pos, nvm, state)
|
local function stop_node2(pos, nvm, state)
|
||||||
nvm.generating = false
|
nvm.running = false
|
||||||
nvm.provided = 0
|
nvm.provided = 0
|
||||||
nvm.load = 0
|
nvm.load = 0
|
||||||
local outdir = M(pos):get_int("outdir")
|
local outdir = M(pos):get_int("outdir")
|
||||||
@ -56,14 +55,16 @@ local function stop_node2(pos, nvm, state)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function start_node3(pos, nvm, state)
|
local function start_node3(pos, nvm, state)
|
||||||
nvm.generating = true
|
local meta = M(pos)
|
||||||
|
nvm.running = true
|
||||||
nvm.provided = 0
|
nvm.provided = 0
|
||||||
local outdir = M(pos):get_int("outdir")
|
techage.evaluate_charge_termination(nvm, meta)
|
||||||
|
local outdir = meta:get_int("outdir")
|
||||||
power.start_storage_calc(pos, Cable, outdir)
|
power.start_storage_calc(pos, Cable, outdir)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function stop_node3(pos, nvm, state)
|
local function stop_node3(pos, nvm, state)
|
||||||
nvm.generating = false
|
nvm.running = false
|
||||||
nvm.provided = 0
|
nvm.provided = 0
|
||||||
local outdir = M(pos):get_int("outdir")
|
local outdir = M(pos):get_int("outdir")
|
||||||
power.start_storage_calc(pos, Cable, outdir)
|
power.start_storage_calc(pos, Cable, outdir)
|
||||||
@ -89,24 +90,30 @@ local State3 = techage.NodeStates:new({
|
|||||||
|
|
||||||
local function node_timer2(pos, elapsed)
|
local function node_timer2(pos, elapsed)
|
||||||
--print("node_timer2")
|
--print("node_timer2")
|
||||||
|
local meta = M(pos)
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
local outdir = M(pos):get_int("outdir")
|
local outdir = meta:get_int("outdir")
|
||||||
nvm.provided = power.provide_power(pos, Axle, outdir, PWR_PERF, nvm.termpoint1, nvm.termpoint2)
|
local tp1 = tonumber(meta:get_string("termpoint1"))
|
||||||
|
local tp2 = tonumber(meta:get_string("termpoint2"))
|
||||||
|
nvm.provided = power.provide_power(pos, Axle, outdir, PWR_PERF, tp1, tp2)
|
||||||
nvm.load = power.get_storage_load(pos, Axle, outdir, PWR_PERF)
|
nvm.load = power.get_storage_load(pos, Axle, outdir, PWR_PERF)
|
||||||
if techage.is_activeformspec(pos) then
|
if techage.is_activeformspec(pos) then
|
||||||
M(pos):set_string("formspec", formspec(State2, pos, nvm))
|
meta:set_string("formspec", formspec(State2, pos, nvm))
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local function node_timer3(pos, elapsed)
|
local function node_timer3(pos, elapsed)
|
||||||
--print("node_timer4")
|
--print("node_timer4")
|
||||||
|
local meta = M(pos)
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
local outdir = M(pos):get_int("outdir")
|
local outdir = M(pos):get_int("outdir")
|
||||||
nvm.provided = power.provide_power(pos, Cable, outdir, PWR_PERF, nvm.termpoint1, nvm.termpoint2)
|
local tp1 = tonumber(meta:get_string("termpoint1"))
|
||||||
|
local tp2 = tonumber(meta:get_string("termpoint2"))
|
||||||
|
nvm.provided = power.provide_power(pos, Cable, outdir, PWR_PERF, tp1, tp2)
|
||||||
nvm.load = power.get_storage_load(pos, Cable, outdir, PWR_PERF)
|
nvm.load = power.get_storage_load(pos, Cable, outdir, PWR_PERF)
|
||||||
if techage.is_activeformspec(pos) then
|
if techage.is_activeformspec(pos) then
|
||||||
M(pos):set_string("formspec", formspec(State3, pos, nvm))
|
meta:set_string("formspec", formspec(State3, pos, nvm))
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@ -117,7 +124,6 @@ local function on_receive_fields2(pos, formname, fields, player)
|
|||||||
end
|
end
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
State2:state_button_event(pos, nvm, fields)
|
State2:state_button_event(pos, nvm, fields)
|
||||||
techage.evaluate_charge_termination(nvm, fields)
|
|
||||||
M(pos):set_string("formspec", formspec(State2, pos, nvm))
|
M(pos):set_string("formspec", formspec(State2, pos, nvm))
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -127,7 +133,6 @@ local function on_receive_fields3(pos, formname, fields, player)
|
|||||||
end
|
end
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
State3:state_button_event(pos, nvm, fields)
|
State3:state_button_event(pos, nvm, fields)
|
||||||
techage.evaluate_charge_termination(nvm, fields)
|
|
||||||
M(pos):set_string("formspec", formspec(State3, pos, nvm))
|
M(pos):set_string("formspec", formspec(State3, pos, nvm))
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -172,7 +177,7 @@ end
|
|||||||
|
|
||||||
local function get_generator_data(pos, tlib2)
|
local function get_generator_data(pos, tlib2)
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
if nvm.generating then
|
if nvm.running then
|
||||||
return {level = (nvm.load or 0) / PWR_PERF, perf = PWR_PERF, capa = PWR_PERF * 2}
|
return {level = (nvm.load or 0) / PWR_PERF, perf = PWR_PERF, capa = PWR_PERF * 2}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -221,6 +226,7 @@ minetest.register_node("techage:t4_source", {
|
|||||||
after_place_node = after_place_node3,
|
after_place_node = after_place_node3,
|
||||||
after_dig_node = after_dig_node3,
|
after_dig_node = after_dig_node3,
|
||||||
get_generator_data = get_generator_data,
|
get_generator_data = get_generator_data,
|
||||||
|
ta3_formspec = techage.generator_settings("ta3", PWR_PERF),
|
||||||
})
|
})
|
||||||
|
|
||||||
power.register_nodes({"techage:t2_source"}, Axle, "gen", {"R"})
|
power.register_nodes({"techage:t2_source"}, Axle, "gen", {"R"})
|
||||||
@ -231,10 +237,8 @@ techage.register_node({"techage:t4_source"}, {
|
|||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
if topic == "delivered" then
|
if topic == "delivered" then
|
||||||
return nvm.provided or 0
|
return nvm.provided or 0
|
||||||
elseif topic == "info" then
|
|
||||||
|
|
||||||
else
|
else
|
||||||
return State:on_receive_message(pos, topic, payload)
|
return State3:on_receive_message(pos, topic, payload)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
@ -245,13 +249,14 @@ control.register_nodes({"techage:t4_source"}, {
|
|||||||
on_request = function(pos, tlib2, topic)
|
on_request = function(pos, tlib2, topic)
|
||||||
if topic == "info" then
|
if topic == "info" then
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
|
local meta = M(pos)
|
||||||
return {
|
return {
|
||||||
type = S("Ele Power Source"),
|
type = S("Ele Power Source"),
|
||||||
number = M(pos):get_string("node_number") or "",
|
number = meta:get_string("node_number") or "",
|
||||||
running = nvm.generating or false,
|
running = nvm.running or false,
|
||||||
available = PWR_PERF,
|
available = PWR_PERF,
|
||||||
provided = nvm.provided or 0,
|
provided = nvm.provided or 0,
|
||||||
termpoint = nvm.termpoint or "unknown",
|
termpoint = meta:get_string("termpoint"),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
TechAge
|
TechAge
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Copyright (C) 2019 Joachim Stolberg
|
Copyright (C) 2019-2021 Joachim Stolberg
|
||||||
|
|
||||||
AGPL v3
|
AGPL v3
|
||||||
See LICENSE.txt for more information
|
See LICENSE.txt for more information
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
TechAge
|
TechAge
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Copyright (C) 2019-2020 Joachim Stolberg
|
Copyright (C) 2019-2021 Joachim Stolberg
|
||||||
|
|
||||||
AGPL v3
|
AGPL v3
|
||||||
See LICENSE.txt for more information
|
See LICENSE.txt for more information
|
||||||
@ -17,7 +17,7 @@ local P2S = minetest.pos_to_string
|
|||||||
local M = minetest.get_meta
|
local M = minetest.get_meta
|
||||||
local S = techage.S
|
local S = techage.S
|
||||||
local Pipe = techage.LiquidPipe
|
local Pipe = techage.LiquidPipe
|
||||||
local liquid = techage.liquid
|
local liquid = networks.liquid
|
||||||
local ValidOilFuels = techage.firebox.ValidOilFuels
|
local ValidOilFuels = techage.firebox.ValidOilFuels
|
||||||
local Burntime = techage.firebox.Burntime
|
local Burntime = techage.firebox.Burntime
|
||||||
|
|
||||||
@ -28,11 +28,12 @@ local BLOCKING_TIME = 0.3 -- 300ms
|
|||||||
|
|
||||||
techage.fuel.CAPACITY = CAPACITY
|
techage.fuel.CAPACITY = CAPACITY
|
||||||
|
|
||||||
-- fuel burning categories (better than...)
|
-- fuel burning categories (equal or better than...)
|
||||||
techage.fuel.BT_BITUMEN = 4
|
techage.fuel.BT_BITUMEN = 5
|
||||||
techage.fuel.BT_OIL = 3
|
techage.fuel.BT_OIL = 4
|
||||||
techage.fuel.BT_FUELOIL = 2
|
techage.fuel.BT_FUELOIL = 3
|
||||||
techage.fuel.BT_NAPHTHA = 1
|
techage.fuel.BT_NAPHTHA = 2
|
||||||
|
techage.fuel.BT_GASOLINE = 1
|
||||||
|
|
||||||
|
|
||||||
function techage.fuel.fuel_container(x, y, nvm)
|
function techage.fuel.fuel_container(x, y, nvm)
|
||||||
@ -95,6 +96,7 @@ function techage.fuel.burntime(name)
|
|||||||
return 0.01 -- not zero !
|
return 0.01 -- not zero !
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- equal or better than the given category (see 'techage.fuel.BT_BITUMEN,...')
|
||||||
function techage.fuel.valid_fuel(name, category)
|
function techage.fuel.valid_fuel(name, category)
|
||||||
return ValidOilFuels[name] and ValidOilFuels[name] <= category
|
return ValidOilFuels[name] and ValidOilFuels[name] <= category
|
||||||
end
|
end
|
||||||
@ -109,7 +111,7 @@ function techage.fuel.on_punch(pos, node, puncher, pointed_thing)
|
|||||||
|
|
||||||
local wielded_item = puncher:get_wielded_item():get_name()
|
local wielded_item = puncher:get_wielded_item():get_name()
|
||||||
local item_count = puncher:get_wielded_item():get_count()
|
local item_count = puncher:get_wielded_item():get_count()
|
||||||
local new_item = liquid.fill_on_punch(nvm, wielded_item, item_count, puncher)
|
local new_item = techage.liquid.fill_on_punch(nvm, wielded_item, item_count, puncher)
|
||||||
if new_item then
|
if new_item then
|
||||||
puncher:set_wielded_item(new_item)
|
puncher:set_wielded_item(new_item)
|
||||||
M(pos):set_string("formspec", techage.fuel.formspec(pos, nvm))
|
M(pos):set_string("formspec", techage.fuel.formspec(pos, nvm))
|
||||||
@ -117,11 +119,11 @@ function techage.fuel.on_punch(pos, node, puncher, pointed_thing)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local ldef = liquid.get_liquid_def(wielded_item)
|
local ldef = techage.liquid.get_liquid_def(wielded_item)
|
||||||
if ldef and ValidOilFuels[ldef.inv_item] then
|
if ldef and ValidOilFuels[ldef.inv_item] then
|
||||||
local lqd = (minetest.registered_nodes[node.name] or {}).liquid
|
local lqd = (minetest.registered_nodes[node.name] or {}).liquid
|
||||||
if not lqd.fuel_cat or ValidOilFuels[ldef.inv_item] <= lqd.fuel_cat then
|
if not lqd.fuel_cat or ValidOilFuels[ldef.inv_item] <= lqd.fuel_cat then
|
||||||
local new_item = liquid.empty_on_punch(pos, nvm, wielded_item, item_count)
|
local new_item = techage.liquid.empty_on_punch(pos, nvm, wielded_item, item_count)
|
||||||
if new_item then
|
if new_item then
|
||||||
puncher:set_wielded_item(new_item)
|
puncher:set_wielded_item(new_item)
|
||||||
M(pos):set_string("formspec", techage.fuel.formspec(pos, nvm))
|
M(pos):set_string("formspec", techage.fuel.formspec(pos, nvm))
|
||||||
@ -154,3 +156,42 @@ function techage.fuel.get_fuel_amount(nvm)
|
|||||||
end
|
end
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function techage.fuel.get_liquid_table(valid_fuel, capacity, start_firebox)
|
||||||
|
return {
|
||||||
|
capa = capacity,
|
||||||
|
fuel_cat = valid_fuel,
|
||||||
|
peek = function(pos)
|
||||||
|
local nvm = techage.get_nvm(pos)
|
||||||
|
return liquid.srv_peek(nvm)
|
||||||
|
end,
|
||||||
|
put = function(pos, indir, name, amount)
|
||||||
|
if techage.fuel.valid_fuel(name, valid_fuel) then
|
||||||
|
local nvm = techage.get_nvm(pos)
|
||||||
|
local res = liquid.srv_put(nvm, name, amount, capacity)
|
||||||
|
start_firebox(pos, nvm)
|
||||||
|
if techage.is_activeformspec(pos) then
|
||||||
|
M(pos):set_string("formspec", techage.fuel.formspec(nvm))
|
||||||
|
end
|
||||||
|
return res
|
||||||
|
end
|
||||||
|
return amount
|
||||||
|
end,
|
||||||
|
take = function(pos, indir, name, amount)
|
||||||
|
local nvm = techage.get_nvm(pos)
|
||||||
|
amount, name = liquid.srv_take(nvm, name, amount)
|
||||||
|
if techage.is_activeformspec(pos) then
|
||||||
|
M(pos):set_string("formspec", techage.fuel.formspec(nvm))
|
||||||
|
end
|
||||||
|
return amount, name
|
||||||
|
end,
|
||||||
|
untake = function(pos, indir, name, amount)
|
||||||
|
local nvm = techage.get_nvm(pos)
|
||||||
|
local leftover = liquid.srv_put(nvm, name, amount, capacity)
|
||||||
|
if techage.is_activeformspec(pos) then
|
||||||
|
M(pos):set_string("formspec", techage.fuel.formspec(nvm))
|
||||||
|
end
|
||||||
|
return leftover
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
@ -67,7 +67,7 @@ local N = techage.get_node_lvm
|
|||||||
--
|
--
|
||||||
|
|
||||||
techage.RUNNING = 1 -- in normal operation/turned on
|
techage.RUNNING = 1 -- in normal operation/turned on
|
||||||
techage.BLOCKED = 2 -- a pushing node is blocked due to a full destination inventory
|
techage.BLOCKED = 2 -- a pushing node is blocked due to a full destination inventory
|
||||||
techage.STANDBY = 3 -- nothing to do (e.g. no input items), or node (world) not loaded
|
techage.STANDBY = 3 -- nothing to do (e.g. no input items), or node (world) not loaded
|
||||||
techage.NOPOWER = 4 -- only for power consuming nodes, no operation
|
techage.NOPOWER = 4 -- only for power consuming nodes, no operation
|
||||||
techage.FAULT = 5 -- any fault state (e.g. wrong source items), which can be fixed by the player
|
techage.FAULT = 5 -- any fault state (e.g. wrong source items), which can be fixed by the player
|
||||||
@ -158,6 +158,12 @@ function techage.needs_power(nvm)
|
|||||||
return state == RUNNING or state == NOPOWER
|
return state == RUNNING or state == NOPOWER
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- consumes power
|
||||||
|
function techage.needs_power2(state)
|
||||||
|
state = state or STOPPED
|
||||||
|
return state == RUNNING or state == NOPOWER
|
||||||
|
end
|
||||||
|
|
||||||
function techage.get_state_string(nvm)
|
function techage.get_state_string(nvm)
|
||||||
return techage.StateStrings[nvm.techage_state or STOPPED]
|
return techage.StateStrings[nvm.techage_state or STOPPED]
|
||||||
end
|
end
|
||||||
|
@ -67,7 +67,7 @@ local function get_liquids(pos)
|
|||||||
-- determine the available input liquids
|
-- determine the available input liquids
|
||||||
local tbl = {}
|
local tbl = {}
|
||||||
for outdir = 1,4 do
|
for outdir = 1,4 do
|
||||||
local name, num = liquid.peek(pos, outdir)
|
local name, num = liquid.peek(pos, Pipe, outdir)
|
||||||
if name then
|
if name then
|
||||||
tbl[name] = outdir
|
tbl[name] = outdir
|
||||||
end
|
end
|
||||||
@ -87,7 +87,7 @@ local function reload_liquids(pos)
|
|||||||
-- determine the available input liquids
|
-- determine the available input liquids
|
||||||
local tbl = {}
|
local tbl = {}
|
||||||
for outdir = 1,4 do
|
for outdir = 1,4 do
|
||||||
local name, num = liquid.peek(pos, outdir)
|
local name, num = liquid.peek(pos, Pipe, outdir)
|
||||||
if name then
|
if name then
|
||||||
tbl[name] = outdir
|
tbl[name] = outdir
|
||||||
end
|
end
|
||||||
@ -155,7 +155,7 @@ local State = techage.NodeStates:new({
|
|||||||
|
|
||||||
local function untake(pos, taken)
|
local function untake(pos, taken)
|
||||||
for _,item in pairs(taken) do
|
for _,item in pairs(taken) do
|
||||||
liquid.untake(pos, item.outdir, item.name, item.num)
|
liquid.untake(pos, Pipe, item.outdir, item.name, item.num)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -210,7 +210,7 @@ local function dosing(pos, nvm, elapsed)
|
|||||||
untake(pos, taken)
|
untake(pos, taken)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local num = liquid.take(pos, outdir, item.name, item.num, starter)
|
local num = liquid.take(pos, Pipe, outdir, item.name, item.num, starter)
|
||||||
if num < item.num then
|
if num < item.num then
|
||||||
taken[#taken + 1] = {outdir = outdir, name = item.name, num = num}
|
taken[#taken + 1] = {outdir = outdir, name = item.name, num = num}
|
||||||
State:standby(pos, nvm)
|
State:standby(pos, nvm)
|
||||||
@ -307,7 +307,6 @@ 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, oldnode, oldmetadata)
|
techage.remove_node(pos, oldnode, oldmetadata)
|
||||||
Pipe:after_dig_node(pos)
|
Pipe:after_dig_node(pos)
|
||||||
liquid.after_dig_pump(pos)
|
|
||||||
techage.del_mem(pos)
|
techage.del_mem(pos)
|
||||||
end,
|
end,
|
||||||
on_receive_fields = on_receive_fields,
|
on_receive_fields = on_receive_fields,
|
||||||
|
@ -105,7 +105,6 @@ minetest.register_node("techage:ta4_liquid_filter_filler", {
|
|||||||
end,
|
end,
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
Pipe:after_dig_node(pos)
|
Pipe:after_dig_node(pos)
|
||||||
liquid.after_dig_pump(pos)
|
|
||||||
techage.del_mem(pos)
|
techage.del_mem(pos)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@ -134,7 +133,7 @@ minetest.register_node("techage:ta4_liquid_filter_filler", {
|
|||||||
end
|
end
|
||||||
if math.random() < 0.5 then
|
if math.random() < 0.5 then
|
||||||
local out_pos = {x=pos.x,y=pos.y-8,z=pos.z}
|
local out_pos = {x=pos.x,y=pos.y-8,z=pos.z}
|
||||||
local leftover = liquid.put(out_pos, networks.side_to_outdir(out_pos, "R"), "techage:lye", 1)
|
local leftover = liquid.put(out_pos, Pipe, networks.side_to_outdir(out_pos, "R"), "techage:lye", 1)
|
||||||
if leftover > 0 then
|
if leftover > 0 then
|
||||||
return amount
|
return amount
|
||||||
end
|
end
|
||||||
|
@ -85,7 +85,7 @@ end
|
|||||||
local function base_waste(pos, payload)
|
local function base_waste(pos, payload)
|
||||||
local pos2 = {x = pos.x, y = pos.y-3, z = pos.z}
|
local pos2 = {x = pos.x, y = pos.y-3, z = pos.z}
|
||||||
local outdir = M(pos2):get_int("outdir")
|
local outdir = M(pos2):get_int("outdir")
|
||||||
return liquid.put(pos2, outdir, payload.name, payload.amount, payload.player_name)
|
return liquid.put(pos2, Pipe, outdir, payload.name, payload.amount, payload.player_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- controlled by the doser
|
-- controlled by the doser
|
||||||
|
@ -117,7 +117,6 @@ minetest.register_node("techage:ta4_reactor_stand", {
|
|||||||
after_dig_node = function(pos, oldnode)
|
after_dig_node = function(pos, oldnode)
|
||||||
Pipe:after_dig_node(pos)
|
Pipe:after_dig_node(pos)
|
||||||
Cable:after_dig_node(pos)
|
Cable:after_dig_node(pos)
|
||||||
liquid.after_dig_pump(pos)
|
|
||||||
techage.del_mem(pos)
|
techage.del_mem(pos)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@ -153,7 +152,7 @@ techage.register_node({"techage:ta4_reactor_stand"}, {
|
|||||||
return nvm.has_power or power.power_available(pos, Cable)
|
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, Pipe, outdir, payload.name, payload.amount, payload.player_name)
|
||||||
elseif topic == "can_start" then
|
elseif topic == "can_start" then
|
||||||
return power.power_available(pos, Cable)
|
return power.power_available(pos, Cable)
|
||||||
elseif topic == "start" then
|
elseif topic == "start" then
|
||||||
|
@ -26,8 +26,7 @@ local power = networks.power
|
|||||||
local control = networks.control
|
local control = networks.control
|
||||||
|
|
||||||
local function formspec(self, pos, nvm)
|
local function formspec(self, pos, nvm)
|
||||||
return techage.generator_formspec(self, pos, nvm, S("Generator"),
|
return techage.generator_formspec(self, pos, nvm, S("Generator"), nvm.provided, PWR_CAPA)
|
||||||
nvm.provided, PWR_CAPA, nvm.running)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function transfer_turbine(pos, topic, payload)
|
local function transfer_turbine(pos, topic, payload)
|
||||||
@ -41,17 +40,18 @@ end
|
|||||||
|
|
||||||
local function start_node(pos, nvm, state)
|
local function start_node(pos, nvm, state)
|
||||||
local outdir = M(pos):get_int("outdir")
|
local outdir = M(pos):get_int("outdir")
|
||||||
power.start_storage_calc(pos, Cable, outdir)
|
techage.evaluate_charge_termination(nvm, M(pos))
|
||||||
transfer_turbine(pos, "start")
|
transfer_turbine(pos, "start")
|
||||||
nvm.running = true
|
nvm.running = true
|
||||||
|
power.start_storage_calc(pos, Cable, outdir)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function stop_node(pos, nvm, state)
|
local function stop_node(pos, nvm, state)
|
||||||
local outdir = M(pos):get_int("outdir")
|
local outdir = M(pos):get_int("outdir")
|
||||||
power.start_storage_calc(pos, Cable, outdir)
|
|
||||||
nvm.provided = 0
|
nvm.provided = 0
|
||||||
transfer_turbine(pos, "stop")
|
transfer_turbine(pos, "stop")
|
||||||
nvm.running = false
|
nvm.running = false
|
||||||
|
power.start_storage_calc(pos, Cable, outdir)
|
||||||
end
|
end
|
||||||
|
|
||||||
local State = techage.NodeStates:new({
|
local State = techage.NodeStates:new({
|
||||||
@ -67,6 +67,7 @@ local State = techage.NodeStates:new({
|
|||||||
})
|
})
|
||||||
|
|
||||||
local function node_timer(pos, elapsed)
|
local function node_timer(pos, elapsed)
|
||||||
|
local meta = M(pos)
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
nvm.firebox_trigger = (nvm.firebox_trigger or 0) - 1
|
nvm.firebox_trigger = (nvm.firebox_trigger or 0) - 1
|
||||||
if nvm.firebox_trigger <= 0 then
|
if nvm.firebox_trigger <= 0 then
|
||||||
@ -74,13 +75,15 @@ local function node_timer(pos, elapsed)
|
|||||||
stop_node(pos, nvm, State)
|
stop_node(pos, nvm, State)
|
||||||
transfer_turbine(pos, "stop")
|
transfer_turbine(pos, "stop")
|
||||||
else
|
else
|
||||||
local outdir = M(pos):get_int("outdir")
|
local outdir = meta:get_int("outdir")
|
||||||
nvm.provided = power.provide_power(pos, Cable, outdir, PWR_CAPA, nvm.termpoint1, nvm.termpoint2)
|
local tp1 = tonumber(meta:get_string("termpoint1"))
|
||||||
|
local tp2 = tonumber(meta:get_string("termpoint2"))
|
||||||
|
nvm.provided = power.provide_power(pos, Cable, outdir, PWR_CAPA, tp1, tp2)
|
||||||
nvm.load = power.get_storage_load(pos, Cable, outdir, PWR_CAPA)
|
nvm.load = power.get_storage_load(pos, Cable, outdir, PWR_CAPA)
|
||||||
State:keep_running(pos, nvm, COUNTDOWN_TICKS)
|
State:keep_running(pos, nvm, COUNTDOWN_TICKS)
|
||||||
end
|
end
|
||||||
if techage.is_activeformspec(pos) then
|
if techage.is_activeformspec(pos) then
|
||||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
meta:set_string("formspec", formspec(State, pos, nvm))
|
||||||
end
|
end
|
||||||
return State:is_active(nvm)
|
return State:is_active(nvm)
|
||||||
end
|
end
|
||||||
@ -91,7 +94,6 @@ local function on_receive_fields(pos, formname, fields, player)
|
|||||||
end
|
end
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
State:state_button_event(pos, nvm, fields)
|
State:state_button_event(pos, nvm, fields)
|
||||||
techage.evaluate_charge_termination(nvm, fields)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_rightclick(pos, node, clicker)
|
local function on_rightclick(pos, node, clicker)
|
||||||
@ -106,6 +108,7 @@ local function after_place_node(pos)
|
|||||||
State:node_init(pos, nvm, number)
|
State: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"))
|
||||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||||
|
techage.evaluate_charge_termination(nvm, M(pos))
|
||||||
Cable:after_place_node(pos)
|
Cable:after_place_node(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -139,6 +142,7 @@ minetest.register_node("techage:generator", {
|
|||||||
after_place_node = after_place_node,
|
after_place_node = after_place_node,
|
||||||
after_dig_node = after_dig_node,
|
after_dig_node = after_dig_node,
|
||||||
get_generator_data = get_generator_data,
|
get_generator_data = get_generator_data,
|
||||||
|
ta3_formspec = techage.generator_settings("ta3", PWR_CAPA),
|
||||||
|
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
groups = {cracky=2, crumbly=2, choppy=2},
|
groups = {cracky=2, crumbly=2, choppy=2},
|
||||||
@ -183,6 +187,7 @@ minetest.register_node("techage:generator_on", {
|
|||||||
after_place_node = after_place_node,
|
after_place_node = after_place_node,
|
||||||
after_dig_node = after_dig_node,
|
after_dig_node = after_dig_node,
|
||||||
get_generator_data = get_generator_data,
|
get_generator_data = get_generator_data,
|
||||||
|
ta3_formspec = techage.generator_settings("ta3", PWR_CAPA),
|
||||||
|
|
||||||
drop = "",
|
drop = "",
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
@ -225,13 +230,14 @@ control.register_nodes({"techage:generator", "techage:generator_on"}, {
|
|||||||
on_request = function(pos, tlib2, topic)
|
on_request = function(pos, tlib2, topic)
|
||||||
if topic == "info" then
|
if topic == "info" then
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
|
local meta = M(pos)
|
||||||
return {
|
return {
|
||||||
type = S("TA3 Generator"),
|
type = S("TA3 Generator"),
|
||||||
number = M(pos):get_string("node_number") or "",
|
number = meta:get_string("node_number") or "",
|
||||||
running = nvm.running or false,
|
running = nvm.running or false,
|
||||||
available = PWR_CAPA,
|
available = PWR_CAPA,
|
||||||
provided = nvm.provided or 0,
|
provided = nvm.provided or 0,
|
||||||
termpoint = nvm.termpoint or "unknown",
|
termpoint = meta:get_string("termpoint"),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
TechAge
|
TechAge
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Copyright (C) 2019-2020 Joachim Stolberg
|
Copyright (C) 2019-2021 Joachim Stolberg
|
||||||
|
|
||||||
AGPL v3
|
AGPL v3
|
||||||
See LICENSE.txt for more information
|
See LICENSE.txt for more information
|
||||||
@ -20,7 +20,7 @@ local S = techage.S
|
|||||||
local firebox = techage.firebox
|
local firebox = techage.firebox
|
||||||
local fuel = techage.fuel
|
local fuel = techage.fuel
|
||||||
local Pipe = techage.LiquidPipe
|
local Pipe = techage.LiquidPipe
|
||||||
local liquid = techage.liquid
|
local liquid = networks.liquid
|
||||||
|
|
||||||
local CYCLE_TIME = 2
|
local CYCLE_TIME = 2
|
||||||
local BURN_CYCLE_FACTOR = 0.5
|
local BURN_CYCLE_FACTOR = 0.5
|
||||||
@ -115,44 +115,10 @@ minetest.register_node("techage:oilfirebox", {
|
|||||||
minetest.after(1, start_firebox, pos, nvm)
|
minetest.after(1, start_firebox, pos, nvm)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
-- liquid = { TODO
|
|
||||||
-- capa = fuel.CAPACITY,
|
|
||||||
-- fuel_cat = fuel.BT_BITUMEN,
|
|
||||||
-- peek = liquid.srv_peek,
|
|
||||||
-- put = function(pos, indir, name, amount)
|
|
||||||
-- if fuel.valid_fuel(name, fuel.BT_BITUMEN) then
|
|
||||||
-- local leftover = liquid.srv_put(pos, indir, name, amount)
|
|
||||||
-- local nvm = techage.get_nvm(pos)
|
|
||||||
-- nvm.liquid = nvm.liquid or {}
|
|
||||||
-- nvm.liquid.amount = nvm.liquid.amount or 0
|
|
||||||
-- start_firebox(pos, nvm)
|
|
||||||
-- if techage.is_activeformspec(pos) then
|
|
||||||
-- local nvm = techage.get_nvm(pos)
|
|
||||||
-- M(pos):set_string("formspec", fuel.formspec(nvm))
|
|
||||||
-- end
|
|
||||||
-- return leftover
|
|
||||||
-- end
|
|
||||||
-- return amount
|
|
||||||
-- end,
|
|
||||||
-- take = function(pos, indir, name, amount)
|
|
||||||
-- amount, name = liquid.srv_take(pos, indir, name, amount)
|
|
||||||
-- if techage.is_activeformspec(pos) then
|
|
||||||
-- local nvm = techage.get_nvm(pos)
|
|
||||||
-- M(pos):set_string("formspec", fuel.formspec(nvm))
|
|
||||||
-- end
|
|
||||||
-- return amount, name
|
|
||||||
-- end
|
|
||||||
-- },
|
|
||||||
-- networks = {
|
|
||||||
-- pipe2 = {
|
|
||||||
-- sides = techage.networks.AllSides, -- Pipe connection sides
|
|
||||||
-- ntype = "tank",
|
|
||||||
-- },
|
|
||||||
-- },
|
|
||||||
})
|
})
|
||||||
|
|
||||||
Pipe:add_secondary_node_names({"techage:oilfirebox"})
|
liquid.register_nodes({"techage:oilfirebox"},
|
||||||
|
Pipe, "tank", nil, fuel.get_liquid_table(fuel.BT_OIL, fuel.CAPACITY, start_firebox))
|
||||||
|
|
||||||
|
|
||||||
techage.register_node({"techage:oilfirebox"}, {
|
techage.register_node({"techage:oilfirebox"}, {
|
||||||
@ -161,7 +127,7 @@ techage.register_node({"techage:oilfirebox"}, {
|
|||||||
if topic == "state" then
|
if topic == "state" then
|
||||||
return nvm.running and "running" or "stopped"
|
return nvm.running and "running" or "stopped"
|
||||||
elseif topic == "fuel" then
|
elseif topic == "fuel" then
|
||||||
return techage.fuel.get_fuel_amount(nvm)
|
return fuel.get_fuel_amount(nvm)
|
||||||
else
|
else
|
||||||
return "unsupported"
|
return "unsupported"
|
||||||
end
|
end
|
||||||
|
@ -20,8 +20,7 @@ local PWR_NEEDED = 3
|
|||||||
local CYCLE_TIME = 2
|
local CYCLE_TIME = 2
|
||||||
|
|
||||||
local Cable = techage.ElectricCable
|
local Cable = techage.ElectricCable
|
||||||
local power = techage.power
|
local power = networks.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)
|
||||||
@ -58,23 +57,6 @@ local function stop_sound(pos)
|
|||||||
end
|
end
|
||||||
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")
|
|
||||||
infotext(pos, "no power")
|
|
||||||
stop_sound(pos)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function node_timer(pos, elapsed)
|
|
||||||
power.consumer_alive(pos, Cable, CYCLE_TIME)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
local function after_place_node(pos)
|
local function after_place_node(pos)
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
Cable:after_place_node(pos)
|
Cable:after_place_node(pos)
|
||||||
@ -89,10 +71,6 @@ local function after_dig_node(pos, oldnode)
|
|||||||
techage.del_mem(pos)
|
techage.del_mem(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function tubelib2_on_update2(pos, outdir, tlib2, node)
|
|
||||||
power.update_network(pos, outdir, tlib2)
|
|
||||||
end
|
|
||||||
|
|
||||||
minetest.register_node("techage:ta3_booster", {
|
minetest.register_node("techage:ta3_booster", {
|
||||||
description = S("TA3 Booster"),
|
description = S("TA3 Booster"),
|
||||||
tiles = {
|
tiles = {
|
||||||
@ -105,19 +83,17 @@ minetest.register_node("techage:ta3_booster", {
|
|||||||
"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 = function(pos, elapsed)
|
||||||
|
local consumed = power.consume_power(pos, Cable, nil, PWR_NEEDED)
|
||||||
|
if consumed == PWR_NEEDED then
|
||||||
|
swap_node(pos, "techage:ta3_booster_on")
|
||||||
|
infotext(pos, "running")
|
||||||
|
play_sound(pos)
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end,
|
||||||
after_place_node = after_place_node,
|
after_place_node = after_place_node,
|
||||||
after_dig_node = after_dig_node,
|
after_dig_node = after_dig_node,
|
||||||
tubelib2_on_update2 = tubelib2_on_update2,
|
|
||||||
networks = {
|
|
||||||
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,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
groups = {cracky=2, crumbly=2, choppy=2},
|
groups = {cracky=2, crumbly=2, choppy=2},
|
||||||
@ -126,7 +102,6 @@ minetest.register_node("techage:ta3_booster", {
|
|||||||
sounds = default.node_sound_wood_defaults(),
|
sounds = default.node_sound_wood_defaults(),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
minetest.register_node("techage:ta3_booster_on", {
|
minetest.register_node("techage:ta3_booster_on", {
|
||||||
tiles = {
|
tiles = {
|
||||||
-- up, down, right, left, back, front
|
-- up, down, right, left, back, front
|
||||||
@ -156,20 +131,17 @@ minetest.register_node("techage:ta3_booster_on", {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
on_timer = node_timer,
|
on_timer = function(pos, elapsed)
|
||||||
|
local consumed = power.consume_power(pos, Cable, nil, PWR_NEEDED)
|
||||||
|
if consumed < PWR_NEEDED then
|
||||||
|
swap_node(pos, "techage:ta3_booster")
|
||||||
|
infotext(pos, "no power")
|
||||||
|
stop_sound(pos)
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end,
|
||||||
after_place_node = after_place_node,
|
after_place_node = after_place_node,
|
||||||
after_dig_node = after_dig_node,
|
after_dig_node = after_dig_node,
|
||||||
tubelib2_on_update2 = tubelib2_on_update2,
|
|
||||||
networks = {
|
|
||||||
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,
|
|
||||||
is_running = function() return true end,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
groups = {not_in_creative_inventory = 1},
|
groups = {not_in_creative_inventory = 1},
|
||||||
@ -179,7 +151,7 @@ minetest.register_node("techage:ta3_booster_on", {
|
|||||||
sounds = default.node_sound_wood_defaults(),
|
sounds = default.node_sound_wood_defaults(),
|
||||||
})
|
})
|
||||||
|
|
||||||
Cable:add_secondary_node_names({"techage:ta3_booster", "techage:ta3_booster_on"})
|
power.register_nodes({"techage:ta3_booster", "techage:ta3_booster_on"}, Cable, "con", {"B", "F", "L", "D", "U"})
|
||||||
|
|
||||||
-- 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"}, {
|
||||||
@ -194,15 +166,16 @@ techage.register_node({"techage:ta3_booster", "techage:ta3_booster_on"}, {
|
|||||||
elseif topic == "start" and not nvm.running then
|
elseif topic == "start" and not nvm.running then
|
||||||
if power.power_available(pos, Cable) then
|
if power.power_available(pos, Cable) then
|
||||||
nvm.running = true
|
nvm.running = true
|
||||||
power.consumer_start(pos, Cable, CYCLE_TIME)
|
|
||||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||||
|
swap_node(pos, "techage:ta3_booster_on")
|
||||||
|
infotext(pos, "running")
|
||||||
|
play_sound(pos)
|
||||||
else
|
else
|
||||||
infotext(pos, "no power")
|
infotext(pos, "no power")
|
||||||
end
|
end
|
||||||
elseif topic == "stop" then
|
elseif topic == "stop" then
|
||||||
nvm.running = false
|
nvm.running = false
|
||||||
swap_node(pos, "techage:ta3_booster")
|
swap_node(pos, "techage:ta3_booster")
|
||||||
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)
|
stop_sound(pos)
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
TechAge
|
TechAge
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Copyright (C) 2019-2020 Joachim Stolberg
|
Copyright (C) 2019-2021 Joachim Stolberg
|
||||||
|
|
||||||
AGPL v3
|
AGPL v3
|
||||||
See LICENSE.txt for more information
|
See LICENSE.txt for more information
|
||||||
@ -19,7 +19,7 @@ local S = techage.S
|
|||||||
local firebox = techage.firebox
|
local firebox = techage.firebox
|
||||||
local fuel = techage.fuel
|
local fuel = techage.fuel
|
||||||
local Pipe = techage.LiquidPipe
|
local Pipe = techage.LiquidPipe
|
||||||
local liquid = techage.liquid
|
local liquid = networks.liquid
|
||||||
|
|
||||||
local CYCLE_TIME = 2
|
local CYCLE_TIME = 2
|
||||||
local EFFICIENCY = 2 -- burn cycles
|
local EFFICIENCY = 2 -- burn cycles
|
||||||
@ -80,38 +80,6 @@ local function booster_cmnd(pos, cmnd)
|
|||||||
{"techage:ta3_booster", "techage:ta3_booster_on"})
|
{"techage:ta3_booster", "techage:ta3_booster_on"})
|
||||||
end
|
end
|
||||||
|
|
||||||
local _liquid = {
|
|
||||||
capa = fuel.CAPACITY,
|
|
||||||
fuel_cat = fuel.BT_BITUMEN,
|
|
||||||
peek = liquid.srv_peek,
|
|
||||||
put = function(pos, indir, name, amount)
|
|
||||||
if fuel.valid_fuel(name, fuel.BT_BITUMEN) then
|
|
||||||
local res = liquid.srv_put(pos, indir, name, amount)
|
|
||||||
if techage.is_activeformspec(pos) then
|
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
M(pos):set_string("formspec", fuel.formspec(nvm))
|
|
||||||
end
|
|
||||||
return res
|
|
||||||
end
|
|
||||||
return amount
|
|
||||||
end,
|
|
||||||
take = function(pos, indir, name, amount)
|
|
||||||
amount, name = liquid.srv_take(pos, indir, name, amount)
|
|
||||||
if techage.is_activeformspec(pos) then
|
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
M(pos):set_string("formspec", fuel.formspec(nvm))
|
|
||||||
end
|
|
||||||
return amount, name
|
|
||||||
end
|
|
||||||
}
|
|
||||||
|
|
||||||
local _networks = {
|
|
||||||
pipe2 = {
|
|
||||||
sides = techage.networks.AllSides, -- Pipe connection sides
|
|
||||||
ntype = "tank",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
minetest.register_node("techage:furnace_firebox", {
|
minetest.register_node("techage:furnace_firebox", {
|
||||||
description = S("TA3 Furnace Oil Burner"),
|
description = S("TA3 Furnace Oil Burner"),
|
||||||
tiles = {
|
tiles = {
|
||||||
@ -134,8 +102,6 @@ minetest.register_node("techage:furnace_firebox", {
|
|||||||
on_punch = fuel.on_punch,
|
on_punch = fuel.on_punch,
|
||||||
on_receive_fields = fuel.on_receive_fields,
|
on_receive_fields = fuel.on_receive_fields,
|
||||||
on_rightclick = fuel.on_rightclick,
|
on_rightclick = fuel.on_rightclick,
|
||||||
liquid = _liquid,
|
|
||||||
networks = _networks,
|
|
||||||
|
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
@ -185,8 +151,6 @@ minetest.register_node("techage:furnace_firebox_on", {
|
|||||||
on_receive_fields = fuel.on_receive_fields,
|
on_receive_fields = fuel.on_receive_fields,
|
||||||
on_punch = fuel.on_punch,
|
on_punch = fuel.on_punch,
|
||||||
on_rightclick = fuel.on_rightclick,
|
on_rightclick = fuel.on_rightclick,
|
||||||
liquid = _liquid,
|
|
||||||
networks = _networks,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
@ -204,7 +168,7 @@ techage.register_node({"techage:furnace_firebox", "techage:furnace_firebox_on"},
|
|||||||
if topic == "state" then
|
if topic == "state" then
|
||||||
return nvm.running and "running" or "stopped"
|
return nvm.running and "running" or "stopped"
|
||||||
elseif topic == "fuel" then
|
elseif topic == "fuel" then
|
||||||
return techage.fuel.get_fuel_amount(nvm)
|
return fuel.get_fuel_amount(nvm)
|
||||||
else
|
else
|
||||||
return "unsupported"
|
return "unsupported"
|
||||||
end
|
end
|
||||||
@ -237,4 +201,5 @@ techage.register_node({"techage:furnace_firebox", "techage:furnace_firebox_on"},
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
Pipe:add_secondary_node_names({"techage:furnace_firebox", "techage:furnace_firebox_on"})
|
liquid.register_nodes({"techage:furnace_firebox", "techage:furnace_firebox_on"},
|
||||||
|
Pipe, "tank", nil, fuel.get_liquid_table(fuel.BT_OIL, fuel.CAPACITY, start_firebox))
|
||||||
|
@ -16,11 +16,11 @@
|
|||||||
local M = minetest.get_meta
|
local M = minetest.get_meta
|
||||||
local S = techage.S
|
local S = techage.S
|
||||||
|
|
||||||
local CYCLE_TIME = 2
|
|
||||||
local PWR_NEEDED = 14
|
local PWR_NEEDED = 14
|
||||||
|
local CYCLE_TIME = 2
|
||||||
|
|
||||||
local Cable = techage.ElectricCable
|
local Cable = techage.ElectricCable
|
||||||
local power = techage.power
|
local power = networks.power
|
||||||
|
|
||||||
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)
|
||||||
@ -31,18 +31,6 @@ local function swap_node(pos, name)
|
|||||||
minetest.swap_node(pos, node)
|
minetest.swap_node(pos, node)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_power(pos)
|
|
||||||
swap_node(pos, "techage:furnace_heater_on")
|
|
||||||
end
|
|
||||||
|
|
||||||
local function on_nopower(pos)
|
|
||||||
swap_node(pos, "techage:furnace_heater")
|
|
||||||
end
|
|
||||||
|
|
||||||
local function node_timer(pos, elapsed)
|
|
||||||
power.consumer_alive(pos, Cable, CYCLE_TIME)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
local function after_place_node(pos)
|
local function after_place_node(pos)
|
||||||
Cable:after_place_node(pos)
|
Cable:after_place_node(pos)
|
||||||
@ -53,10 +41,6 @@ local function after_dig_node(pos, oldnode)
|
|||||||
techage.del_mem(pos)
|
techage.del_mem(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function tubelib2_on_update2(pos, outdir, tlib2, node)
|
|
||||||
power.update_network(pos, outdir, tlib2)
|
|
||||||
end
|
|
||||||
|
|
||||||
minetest.register_node("techage:furnace_heater", {
|
minetest.register_node("techage:furnace_heater", {
|
||||||
description = S("TA4 Furnace Heater"),
|
description = S("TA4 Furnace Heater"),
|
||||||
tiles = {
|
tiles = {
|
||||||
@ -69,19 +53,15 @@ minetest.register_node("techage:furnace_heater", {
|
|||||||
"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 = function(pos, elapsed)
|
||||||
|
local consumed = power.consume_power(pos, Cable, nil, PWR_NEEDED)
|
||||||
|
if consumed == PWR_NEEDED then
|
||||||
|
swap_node(pos, "techage:furnace_heater_on")
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end,
|
||||||
after_place_node = after_place_node,
|
after_place_node = after_place_node,
|
||||||
after_dig_node = after_dig_node,
|
after_dig_node = after_dig_node,
|
||||||
tubelib2_on_update2 = tubelib2_on_update2,
|
|
||||||
networks = {
|
|
||||||
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,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
groups = {cracky=2, crumbly=2, choppy=2},
|
groups = {cracky=2, crumbly=2, choppy=2},
|
||||||
@ -102,20 +82,15 @@ 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",
|
||||||
},
|
},
|
||||||
|
|
||||||
on_timer = node_timer,
|
on_timer = function(pos, elapsed)
|
||||||
|
local consumed = power.consume_power(pos, Cable, nil, PWR_NEEDED)
|
||||||
|
if consumed < PWR_NEEDED then
|
||||||
|
swap_node(pos, "techage:furnace_heater")
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end,
|
||||||
after_place_node = after_place_node,
|
after_place_node = after_place_node,
|
||||||
after_dig_node = after_dig_node,
|
after_dig_node = after_dig_node,
|
||||||
tubelib2_on_update2 = tubelib2_on_update2,
|
|
||||||
networks = {
|
|
||||||
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,
|
|
||||||
is_running = function() return true end,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
light_source = 8,
|
light_source = 8,
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
@ -126,16 +101,7 @@ minetest.register_node("techage:furnace_heater_on", {
|
|||||||
sounds = default.node_sound_wood_defaults(),
|
sounds = default.node_sound_wood_defaults(),
|
||||||
})
|
})
|
||||||
|
|
||||||
Cable:add_secondary_node_names({"techage:furnace_heater", "techage:furnace_heater_on"})
|
power.register_nodes({"techage:furnace_heater", "techage:furnace_heater_on"}, Cable, "con", {"B", "F", "L", "D", "U"})
|
||||||
|
|
||||||
minetest.register_craft({
|
|
||||||
output = "techage:furnace_heater",
|
|
||||||
recipe = {
|
|
||||||
{'techage:aluminum', 'default:steel_ingot', 'techage:aluminum'},
|
|
||||||
{'techage:basalt_stone', 'basic_materials:heating_element', 'techage:basalt_stone'},
|
|
||||||
{'techage:aluminum', 'techage:ta4_furnace_ceramic', 'techage:aluminum'},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
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
|
||||||
@ -148,16 +114,23 @@ techage.register_node({"techage:furnace_heater", "techage:furnace_heater_on"}, {
|
|||||||
elseif topic == "start" and not nvm.running then
|
elseif topic == "start" and not nvm.running then
|
||||||
if power.power_available(pos, Cable) then
|
if power.power_available(pos, Cable) then
|
||||||
nvm.running = true
|
nvm.running = true
|
||||||
power.consumer_start(pos, Cable, CYCLE_TIME)
|
|
||||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
elseif topic == "stop" and nvm.running then
|
elseif topic == "stop" and nvm.running then
|
||||||
nvm.running = false
|
nvm.running = false
|
||||||
swap_node(pos, "techage:furnace_heater")
|
swap_node(pos, "techage:furnace_heater")
|
||||||
power.consumer_stop(pos, Cable)
|
|
||||||
minetest.get_node_timer(pos):stop()
|
minetest.get_node_timer(pos):stop()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
minetest.register_craft({
|
||||||
|
output = "techage:furnace_heater",
|
||||||
|
recipe = {
|
||||||
|
{'techage:aluminum', 'default:steel_ingot', 'techage:aluminum'},
|
||||||
|
{'techage:basalt_stone', 'basic_materials:heating_element', 'techage:basalt_stone'},
|
||||||
|
{'techage:aluminum', 'techage:ta4_furnace_ceramic', 'techage:aluminum'},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
92
init.lua
92
init.lua
@ -3,7 +3,7 @@
|
|||||||
TechAge
|
TechAge
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Copyright (C) 2019-2020 Joachim Stolberg
|
Copyright (C) 2019-2021 Joachim Stolberg
|
||||||
|
|
||||||
AGPL v3
|
AGPL v3
|
||||||
See LICENSE.txt for more information
|
See LICENSE.txt for more information
|
||||||
@ -13,7 +13,7 @@
|
|||||||
techage = {}
|
techage = {}
|
||||||
|
|
||||||
-- Version for compatibility checks, see readme.md/history
|
-- Version for compatibility checks, see readme.md/history
|
||||||
techage.version = 0.26
|
techage.version = 1.00
|
||||||
|
|
||||||
if minetest.global_exists("tubelib") then
|
if minetest.global_exists("tubelib") then
|
||||||
minetest.log("error", "[techage] Techage can't be used together with the mod tubelib!")
|
minetest.log("error", "[techage] Techage can't be used together with the mod tubelib!")
|
||||||
@ -113,10 +113,10 @@ dofile(MP.."/power/powerswitchbox_legacy.lua")
|
|||||||
dofile(MP.."/power/powerswitchbox.lua")
|
dofile(MP.."/power/powerswitchbox.lua")
|
||||||
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/ta4_cable.lua")
|
||||||
--dofile(MP.."/power/ta4_cable_wall_entry.lua")
|
dofile(MP.."/power/ta4_cable_wall_entry.lua")
|
||||||
--dofile(MP.."/power/laser.lua")
|
dofile(MP.."/power/laser.lua")
|
||||||
|
|
||||||
-- Iron Age
|
-- Iron Age
|
||||||
dofile(MP.."/iron_age/main.lua")
|
dofile(MP.."/iron_age/main.lua")
|
||||||
@ -143,8 +143,8 @@ dofile(MP.."/steam_engine/flywheel.lua")
|
|||||||
|
|
||||||
-- Liquids I
|
-- Liquids I
|
||||||
dofile(MP.."/liquids/liquid_pipe.lua")
|
dofile(MP.."/liquids/liquid_pipe.lua")
|
||||||
--dofile(MP.."/liquids/valve.lua")
|
dofile(MP.."/liquids/valve.lua")
|
||||||
--dofile(MP.."/liquids/pipe_wall_entry.lua")
|
dofile(MP.."/liquids/pipe_wall_entry.lua")
|
||||||
|
|
||||||
-- Basic Machines
|
-- Basic Machines
|
||||||
dofile(MP.."/basic_machines/consumer.lua") -- consumer base model
|
dofile(MP.."/basic_machines/consumer.lua") -- consumer base model
|
||||||
@ -165,15 +165,15 @@ dofile(MP.."/basic_machines/ta4_chest.lua")
|
|||||||
dofile(MP.."/basic_machines/ta4_injector.lua")
|
dofile(MP.."/basic_machines/ta4_injector.lua")
|
||||||
dofile(MP.."/basic_machines/itemsource.lua")
|
dofile(MP.."/basic_machines/itemsource.lua")
|
||||||
dofile(MP.."/basic_machines/recycler.lua")
|
dofile(MP.."/basic_machines/recycler.lua")
|
||||||
--dofile(MP.."/basic_machines/concentrator.lua")
|
dofile(MP.."/basic_machines/concentrator.lua")
|
||||||
|
|
||||||
-- Liquids II
|
-- Liquids II
|
||||||
--dofile(MP.."/liquids/tank.lua")
|
dofile(MP.."/liquids/tank.lua")
|
||||||
--dofile(MP.."/liquids/filler.lua")
|
dofile(MP.."/liquids/filler.lua")
|
||||||
--dofile(MP.."/liquids/silo.lua")
|
dofile(MP.."/liquids/silo.lua")
|
||||||
--dofile(MP.."/liquids/pump.lua")
|
dofile(MP.."/liquids/pump.lua")
|
||||||
--dofile(MP.."/liquids/waterpump.lua")
|
dofile(MP.."/liquids/waterpump.lua")
|
||||||
--dofile(MP.."/liquids/waterinlet.lua")
|
dofile(MP.."/liquids/waterinlet.lua")
|
||||||
|
|
||||||
-- Coal power station
|
-- Coal power station
|
||||||
dofile(MP.."/coal_power_station/firebox.lua")
|
dofile(MP.."/coal_power_station/firebox.lua")
|
||||||
@ -185,19 +185,19 @@ dofile(MP.."/coal_power_station/cooler.lua")
|
|||||||
dofile(MP.."/coal_power_station/oilfirebox.lua")
|
dofile(MP.."/coal_power_station/oilfirebox.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")
|
||||||
--dofile(MP.."/tools/repairkit.lua")
|
dofile(MP.."/tools/repairkit.lua")
|
||||||
--dofile(MP.."/tools/pipe_wrench.lua")
|
dofile(MP.."/tools/pipe_wrench.lua")
|
||||||
--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")
|
||||||
@ -214,19 +214,19 @@ dofile(MP.."/lamps/growlight.lua")
|
|||||||
dofile(MP.."/lamps/lampholder.lua")
|
dofile(MP.."/lamps/lampholder.lua")
|
||||||
|
|
||||||
-- Oil
|
-- Oil
|
||||||
--dofile(MP.."/oil/explore.lua")
|
dofile(MP.."/oil/explore.lua")
|
||||||
--dofile(MP.."/oil/tower.lua")
|
dofile(MP.."/oil/tower.lua")
|
||||||
--dofile(MP.."/oil/drillbox.lua")
|
dofile(MP.."/oil/drillbox.lua")
|
||||||
--dofile(MP.."/oil/pumpjack.lua")
|
dofile(MP.."/oil/pumpjack.lua")
|
||||||
--dofile(MP.."/oil/distiller.lua")
|
dofile(MP.."/oil/distiller.lua")
|
||||||
--dofile(MP.."/oil/reboiler.lua")
|
dofile(MP.."/oil/reboiler.lua")
|
||||||
-- -- dofile(MP.."/oil/gasflare.lua")
|
-- dofile(MP.."/oil/gasflare.lua")
|
||||||
|
|
||||||
-- TA3 power based
|
-- TA3 power based
|
||||||
--dofile(MP.."/ta3_power/tiny_generator.lua")
|
dofile(MP.."/ta3_power/tiny_generator.lua")
|
||||||
dofile(MP.."/ta3_power/akkubox.lua")
|
dofile(MP.."/ta3_power/akkubox.lua")
|
||||||
--dofile(MP.."/ta3_power/axle2power.lua")
|
dofile(MP.."/ta3_power/axle2power.lua")
|
||||||
--dofile(MP.."/ta3_power/power2axle.lua")
|
dofile(MP.."/ta3_power/power2axle.lua")
|
||||||
|
|
||||||
-- Digtron
|
-- Digtron
|
||||||
--if minetest.global_exists("digtron") then
|
--if minetest.global_exists("digtron") then
|
||||||
@ -262,9 +262,9 @@ dofile(MP.."/recipe_checker.lua")
|
|||||||
dofile(MP.."/.test/sink.lua")
|
dofile(MP.."/.test/sink.lua")
|
||||||
|
|
||||||
-- Solar
|
-- Solar
|
||||||
--dofile(MP.."/solar/minicell.lua")
|
dofile(MP.."/solar/minicell.lua")
|
||||||
--dofile(MP.."/solar/solarcell.lua")
|
dofile(MP.."/solar/solarcell.lua")
|
||||||
--dofile(MP.."/solar/inverter.lua")
|
dofile(MP.."/solar/inverter.lua")
|
||||||
|
|
||||||
-- Wind
|
-- Wind
|
||||||
--dofile(MP.."/wind_turbine/rotor.lua")
|
--dofile(MP.."/wind_turbine/rotor.lua")
|
||||||
@ -311,14 +311,14 @@ dofile(MP.."/lua_controller/controller.lua")
|
|||||||
--dofile(MP.."/lua_controller/terminal.lua")
|
--dofile(MP.."/lua_controller/terminal.lua")
|
||||||
|
|
||||||
-- Items
|
-- Items
|
||||||
--dofile(MP.."/items/registered_nodes.lua")
|
dofile(MP.."/items/registered_nodes.lua")
|
||||||
--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")
|
||||||
|
@ -26,4 +26,5 @@ techage.FILLING_ITEMS = {
|
|||||||
"default:goldblock",
|
"default:goldblock",
|
||||||
"default:mese",
|
"default:mese",
|
||||||
"default:diamondblock",
|
"default:diamondblock",
|
||||||
|
"techage:power_pole3",
|
||||||
}
|
}
|
@ -165,12 +165,12 @@ local names = networks.register_junction("techage:ta3_junctionpipe", 1/8, Boxes,
|
|||||||
sounds = default.node_sound_metal_defaults(),
|
sounds = default.node_sound_metal_defaults(),
|
||||||
|
|
||||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||||
local name = "techage:ta3_junctionpipe"..techage.junction_type(pos, Pipe)
|
local name = "techage:ta3_junctionpipe" .. networks.junction_type(pos, Pipe)
|
||||||
minetest.swap_node(pos, {name = name, param2 = 0})
|
minetest.swap_node(pos, {name = name, param2 = 0})
|
||||||
Pipe:after_place_node(pos)
|
Pipe:after_place_node(pos)
|
||||||
end,
|
end,
|
||||||
tubelib2_on_update2 = function(pos, dir1, tlib2, node)
|
tubelib2_on_update2 = function(pos, dir1, tlib2, node)
|
||||||
local name = "techage:ta3_junctionpipe"..techage.junction_type(pos, Pipe)
|
local name = "techage:ta3_junctionpipe" .. networks.junction_type(pos, Pipe)
|
||||||
minetest.swap_node(pos, {name = name, param2 = 0})
|
minetest.swap_node(pos, {name = name, param2 = 0})
|
||||||
power.update_network(pos, 0, tlib2, node)
|
power.update_network(pos, 0, tlib2, node)
|
||||||
end,
|
end,
|
||||||
|
@ -1,245 +0,0 @@
|
|||||||
--[[
|
|
||||||
|
|
||||||
TechAge
|
|
||||||
=======
|
|
||||||
|
|
||||||
Copyright (C) 2019-2020 Joachim Stolberg
|
|
||||||
|
|
||||||
AGPL v3
|
|
||||||
See LICENSE.txt for more information
|
|
||||||
|
|
||||||
Liquid transportation API via Pipe(s) (peer, put, take)
|
|
||||||
|
|
||||||
]]--
|
|
||||||
|
|
||||||
local P2S = minetest.pos_to_string
|
|
||||||
local M = minetest.get_meta
|
|
||||||
local N = function(pos) return minetest.get_node(pos).name end
|
|
||||||
local LQD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).liquid end
|
|
||||||
local Pipe = techage.LiquidPipe
|
|
||||||
local S = techage.S
|
|
||||||
|
|
||||||
local net_def = techage.networks.net_def
|
|
||||||
local networks = techage.networks
|
|
||||||
|
|
||||||
local liquid = techage.liquid
|
|
||||||
|
|
||||||
--
|
|
||||||
-- Networks
|
|
||||||
--
|
|
||||||
|
|
||||||
-- determine network ID (largest hash number of all pumps)
|
|
||||||
local function determine_netID(pos, outdir)
|
|
||||||
local netID = 0
|
|
||||||
networks.connection_walk(pos, outdir, Pipe, function(pos, indir, node)
|
|
||||||
local ntype = net_def(pos, "pipe2").ntype
|
|
||||||
if ntype and ntype == "pump" then
|
|
||||||
local new = minetest.hash_node_position(pos) * 8 + outdir
|
|
||||||
if netID <= new then
|
|
||||||
netID = new
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
return netID
|
|
||||||
end
|
|
||||||
|
|
||||||
-- store network ID on each pump like node
|
|
||||||
local function store_netID(pos, outdir, netID)
|
|
||||||
networks.connection_walk(pos, outdir, Pipe, function(pos, indir, node)
|
|
||||||
local ntype = net_def(pos, "pipe2").ntype
|
|
||||||
if ntype and ntype == "pump" then
|
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
local outdir = networks.Flip[indir]
|
|
||||||
nvm.pipe2 = nvm.pipe2 or {}
|
|
||||||
nvm.pipe2.netIDs = nvm.pipe2.netIDs or {}
|
|
||||||
nvm.pipe2.netIDs[outdir] = netID
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- delete network and ID on each pump like node
|
|
||||||
local function delete_netID(pos, outdir)
|
|
||||||
local netID = 0
|
|
||||||
networks.connection_walk(pos, outdir, Pipe, function(pos, indir, node)
|
|
||||||
local ntype = net_def(pos, "pipe2").ntype
|
|
||||||
if ntype and ntype == "pump" then
|
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
local outdir = networks.Flip[indir]
|
|
||||||
if nvm.pipe2 and nvm.pipe2.netIDs and nvm.pipe2.netIDs[outdir] then
|
|
||||||
netID = nvm.pipe2.netIDs[outdir]
|
|
||||||
nvm.pipe2.netIDs[outdir] = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
networks.delete_network("pipe2", netID)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function get_netID(pos, outdir)
|
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
if not nvm.pipe2 or not nvm.pipe2.netIDs or not nvm.pipe2.netIDs[outdir] then
|
|
||||||
local netID = determine_netID(pos, outdir)
|
|
||||||
store_netID(pos, outdir, netID)
|
|
||||||
end
|
|
||||||
return nvm.pipe2 and nvm.pipe2.netIDs and nvm.pipe2.netIDs[outdir]
|
|
||||||
end
|
|
||||||
|
|
||||||
-- return list of nodes {pos = ..., indir = ...} of given type
|
|
||||||
local function get_network_table(pos, outdir, ntype)
|
|
||||||
local netID = get_netID(pos, outdir)
|
|
||||||
if netID then
|
|
||||||
local netw = networks.get_network("pipe2", netID)
|
|
||||||
if not netw then
|
|
||||||
netw = networks.collect_network_nodes(pos, outdir, Pipe)
|
|
||||||
networks.set_network("pipe2", netID, netw)
|
|
||||||
end
|
|
||||||
if not netw[ntype] then -- connection lost (e.g. tank cart)?
|
|
||||||
-- reactivate network
|
|
||||||
networks.node_connections(pos, Pipe)
|
|
||||||
delete_netID(pos, outdir)
|
|
||||||
end
|
|
||||||
--print("netw", string.format("%012X", netID), dump(netw[ntype]))
|
|
||||||
return netw[ntype] or {}
|
|
||||||
end
|
|
||||||
return {}
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
--
|
|
||||||
-- Client remote functions
|
|
||||||
--
|
|
||||||
|
|
||||||
-- Determine and return liquid 'name' from the
|
|
||||||
-- remote inventory.
|
|
||||||
function liquid.peek(pos, outdir)
|
|
||||||
for _,item in ipairs(get_network_table(pos, outdir, "tank")) do
|
|
||||||
local liq = LQD(item.pos)
|
|
||||||
if liq and liq.peek then
|
|
||||||
return liq.peek(item.pos, item.indir)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Add given amount of liquid to the remote inventory.
|
|
||||||
-- return leftover amount
|
|
||||||
function liquid.put(pos, outdir, name, amount, player_name)
|
|
||||||
for _,item in ipairs(get_network_table(pos, outdir, "tank")) do
|
|
||||||
local liq = LQD(item.pos)
|
|
||||||
if liq and liq.put and liq.peek then
|
|
||||||
-- wrong items?
|
|
||||||
local peek = liq.peek(item.pos, item.indir)
|
|
||||||
if peek and peek ~= name then return amount or 0 end
|
|
||||||
if player_name then
|
|
||||||
local num = techage.get_node_number(pos) or "000"
|
|
||||||
techage.mark_position(player_name, item.pos, "("..num..") put", "", 1)
|
|
||||||
end
|
|
||||||
amount = liq.put(item.pos, item.indir, name, amount)
|
|
||||||
if not amount or amount == 0 then break end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return amount or 0
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Take given amount of liquid from the remote inventory.
|
|
||||||
-- return taken amount and item name
|
|
||||||
function liquid.take(pos, outdir, name, amount, player_name)
|
|
||||||
local taken = 0
|
|
||||||
for _,item in ipairs(get_network_table(pos, outdir, "tank")) do
|
|
||||||
local liq = LQD(item.pos)
|
|
||||||
if liq and liq.take then
|
|
||||||
if player_name then
|
|
||||||
local num = techage.get_node_number(pos)
|
|
||||||
techage.mark_position(player_name, item.pos, "("..num..") take", "", 1)
|
|
||||||
end
|
|
||||||
taken, name = liq.take(item.pos, item.indir, name, amount)
|
|
||||||
if taken and name and taken > 0 then
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return taken, name
|
|
||||||
end
|
|
||||||
|
|
||||||
function liquid.untake(pos, outdir, name, amount)
|
|
||||||
for _,item in ipairs(get_network_table(pos, outdir, "tank")) do
|
|
||||||
local liq = LQD(item.pos)
|
|
||||||
if liq and liq.untake then
|
|
||||||
amount = liq.untake(item.pos, item.indir, name, amount)
|
|
||||||
if not amount or amount == 0 then break end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return amount or 0
|
|
||||||
end
|
|
||||||
|
|
||||||
--
|
|
||||||
-- Server local functions
|
|
||||||
--
|
|
||||||
|
|
||||||
function liquid.srv_peek(pos, indir)
|
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
nvm.liquid = nvm.liquid or {}
|
|
||||||
return nvm.liquid.name
|
|
||||||
end
|
|
||||||
|
|
||||||
function liquid.srv_put(pos, indir, name, amount)
|
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
nvm.liquid = nvm.liquid or {}
|
|
||||||
amount = amount or 0
|
|
||||||
if not nvm.liquid.name then
|
|
||||||
nvm.liquid.name = name
|
|
||||||
nvm.liquid.amount = amount
|
|
||||||
return 0
|
|
||||||
elseif nvm.liquid.name == name then
|
|
||||||
nvm.liquid.amount = nvm.liquid.amount or 0
|
|
||||||
local capa = LQD(pos).capa
|
|
||||||
if nvm.liquid.amount + amount <= capa then
|
|
||||||
nvm.liquid.amount = nvm.liquid.amount + amount
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
local rest = nvm.liquid.amount + amount - capa
|
|
||||||
nvm.liquid.amount = capa
|
|
||||||
return rest
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return amount
|
|
||||||
end
|
|
||||||
|
|
||||||
function liquid.srv_take(pos, indir, name, amount)
|
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
nvm.liquid = nvm.liquid or {}
|
|
||||||
amount = amount or 0
|
|
||||||
if not name or nvm.liquid.name == name then
|
|
||||||
name = nvm.liquid.name
|
|
||||||
nvm.liquid.amount = nvm.liquid.amount or 0
|
|
||||||
if nvm.liquid.amount > amount then
|
|
||||||
nvm.liquid.amount = nvm.liquid.amount - amount
|
|
||||||
return amount, name
|
|
||||||
else
|
|
||||||
local rest = nvm.liquid.amount
|
|
||||||
local name = nvm.liquid.name
|
|
||||||
nvm.liquid.amount = 0
|
|
||||||
nvm.liquid.name = nil
|
|
||||||
return rest, name
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-- To be called from each node via 'tubelib2_on_update2'
|
|
||||||
-- 'output' is optional and only needed for nodes with dedicated
|
|
||||||
-- pipe sides (e.g. pumps).
|
|
||||||
function liquid.update_network(pos, outdir)
|
|
||||||
networks.node_connections(pos, Pipe)
|
|
||||||
delete_netID(pos, outdir)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- To be called from each pump in 'after_dig_node'
|
|
||||||
-- before calling 'techage.del_mem(pos)'
|
|
||||||
function liquid.after_dig_pump(pos)
|
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
if nvm.pipe2 and nvm.pipe2.netIDs then
|
|
||||||
for outdir, netID in pairs(nvm.pipe2.netIDs) do
|
|
||||||
networks.delete_network("pipe2", netID)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
@ -3,7 +3,7 @@
|
|||||||
TechAge
|
TechAge
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Copyright (C) 2019-2020 Joachim Stolberg
|
Copyright (C) 2019-2021 Joachim Stolberg
|
||||||
|
|
||||||
AGPL v3
|
AGPL v3
|
||||||
See LICENSE.txt for more information
|
See LICENSE.txt for more information
|
||||||
@ -17,35 +17,14 @@ local P2S = minetest.pos_to_string
|
|||||||
local M = minetest.get_meta
|
local M = minetest.get_meta
|
||||||
local S = techage.S
|
local S = techage.S
|
||||||
local Pipe = techage.LiquidPipe
|
local Pipe = techage.LiquidPipe
|
||||||
local networks = techage.networks
|
local liquid = networks.liquid
|
||||||
local liquid = techage.liquid
|
local Flip = networks.Flip
|
||||||
local Flip = techage.networks.Flip
|
|
||||||
|
|
||||||
local STANDBY_TICKS = 3
|
local STANDBY_TICKS = 3
|
||||||
local COUNTDOWN_TICKS = 4
|
local COUNTDOWN_TICKS = 4
|
||||||
local CYCLE_TIME = 2
|
local CYCLE_TIME = 2
|
||||||
local CAPA = 4
|
local CAPA = 4
|
||||||
|
|
||||||
-- to mark the pump source and destinstion node
|
|
||||||
local DebugCache = {}
|
|
||||||
|
|
||||||
local function set_starter_name(pos, clicker)
|
|
||||||
local key = minetest.hash_node_position(pos)
|
|
||||||
DebugCache[key] = {starter = clicker:get_player_name(), count = 10}
|
|
||||||
end
|
|
||||||
|
|
||||||
local function get_starter_name(pos)
|
|
||||||
local key = minetest.hash_node_position(pos)
|
|
||||||
local def = DebugCache[key]
|
|
||||||
if def then
|
|
||||||
def.count = (def.count or 0) - 1
|
|
||||||
if def.count > 0 then
|
|
||||||
return def.starter
|
|
||||||
end
|
|
||||||
DebugCache[key] = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local State3 = techage.NodeStates:new({
|
local State3 = techage.NodeStates:new({
|
||||||
node_name_passive = "techage:t3_pump",
|
node_name_passive = "techage:t3_pump",
|
||||||
node_name_active = "techage:t3_pump_on",
|
node_name_active = "techage:t3_pump_on",
|
||||||
@ -63,14 +42,15 @@ local State4 = techage.NodeStates:new({
|
|||||||
})
|
})
|
||||||
|
|
||||||
local function pumping(pos, nvm, state, capa)
|
local function pumping(pos, nvm, state, capa)
|
||||||
|
local mem = techage.get_mem(pos)
|
||||||
|
mem.dbg_cycles = (mem.dbg_cycles or 0) - 1
|
||||||
local outdir = M(pos):get_int("outdir")
|
local outdir = M(pos):get_int("outdir")
|
||||||
local starter = get_starter_name(pos)
|
|
||||||
--print("pumping", outdir, Flip[outdir])
|
--print("pumping", outdir, Flip[outdir])
|
||||||
local taken, name = liquid.take(pos, Flip[outdir], nil, capa, starter)
|
local taken, name = liquid.take(pos, Pipe, Flip[outdir], nil, capa, mem.dbg_cycles > 0)
|
||||||
if taken > 0 then
|
if taken > 0 then
|
||||||
local leftover = liquid.put(pos, outdir, name, taken, starter)
|
local leftover = liquid.put(pos, Pipe, outdir, name, taken, mem.dbg_cycles > 0)
|
||||||
if leftover then
|
if leftover and leftover > 0 then
|
||||||
liquid.untake(pos, Flip[outdir], name, leftover)
|
liquid.untake(pos, Pipe, Flip[outdir], name, leftover)
|
||||||
if leftover == taken then
|
if leftover == taken then
|
||||||
state:blocked(pos, nvm)
|
state:blocked(pos, nvm)
|
||||||
return
|
return
|
||||||
@ -117,25 +97,22 @@ local function on_rightclick(pos, node, clicker)
|
|||||||
|
|
||||||
local nvm = techage.get_nvm(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)
|
local mem = techage.get_mem(pos)
|
||||||
|
mem.dbg_cycles = 5
|
||||||
State3:start(pos, nvm)
|
State3:start(pos, nvm)
|
||||||
elseif node.name == "techage:t3_pump_on" then
|
elseif node.name == "techage:t3_pump_on" then
|
||||||
State3:stop(pos, nvm)
|
State3:stop(pos, nvm)
|
||||||
elseif node.name == "techage:t4_pump" then
|
elseif node.name == "techage:t4_pump" then
|
||||||
set_starter_name(pos, clicker)
|
local mem = techage.get_mem(pos)
|
||||||
|
mem.dbg_cycles = 5
|
||||||
State4:start(pos, nvm)
|
State4:start(pos, nvm)
|
||||||
elseif node.name == "techage:t4_pump_on" then
|
elseif node.name == "techage:t4_pump_on" then
|
||||||
State4:stop(pos, nvm)
|
State4:stop(pos, nvm)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function tubelib2_on_update2(pos, outdir, tlib2, node)
|
|
||||||
liquid.update_network(pos, outdir)
|
|
||||||
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)
|
||||||
liquid.after_dig_pump(pos)
|
|
||||||
techage.del_mem(pos)
|
techage.del_mem(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -215,23 +192,14 @@ local ta4_tiles_act = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
local nworks = {
|
|
||||||
pipe2 = {
|
|
||||||
sides = {L = 1, R = 1}, -- Pipe connection side
|
|
||||||
ntype = "pump",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
minetest.register_node("techage:t3_pump", {
|
minetest.register_node("techage:t3_pump", {
|
||||||
description = S("TA3 Pump"),
|
description = S("TA3 Pump"),
|
||||||
tiles = ta3_tiles_pas,
|
tiles = ta3_tiles_pas,
|
||||||
after_place_node = after_place_node3,
|
after_place_node = after_place_node3,
|
||||||
on_rightclick = on_rightclick,
|
on_rightclick = on_rightclick,
|
||||||
tubelib2_on_update2 = tubelib2_on_update2,
|
|
||||||
on_timer = node_timer3,
|
on_timer = node_timer3,
|
||||||
after_dig_node = after_dig_node,
|
after_dig_node = after_dig_node,
|
||||||
on_rotate = screwdriver.disallow,
|
on_rotate = screwdriver.disallow,
|
||||||
networks = nworks,
|
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
on_rotate = screwdriver.disallow,
|
on_rotate = screwdriver.disallow,
|
||||||
groups = {cracky=2},
|
groups = {cracky=2},
|
||||||
@ -244,11 +212,9 @@ minetest.register_node("techage:t3_pump_on", {
|
|||||||
tiles = ta3_tiles_act,
|
tiles = ta3_tiles_act,
|
||||||
--after_place_node = after_place_node3,
|
--after_place_node = after_place_node3,
|
||||||
on_rightclick = on_rightclick,
|
on_rightclick = on_rightclick,
|
||||||
tubelib2_on_update2 = tubelib2_on_update2,
|
|
||||||
on_timer = node_timer3,
|
on_timer = node_timer3,
|
||||||
after_dig_node = after_dig_node,
|
after_dig_node = after_dig_node,
|
||||||
on_rotate = screwdriver.disallow,
|
on_rotate = screwdriver.disallow,
|
||||||
networks = nworks,
|
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
on_rotate = screwdriver.disallow,
|
on_rotate = screwdriver.disallow,
|
||||||
diggable = false,
|
diggable = false,
|
||||||
@ -262,11 +228,9 @@ minetest.register_node("techage:t4_pump", {
|
|||||||
tiles = ta4_tiles_pas,
|
tiles = ta4_tiles_pas,
|
||||||
after_place_node = after_place_node4,
|
after_place_node = after_place_node4,
|
||||||
on_rightclick = on_rightclick,
|
on_rightclick = on_rightclick,
|
||||||
tubelib2_on_update2 = tubelib2_on_update2,
|
|
||||||
on_timer = node_timer4,
|
on_timer = node_timer4,
|
||||||
after_dig_node = after_dig_node,
|
after_dig_node = after_dig_node,
|
||||||
on_rotate = screwdriver.disallow,
|
on_rotate = screwdriver.disallow,
|
||||||
networks = nworks,
|
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
on_rotate = screwdriver.disallow,
|
on_rotate = screwdriver.disallow,
|
||||||
groups = {cracky=2},
|
groups = {cracky=2},
|
||||||
@ -279,11 +243,9 @@ minetest.register_node("techage:t4_pump_on", {
|
|||||||
tiles = ta4_tiles_act,
|
tiles = ta4_tiles_act,
|
||||||
--after_place_node = after_place_node4,
|
--after_place_node = after_place_node4,
|
||||||
on_rightclick = on_rightclick,
|
on_rightclick = on_rightclick,
|
||||||
tubelib2_on_update2 = tubelib2_on_update2,
|
|
||||||
on_timer = node_timer4,
|
on_timer = node_timer4,
|
||||||
after_dig_node = after_dig_node,
|
after_dig_node = after_dig_node,
|
||||||
on_rotate = screwdriver.disallow,
|
on_rotate = screwdriver.disallow,
|
||||||
networks = nworks,
|
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
on_rotate = screwdriver.disallow,
|
on_rotate = screwdriver.disallow,
|
||||||
diggable = false,
|
diggable = false,
|
||||||
@ -304,10 +266,11 @@ techage.register_node({"techage:t4_pump", "techage:t4_pump_on"}, {
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
Pipe:add_secondary_node_names({
|
-- Pumps have to provide one output and one input side
|
||||||
|
liquid.register_nodes({
|
||||||
"techage:t3_pump", "techage:t3_pump_on",
|
"techage:t3_pump", "techage:t3_pump_on",
|
||||||
"techage:t4_pump", "techage:t4_pump_on",
|
"techage:t4_pump", "techage:t4_pump_on",
|
||||||
})
|
}, Pipe, "pump", {"L", "R"}, {})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "techage:t3_pump 2",
|
output = "techage:t3_pump 2",
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
TechAge
|
TechAge
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Copyright (C) 2019-2020 Joachim Stolberg
|
Copyright (C) 2019-2021 Joachim Stolberg
|
||||||
|
|
||||||
AGPL v3
|
AGPL v3
|
||||||
See LICENSE.txt for more information
|
See LICENSE.txt for more information
|
||||||
@ -18,7 +18,7 @@ local M = minetest.get_meta
|
|||||||
local S = techage.S
|
local S = techage.S
|
||||||
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
|
||||||
local Pipe = techage.LiquidPipe
|
local Pipe = techage.LiquidPipe
|
||||||
local liquid = techage.liquid
|
local liquid = networks.liquid
|
||||||
|
|
||||||
local INV_SIZE = 8
|
local INV_SIZE = 8
|
||||||
local STACKMAX = 99
|
local STACKMAX = 99
|
||||||
@ -170,13 +170,6 @@ local tLiquid = {
|
|||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
local tNetworks = {
|
|
||||||
pipe2 = {
|
|
||||||
sides = techage.networks.AllSides, -- Pipe connection sides
|
|
||||||
ntype = "tank",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
minetest.register_node("techage:ta3_silo", {
|
minetest.register_node("techage:ta3_silo", {
|
||||||
description = S("TA3 Silo"),
|
description = S("TA3 Silo"),
|
||||||
tiles = {
|
tiles = {
|
||||||
@ -203,16 +196,11 @@ minetest.register_node("techage:ta3_silo", {
|
|||||||
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,
|
||||||
tubelib2_on_update2 = function(pos, outdir, tlib2, node)
|
|
||||||
liquid.update_network(pos, outdir)
|
|
||||||
end,
|
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
Pipe:after_dig_node(pos)
|
Pipe:after_dig_node(pos)
|
||||||
techage.remove_node(pos, oldnode, oldmetadata)
|
techage.remove_node(pos, oldnode, oldmetadata)
|
||||||
techage.del_mem(pos)
|
techage.del_mem(pos)
|
||||||
end,
|
end,
|
||||||
liquid = tLiquid,
|
|
||||||
networks = tNetworks,
|
|
||||||
can_dig = can_dig,
|
can_dig = can_dig,
|
||||||
allow_metadata_inventory_put = allow_metadata_inventory_put,
|
allow_metadata_inventory_put = allow_metadata_inventory_put,
|
||||||
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
||||||
@ -249,16 +237,11 @@ minetest.register_node("techage:ta4_silo", {
|
|||||||
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,
|
||||||
tubelib2_on_update2 = function(pos, outdir, tlib2, node)
|
|
||||||
liquid.update_network(pos, outdir)
|
|
||||||
end,
|
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
Pipe:after_dig_node(pos)
|
Pipe:after_dig_node(pos)
|
||||||
techage.remove_node(pos, oldnode, oldmetadata)
|
techage.remove_node(pos, oldnode, oldmetadata)
|
||||||
techage.del_mem(pos)
|
techage.del_mem(pos)
|
||||||
end,
|
end,
|
||||||
liquid = tLiquid,
|
|
||||||
networks = tNetworks,
|
|
||||||
can_dig = can_dig,
|
can_dig = can_dig,
|
||||||
allow_metadata_inventory_put = allow_metadata_inventory_put,
|
allow_metadata_inventory_put = allow_metadata_inventory_put,
|
||||||
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
||||||
@ -335,7 +318,7 @@ techage.register_node({"techage:ta3_silo", "techage:ta4_silo"}, {
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
Pipe:add_secondary_node_names({"techage:ta3_silo", "techage:ta4_silo"})
|
liquid.register_nodes({"techage:ta3_silo", "techage:ta4_silo"}, Pipe, "tank", nil, tLiquid)
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "techage:ta3_silo",
|
output = "techage:ta3_silo",
|
||||||
|
119
liquids/tank.lua
119
liquids/tank.lua
@ -3,7 +3,7 @@
|
|||||||
TechAge
|
TechAge
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Copyright (C) 2019-2020 Joachim Stolberg
|
Copyright (C) 2019-2021 Joachim Stolberg
|
||||||
|
|
||||||
AGPL v3
|
AGPL v3
|
||||||
See LICENSE.txt for more information
|
See LICENSE.txt for more information
|
||||||
@ -15,23 +15,25 @@
|
|||||||
local S2P = minetest.string_to_pos
|
local S2P = minetest.string_to_pos
|
||||||
local P2S = minetest.pos_to_string
|
local P2S = minetest.pos_to_string
|
||||||
local M = minetest.get_meta
|
local M = minetest.get_meta
|
||||||
|
local N = tubelib2.get_node_lvm
|
||||||
|
local LQD = function(pos) return (minetest.registered_nodes[N(pos).name] or {}).liquid end
|
||||||
local S = techage.S
|
local S = techage.S
|
||||||
local Pipe = techage.LiquidPipe
|
local Pipe = techage.LiquidPipe
|
||||||
local liquid = techage.liquid
|
local liquid = networks.liquid
|
||||||
|
|
||||||
local CAPACITY = 1000
|
local CAPACITY = 1000
|
||||||
|
|
||||||
local function on_rightclick(pos, node, clicker)
|
local function on_rightclick(pos, node, clicker)
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
techage.set_activeformspec(pos, clicker)
|
techage.set_activeformspec(pos, clicker)
|
||||||
M(pos):set_string("formspec", liquid.formspec(pos, nvm))
|
M(pos):set_string("formspec", techage.liquid.formspec(pos, nvm))
|
||||||
minetest.get_node_timer(pos):start(2)
|
minetest.get_node_timer(pos):start(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function node_timer(pos, elapsed)
|
local function node_timer(pos, elapsed)
|
||||||
if techage.is_activeformspec(pos) then
|
if techage.is_activeformspec(pos) then
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
M(pos):set_string("formspec", liquid.formspec(pos, nvm))
|
M(pos):set_string("formspec", techage.liquid.formspec(pos, nvm))
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
@ -41,14 +43,19 @@ 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
|
||||||
return liquid.is_empty(pos)
|
return techage.liquid.is_empty(pos)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function peek_liquid(pos)
|
||||||
|
local nvm = techage.get_nvm(pos)
|
||||||
|
return liquid.srv_peek(nvm)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function take_liquid(pos, indir, name, amount)
|
local function take_liquid(pos, indir, name, amount)
|
||||||
amount, name = liquid.srv_take(pos, indir, name, amount)
|
local nvm = techage.get_nvm(pos)
|
||||||
|
amount, name = liquid.srv_take(nvm, name, amount)
|
||||||
if techage.is_activeformspec(pos) then
|
if techage.is_activeformspec(pos) then
|
||||||
local nvm = techage.get_nvm(pos)
|
M(pos):set_string("formspec", techage.liquid.formspec(pos, nvm))
|
||||||
M(pos):set_string("formspec", liquid.formspec(pos, nvm))
|
|
||||||
end
|
end
|
||||||
return amount, name
|
return amount, name
|
||||||
end
|
end
|
||||||
@ -57,10 +64,10 @@ local function put_liquid(pos, indir, name, amount)
|
|||||||
-- check if it is not powder
|
-- check if it is not powder
|
||||||
local ndef = minetest.registered_craftitems[name] or {}
|
local ndef = minetest.registered_craftitems[name] or {}
|
||||||
if not ndef.groups or ndef.groups.powder ~= 1 then
|
if not ndef.groups or ndef.groups.powder ~= 1 then
|
||||||
local leftover = liquid.srv_put(pos, indir, name, amount)
|
local nvm = techage.get_nvm(pos)
|
||||||
|
local leftover = liquid.srv_put(nvm, name, amount, LQD(pos).capa)
|
||||||
if techage.is_activeformspec(pos) then
|
if techage.is_activeformspec(pos) then
|
||||||
local nvm = techage.get_nvm(pos)
|
M(pos):set_string("formspec", techage.liquid.formspec(pos, nvm))
|
||||||
M(pos):set_string("formspec", liquid.formspec(pos, nvm))
|
|
||||||
end
|
end
|
||||||
return leftover
|
return leftover
|
||||||
end
|
end
|
||||||
@ -68,21 +75,14 @@ local function put_liquid(pos, indir, name, amount)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function untake_liquid(pos, indir, name, amount)
|
local function untake_liquid(pos, indir, name, amount)
|
||||||
local leftover = liquid.srv_put(pos, indir, name, amount)
|
local nvm = techage.get_nvm(pos)
|
||||||
|
local leftover = liquid.srv_put(nvm, name, amount, LQD(pos).capa)
|
||||||
if techage.is_activeformspec(pos) then
|
if techage.is_activeformspec(pos) then
|
||||||
local nvm = techage.get_nvm(pos)
|
M(pos):set_string("formspec", techage.liquid.formspec(pos, nvm))
|
||||||
M(pos):set_string("formspec", liquid.formspec(pos, nvm))
|
|
||||||
end
|
end
|
||||||
return leftover
|
return leftover
|
||||||
end
|
end
|
||||||
|
|
||||||
local networks_def = {
|
|
||||||
pipe2 = {
|
|
||||||
sides = techage.networks.AllSides, -- Pipe connection sides
|
|
||||||
ntype = "tank",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
minetest.register_node("techage:ta3_tank", {
|
minetest.register_node("techage:ta3_tank", {
|
||||||
description = S("TA3 Tank"),
|
description = S("TA3 Tank"),
|
||||||
tiles = {
|
tiles = {
|
||||||
@ -101,27 +101,16 @@ minetest.register_node("techage:ta3_tank", {
|
|||||||
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", liquid.formspec(pos, nvm))
|
meta:set_string("formspec", techage.liquid.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,
|
||||||
tubelib2_on_update2 = function(pos, outdir, tlib2, node)
|
|
||||||
liquid.update_network(pos, outdir)
|
|
||||||
end,
|
|
||||||
on_timer = node_timer,
|
on_timer = node_timer,
|
||||||
on_punch = liquid.on_punch,
|
on_punch = techage.liquid.on_punch,
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
Pipe:after_dig_node(pos)
|
Pipe:after_dig_node(pos)
|
||||||
techage.remove_node(pos, oldnode, oldmetadata)
|
techage.remove_node(pos, oldnode, oldmetadata)
|
||||||
end,
|
end,
|
||||||
liquid = {
|
|
||||||
capa = CAPACITY,
|
|
||||||
peek = liquid.srv_peek,
|
|
||||||
put = put_liquid,
|
|
||||||
take = take_liquid,
|
|
||||||
untake = untake_liquid,
|
|
||||||
},
|
|
||||||
networks = networks_def,
|
|
||||||
on_rightclick = on_rightclick,
|
on_rightclick = on_rightclick,
|
||||||
can_dig = can_dig,
|
can_dig = can_dig,
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
@ -131,6 +120,16 @@ minetest.register_node("techage:ta3_tank", {
|
|||||||
sounds = default.node_sound_metal_defaults(),
|
sounds = default.node_sound_metal_defaults(),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
liquid.register_nodes({"techage:ta3_tank"},
|
||||||
|
Pipe, "tank", nil, {
|
||||||
|
capa = CAPACITY,
|
||||||
|
peek = peek_liquid,
|
||||||
|
put = put_liquid,
|
||||||
|
take = take_liquid,
|
||||||
|
untake = untake_liquid,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
minetest.register_node("techage:oiltank", {
|
minetest.register_node("techage:oiltank", {
|
||||||
description = S("Oil Tank"),
|
description = S("Oil Tank"),
|
||||||
tiles = {
|
tiles = {
|
||||||
@ -161,27 +160,16 @@ minetest.register_node("techage:oiltank", {
|
|||||||
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", liquid.formspec(pos, nvm))
|
meta:set_string("formspec", techage.liquid.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,
|
||||||
tubelib2_on_update2 = function(pos, outdir, tlib2, node)
|
|
||||||
liquid.update_network(pos, outdir)
|
|
||||||
end,
|
|
||||||
on_timer = node_timer,
|
on_timer = node_timer,
|
||||||
on_punch = liquid.on_punch,
|
on_punch = techage.liquid.on_punch,
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
Pipe:after_dig_node(pos)
|
Pipe:after_dig_node(pos)
|
||||||
techage.remove_node(pos, oldnode, oldmetadata)
|
techage.remove_node(pos, oldnode, oldmetadata)
|
||||||
end,
|
end,
|
||||||
liquid = {
|
|
||||||
capa = CAPACITY * 4,
|
|
||||||
peek = liquid.srv_peek,
|
|
||||||
put = put_liquid,
|
|
||||||
take = take_liquid,
|
|
||||||
untake = untake_liquid,
|
|
||||||
},
|
|
||||||
networks = networks_def,
|
|
||||||
on_rightclick = on_rightclick,
|
on_rightclick = on_rightclick,
|
||||||
can_dig = can_dig,
|
can_dig = can_dig,
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
@ -191,6 +179,16 @@ minetest.register_node("techage:oiltank", {
|
|||||||
sounds = default.node_sound_metal_defaults(),
|
sounds = default.node_sound_metal_defaults(),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
liquid.register_nodes({"techage:oiltank"},
|
||||||
|
Pipe, "tank", nil, {
|
||||||
|
capa = CAPACITY * 4,
|
||||||
|
peek = peek_liquid,
|
||||||
|
put = put_liquid,
|
||||||
|
take = take_liquid,
|
||||||
|
untake = untake_liquid,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
minetest.register_node("techage:ta4_tank", {
|
minetest.register_node("techage:ta4_tank", {
|
||||||
description = S("TA4 Tank"),
|
description = S("TA4 Tank"),
|
||||||
tiles = {
|
tiles = {
|
||||||
@ -210,13 +208,10 @@ minetest.register_node("techage:ta4_tank", {
|
|||||||
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", liquid.formspec(pos, nvm))
|
meta:set_string("formspec", techage.liquid.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,
|
||||||
tubelib2_on_update2 = function(pos, outdir, tlib2, node)
|
|
||||||
liquid.update_network(pos, outdir)
|
|
||||||
end,
|
|
||||||
on_receive_fields = function(pos, formname, fields, player)
|
on_receive_fields = function(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
|
||||||
@ -226,19 +221,11 @@ minetest.register_node("techage:ta4_tank", {
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
on_timer = node_timer,
|
on_timer = node_timer,
|
||||||
on_punch = liquid.on_punch,
|
on_punch = techage.liquid.on_punch,
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
Pipe:after_dig_node(pos)
|
Pipe:after_dig_node(pos)
|
||||||
techage.remove_node(pos, oldnode, oldmetadata)
|
techage.remove_node(pos, oldnode, oldmetadata)
|
||||||
end,
|
end,
|
||||||
liquid = {
|
|
||||||
capa = CAPACITY * 2,
|
|
||||||
peek = liquid.srv_peek,
|
|
||||||
put = put_liquid,
|
|
||||||
take = take_liquid,
|
|
||||||
untake = untake_liquid,
|
|
||||||
},
|
|
||||||
networks = networks_def,
|
|
||||||
on_rightclick = on_rightclick,
|
on_rightclick = on_rightclick,
|
||||||
can_dig = can_dig,
|
can_dig = can_dig,
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
@ -248,9 +235,17 @@ minetest.register_node("techage:ta4_tank", {
|
|||||||
sounds = default.node_sound_metal_defaults(),
|
sounds = default.node_sound_metal_defaults(),
|
||||||
})
|
})
|
||||||
|
|
||||||
techage.register_node({"techage:ta3_tank", "techage:ta4_tank", "techage:oiltank"}, liquid.recv_message)
|
liquid.register_nodes({"techage:ta4_tank"},
|
||||||
|
Pipe, "tank", nil, {
|
||||||
|
capa = CAPACITY * 2,
|
||||||
|
peek = peek_liquid,
|
||||||
|
put = put_liquid,
|
||||||
|
take = take_liquid,
|
||||||
|
untake = untake_liquid,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
Pipe:add_secondary_node_names({"techage:ta3_tank", "techage:ta4_tank", "techage:oiltank"})
|
techage.register_node({"techage:ta3_tank", "techage:ta4_tank", "techage:oiltank"}, techage.liquid.recv_message)
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "techage:ta3_tank 2",
|
output = "techage:ta3_tank 2",
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
TechAge
|
TechAge
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Copyright (C) 2019-2020 Joachim Stolberg
|
Copyright (C) 2019-2021 Joachim Stolberg
|
||||||
|
|
||||||
AGPL v3
|
AGPL v3
|
||||||
See LICENSE.txt for more information
|
See LICENSE.txt for more information
|
||||||
@ -17,73 +17,7 @@ local P2S = minetest.pos_to_string
|
|||||||
local M = minetest.get_meta
|
local M = minetest.get_meta
|
||||||
local S = techage.S
|
local S = techage.S
|
||||||
local Pipe = techage.LiquidPipe
|
local Pipe = techage.LiquidPipe
|
||||||
local liquid = techage.liquid
|
local liquid = networks.liquid
|
||||||
|
|
||||||
local function switch_node(pos, node)
|
|
||||||
if node.name == "techage:ta3_valve_open" then
|
|
||||||
node.name = "techage:ta3_valve_closed"
|
|
||||||
--node.name = "default:dirt"
|
|
||||||
minetest.swap_node(pos, node)
|
|
||||||
local number = M(pos):get_string("node_number")
|
|
||||||
M(pos):set_string("infotext", S("TA3 Valve closed")..": "..number)
|
|
||||||
Pipe:after_dig_tube(pos, {name = "techage:ta3_valve_open", param2 = node.param2})
|
|
||||||
elseif node.name == "techage:ta3_valve_closed" then
|
|
||||||
node.name = "techage:ta3_valve_open"
|
|
||||||
minetest.swap_node(pos, node)
|
|
||||||
local number = M(pos):get_string("node_number")
|
|
||||||
M(pos):set_string("infotext", S("TA3 Valve open")..": "..number)
|
|
||||||
Pipe:after_place_tube(pos)
|
|
||||||
end
|
|
||||||
minetest.sound_play("techage_valve", {
|
|
||||||
pos = pos,
|
|
||||||
gain = 1,
|
|
||||||
max_hear_distance = 10})
|
|
||||||
end
|
|
||||||
|
|
||||||
local function on_rightclick(pos, node, clicker)
|
|
||||||
if not minetest.is_protected(pos, clicker:get_player_name()) then
|
|
||||||
switch_node(pos, node)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--local function node_timer(pos, elapsed)
|
|
||||||
-- if techage.is_activeformspec(pos) then
|
|
||||||
-- local nvm = techage.get_nvm(pos)
|
|
||||||
-- M(pos):set_string("formspec", liquid.formspec(pos, nvm))
|
|
||||||
-- return true
|
|
||||||
-- end
|
|
||||||
-- return false
|
|
||||||
--end
|
|
||||||
|
|
||||||
--local function can_dig(pos, player)
|
|
||||||
-- if minetest.is_protected(pos, player:get_player_name()) then
|
|
||||||
-- return false
|
|
||||||
-- end
|
|
||||||
-- return liquid.is_empty(pos)
|
|
||||||
--end
|
|
||||||
|
|
||||||
--local function take_liquid(pos, indir, name, amount)
|
|
||||||
-- amount, name = liquid.srv_take(pos, indir, name, amount)
|
|
||||||
-- if techage.is_activeformspec(pos) then
|
|
||||||
-- local nvm = techage.get_nvm(pos)
|
|
||||||
-- M(pos):set_string("formspec", liquid.formspec(pos, nvm))
|
|
||||||
-- end
|
|
||||||
-- return amount, name
|
|
||||||
--end
|
|
||||||
|
|
||||||
--local function put_liquid(pos, indir, name, amount)
|
|
||||||
-- -- check if it is not powder
|
|
||||||
-- local ndef = minetest.registered_craftitems[name] or {}
|
|
||||||
-- if not ndef.groups or ndef.groups.powder ~= 1 then
|
|
||||||
-- local leftover = liquid.srv_put(pos, indir, name, amount)
|
|
||||||
-- if techage.is_activeformspec(pos) then
|
|
||||||
-- local nvm = techage.get_nvm(pos)
|
|
||||||
-- M(pos):set_string("formspec", liquid.formspec(pos, nvm))
|
|
||||||
-- end
|
|
||||||
-- return leftover
|
|
||||||
-- end
|
|
||||||
-- return amount
|
|
||||||
--end
|
|
||||||
|
|
||||||
minetest.register_node("techage:ta3_valve_open", {
|
minetest.register_node("techage:ta3_valve_open", {
|
||||||
description = S("TA Valve"),
|
description = S("TA Valve"),
|
||||||
@ -102,21 +36,24 @@ minetest.register_node("techage:ta3_valve_open", {
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
local meta = M(pos)
|
local meta = M(pos)
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
nvm.liquid = {}
|
|
||||||
local number = techage.add_node(pos, "techage:ta3_valve_closed")
|
local number = techage.add_node(pos, "techage:ta3_valve_closed")
|
||||||
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("infotext", S("TA3 Valve open")..": "..number)
|
meta:set_string("infotext", S("TA3 Valve")..": "..number)
|
||||||
return false
|
return false
|
||||||
end,
|
end,
|
||||||
|
on_rightclick = function(pos, node, clicker)
|
||||||
|
if liquid.turn_valve_off(pos, Pipe, "techage:ta3_valve_closed", "techage:ta3_valve_open") then
|
||||||
|
minetest.sound_play("techage_valve", {
|
||||||
|
pos = pos,
|
||||||
|
gain = 1,
|
||||||
|
max_hear_distance = 10})
|
||||||
|
end
|
||||||
|
end,
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
Pipe:after_dig_tube(pos, oldnode, oldmetadata)
|
Pipe:after_dig_tube(pos, oldnode, oldmetadata)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_rightclick = on_rightclick,
|
|
||||||
|
|
||||||
paramtype2 = "facedir", -- important!
|
paramtype2 = "facedir", -- important!
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
node_box = {
|
node_box = {
|
||||||
@ -146,17 +83,19 @@ minetest.register_node("techage:ta3_valve_closed", {
|
|||||||
"techage_gaspipe_valve_hole.png",
|
"techage_gaspipe_valve_hole.png",
|
||||||
},
|
},
|
||||||
|
|
||||||
tubelib2_on_update2 = function(pos, outdir, tlib2, node)
|
on_rightclick = function(pos, node, clicker)
|
||||||
liquid.update_network(pos, outdir)
|
if liquid.turn_valve_on(pos, Pipe, "techage:ta3_valve_closed", "techage:ta3_valve_open") then
|
||||||
|
minetest.sound_play("techage_valve", {
|
||||||
|
pos = pos,
|
||||||
|
gain = 1,
|
||||||
|
max_hear_distance = 10})
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
Pipe:after_dig_node(pos)
|
Pipe:after_dig_node(pos)
|
||||||
techage.remove_node(pos, oldnode, oldmetadata)
|
techage.remove_node(pos, oldnode, oldmetadata)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_rightclick = on_rightclick,
|
|
||||||
|
|
||||||
paramtype2 = "facedir", -- important!
|
paramtype2 = "facedir", -- important!
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
node_box = {
|
node_box = {
|
||||||
@ -180,10 +119,10 @@ techage.register_node({"techage:ta3_valve_closed", "techage:ta3_valve_open"}, {
|
|||||||
on_recv_message = function(pos, src, topic, payload)
|
on_recv_message = function(pos, src, topic, payload)
|
||||||
local node = techage.get_node_lvm(pos)
|
local node = techage.get_node_lvm(pos)
|
||||||
if topic == "on" and node.name == "techage:ta3_valve_closed" then
|
if topic == "on" and node.name == "techage:ta3_valve_closed" then
|
||||||
switch_node(pos, node)
|
liquid.turn_valve_on(pos, Pipe, "techage:ta3_valve_closed", "techage:ta3_valve_open")
|
||||||
return true
|
return true
|
||||||
elseif topic == "off" and node.name == "techage:ta3_valve_open" then
|
elseif topic == "off" and node.name == "techage:ta3_valve_open" then
|
||||||
switch_node(pos, node)
|
liquid.turn_valve_off(pos, Pipe, "techage:ta3_valve_closed", "techage:ta3_valve_open")
|
||||||
return true
|
return true
|
||||||
elseif topic == "state" then
|
elseif topic == "state" then
|
||||||
if node.name == "techage:ta3_valve_open" then
|
if node.name == "techage:ta3_valve_open" then
|
||||||
@ -196,6 +135,8 @@ techage.register_node({"techage:ta3_valve_closed", "techage:ta3_valve_open"}, {
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
liquid.register_nodes({"techage:ta3_valve_closed"}, Pipe, "special", {}, {})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "techage:ta3_valve_open",
|
output = "techage:ta3_valve_open",
|
||||||
recipe = {
|
recipe = {
|
||||||
|
@ -87,7 +87,7 @@ local function pumping(pos, nvm)
|
|||||||
power.consumer_alive(pos, Cable, CYCLE_TIME)
|
power.consumer_alive(pos, Cable, CYCLE_TIME)
|
||||||
end
|
end
|
||||||
if nvm.running then
|
if nvm.running then
|
||||||
local leftover = liquid.put(pos, 6, "techage:water", 1)
|
local leftover = liquid.put(pos, Pipe, 6, "techage:water", 1)
|
||||||
if leftover and leftover > 0 then
|
if leftover and leftover > 0 then
|
||||||
State:blocked(pos, nvm)
|
State:blocked(pos, nvm)
|
||||||
return
|
return
|
||||||
@ -126,7 +126,6 @@ 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)
|
||||||
Cable:after_dig_node(pos)
|
Cable:after_dig_node(pos)
|
||||||
liquid.after_dig_pump(pos)
|
|
||||||
techage.del_mem(pos)
|
techage.del_mem(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
TechAge
|
TechAge
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Copyright (C) 2019-2020 Joachim Stolberg
|
Copyright (C) 2019-2021 Joachim Stolberg
|
||||||
|
|
||||||
AGPL v3
|
AGPL v3
|
||||||
See LICENSE.txt for more information
|
See LICENSE.txt for more information
|
||||||
@ -17,8 +17,7 @@ local P2S = minetest.pos_to_string
|
|||||||
local M = minetest.get_meta
|
local M = minetest.get_meta
|
||||||
local S = techage.S
|
local S = techage.S
|
||||||
local Pipe = techage.LiquidPipe
|
local Pipe = techage.LiquidPipe
|
||||||
local networks = techage.networks
|
local liquid = networks.liquid
|
||||||
local liquid = techage.liquid
|
|
||||||
|
|
||||||
|
|
||||||
local function orientation(pos, names)
|
local function orientation(pos, names)
|
||||||
@ -40,10 +39,6 @@ local function after_place_node(pos, placer)
|
|||||||
Pipe:after_place_node(pos)
|
Pipe:after_place_node(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function tubelib2_on_update2(pos, dir, tlib2, node)
|
|
||||||
liquid.update_network(pos, dir, tlib2)
|
|
||||||
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)
|
||||||
end
|
end
|
||||||
@ -73,9 +68,7 @@ minetest.register_node("techage:ta3_distiller_base", {
|
|||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = {-1/2, -1/2, -1/2, 1/2, 1/2, 1/2},
|
fixed = {-1/2, -1/2, -1/2, 1/2, 1/2, 1/2},
|
||||||
},
|
},
|
||||||
|
|
||||||
after_place_node = after_place_node,
|
after_place_node = after_place_node,
|
||||||
tubelib2_on_update2 = tubelib2_on_update2,
|
|
||||||
after_dig_node = after_dig_node,
|
after_dig_node = after_dig_node,
|
||||||
|
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
@ -83,15 +76,10 @@ minetest.register_node("techage:ta3_distiller_base", {
|
|||||||
groups = {cracky=2},
|
groups = {cracky=2},
|
||||||
is_ground_content = false,
|
is_ground_content = false,
|
||||||
sounds = default.node_sound_stone_defaults(),
|
sounds = default.node_sound_stone_defaults(),
|
||||||
|
|
||||||
networks = {
|
|
||||||
pipe2 = {
|
|
||||||
sides = {B=1}, -- Pipe connection sides
|
|
||||||
ntype = "pump",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
liquid.register_nodes({"techage:ta3_distiller_base"}, Pipe, "pump", {"B"}, {})
|
||||||
|
|
||||||
minetest.register_node("techage:ta3_distiller1", {
|
minetest.register_node("techage:ta3_distiller1", {
|
||||||
description = S("TA3 Distillation Tower 1"),
|
description = S("TA3 Distillation Tower 1"),
|
||||||
tiles = {"techage_distiller1.png"},
|
tiles = {"techage_distiller1.png"},
|
||||||
@ -112,8 +100,6 @@ minetest.register_node("techage:ta3_distiller1", {
|
|||||||
after_place_node(pos, placer)
|
after_place_node(pos, placer)
|
||||||
return res
|
return res
|
||||||
end,
|
end,
|
||||||
|
|
||||||
tubelib2_on_update2 = tubelib2_on_update2,
|
|
||||||
after_dig_node = after_dig_node,
|
after_dig_node = after_dig_node,
|
||||||
|
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
@ -122,15 +108,10 @@ minetest.register_node("techage:ta3_distiller1", {
|
|||||||
groups = {cracky=2},
|
groups = {cracky=2},
|
||||||
is_ground_content = false,
|
is_ground_content = false,
|
||||||
sounds = default.node_sound_metal_defaults(),
|
sounds = default.node_sound_metal_defaults(),
|
||||||
|
|
||||||
networks = {
|
|
||||||
pipe2 = {
|
|
||||||
sides = {F=1}, -- Pipe connection sides
|
|
||||||
ntype = "tank",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
liquid.register_nodes({"techage:ta3_distiller1"}, Pipe, "pump", {"F"}, {})
|
||||||
|
|
||||||
minetest.register_node("techage:ta3_distiller2", {
|
minetest.register_node("techage:ta3_distiller2", {
|
||||||
description = S("TA3 Distillation Tower 2"),
|
description = S("TA3 Distillation Tower 2"),
|
||||||
tiles = {"techage_distiller2.png"},
|
tiles = {"techage_distiller2.png"},
|
||||||
@ -175,8 +156,6 @@ minetest.register_node("techage:ta3_distiller3", {
|
|||||||
local res = orientation(pos, {"techage:ta3_distiller2"})
|
local res = orientation(pos, {"techage:ta3_distiller2"})
|
||||||
return res
|
return res
|
||||||
end,
|
end,
|
||||||
|
|
||||||
tubelib2_on_update2 = tubelib2_on_update2,
|
|
||||||
after_dig_node = after_dig_node,
|
after_dig_node = after_dig_node,
|
||||||
|
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
@ -185,15 +164,10 @@ minetest.register_node("techage:ta3_distiller3", {
|
|||||||
groups = {cracky=2},
|
groups = {cracky=2},
|
||||||
is_ground_content = false,
|
is_ground_content = false,
|
||||||
sounds = default.node_sound_metal_defaults(),
|
sounds = default.node_sound_metal_defaults(),
|
||||||
|
|
||||||
networks = {
|
|
||||||
pipe2 = {
|
|
||||||
sides = {B=1}, -- Pipe connection sides
|
|
||||||
ntype = "pump",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
liquid.register_nodes({"techage:ta3_distiller3"}, Pipe, "pump", {"B"}, {})
|
||||||
|
|
||||||
minetest.register_node("techage:ta3_distiller4", {
|
minetest.register_node("techage:ta3_distiller4", {
|
||||||
description = S("TA3 Distillation Tower 4"),
|
description = S("TA3 Distillation Tower 4"),
|
||||||
tiles = {"techage_distiller4.png"},
|
tiles = {"techage_distiller4.png"},
|
||||||
@ -213,8 +187,6 @@ minetest.register_node("techage:ta3_distiller4", {
|
|||||||
after_place_node(pos, placer)
|
after_place_node(pos, placer)
|
||||||
return res
|
return res
|
||||||
end,
|
end,
|
||||||
|
|
||||||
tubelib2_on_update2 = tubelib2_on_update2,
|
|
||||||
after_dig_node = after_dig_node,
|
after_dig_node = after_dig_node,
|
||||||
|
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
@ -223,40 +195,28 @@ minetest.register_node("techage:ta3_distiller4", {
|
|||||||
groups = {cracky=2},
|
groups = {cracky=2},
|
||||||
is_ground_content = false,
|
is_ground_content = false,
|
||||||
sounds = default.node_sound_metal_defaults(),
|
sounds = default.node_sound_metal_defaults(),
|
||||||
|
|
||||||
networks = {
|
|
||||||
pipe2 = {
|
|
||||||
sides = {U=1}, -- Pipe connection sides
|
|
||||||
ntype = "pump",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
liquid.register_nodes({"techage:ta3_distiller4"}, Pipe, "pump", {"U"}, {})
|
||||||
|
|
||||||
Pipe:add_secondary_node_names({
|
local Liquids = {"techage:bitumen", "techage:fueloil", "techage:naphtha", "techage:gasoline", "techage:gas"}
|
||||||
"techage:ta3_distiller_base", "techage:ta3_distiller1",
|
local YPos = {-1, 2, 4, 6, 7}
|
||||||
"techage:ta3_distiller3", "techage:ta3_distiller4",
|
|
||||||
})
|
|
||||||
|
|
||||||
local Liquids = {
|
|
||||||
[-1] = "techage:bitumen",
|
|
||||||
[2] = "techage:fueloil",
|
|
||||||
[4] = "techage:naphtha",
|
|
||||||
[6] = "techage:gasoline",
|
|
||||||
[7] = "techage:gas",
|
|
||||||
}
|
|
||||||
|
|
||||||
techage.register_node({"techage:ta3_distiller1"}, {
|
techage.register_node({"techage:ta3_distiller1"}, {
|
||||||
on_transfer = function(pos, in_dir, topic, payload)
|
on_transfer = function(pos, in_dir, topic, payload)
|
||||||
if topic == "put" then
|
if topic == "put" then
|
||||||
local leftover = 0
|
local nvm = techage.get_nvm(pos)
|
||||||
local outdir = M(pos):get_int("outdir")
|
nvm.idx = nvm.idx or 1
|
||||||
for _,y in ipairs({-1, 2, 4, 6, 7}) do
|
local outdir
|
||||||
local pos2 = {x = pos.x, y = pos.y + y, z = pos.z}
|
if nvm.idx == 5 then
|
||||||
if y == 7 then
|
outdir = 6 -- up
|
||||||
outdir = 6
|
else
|
||||||
end
|
outdir = M(pos):get_int("outdir")
|
||||||
leftover = leftover + liquid.put(pos2, outdir, Liquids[y], 1)
|
end
|
||||||
|
local pos2 = {x = pos.x, y = pos.y + YPos[nvm.idx], z = pos.z}
|
||||||
|
local leftover = liquid.put(pos2, Pipe, outdir, Liquids[nvm.idx], 1)
|
||||||
|
if leftover == 0 then
|
||||||
|
nvm.idx = (nvm.idx % 5) + 1
|
||||||
end
|
end
|
||||||
return leftover
|
return leftover
|
||||||
end
|
end
|
||||||
|
@ -238,7 +238,7 @@ local tubing = {
|
|||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
if not nvm.assemble_locked then
|
if not nvm.assemble_locked then
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
if meta:get_int("push_dir") == in_dir or in_dir == 5 then
|
if meta:get_int("push_dir") == in_dir then
|
||||||
local inv = M(pos):get_inventory()
|
local inv = M(pos):get_inventory()
|
||||||
CRD(pos).State:start_if_standby(pos)
|
CRD(pos).State:start_if_standby(pos)
|
||||||
return techage.put_items(inv, "src", stack)
|
return techage.put_items(inv, "src", stack)
|
||||||
@ -299,6 +299,7 @@ local _, node_name_ta3, _ =
|
|||||||
sounds = default.node_sound_wood_defaults(),
|
sounds = default.node_sound_wood_defaults(),
|
||||||
num_items = {0,1,1,1},
|
num_items = {0,1,1,1},
|
||||||
power_consumption = {0,10,16,24},
|
power_consumption = {0,10,16,24},
|
||||||
|
tube_sides = {L=1, R=1},
|
||||||
},
|
},
|
||||||
{false, false, true, false}) -- TA3 only
|
{false, false, true, false}) -- TA3 only
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ local OIL_MAX = 20000
|
|||||||
local DEPTH_MIN = 16
|
local DEPTH_MIN = 16
|
||||||
local DEPTH_MAX = 25*16
|
local DEPTH_MAX = 25*16
|
||||||
local DEPTH_STEP = 16
|
local DEPTH_STEP = 16
|
||||||
local YPOS_MAX = -6*16 -- oil can found below this level
|
local YPOS_MAX = -6*16 -- oil can't found below this level
|
||||||
local OIL_BUBBLE_SIZE = 4096
|
local OIL_BUBBLE_SIZE = 4096
|
||||||
|
|
||||||
local seed = tonumber(minetest.settings:get("techage_oil_exploration_seed")) or 1234 -- confidental!
|
local seed = tonumber(minetest.settings:get("techage_oil_exploration_seed")) or 1234 -- confidental!
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
TechAge
|
TechAge
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Copyright (C) 2019-2020 Joachim Stolberg
|
Copyright (C) 2019-2021 Joachim Stolberg
|
||||||
|
|
||||||
AGPL v3
|
AGPL v3
|
||||||
See LICENSE.txt for more information
|
See LICENSE.txt for more information
|
||||||
@ -18,7 +18,7 @@ local M = minetest.get_meta
|
|||||||
local P = minetest.string_to_pos
|
local P = minetest.string_to_pos
|
||||||
local S = techage.S
|
local S = techage.S
|
||||||
local Pipe = techage.LiquidPipe
|
local Pipe = techage.LiquidPipe
|
||||||
local liquid = techage.liquid
|
local liquid = networks.liquid
|
||||||
|
|
||||||
-- Consumer Related Data
|
-- Consumer Related Data
|
||||||
local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).consumer end
|
local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).consumer end
|
||||||
@ -103,7 +103,7 @@ end
|
|||||||
|
|
||||||
local function pumping(pos, crd, meta, nvm)
|
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, Pipe, 6, "techage:oil_source", 1)
|
||||||
if leftover and leftover > 0 then
|
if leftover and leftover > 0 then
|
||||||
crd.State:blocked(pos, nvm)
|
crd.State:blocked(pos, nvm)
|
||||||
stop_sound(pos)
|
stop_sound(pos)
|
||||||
@ -211,12 +211,6 @@ local _, node_name_ta3, _ =
|
|||||||
end
|
end
|
||||||
Pipe:after_place_node(pos)
|
Pipe:after_place_node(pos)
|
||||||
end,
|
end,
|
||||||
networks = {
|
|
||||||
pipe2 = {
|
|
||||||
sides = {U = 1}, -- Pipe connection side
|
|
||||||
ntype = "pump",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
power_sides = {F=1, B=1, L=1, R=1, D=1},
|
power_sides = {F=1, B=1, L=1, R=1, D=1},
|
||||||
on_rightclick = on_rightclick,
|
on_rightclick = on_rightclick,
|
||||||
on_receive_fields = on_receive_fields,
|
on_receive_fields = on_receive_fields,
|
||||||
@ -244,5 +238,5 @@ minetest.register_craft({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
Pipe:add_secondary_node_names({"techage:ta3_pumpjack_pas", "techage:ta3_pumpjack_act"})
|
liquid.register_nodes({"techage:ta3_pumpjack_pas", "techage:ta3_pumpjack_act"}, Pipe, "pump", {"U"}, {})
|
||||||
|
|
||||||
|
257
oil/reboiler.lua
257
oil/reboiler.lua
@ -3,7 +3,7 @@
|
|||||||
TechAge
|
TechAge
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Copyright (C) 2019-2020 Joachim Stolberg
|
Copyright (C) 2019-2021 Joachim Stolberg
|
||||||
|
|
||||||
AGPL v3
|
AGPL v3
|
||||||
See LICENSE.txt for more information
|
See LICENSE.txt for more information
|
||||||
@ -16,15 +16,14 @@ local S2P = minetest.string_to_pos
|
|||||||
local P2S = minetest.pos_to_string
|
local P2S = minetest.pos_to_string
|
||||||
local M = minetest.get_meta
|
local M = minetest.get_meta
|
||||||
local S = techage.S
|
local S = techage.S
|
||||||
|
local Flip = networks.Flip
|
||||||
local Pipe = techage.LiquidPipe
|
local Pipe = techage.LiquidPipe
|
||||||
local networks = techage.networks
|
|
||||||
local liquid = techage.liquid
|
|
||||||
local Flip = techage.networks.Flip
|
|
||||||
local Cable = techage.ElectricCable
|
local Cable = techage.ElectricCable
|
||||||
local power = techage.power
|
local liquid = networks.liquid
|
||||||
|
local power = networks.power
|
||||||
|
|
||||||
local CYCLE_TIME = 16
|
local CYCLE_TIME = 2
|
||||||
local CAPA = 12
|
local WAITING_CYCLES = 5 -- in case BLOCKED
|
||||||
local PWR_NEEDED = 14
|
local PWR_NEEDED = 14
|
||||||
|
|
||||||
local function play_sound(pos)
|
local function play_sound(pos)
|
||||||
@ -51,90 +50,98 @@ end
|
|||||||
|
|
||||||
local function swap_node(pos, on)
|
local function swap_node(pos, on)
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
if on then
|
local node = techage.get_node_lvm(pos)
|
||||||
local node = techage.get_node_lvm(pos)
|
if on and node.name == "techage:ta3_reboiler" then
|
||||||
node.name = "techage:ta3_reboiler_on"
|
node.name = "techage:ta3_reboiler_on"
|
||||||
minetest.swap_node(pos, node)
|
minetest.swap_node(pos, node)
|
||||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
|
||||||
play_sound(pos)
|
play_sound(pos)
|
||||||
elseif not on and nvm.running then
|
elseif not on and node.name == "techage:ta3_reboiler_on" then
|
||||||
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()
|
|
||||||
nvm.running = false
|
|
||||||
power.consumer_stop(pos, Cable)
|
|
||||||
stop_sound(pos)
|
stop_sound(pos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_power(pos)
|
local function pump_cmnd(pos)
|
||||||
swap_node(pos, true)
|
local leftover = techage.transfer(
|
||||||
end
|
|
||||||
|
|
||||||
local function on_nopower(pos)
|
|
||||||
swap_node(pos, false)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function is_running(pos, nvm)
|
|
||||||
return nvm.running
|
|
||||||
end
|
|
||||||
|
|
||||||
local function pump_cmnd(pos, cmnd, payload)
|
|
||||||
return techage.transfer(
|
|
||||||
pos,
|
pos,
|
||||||
"R", -- outdir
|
"R", -- outdir
|
||||||
cmnd, -- topic
|
"put", -- topic
|
||||||
payload, -- payload
|
nil, -- payload
|
||||||
Pipe, -- Pipe
|
Pipe, -- Pipe
|
||||||
{"techage:ta3_distiller1"})
|
{"techage:ta3_distiller1"})
|
||||||
|
|
||||||
|
-- number of processed oil items
|
||||||
|
return 1 - (tonumber(leftover) or 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function node_timer(pos, elapsed)
|
local function new_state(pos, nvm, state)
|
||||||
local nvm = techage.get_nvm(pos)
|
if nvm.state ~= state then
|
||||||
nvm.liquid = nvm.liquid or {}
|
nvm.state = state
|
||||||
nvm.liquid.amount = nvm.liquid.amount or 0
|
M(pos):set_string("infotext", S("TA3 Oil Reboiler") .. ": " .. techage.StateStrings[state])
|
||||||
|
swap_node(pos, state == techage.RUNNING)
|
||||||
if not nvm.error or nvm.error == 0 then
|
|
||||||
power.consumer_alive(pos, Cable, CYCLE_TIME)
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if nvm.liquid.amount >= 5 and nvm.liquid.name == "techage:oil_source" then
|
local function on_timer(pos)
|
||||||
nvm.liquid.amount = nvm.liquid.amount - 5
|
local nvm = techage.get_nvm(pos)
|
||||||
local leftover = pump_cmnd(pos, "put")
|
nvm.oil_amount = nvm.oil_amount or 0
|
||||||
if (tonumber(leftover) or 1) > 0 then
|
|
||||||
nvm.liquid.amount = nvm.liquid.amount + 5
|
-- Power handling
|
||||||
nvm.error = 2 -- = 2 pump cycles
|
if nvm.state == techage.STOPPED then
|
||||||
M(pos):set_string("infotext", S("TA3 Oil Reboiler: blocked"))
|
local consumed = power.consume_power(pos, Cable, nil, PWR_NEEDED)
|
||||||
swap_node(pos, false)
|
if consumed == PWR_NEEDED then
|
||||||
return false
|
new_state(pos, nvm, techage.RUNNING)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
elseif nvm.state == techage.RUNNING then
|
||||||
|
local consumed = power.consume_power(pos, Cable, nil, PWR_NEEDED)
|
||||||
|
if consumed < PWR_NEEDED then
|
||||||
|
local nvm = techage.get_nvm(pos)
|
||||||
|
new_state(pos, nvm, techage.STOPPED)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
elseif nvm.state == techage.BLOCKED or nvm.state == techage.STANDBY then
|
||||||
|
if not power.power_available(pos, Cable) then
|
||||||
|
local nvm = techage.get_nvm(pos)
|
||||||
|
new_state(pos, nvm, techage.STOPPED)
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
swap_node(pos, false)
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
local function start_node(pos)
|
-- Oil handling
|
||||||
local nvm = techage.get_nvm(pos)
|
if nvm.state == techage.RUNNING then
|
||||||
if nvm.running then return end
|
if nvm.oil_amount >= 1 then
|
||||||
|
local processed = pump_cmnd(pos)
|
||||||
nvm.liquid = nvm.liquid or {}
|
nvm.oil_amount = nvm.oil_amount - processed
|
||||||
nvm.liquid.amount = nvm.liquid.amount or 0
|
nvm.waiting_cycles = WAITING_CYCLES
|
||||||
if nvm.liquid.amount >= 5 and nvm.liquid.name == "techage:oil_source" then
|
if processed == 0 then
|
||||||
if power.power_available(pos, Cable) then
|
new_state(pos, nvm, techage.BLOCKED)
|
||||||
if node_timer(pos, CYCLE_TIME) then
|
else
|
||||||
nvm.running = true
|
new_state(pos, nvm, techage.RUNNING)
|
||||||
power.consumer_start(pos, Cable, CYCLE_TIME)
|
end
|
||||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
else
|
||||||
|
nvm.waiting_cycles = nvm.waiting_cycles - 1
|
||||||
|
if nvm.waiting_cycles <= 0 then
|
||||||
|
new_state(pos, nvm, techage.STANDBY)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
elseif nvm.state == techage.BLOCKED then
|
||||||
|
nvm.waiting_cycles = nvm.waiting_cycles - 1
|
||||||
|
if nvm.waiting_cycles <= 0 then
|
||||||
|
new_state(pos, nvm, techage.RUNNING)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
-- STANDBY: 'put' will trigger the state change
|
||||||
end
|
end
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local function after_place_node(pos)
|
local function after_place_node(pos)
|
||||||
|
local nvm = techage.get_nvm(pos)
|
||||||
|
new_state(pos, nvm, techage.STOPPED)
|
||||||
Pipe:after_place_node(pos)
|
Pipe:after_place_node(pos)
|
||||||
Cable:after_place_node(pos)
|
Cable.after_place_node(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function after_dig_node(pos, oldnode)
|
local function after_dig_node(pos, oldnode)
|
||||||
@ -143,51 +150,13 @@ local function after_dig_node(pos, oldnode)
|
|||||||
techage.del_mem(pos)
|
techage.del_mem(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function tubelib2_on_update2(pos, outdir, tlib2, node)
|
local function on_rightclick(pos, node, clicker)
|
||||||
if tlib2.tube_type == "pipe2" then
|
local nvm = techage.get_nvm(pos)
|
||||||
liquid.update_network(pos, outdir, tlib2)
|
nvm.oil_amount = 0
|
||||||
else
|
new_state(pos, nvm, techage.STOPPED)
|
||||||
power.update_network(pos, outdir, tlib2)
|
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local liquid_def = {
|
|
||||||
capa = CAPA,
|
|
||||||
peek = liquid.srv_peek,
|
|
||||||
put = function(pos, indir, name, amount)
|
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
if nvm.error and nvm.error > 0 then
|
|
||||||
nvm.error = nvm.error - 1
|
|
||||||
if nvm.error <= 0 then
|
|
||||||
M(pos):set_string("infotext", S("TA3 Oil Reboiler"))
|
|
||||||
start_node(pos)
|
|
||||||
return liquid.srv_put(pos, indir, name, amount)
|
|
||||||
else
|
|
||||||
return amount
|
|
||||||
end
|
|
||||||
else
|
|
||||||
start_node(pos)
|
|
||||||
return liquid.srv_put(pos, indir, name, amount)
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
take = liquid.srv_take,
|
|
||||||
}
|
|
||||||
|
|
||||||
local net_def = {
|
|
||||||
pipe2 = {
|
|
||||||
sides = {L = true, R = true}, -- Pipe connection sides
|
|
||||||
ntype = "tank",
|
|
||||||
},
|
|
||||||
ele1 = {
|
|
||||||
sides = techage.networks.AllSides, -- Cable connection sides
|
|
||||||
ntype = "con1",
|
|
||||||
on_power = on_power,
|
|
||||||
on_nopower = on_nopower,
|
|
||||||
nominal = PWR_NEEDED,
|
|
||||||
is_running = is_running,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
minetest.register_node("techage:ta3_reboiler", {
|
minetest.register_node("techage:ta3_reboiler", {
|
||||||
description = S("TA3 Oil Reboiler"),
|
description = S("TA3 Oil Reboiler"),
|
||||||
tiles = {
|
tiles = {
|
||||||
@ -200,26 +169,10 @@ minetest.register_node("techage:ta3_reboiler", {
|
|||||||
"techage_filling_ta3.png^techage_appl_reboiler.png^techage_frame_ta3.png",
|
"techage_filling_ta3.png^techage_appl_reboiler.png^techage_frame_ta3.png",
|
||||||
},
|
},
|
||||||
|
|
||||||
after_place_node = function(pos, placer)
|
on_timer = on_timer,
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
nvm.liquid = {}
|
|
||||||
local meta = M(pos)
|
|
||||||
meta:set_string("infotext", S("TA3 Oil Reboiler"))
|
|
||||||
meta:set_int("outdir", networks.side_to_outdir(pos, "R"))
|
|
||||||
local number = techage.add_node(pos, "techage:ta3_reboiler")
|
|
||||||
meta:set_string("node_number", number)
|
|
||||||
meta:set_string("owner", placer:get_player_name())
|
|
||||||
Pipe:after_place_node(pos)
|
|
||||||
power.after_place_node(pos)
|
|
||||||
end,
|
|
||||||
|
|
||||||
tubelib2_on_update2 = tubelib2_on_update2,
|
|
||||||
on_timer = node_timer,
|
|
||||||
after_place_node = after_place_node,
|
after_place_node = after_place_node,
|
||||||
after_dig_node = after_dig_node,
|
after_dig_node = after_dig_node,
|
||||||
after_dig_node = after_dig_node,
|
on_rightclick = on_rightclick,
|
||||||
liquid = liquid_def,
|
|
||||||
networks = net_def,
|
|
||||||
|
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
on_rotate = screwdriver.disallow,
|
on_rotate = screwdriver.disallow,
|
||||||
@ -258,10 +211,8 @@ minetest.register_node("techage:ta3_reboiler_on", {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
tubelib2_on_update2 = tubelib2_on_update2,
|
on_timer = on_timer,
|
||||||
on_timer = node_timer,
|
on_rightclick = on_rightclick,
|
||||||
liquid = liquid_def,
|
|
||||||
networks = net_def,
|
|
||||||
|
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
on_rotate = screwdriver.disallow,
|
on_rotate = screwdriver.disallow,
|
||||||
@ -271,25 +222,43 @@ minetest.register_node("techage:ta3_reboiler_on", {
|
|||||||
sounds = default.node_sound_metal_defaults(),
|
sounds = default.node_sound_metal_defaults(),
|
||||||
})
|
})
|
||||||
|
|
||||||
Pipe:add_secondary_node_names({"techage:ta3_reboiler", "techage:ta3_reboiler_on"})
|
local liquid_def = {
|
||||||
Cable:add_secondary_node_names({"techage:ta3_reboiler", "techage:ta3_reboiler_on"})
|
peek = function(pos)
|
||||||
|
local nvm = techage.get_nvm(pos)
|
||||||
|
return liquid.srv_peek(nvm)
|
||||||
|
end,
|
||||||
|
put = function(pos, indir, name, amount)
|
||||||
|
local nvm = techage.get_nvm(pos)
|
||||||
|
nvm.oil_amount = nvm.oil_amount or 0
|
||||||
|
|
||||||
|
if nvm.state == techage.STANDBY or nvm.state == techage.RUNNING then
|
||||||
|
if name == "techage:oil_source" and amount > 0 then
|
||||||
|
if nvm.state == techage.STANDBY then
|
||||||
|
new_state(pos, nvm, techage.RUNNING)
|
||||||
|
end
|
||||||
|
-- Take one oil item every 2 cycles
|
||||||
|
-- Hint: We have to take two items, because the pump will pause for 4 cycles,
|
||||||
|
-- if nothing is taken.
|
||||||
|
nvm.take = nvm.take ~= true
|
||||||
|
if nvm.take and nvm.oil_amount < 5 then
|
||||||
|
nvm.oil_amount = nvm.oil_amount + 2
|
||||||
|
return amount - 2
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return amount
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
liquid.register_nodes({"techage:ta3_reboiler", "techage:ta3_reboiler_on"}, Pipe, "tank", {"L", "R"}, liquid_def)
|
||||||
|
power.register_nodes({"techage:ta3_reboiler", "techage:ta3_reboiler_on"}, Cable, "con")
|
||||||
|
|
||||||
techage.register_node({"techage:ta3_reboiler", "techage:ta3_reboiler_on"}, {
|
techage.register_node({"techage:ta3_reboiler", "techage:ta3_reboiler_on"}, {
|
||||||
on_recv_message = function(pos, src, topic, payload)
|
on_recv_message = function(pos, src, topic, payload)
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
if topic == "on" then
|
if topic == "state" then
|
||||||
start_node(pos)
|
nvm.state = nvm.state or techage.STOPPED
|
||||||
return true
|
return techage.StateStrings[nvm.state]
|
||||||
elseif topic == "off" then
|
|
||||||
swap_node(pos, false)
|
|
||||||
return true
|
|
||||||
elseif topic == "state" then
|
|
||||||
if nvm.error and nvm.error > 0 then
|
|
||||||
return "blocked"
|
|
||||||
elseif nvm.running then
|
|
||||||
return "running"
|
|
||||||
end
|
|
||||||
return "stopped"
|
|
||||||
else
|
else
|
||||||
return "unsupported"
|
return "unsupported"
|
||||||
end
|
end
|
||||||
|
@ -37,6 +37,8 @@ local Cable = tubelib2.Tube:new({
|
|||||||
minetest.swap_node(pos, {name = name, param2 = param2 % 32})
|
minetest.swap_node(pos, {name = name, param2 = param2 % 32})
|
||||||
elseif name == "techage:power_line" or name == "techage:power_lineS" or name == "techage:power_lineA" then
|
elseif name == "techage:power_line" or name == "techage:power_lineS" or name == "techage:power_lineA" then
|
||||||
minetest.swap_node(pos, {name = "techage:power_line"..tube_type, param2 = param2 % 32})
|
minetest.swap_node(pos, {name = "techage:power_line"..tube_type, param2 = param2 % 32})
|
||||||
|
elseif name == "techage:power_pole2" then
|
||||||
|
-- nothing
|
||||||
elseif not networks.hidden_name(pos) then
|
elseif not networks.hidden_name(pos) then
|
||||||
minetest.swap_node(pos, {name = "techage:electric_cable"..tube_type, param2 = param2 % 32})
|
minetest.swap_node(pos, {name = "techage:electric_cable"..tube_type, param2 = param2 % 32})
|
||||||
end
|
end
|
||||||
@ -47,7 +49,7 @@ local Cable = tubelib2.Tube:new({
|
|||||||
|
|
||||||
-- Enable hidden cables
|
-- Enable hidden cables
|
||||||
networks.use_metadata(Cable)
|
networks.use_metadata(Cable)
|
||||||
networks.register_hidden_message("Use the tool to remove the node.")
|
networks.register_hidden_message("Use the trowel tool to remove the node.")
|
||||||
networks.register_filling_items(techage.FILLING_ITEMS)
|
networks.register_filling_items(techage.FILLING_ITEMS)
|
||||||
|
|
||||||
-- Use global callback instead of node related functions
|
-- Use global callback instead of node related functions
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
TechAge
|
TechAge
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Copyright (C) 2019-2020 Joachim Stolberg
|
Copyright (C) 2019-2021 Joachim Stolberg
|
||||||
|
|
||||||
AGPL v3
|
AGPL v3
|
||||||
See LICENSE.txt for more information
|
See LICENSE.txt for more information
|
||||||
@ -24,10 +24,6 @@ local in_range = techage.in_range
|
|||||||
local power = networks.power
|
local power = networks.power
|
||||||
techage.power = {}
|
techage.power = {}
|
||||||
|
|
||||||
-- Charge termination areas
|
|
||||||
local Cp2Idx = {["40% - 60%"] = 1, ["60% - 80%"] = 2, ["80% - 100%"] = 3}
|
|
||||||
|
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-- Helper function
|
-- Helper function
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
@ -131,8 +127,8 @@ function techage.formspec_charging_bar(pos, x, y, label, data)
|
|||||||
|
|
||||||
if data then
|
if data then
|
||||||
charging = data.provided - data.consumed
|
charging = data.provided - data.consumed
|
||||||
consumed = data.consumed
|
consumed = round(data.consumed)
|
||||||
available = data.available
|
available = round(data.available)
|
||||||
if charging > 0 then
|
if charging > 0 then
|
||||||
percent = 50 + (charging / data.available * 50)
|
percent = 50 + (charging / data.available * 50)
|
||||||
elseif charging < 0 then
|
elseif charging < 0 then
|
||||||
@ -159,26 +155,6 @@ function techage.formspec_storage_bar(pos, x, y, label, curr_load, max_load)
|
|||||||
"container_end[]"
|
"container_end[]"
|
||||||
end
|
end
|
||||||
|
|
||||||
function techage.formspec_charge_termination(pos, x, y, label, value, running)
|
|
||||||
local idx = Cp2Idx[value] or 2
|
|
||||||
value = value or 0
|
|
||||||
|
|
||||||
if running then
|
|
||||||
return "container[" .. x .. "," .. y .. "]" ..
|
|
||||||
"box[0,0;3.2,1.5;#395c74]" ..
|
|
||||||
"label[0.2,0;" .. label .. "]" ..
|
|
||||||
"box[0.2,0.6;2.7,0.7;#000000]" ..
|
|
||||||
"label[0.3,0.75;" .. value .. "]" ..
|
|
||||||
"container_end[]"
|
|
||||||
else
|
|
||||||
return "container[" .. x .. "," .. y .. "]" ..
|
|
||||||
"box[0,0;3.2,1.5;#395c74]" ..
|
|
||||||
"label[0.2,0;" .. label .. "]" ..
|
|
||||||
"dropdown[0.2,0.6;3.0;termpoint;40% - 60%,60% - 80%,80% - 100%;" .. idx .. "]" ..
|
|
||||||
"container_end[]"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-- API formspec functions
|
-- API formspec functions
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
@ -195,33 +171,83 @@ function techage.storage_formspec(self, pos, nvm, label, netw_data, curr_load, m
|
|||||||
"tooltip[2.7,2;1,1;" .. self:get_state_tooltip(nvm) .. "]"
|
"tooltip[2.7,2;1,1;" .. self:get_state_tooltip(nvm) .. "]"
|
||||||
end
|
end
|
||||||
|
|
||||||
function techage.generator_formspec(self, pos, nvm, label, provided, max_available, running)
|
function techage.generator_formspec(self, pos, nvm, label, provided, max_available)
|
||||||
return "size[6,4]" ..
|
return "size[5,4]" ..
|
||||||
default.gui_bg ..
|
default.gui_bg ..
|
||||||
default.gui_bg_img ..
|
default.gui_bg_img ..
|
||||||
default.gui_slots ..
|
default.gui_slots ..
|
||||||
"box[0,-0.1;5.8,0.5;#c6e8ff]" ..
|
"box[0,-0.1;4.8,0.5;#c6e8ff]" ..
|
||||||
"label[0.2,-0.1;" .. minetest.colorize( "#000000", label) .. "]" ..
|
"label[0.2,-0.1;" .. minetest.colorize( "#000000", label) .. "]" ..
|
||||||
techage.formspec_power_bar(pos, 0, 0.8, S("power"), provided, max_available) ..
|
techage.formspec_power_bar(pos, 0, 0.8, S("power"), provided, max_available) ..
|
||||||
"image_button[3.8,2.9;1,1;" .. self:get_state_button_image(nvm) .. ";state_button;]" ..
|
"image_button[3.2,2.0;1,1;" .. self:get_state_button_image(nvm) .. ";state_button;]" ..
|
||||||
"tooltip[3.8,2.9;1,1;" .. self:get_state_tooltip(nvm) .. "]" ..
|
"tooltip[3.2,2.0;1,1;" .. self:get_state_tooltip(nvm) .. "]"
|
||||||
techage.formspec_charge_termination(pos, 2.6, 0.8, S("Charge termination"), nvm.termpoint, running)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function techage.evaluate_charge_termination(nvm, fields)
|
function techage.generator_settings(tier, available)
|
||||||
if fields.termpoint and not nvm.running then
|
if tier == "ta3" then
|
||||||
nvm.termpoint = fields.termpoint
|
return {
|
||||||
if fields.termpoint == "40% - 60%" then
|
{
|
||||||
nvm.termpoint1 = 0.4
|
type = "const",
|
||||||
nvm.termpoint2 = 0.6
|
name = "available",
|
||||||
elseif fields.termpoint == "60% - 80%" then
|
label = S("Maximum output [ku]"),
|
||||||
nvm.termpoint1 = 0.6
|
tooltip = S("The maximum power the generator can provide"),
|
||||||
nvm.termpoint2 = 0.8
|
value = available,
|
||||||
elseif fields.termpoint == "80% - 100%" then
|
},
|
||||||
nvm.termpoint1 = 0.8
|
{
|
||||||
nvm.termpoint2 = 1.0
|
type = "output",
|
||||||
end
|
name = "provided",
|
||||||
return true
|
label = S("Current output [ku]"),
|
||||||
|
tooltip = S("The current power the generator provides"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type = "dropdown",
|
||||||
|
choices = "40% - 60%,60% - 80%,80% - 100%",
|
||||||
|
name = "termpoint",
|
||||||
|
label = S("Charge termination"),
|
||||||
|
tooltip = S("Range in which the generator reduces its power"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return {
|
||||||
|
{
|
||||||
|
type = "const",
|
||||||
|
name = "available",
|
||||||
|
label = S("Maximum output [ku]"),
|
||||||
|
tooltip = S("The maximum power the generator can provide"),
|
||||||
|
value = available,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type = "output",
|
||||||
|
name = "provided",
|
||||||
|
label = S("Current output [ku]"),
|
||||||
|
tooltip = S("The current power the generator provides"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type = "dropdown",
|
||||||
|
choices = "40% - 60%,60% - 80%,80% - 100%",
|
||||||
|
name = "termpoint",
|
||||||
|
label = S("Charge termination"),
|
||||||
|
tooltip = S("Range in which the generator reduces its power"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function techage.evaluate_charge_termination(nvm, meta)
|
||||||
|
local termpoint = meta:get_string("termpoint")
|
||||||
|
if termpoint == "40% - 60%" then
|
||||||
|
meta:set_string("termpoint1", 0.4)
|
||||||
|
meta:set_string("termpoint2", 0.6)
|
||||||
|
elseif termpoint == "60% - 80%" then
|
||||||
|
meta:set_string("termpoint1", 0.6)
|
||||||
|
meta:set_string("termpoint2", 0.8)
|
||||||
|
elseif termpoint == "80% - 100%" then
|
||||||
|
meta:set_string("termpoint1", 0.8)
|
||||||
|
meta:set_string("termpoint2", 1.0)
|
||||||
|
else
|
||||||
|
meta:set_string("termpoint", "80% - 100%")
|
||||||
|
meta:set_string("termpoint1", 0.8)
|
||||||
|
meta:set_string("termpoint2", 1.0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -130,6 +130,12 @@ minetest.register_node("techage:gearbox_on", {
|
|||||||
|
|
||||||
power.register_nodes({"techage:gearbox", "techage:gearbox_on"}, Axle, "junc")
|
power.register_nodes({"techage:gearbox", "techage:gearbox_on"}, Axle, "junc")
|
||||||
|
|
||||||
|
techage.register_node({"techage:gearbox", "techage:gearbox_on"}, {
|
||||||
|
on_node_load = function(pos, node)
|
||||||
|
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "techage:gearbox 2",
|
output = "techage:gearbox 2",
|
||||||
recipe = {
|
recipe = {
|
||||||
|
@ -19,8 +19,7 @@ local M = minetest.get_meta
|
|||||||
local S = techage.S
|
local S = techage.S
|
||||||
|
|
||||||
local Cable = techage.ElectricCable
|
local Cable = techage.ElectricCable
|
||||||
local power = techage.power
|
local power = networks.power
|
||||||
local networks = techage.networks
|
|
||||||
|
|
||||||
minetest.register_node("techage:ta4_laser_emitter", {
|
minetest.register_node("techage:ta4_laser_emitter", {
|
||||||
description = S("TA4 Laser Beam Emitter"),
|
description = S("TA4 Laser Beam Emitter"),
|
||||||
@ -122,9 +121,7 @@ minetest.register_node("techage:ta4_laser_receiver", {
|
|||||||
sounds = default.node_sound_wood_defaults(),
|
sounds = default.node_sound_wood_defaults(),
|
||||||
})
|
})
|
||||||
|
|
||||||
Cable:add_secondary_node_names({"techage:ta4_laser_emitter", "techage:ta4_laser_receiver"})
|
power.register_nodes({"techage:ta4_laser_emitter", "techage:ta4_laser_receiver"}, Cable, "special", {"F"})
|
||||||
Cable:set_valid_sides("techage:ta4_laser_emitter", {"F"})
|
|
||||||
Cable:set_valid_sides("techage:ta4_laser_receiver", {"F"})
|
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "techage:ta4_laser_emitter",
|
output = "techage:ta4_laser_emitter",
|
||||||
|
@ -43,10 +43,7 @@ minetest.register_node("techage:power_line", {
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
if oldmetadata and oldmetadata.fields and oldmetadata.fields.tl2_param2 then
|
Cable:after_dig_tube(pos, oldnode)
|
||||||
oldnode.param2 = oldmetadata.fields.tl2_param2
|
|
||||||
Cable:after_dig_tube(pos, oldnode)
|
|
||||||
end
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
paramtype2 = "facedir", -- important!
|
paramtype2 = "facedir", -- important!
|
||||||
@ -85,10 +82,7 @@ minetest.register_node("techage:power_lineS", {
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
if oldmetadata and oldmetadata.fields and oldmetadata.fields.tl2_param2 then
|
Cable:after_dig_tube(pos, oldnode)
|
||||||
oldnode.param2 = oldmetadata.fields.tl2_param2
|
|
||||||
Cable:after_dig_tube(pos, oldnode)
|
|
||||||
end
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
paramtype2 = "facedir", -- important!
|
paramtype2 = "facedir", -- important!
|
||||||
@ -133,10 +127,7 @@ minetest.register_node("techage:power_lineA", {
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
if oldmetadata and oldmetadata.fields and oldmetadata.fields.tl2_param2 then
|
Cable:after_dig_tube(pos, oldnode)
|
||||||
oldnode.param2 = oldmetadata.fields.tl2_param2
|
|
||||||
Cable:after_dig_tube(pos, oldnode)
|
|
||||||
end
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
paramtype2 = "facedir", -- important!
|
paramtype2 = "facedir", -- important!
|
||||||
@ -213,13 +204,7 @@ minetest.register_node("techage:power_pole2", {
|
|||||||
end,
|
end,
|
||||||
can_dig = can_dig,
|
can_dig = can_dig,
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
if oldmetadata and oldmetadata.fields and oldmetadata.fields.tl2_param2 then
|
Cable:after_dig_tube(pos, oldnode)
|
||||||
oldnode.param2 = oldmetadata.fields.tl2_param2
|
|
||||||
Cable:after_dig_tube(pos, oldnode)
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
tubelib2_on_update2 = function(pos, dir1, tlib2, node)
|
|
||||||
power.update_network(pos, nil, tlib2)
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_rotate = screwdriver.disallow, -- important!
|
on_rotate = screwdriver.disallow, -- important!
|
||||||
@ -303,20 +288,10 @@ minetest.register_node("techage:power_pole_conn", {
|
|||||||
},
|
},
|
||||||
connects_to = {"techage:power_line", "techage:power_lineS", "techage:power_lineA"},
|
connects_to = {"techage:power_line", "techage:power_lineS", "techage:power_lineA"},
|
||||||
|
|
||||||
-- after_place_node -- see techage:power_pole
|
can_dig = can_dig,
|
||||||
tubelib2_on_update2 = function(pos, dir1, tlib2, node)
|
|
||||||
power.update_network(pos, nil, tlib2)
|
|
||||||
end,
|
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
Cable:after_dig_node(pos)
|
Cable:after_dig_node(pos)
|
||||||
end,
|
end,
|
||||||
can_dig = can_dig,
|
|
||||||
networks = {
|
|
||||||
ele1 = {
|
|
||||||
sides = networks.AllSides, -- connection sides for cables
|
|
||||||
ntype = "junc",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
drop = "techage:power_pole",
|
drop = "techage:power_pole",
|
||||||
on_rotate = screwdriver.disallow, -- important!
|
on_rotate = screwdriver.disallow, -- important!
|
||||||
@ -328,8 +303,7 @@ minetest.register_node("techage:power_pole_conn", {
|
|||||||
sounds = default.node_sound_defaults(),
|
sounds = default.node_sound_defaults(),
|
||||||
})
|
})
|
||||||
|
|
||||||
Cable:add_secondary_node_names({"techage:power_pole_conn"})
|
power.register_nodes({"techage:power_pole_conn"}, Cable, "junc")
|
||||||
|
|
||||||
|
|
||||||
minetest.register_node("techage:power_pole3", {
|
minetest.register_node("techage:power_pole3", {
|
||||||
description = S("TA Power Pole"),
|
description = S("TA Power Pole"),
|
||||||
|
@ -18,7 +18,7 @@ local P2S = minetest.pos_to_string
|
|||||||
local M = minetest.get_meta
|
local M = minetest.get_meta
|
||||||
local S = techage.S
|
local S = techage.S
|
||||||
|
|
||||||
local power = techage.power
|
local power = networks.power
|
||||||
|
|
||||||
local ELE2_MAX_CABLE_LENGHT = 200
|
local ELE2_MAX_CABLE_LENGHT = 200
|
||||||
|
|
||||||
@ -40,13 +40,10 @@ local Cable = tubelib2.Tube:new({
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
--Cable:register_on_tube_update(function(node, pos, out_dir, peer_pos, peer_in_dir)
|
-- Use global callback instead of node related functions
|
||||||
-- local ndef = minetest.registered_nodes[node.name]
|
Cable:register_on_tube_update2(function(pos, outdir, tlib2, node)
|
||||||
-- if ndef and ndef.after_tube_update then
|
power.update_network(pos, outdir, tlib2, node)
|
||||||
-- minetest.registered_nodes[node.name].after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir)
|
end)
|
||||||
-- end
|
|
||||||
--end)
|
|
||||||
|
|
||||||
|
|
||||||
minetest.register_node("techage:ta4_power_cableS", {
|
minetest.register_node("techage:ta4_power_cableS", {
|
||||||
description = S("TA4 Low Power Cable"),
|
description = S("TA4 Low Power Cable"),
|
||||||
@ -155,17 +152,11 @@ minetest.register_node("techage:ta4_power_box", {
|
|||||||
Cable:after_place_node(pos)
|
Cable:after_place_node(pos)
|
||||||
end,
|
end,
|
||||||
tubelib2_on_update2 = function(pos, dir1, tlib2, node)
|
tubelib2_on_update2 = function(pos, dir1, tlib2, node)
|
||||||
power.update_network(pos, nil, tlib2)
|
power.update_network(pos, 0, tlib2, node)
|
||||||
end,
|
end,
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
Cable:after_dig_node(pos)
|
Cable:after_dig_node(pos)
|
||||||
end,
|
end,
|
||||||
networks = {
|
|
||||||
ele2 = {
|
|
||||||
sides = {L=1, R=1, F=1, B=1},
|
|
||||||
ntype = "junc",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
on_rotate = screwdriver.disallow, -- important!
|
on_rotate = screwdriver.disallow, -- important!
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
@ -176,7 +167,7 @@ minetest.register_node("techage:ta4_power_box", {
|
|||||||
sounds = default.node_sound_defaults(),
|
sounds = default.node_sound_defaults(),
|
||||||
})
|
})
|
||||||
|
|
||||||
Cable:add_secondary_node_names({"techage:ta4_power_box"})
|
power.register_nodes({"techage:ta4_power_box"}, Cable, "junc", {"L", "R", "F", "B"})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "techage:ta4_power_cableS 8",
|
output = "techage:ta4_power_cableS 8",
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
TechAge
|
TechAge
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Copyright (C) 2019-2020 Joachim Stolberg
|
Copyright (C) 2019-2021 Joachim Stolberg
|
||||||
|
|
||||||
AGPL v3
|
AGPL v3
|
||||||
See LICENSE.txt for more information
|
See LICENSE.txt for more information
|
||||||
@ -20,8 +20,8 @@ local S2P = minetest.string_to_pos
|
|||||||
|
|
||||||
local Cable = techage.ElectricCable
|
local Cable = techage.ElectricCable
|
||||||
local Solar = techage.TA4_Cable
|
local Solar = techage.TA4_Cable
|
||||||
local power = techage.power
|
local power = networks.power
|
||||||
local networks = techage.networks
|
local control = networks.control
|
||||||
|
|
||||||
local CYCLE_TIME = 2
|
local CYCLE_TIME = 2
|
||||||
local PWR_PERF = 100
|
local PWR_PERF = 100
|
||||||
@ -29,13 +29,19 @@ local PWR_PERF = 100
|
|||||||
local function determine_power(pos, nvm)
|
local function determine_power(pos, nvm)
|
||||||
-- determine DC node position
|
-- determine DC node position
|
||||||
local outdir = M(pos):get_int("leftdir")
|
local outdir = M(pos):get_int("leftdir")
|
||||||
local max_power, num_inverter = power.get_power(pos, outdir, Solar, "techage:ta4_solar_inverter")
|
local netw = networks.get_network_table(pos, Solar, outdir) or {}
|
||||||
if num_inverter == 1 then
|
local num_inv = #(netw.con or {})
|
||||||
|
local max_power = 0
|
||||||
|
for _, power in ipairs(control.request(pos, Solar, outdir, "junc", "power")) do
|
||||||
|
max_power = max_power + power
|
||||||
|
end
|
||||||
|
|
||||||
|
if num_inv == 1 then -- only one inverter is allowed
|
||||||
nvm.max_power = math.min(PWR_PERF, max_power)
|
nvm.max_power = math.min(PWR_PERF, max_power)
|
||||||
else
|
else
|
||||||
nvm.max_power = 0
|
nvm.max_power = 0
|
||||||
end
|
end
|
||||||
return max_power, num_inverter
|
return max_power, num_inv
|
||||||
end
|
end
|
||||||
|
|
||||||
local function determine_power_from_time_to_time(pos, nvm)
|
local function determine_power_from_time_to_time(pos, nvm)
|
||||||
@ -46,7 +52,7 @@ local function determine_power_from_time_to_time(pos, nvm)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
nvm.ticks = nvm.ticks or 0
|
nvm.ticks = nvm.ticks or 0
|
||||||
if (nvm.ticks % 10) == 0 then -- calculate max_power not to often
|
if (nvm.ticks % 30) == 0 then -- calculate max_power not to often
|
||||||
determine_power(pos, nvm)
|
determine_power(pos, nvm)
|
||||||
else
|
else
|
||||||
nvm.max_power = nvm.max_power or 0
|
nvm.max_power = nvm.max_power or 0
|
||||||
@ -56,7 +62,7 @@ end
|
|||||||
|
|
||||||
local function formspec(self, pos, nvm)
|
local function formspec(self, pos, nvm)
|
||||||
local max_power = nvm.max_power or 0
|
local max_power = nvm.max_power or 0
|
||||||
local delivered = nvm.delivered or 0
|
local provided = nvm.provided or 0
|
||||||
local arrow = "image[2.5,1.5;1,1;techage_form_arrow_bg.png^[transformR270]"
|
local arrow = "image[2.5,1.5;1,1;techage_form_arrow_bg.png^[transformR270]"
|
||||||
if nvm.running then
|
if nvm.running then
|
||||||
arrow = "image[2.5,1.5;1,1;techage_form_arrow_fg.png^[transformR270]"
|
arrow = "image[2.5,1.5;1,1;techage_form_arrow_fg.png^[transformR270]"
|
||||||
@ -67,8 +73,8 @@ local function formspec(self, pos, nvm)
|
|||||||
default.gui_slots..
|
default.gui_slots..
|
||||||
"box[0,-0.1;5.8,0.5;#c6e8ff]"..
|
"box[0,-0.1;5.8,0.5;#c6e8ff]"..
|
||||||
"label[2.5,-0.1;"..minetest.colorize( "#000000", S("Inverter")).."]"..
|
"label[2.5,-0.1;"..minetest.colorize( "#000000", S("Inverter")).."]"..
|
||||||
power.formspec_label_bar(pos, 0, 0.8, S("Power DC"), PWR_PERF, max_power)..
|
techage.formspec_power_bar(pos, 0, 0.8, S("Power DC"), max_power, PWR_PERF)..
|
||||||
power.formspec_label_bar(pos, 3.5, 0.8, S("Power AC"), max_power, delivered)..
|
techage.formspec_power_bar(pos, 3.5, 0.8, S("Power AC"), provided, max_power)..
|
||||||
arrow..
|
arrow..
|
||||||
"image_button[2.5,3;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
|
"image_button[2.5,3;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
|
||||||
"tooltip[2.5,3;1,1;"..self:get_state_tooltip(nvm).."]"
|
"tooltip[2.5,3;1,1;"..self:get_state_tooltip(nvm).."]"
|
||||||
@ -82,18 +88,20 @@ local function can_start(pos, nvm, state)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function start_node(pos, nvm, state)
|
local function start_node(pos, nvm, state)
|
||||||
|
local meta = M(pos)
|
||||||
nvm.running = true
|
nvm.running = true
|
||||||
nvm.delivered = 0
|
nvm.provided = 0
|
||||||
nvm.ticks = 0
|
nvm.ticks = 0
|
||||||
local outdir = M(pos):get_int("outdir")
|
local outdir = meta:get_int("outdir")
|
||||||
power.generator_start(pos, Cable, CYCLE_TIME, outdir, nvm.max_power)
|
techage.evaluate_charge_termination(nvm, meta)
|
||||||
|
power.start_storage_calc(pos, Cable, outdir)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function stop_node(pos, nvm, state)
|
local function stop_node(pos, nvm, state)
|
||||||
nvm.running = false
|
nvm.running = false
|
||||||
nvm.delivered = 0
|
nvm.provided = 0
|
||||||
local outdir = M(pos):get_int("outdir")
|
local outdir = M(pos):get_int("outdir")
|
||||||
power.generator_stop(pos, Cable, outdir)
|
power.start_storage_calc(pos, Cable, outdir)
|
||||||
end
|
end
|
||||||
|
|
||||||
local State = techage.NodeStates:new({
|
local State = techage.NodeStates:new({
|
||||||
@ -108,16 +116,18 @@ local State = techage.NodeStates:new({
|
|||||||
})
|
})
|
||||||
|
|
||||||
local function node_timer(pos, elapsed)
|
local function node_timer(pos, elapsed)
|
||||||
|
local meta = M(pos)
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
determine_power_from_time_to_time(pos, nvm)
|
determine_power_from_time_to_time(pos, nvm)
|
||||||
--if nvm.max_power > 0 then
|
local outdir = M(pos):get_int("outdir")
|
||||||
local outdir = M(pos):get_int("outdir")
|
local tp1 = tonumber(meta:get_string("termpoint1"))
|
||||||
nvm.delivered = power.generator_alive(pos, Cable, CYCLE_TIME, outdir, nvm.max_power)
|
local tp2 = tonumber(meta:get_string("termpoint2"))
|
||||||
--else
|
if nvm.max_power and nvm.max_power > 0 then
|
||||||
--nvm.delivered = 0
|
nvm.provided = power.provide_power(pos, Cable, outdir, nvm.max_power, tp1, tp2)
|
||||||
--end
|
nvm.load = power.get_storage_load(pos, Cable, outdir, nvm.max_power)
|
||||||
|
end
|
||||||
if techage.is_activeformspec(pos) then
|
if techage.is_activeformspec(pos) then
|
||||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
meta:set_string("formspec", formspec(State, pos, nvm))
|
||||||
end
|
end
|
||||||
State:trigger_state(pos, nvm)
|
State:trigger_state(pos, nvm)
|
||||||
return true
|
return true
|
||||||
@ -142,8 +152,11 @@ local function on_rightclick(pos, node, clicker)
|
|||||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function tubelib2_on_update2(pos, outdir, tlib2, node)
|
local function get_generator_data(pos, tlib2)
|
||||||
power.update_network(pos, outdir, tlib2)
|
local nvm = techage.get_nvm(pos)
|
||||||
|
if nvm.running then
|
||||||
|
return {level = (nvm.load or 0) / nvm.max_power, perf = nvm.max_power, capa = nvm.max_power * 2}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_node("techage:ta4_solar_inverter", {
|
minetest.register_node("techage:ta4_solar_inverter", {
|
||||||
@ -179,38 +192,48 @@ minetest.register_node("techage:ta4_solar_inverter", {
|
|||||||
techage.del_mem(pos)
|
techage.del_mem(pos)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
tubelib2_on_update2 = tubelib2_on_update2,
|
|
||||||
on_receive_fields = on_receive_fields,
|
on_receive_fields = on_receive_fields,
|
||||||
on_rightclick = on_rightclick,
|
on_rightclick = on_rightclick,
|
||||||
on_timer = node_timer,
|
on_timer = node_timer,
|
||||||
networks = {
|
get_generator_data = get_generator_data,
|
||||||
ele1 = {
|
ta3_formspec = techage.generator_settings("ta4", PWR_PERF)
|
||||||
sides = {R = 1},
|
|
||||||
ntype = "gen1",
|
|
||||||
nominal = PWR_PERF,
|
|
||||||
regenerative = true,
|
|
||||||
},
|
|
||||||
ele2 = {
|
|
||||||
sides = {L = 1},
|
|
||||||
ntype = "con1",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
Cable:add_secondary_node_names({"techage:ta4_solar_inverter"})
|
power.register_nodes({"techage:ta4_solar_inverter"}, Cable, "gen", {"R"})
|
||||||
Solar:add_secondary_node_names({"techage:ta4_solar_inverter"})
|
power.register_nodes({"techage:ta4_solar_inverter"}, Solar, "con", {"L"})
|
||||||
|
|
||||||
techage.register_node({"techage:ta4_solar_inverter"}, {
|
techage.register_node({"techage:ta4_solar_inverter"}, {
|
||||||
on_recv_message = function(pos, src, topic, payload)
|
on_recv_message = function(pos, src, topic, payload)
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
if topic == "delivered" then
|
if topic == "delivered" then
|
||||||
return math.floor((nvm.delivered or 0) + 0.5)
|
return math.floor((nvm.provided or 0) + 0.5)
|
||||||
else
|
else
|
||||||
return State:on_receive_message(pos, topic, payload)
|
return State:on_receive_message(pos, topic, payload)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
control.register_nodes({"techage:ta4_solar_inverter"}, {
|
||||||
|
on_receive = function(pos, tlib2, topic, payload)
|
||||||
|
end,
|
||||||
|
on_request = function(pos, tlib2, topic)
|
||||||
|
if topic == "info" then
|
||||||
|
local nvm = techage.get_nvm(pos)
|
||||||
|
local meta = M(pos)
|
||||||
|
return {
|
||||||
|
type = S("TA4 Solar Inverter"),
|
||||||
|
number = meta:get_string("node_number") or "",
|
||||||
|
running = nvm.running or false,
|
||||||
|
available = nvm.max_power or 0,
|
||||||
|
provided = nvm.provided or 0,
|
||||||
|
termpoint = meta:get_string("termpoint"),
|
||||||
|
}
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "techage:ta4_solar_inverter",
|
output = "techage:ta4_solar_inverter",
|
||||||
recipe = {
|
recipe = {
|
||||||
|
@ -20,7 +20,8 @@ local S = techage.S
|
|||||||
local PWR_PERF = 3
|
local PWR_PERF = 3
|
||||||
|
|
||||||
local Cable = techage.TA4_Cable
|
local Cable = techage.TA4_Cable
|
||||||
local power = techage.power
|
local power = networks.power
|
||||||
|
local control = networks.control
|
||||||
|
|
||||||
local function temperature(pos)
|
local function temperature(pos)
|
||||||
local data = minetest.get_biome_data(pos)
|
local data = minetest.get_biome_data(pos)
|
||||||
@ -32,7 +33,7 @@ end
|
|||||||
|
|
||||||
-- return the required param2 for solar modules
|
-- return the required param2 for solar modules
|
||||||
local function get_param2(pos, side)
|
local function get_param2(pos, side)
|
||||||
local dir = techage.networks.side_to_outdir(pos, side)
|
local dir = networks.side_to_outdir(pos, side)
|
||||||
return (dir + 1) % 4
|
return (dir + 1) % 4
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -89,25 +90,9 @@ local function after_dig_node(pos, oldnode)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function tubelib2_on_update2(pos, outdir, tlib2, node)
|
local function tubelib2_on_update2(pos, outdir, tlib2, node)
|
||||||
power.update_network(pos, nil, tlib2)
|
power.update_network(pos, 0, tlib2, node)
|
||||||
end
|
end
|
||||||
|
|
||||||
local net_def1 = {
|
|
||||||
ele2 = {
|
|
||||||
sides = {F=1, B=1},
|
|
||||||
ntype = "junc",
|
|
||||||
on_getpower = on_getpower1,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
local net_def2 = {
|
|
||||||
ele2 = {
|
|
||||||
sides = {F=1, B=1},
|
|
||||||
ntype = "junc",
|
|
||||||
on_getpower = on_getpower2,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
minetest.register_node("techage:ta4_solar_module", {
|
minetest.register_node("techage:ta4_solar_module", {
|
||||||
description = S("TA4 Solar Module"),
|
description = S("TA4 Solar Module"),
|
||||||
inventory_image = "techage_solar_module_top.png",
|
inventory_image = "techage_solar_module_top.png",
|
||||||
@ -170,7 +155,6 @@ minetest.register_node("techage:ta4_solar_carrier", {
|
|||||||
after_place_node = after_place_node,
|
after_place_node = after_place_node,
|
||||||
after_dig_node = after_dig_node,
|
after_dig_node = after_dig_node,
|
||||||
tubelib2_on_update2 = tubelib2_on_update2,
|
tubelib2_on_update2 = tubelib2_on_update2,
|
||||||
networks = net_def1,
|
|
||||||
|
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
use_texture_alpha = techage.CLIP,
|
use_texture_alpha = techage.CLIP,
|
||||||
@ -210,7 +194,6 @@ minetest.register_node("techage:ta4_solar_carrierB", {
|
|||||||
after_place_node = after_place_node,
|
after_place_node = after_place_node,
|
||||||
after_dig_node = after_dig_node,
|
after_dig_node = after_dig_node,
|
||||||
tubelib2_on_update2 = tubelib2_on_update2,
|
tubelib2_on_update2 = tubelib2_on_update2,
|
||||||
networks = net_def2,
|
|
||||||
|
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
use_texture_alpha = techage.CLIP,
|
use_texture_alpha = techage.CLIP,
|
||||||
@ -249,8 +232,29 @@ minetest.register_node("techage:ta4_solar_carrierT", {
|
|||||||
sounds = default.node_sound_stone_defaults(),
|
sounds = default.node_sound_stone_defaults(),
|
||||||
})
|
})
|
||||||
|
|
||||||
Cable:add_secondary_node_names({"techage:ta4_solar_carrier", "techage:ta4_solar_carrierB"})
|
power.register_nodes({"techage:ta4_solar_carrier", "techage:ta4_solar_carrierB"}, Cable, "junc", {"F", "B"})
|
||||||
|
|
||||||
|
control.register_nodes({"techage:ta4_solar_carrier"}, {
|
||||||
|
on_receive = function(pos, tlib2, topic, payload)
|
||||||
|
end,
|
||||||
|
on_request = function(pos, tlib2, topic)
|
||||||
|
if topic == "power" then
|
||||||
|
return on_getpower1(pos)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
control.register_nodes({"techage:ta4_solar_carrierB"}, {
|
||||||
|
on_receive = function(pos, tlib2, topic, payload)
|
||||||
|
end,
|
||||||
|
on_request = function(pos, tlib2, topic)
|
||||||
|
if topic == "power" then
|
||||||
|
return on_getpower2(pos)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "techage:ta4_solar_module",
|
output = "techage:ta4_solar_module",
|
||||||
@ -288,13 +292,3 @@ minetest.register_craft({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
--minetest.register_lbm({
|
|
||||||
-- label = "Repair Carrier Module",
|
|
||||||
-- name = "techage:ta4_solar_carrier",
|
|
||||||
-- nodenames = {"techage:ta4_solar_carrier", "techage:ta4_solar_carrierB"},
|
|
||||||
-- run_at_every_load = false,
|
|
||||||
-- action = function(pos, node)
|
|
||||||
-- local ndef = minetest.registered_nodes[node.name]
|
|
||||||
-- ndef.after_place_node(pos)
|
|
||||||
-- end,
|
|
||||||
--})
|
|
||||||
|
@ -31,15 +31,7 @@ local function switch_axles(pos, on)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function formspec(self, pos, nvm)
|
local function formspec(self, pos, nvm)
|
||||||
return "size[4,4]" ..
|
return techage.generator_formspec(self, pos, nvm, S("Flywheel"), nvm.provided, PWR_PERF)
|
||||||
"box[0,-0.1;3.8,0.5;#c6e8ff]" ..
|
|
||||||
"label[1,-0.1;" .. minetest.colorize( "#000000", S("Flywheel")) .. "]" ..
|
|
||||||
default.gui_bg ..
|
|
||||||
default.gui_bg_img ..
|
|
||||||
default.gui_slots ..
|
|
||||||
techage.formspec_power_bar(pos, 0, 0.8, S("power"), nvm.provided, PWR_PERF) ..
|
|
||||||
"image_button[2.8,2;1,1;" .. self:get_state_button_image(nvm) .. ";state_button;]" ..
|
|
||||||
"tooltip[2.8,2;1,1; " .. self:get_state_tooltip(nvm) .. "]"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function transfer_cylinder(pos, topic, payload)
|
local function transfer_cylinder(pos, topic, payload)
|
||||||
@ -54,18 +46,18 @@ end
|
|||||||
local function start_node(pos, nvm, state)
|
local function start_node(pos, nvm, state)
|
||||||
switch_axles(pos, true)
|
switch_axles(pos, true)
|
||||||
local outdir = M(pos):get_int("outdir")
|
local outdir = M(pos):get_int("outdir")
|
||||||
power.start_storage_calc(pos, Axle, outdir)
|
|
||||||
transfer_cylinder(pos, "start")
|
transfer_cylinder(pos, "start")
|
||||||
nvm.running = true
|
nvm.running = true
|
||||||
|
power.start_storage_calc(pos, Axle, outdir)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function stop_node(pos, nvm, state)
|
local function stop_node(pos, nvm, state)
|
||||||
switch_axles(pos, false)
|
switch_axles(pos, false)
|
||||||
local outdir = M(pos):get_int("outdir")
|
local outdir = M(pos):get_int("outdir")
|
||||||
power.start_storage_calc(pos, Axle, outdir)
|
|
||||||
nvm.provided = 0
|
nvm.provided = 0
|
||||||
transfer_cylinder(pos, "stop")
|
transfer_cylinder(pos, "stop")
|
||||||
nvm.running = false
|
nvm.running = false
|
||||||
|
power.start_storage_calc(pos, Axle, outdir)
|
||||||
end
|
end
|
||||||
|
|
||||||
local State = techage.NodeStates:new({
|
local State = techage.NodeStates:new({
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
TechAge
|
TechAge
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Copyright (C) 2019-2020 Joachim Stolberg
|
Copyright (C) 2019-2021 Joachim Stolberg
|
||||||
|
|
||||||
AGPL v3
|
AGPL v3
|
||||||
See LICENSE.txt for more information
|
See LICENSE.txt for more information
|
||||||
@ -20,8 +20,7 @@ local S2P = minetest.string_to_pos
|
|||||||
|
|
||||||
local Cable = techage.ElectricCable
|
local Cable = techage.ElectricCable
|
||||||
local Axle = techage.Axle
|
local Axle = techage.Axle
|
||||||
local power = techage.power
|
local power = networks.power
|
||||||
local networks = techage.networks
|
|
||||||
|
|
||||||
local CYCLE_TIME = 2
|
local CYCLE_TIME = 2
|
||||||
local PWR_PERF = 24
|
local PWR_PERF = 24
|
||||||
@ -35,64 +34,54 @@ local function swap_node(pos, name)
|
|||||||
minetest.swap_node(pos, node)
|
minetest.swap_node(pos, node)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_power(pos)
|
local function node_timer_on(pos, elapsed)
|
||||||
|
local meta = M(pos)
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
nvm.axle = nvm.axle or {}
|
local outdir = meta:get_int("outdir")
|
||||||
nvm.consumer_powered = true
|
nvm.buffer = nvm.buffer or 0
|
||||||
M(pos):set_string("infotext", S("TA2 Power Generator"))
|
|
||||||
swap_node(pos, "techage:ta2_generator_on")
|
|
||||||
nvm.ticks = 0
|
|
||||||
local outdir = M(pos):get_int("outdir")
|
|
||||||
nvm.axle.curr_power = techage.power.needed_power(pos, Cable, outdir)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function on_nopower(pos)
|
local amount = math.min(PWR_PERF * 2 - nvm.buffer, PWR_PERF)
|
||||||
local nvm = techage.get_nvm(pos)
|
local taken = power.consume_power(pos, Axle, networks.Flip[outdir], amount)
|
||||||
nvm.consumer_powered = false
|
print("node_timer_on", amount, taken, nvm.buffer)
|
||||||
if (nvm.ticks or 0) < 4 then
|
nvm.buffer = nvm.buffer + taken - 1 -- some loss
|
||||||
M(pos):set_string("infotext", S("TA2 Power Generator: Overload fault?\n(restart with right-click)"))
|
|
||||||
|
if nvm.buffer >= PWR_PERF then
|
||||||
|
local tp1 = tonumber(meta:get_string("termpoint1"))
|
||||||
|
local tp2 = tonumber(meta:get_string("termpoint2"))
|
||||||
|
nvm.provided = power.provide_power(pos, Cable, outdir, PWR_PERF, tp1, tp2)
|
||||||
|
nvm.load = power.get_storage_load(pos, Cable, outdir, PWR_PERF)
|
||||||
|
nvm.buffer = nvm.buffer - nvm.provided
|
||||||
|
print("provided", nvm.provided, nvm.load, nvm.buffer)
|
||||||
end
|
end
|
||||||
nvm.ticks = 0
|
if amount > 0 and taken == 0 then
|
||||||
end
|
swap_node(pos, "techage:ta2_generator_off")
|
||||||
|
|
||||||
local function node_timer(pos, elapsed)
|
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
nvm.axle = nvm.axle or {}
|
|
||||||
|
|
||||||
-- trigger network on consumer side
|
|
||||||
nvm.ticks = (nvm.ticks or 0) + 1
|
|
||||||
if nvm.ticks % 2 then
|
|
||||||
power.consumer_alive(pos, Axle, CYCLE_TIME)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- handle generator side delayed
|
|
||||||
if nvm.ticks > 3 then
|
|
||||||
local outdir = M(pos):get_int("outdir")
|
local outdir = M(pos):get_int("outdir")
|
||||||
|
nvm.running = false
|
||||||
if nvm.consumer_powered and not nvm.running_as_generator then
|
power.start_storage_calc(pos, Cable, outdir)
|
||||||
nvm.running_as_generator = true
|
|
||||||
power.generator_start(pos, Cable, CYCLE_TIME, outdir, nvm.max_power)
|
|
||||||
elseif not nvm.consumer_powered and nvm.running_as_generator then
|
|
||||||
nvm.running_as_generator = false
|
|
||||||
power.generator_stop(pos, Cable, outdir)
|
|
||||||
end
|
|
||||||
|
|
||||||
if nvm.running_as_generator then
|
|
||||||
nvm.axle.curr_power = power.generator_alive(pos, Cable, CYCLE_TIME, outdir, PWR_PERF) + 1
|
|
||||||
else
|
|
||||||
swap_node(pos, "techage:ta2_generator_off")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local function tubelib2_on_update2(pos, outdir, tlib2, node)
|
local function node_timer_off(pos, elapsed)
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
nvm.axle = nvm.axle or {}
|
local outdir = M(pos):get_int("outdir")
|
||||||
nvm.axle.curr_power = 1
|
|
||||||
power.update_network(pos, outdir, tlib2)
|
if power.power_available(pos, Axle, networks.Flip[outdir]) then
|
||||||
|
swap_node(pos, "techage:ta2_generator_on")
|
||||||
|
nvm.running = true
|
||||||
|
power.start_storage_calc(pos, Cable, outdir)
|
||||||
|
end
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function get_generator_data(pos, tlib2)
|
||||||
|
local nvm = techage.get_nvm(pos)
|
||||||
|
if nvm.running then
|
||||||
|
return {level = (nvm.load or 0) / PWR_PERF, perf = PWR_PERF, capa = PWR_PERF * 2}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
minetest.register_node("techage:ta2_generator_off", {
|
minetest.register_node("techage:ta2_generator_off", {
|
||||||
description = S("TA2 Power Generator"),
|
description = S("TA2 Power Generator"),
|
||||||
tiles = {
|
tiles = {
|
||||||
@ -110,24 +99,10 @@ minetest.register_node("techage:ta2_generator_off", {
|
|||||||
is_ground_content = false,
|
is_ground_content = false,
|
||||||
|
|
||||||
after_place_node = function(pos)
|
after_place_node = function(pos)
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
nvm.axle = nvm.axle or {}
|
|
||||||
nvm.axle.curr_power = 1
|
|
||||||
nvm.consumer_powered = false
|
|
||||||
nvm.running_as_generator = false
|
|
||||||
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
|
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
|
||||||
M(pos):set_int("leftdir", networks.side_to_outdir(pos, "L"))
|
|
||||||
Cable:after_place_node(pos)
|
Cable:after_place_node(pos)
|
||||||
Axle:after_place_node(pos)
|
Axle:after_place_node(pos)
|
||||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||||
power.consumer_start(pos, Axle, CYCLE_TIME*2)
|
|
||||||
M(pos):set_string("infotext", S("TA2 Power Generator"))
|
|
||||||
end,
|
|
||||||
|
|
||||||
on_rightclick = function(pos, node, clicker)
|
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
nvm.axle = nvm.axle or {}
|
|
||||||
nvm.axle.curr_power = 1
|
|
||||||
M(pos):set_string("infotext", S("TA2 Power Generator"))
|
M(pos):set_string("infotext", S("TA2 Power Generator"))
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@ -137,21 +112,8 @@ minetest.register_node("techage:ta2_generator_off", {
|
|||||||
techage.del_mem(pos)
|
techage.del_mem(pos)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
tubelib2_on_update2 = tubelib2_on_update2,
|
on_timer = node_timer_off,
|
||||||
on_timer = node_timer,
|
get_generator_data = get_generator_data,
|
||||||
networks = {
|
|
||||||
ele1 = {
|
|
||||||
sides = {R = 1},
|
|
||||||
ntype = "gen1",
|
|
||||||
nominal = PWR_PERF,
|
|
||||||
},
|
|
||||||
axle = {
|
|
||||||
sides = {L = 1},
|
|
||||||
ntype = "con1",
|
|
||||||
on_power = on_power,
|
|
||||||
on_nopower = on_nopower,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node("techage:ta2_generator_on", {
|
minetest.register_node("techage:ta2_generator_on", {
|
||||||
@ -199,21 +161,8 @@ minetest.register_node("techage:ta2_generator_on", {
|
|||||||
groups = {not_in_creative_inventory=1},
|
groups = {not_in_creative_inventory=1},
|
||||||
diggable = false,
|
diggable = false,
|
||||||
|
|
||||||
tubelib2_on_update2 = tubelib2_on_update2,
|
on_timer = node_timer_on,
|
||||||
on_timer = node_timer,
|
get_generator_data = get_generator_data,
|
||||||
networks = {
|
|
||||||
ele1 = {
|
|
||||||
sides = {R = 1},
|
|
||||||
ntype = "gen1",
|
|
||||||
nominal = PWR_PERF,
|
|
||||||
},
|
|
||||||
axle = {
|
|
||||||
sides = {L = 1},
|
|
||||||
ntype = "con1",
|
|
||||||
on_power = on_power,
|
|
||||||
on_nopower = on_nopower,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
techage.register_node({"techage:ta2_generator_off", "techage:ta2_generator_on"}, {
|
techage.register_node({"techage:ta2_generator_off", "techage:ta2_generator_on"}, {
|
||||||
@ -222,8 +171,8 @@ techage.register_node({"techage:ta2_generator_off", "techage:ta2_generator_on"},
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
Cable:add_secondary_node_names({"techage:ta2_generator_off", "techage:ta2_generator_on"})
|
power.register_nodes({"techage:ta2_generator_off", "techage:ta2_generator_on"}, Axle, "con", {"L"})
|
||||||
Axle:add_secondary_node_names({"techage:ta2_generator_off", "techage:ta2_generator_on"})
|
power.register_nodes({"techage:ta2_generator_off", "techage:ta2_generator_on"}, Cable, "gen", {"R"})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "techage:ta2_generator_off",
|
output = "techage:ta2_generator_off",
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
TechAge
|
TechAge
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Copyright (C) 2019-2020 Joachim Stolberg
|
Copyright (C) 2019-2021 Joachim Stolberg
|
||||||
|
|
||||||
AGPL v3
|
AGPL v3
|
||||||
See LICENSE.txt for more information
|
See LICENSE.txt for more information
|
||||||
@ -20,17 +20,15 @@ local S2P = minetest.string_to_pos
|
|||||||
|
|
||||||
local Cable = techage.ElectricCable
|
local Cable = techage.ElectricCable
|
||||||
local Axle = techage.Axle
|
local Axle = techage.Axle
|
||||||
local power = techage.power
|
local power = networks.power
|
||||||
local networks = techage.networks
|
|
||||||
|
|
||||||
local CYCLE_TIME = 2
|
local CYCLE_TIME = 2
|
||||||
local PWR_PERF = 40
|
local PWR_PERF = 40
|
||||||
|
|
||||||
-- Axles texture animation
|
-- Axles texture animation
|
||||||
local function switch_axles(pos, on)
|
local function switch_axles(pos, on)
|
||||||
for _,outdir in ipairs(networks.get_node_connections(pos, "axle")) do
|
local outdir = M(pos):get_int("outdir")
|
||||||
Axle:switch_tube_line(pos, outdir, on and "on" or "off")
|
Axle:switch_tube_line(pos, outdir, on and "on" or "off")
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function swap_node(pos, name)
|
local function swap_node(pos, name)
|
||||||
@ -42,64 +40,48 @@ local function swap_node(pos, name)
|
|||||||
minetest.swap_node(pos, node)
|
minetest.swap_node(pos, node)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_power(pos)
|
local function node_timer_on(pos, elapsed)
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
nvm.ele1 = nvm.ele1 or {}
|
|
||||||
nvm.consumer_powered = true
|
|
||||||
M(pos):set_string("infotext", S("TA3 Electric Motor"))
|
|
||||||
swap_node(pos, "techage:ta3_motor_on")
|
|
||||||
nvm.ticks = 0
|
|
||||||
local outdir = M(pos):get_int("outdir")
|
local outdir = M(pos):get_int("outdir")
|
||||||
nvm.ele1.curr_power = techage.power.needed_power(pos, Axle, outdir)
|
nvm.buffer = nvm.buffer or 0
|
||||||
end
|
|
||||||
|
|
||||||
local function on_nopower(pos)
|
local amount = math.min(PWR_PERF * 2 - nvm.buffer, PWR_PERF)
|
||||||
local nvm = techage.get_nvm(pos)
|
local taken = power.consume_power(pos, Cable, networks.Flip[outdir], amount)
|
||||||
nvm.consumer_powered = false
|
nvm.buffer = nvm.buffer + taken - 1 -- some loss
|
||||||
if (nvm.ticks or 0) < 4 then
|
|
||||||
M(pos):set_string("infotext", S("TA3 Electric Motor: Overload fault?\n(restart with right-click)"))
|
if nvm.buffer >= PWR_PERF then
|
||||||
|
nvm.provided = power.provide_power(pos, Axle, outdir, PWR_PERF)
|
||||||
|
nvm.load = power.get_storage_load(pos, Axle, outdir, PWR_PERF)
|
||||||
|
nvm.buffer = nvm.buffer - nvm.provided
|
||||||
end
|
end
|
||||||
nvm.ticks = 0
|
if amount > 0 and taken == 0 then
|
||||||
end
|
swap_node(pos, "techage:ta3_motor_off")
|
||||||
|
switch_axles(pos, false)
|
||||||
local function node_timer(pos, elapsed)
|
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
nvm.ele1 = nvm.ele1 or {}
|
|
||||||
|
|
||||||
-- trigger network on consumer side
|
|
||||||
nvm.ticks = (nvm.ticks or 0) + 1
|
|
||||||
if nvm.ticks % 2 then
|
|
||||||
power.consumer_alive(pos, Cable, CYCLE_TIME)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- handle generator side delayed
|
|
||||||
if nvm.ticks > 3 then
|
|
||||||
local outdir = M(pos):get_int("outdir")
|
local outdir = M(pos):get_int("outdir")
|
||||||
|
nvm.running = false
|
||||||
if nvm.consumer_powered and not nvm.running_as_generator then
|
power.start_storage_calc(pos, Cable, outdir)
|
||||||
nvm.running_as_generator = true
|
|
||||||
power.generator_start(pos, Axle, CYCLE_TIME, outdir, nvm.max_power)
|
|
||||||
switch_axles(pos, true)
|
|
||||||
elseif not nvm.consumer_powered and nvm.running_as_generator then
|
|
||||||
nvm.running_as_generator = false
|
|
||||||
power.generator_stop(pos, Axle, outdir)
|
|
||||||
switch_axles(pos, false)
|
|
||||||
end
|
|
||||||
|
|
||||||
if nvm.running_as_generator then
|
|
||||||
nvm.ele1.curr_power = power.generator_alive(pos, Axle, CYCLE_TIME, outdir, PWR_PERF) + 1
|
|
||||||
else
|
|
||||||
swap_node(pos, "techage:ta3_motor_off")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local function tubelib2_on_update2(pos, outdir, tlib2, node)
|
local function node_timer_off(pos, elapsed)
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
nvm.ele1 = nvm.ele1 or {}
|
local outdir = M(pos):get_int("outdir")
|
||||||
nvm.ele1.curr_power = 1
|
|
||||||
power.update_network(pos, outdir, tlib2)
|
if power.power_available(pos, Cable) then
|
||||||
|
swap_node(pos, "techage:ta3_motor_on")
|
||||||
|
switch_axles(pos, true)
|
||||||
|
nvm.running = true
|
||||||
|
power.start_storage_calc(pos, Cable, outdir)
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
local function get_generator_data(pos, tlib2)
|
||||||
|
local nvm = techage.get_nvm(pos)
|
||||||
|
if nvm.running then
|
||||||
|
return {level = (nvm.load or 0) / PWR_PERF, perf = PWR_PERF, capa = PWR_PERF * 2}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_node("techage:ta3_motor_off", {
|
minetest.register_node("techage:ta3_motor_off", {
|
||||||
@ -119,24 +101,10 @@ minetest.register_node("techage:ta3_motor_off", {
|
|||||||
is_ground_content = false,
|
is_ground_content = false,
|
||||||
|
|
||||||
after_place_node = function(pos)
|
after_place_node = function(pos)
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
nvm.ele1 = nvm.ele1 or {}
|
|
||||||
nvm.ele1.curr_power = 1
|
|
||||||
nvm.consumer_powered = false
|
|
||||||
nvm.running_as_generator = false
|
|
||||||
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
|
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
|
||||||
M(pos):set_int("leftdir", networks.side_to_outdir(pos, "L"))
|
|
||||||
Cable:after_place_node(pos)
|
Cable:after_place_node(pos)
|
||||||
Axle:after_place_node(pos)
|
Axle:after_place_node(pos)
|
||||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||||
power.consumer_start(pos, Cable, CYCLE_TIME*2)
|
|
||||||
M(pos):set_string("infotext", S("TA3 Electric Motor"))
|
|
||||||
end,
|
|
||||||
|
|
||||||
on_rightclick = function(pos, node, clicker)
|
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
nvm.ele1 = nvm.ele1 or {}
|
|
||||||
nvm.ele1.curr_power = 1
|
|
||||||
M(pos):set_string("infotext", S("TA3 Electric Motor"))
|
M(pos):set_string("infotext", S("TA3 Electric Motor"))
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@ -146,21 +114,8 @@ minetest.register_node("techage:ta3_motor_off", {
|
|||||||
techage.del_mem(pos)
|
techage.del_mem(pos)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
tubelib2_on_update2 = tubelib2_on_update2,
|
on_timer = node_timer_off,
|
||||||
on_timer = node_timer,
|
get_generator_data = get_generator_data,
|
||||||
networks = {
|
|
||||||
axle = {
|
|
||||||
sides = {R = 1},
|
|
||||||
ntype = "gen1",
|
|
||||||
nominal = PWR_PERF,
|
|
||||||
},
|
|
||||||
ele1 = {
|
|
||||||
sides = {L = 1},
|
|
||||||
ntype = "con1",
|
|
||||||
on_power = on_power,
|
|
||||||
on_nopower = on_nopower,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node("techage:ta3_motor_on", {
|
minetest.register_node("techage:ta3_motor_on", {
|
||||||
@ -208,21 +163,8 @@ minetest.register_node("techage:ta3_motor_on", {
|
|||||||
groups = {not_in_creative_inventory=1},
|
groups = {not_in_creative_inventory=1},
|
||||||
diggable = false,
|
diggable = false,
|
||||||
|
|
||||||
tubelib2_on_update2 = tubelib2_on_update2,
|
on_timer = node_timer_on,
|
||||||
on_timer = node_timer,
|
get_generator_data = get_generator_data,
|
||||||
networks = {
|
|
||||||
axle = {
|
|
||||||
sides = {R = 1},
|
|
||||||
ntype = "gen1",
|
|
||||||
nominal = PWR_PERF,
|
|
||||||
},
|
|
||||||
ele1 = {
|
|
||||||
sides = {L = 1},
|
|
||||||
ntype = "con1",
|
|
||||||
on_power = on_power,
|
|
||||||
on_nopower = on_nopower,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
techage.register_node({"techage:ta3_motor_off", "techage:ta3_motor_on"}, {
|
techage.register_node({"techage:ta3_motor_off", "techage:ta3_motor_on"}, {
|
||||||
@ -231,8 +173,8 @@ techage.register_node({"techage:ta3_motor_off", "techage:ta3_motor_on"}, {
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
Cable:add_secondary_node_names({"techage:ta3_motor_off", "techage:ta3_motor_on"})
|
power.register_nodes({"techage:ta3_motor_off", "techage:ta3_motor_on"}, Axle, "gen", {"R"})
|
||||||
Axle:add_secondary_node_names({"techage:ta3_motor_off", "techage:ta3_motor_on"})
|
power.register_nodes({"techage:ta3_motor_off", "techage:ta3_motor_on"}, Cable, "con", {"L"})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "techage:ta3_motor_off",
|
output = "techage:ta3_motor_off",
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
TechAge
|
TechAge
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Copyright (C) 2019-2020 Joachim Stolberg
|
Copyright (C) 2019-2021 Joachim Stolberg
|
||||||
|
|
||||||
AGPL v3
|
AGPL v3
|
||||||
See LICENSE.txt for more information
|
See LICENSE.txt for more information
|
||||||
@ -18,11 +18,10 @@ local S = techage.S
|
|||||||
|
|
||||||
local Cable = techage.ElectricCable
|
local Cable = techage.ElectricCable
|
||||||
local firebox = techage.firebox
|
local firebox = techage.firebox
|
||||||
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 power = networks.power
|
||||||
local networks = techage.networks
|
local liquid = networks.liquid
|
||||||
|
|
||||||
local CYCLE_TIME = 2
|
local CYCLE_TIME = 2
|
||||||
local PWR_CAPA = 12
|
local PWR_CAPA = 12
|
||||||
@ -34,12 +33,12 @@ local function formspec(self, pos, nvm)
|
|||||||
default.gui_bg_img..
|
default.gui_bg_img..
|
||||||
default.gui_slots..
|
default.gui_slots..
|
||||||
"box[0,-0.1;4.8,0.5;#c6e8ff]"..
|
"box[0,-0.1;4.8,0.5;#c6e8ff]"..
|
||||||
"label[1.5,-0.1;"..minetest.colorize( "#000000", S("Tiny Generator")).."]"..
|
"label[0.2,-0.1;"..minetest.colorize( "#000000", S("Tiny Generator")).."]"..
|
||||||
fuel.fuel_container(0, 0.9, nvm)..
|
fuel.fuel_container(0, 0.9, nvm)..
|
||||||
"image[1.4,1.6;1,1;techage_form_arrow_bg.png^[transformR270]"..
|
"image[1.4,1.6;1,1;techage_form_arrow_bg.png^[transformR270]"..
|
||||||
"image_button[1.4,3.2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
|
"image_button[1.4,3.2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
|
||||||
"tooltip[1.5,3;1,1;"..self:get_state_tooltip(nvm).."]"..
|
"tooltip[1.5,3;1,1;"..self:get_state_tooltip(nvm).."]"..
|
||||||
power.formspec_label_bar(pos, 2.5, 0.8, S("Electricity"), PWR_CAPA, nvm.provided)
|
techage.formspec_power_bar(pos, 2.5, 0.8, S("Electricity"), nvm.provided, PWR_CAPA)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function play_sound(pos)
|
local function play_sound(pos)
|
||||||
@ -74,7 +73,7 @@ end
|
|||||||
local function start_node(pos, nvm, state)
|
local function start_node(pos, nvm, state)
|
||||||
nvm.running = true -- needed by fuel_lib
|
nvm.running = true -- needed by fuel_lib
|
||||||
local outdir = M(pos):get_int("outdir")
|
local outdir = M(pos):get_int("outdir")
|
||||||
power.generator_start(pos, Cable, CYCLE_TIME, outdir)
|
power.start_storage_calc(pos, Cable, outdir)
|
||||||
play_sound(pos)
|
play_sound(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -82,7 +81,7 @@ local function stop_node(pos, nvm, state)
|
|||||||
nvm.running = false
|
nvm.running = false
|
||||||
nvm.provided = 0
|
nvm.provided = 0
|
||||||
local outdir = M(pos):get_int("outdir")
|
local outdir = M(pos):get_int("outdir")
|
||||||
power.generator_stop(pos, Cable, outdir)
|
power.start_storage_calc(pos, Cable, outdir)
|
||||||
stop_sound(pos)
|
stop_sound(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -122,15 +121,19 @@ local function burning(pos, nvm)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function node_timer(pos, elapsed)
|
local function node_timer(pos, elapsed)
|
||||||
|
local meta = M(pos)
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
local outdir = M(pos):get_int("outdir")
|
local outdir = meta:get_int("outdir")
|
||||||
|
local tp1 = tonumber(meta:get_string("termpoint1"))
|
||||||
|
local tp2 = tonumber(meta:get_string("termpoint2"))
|
||||||
if nvm.running and burning(pos, nvm) then
|
if nvm.running and burning(pos, nvm) then
|
||||||
nvm.provided = power.generator_alive(pos, Cable, CYCLE_TIME, outdir)
|
nvm.provided = power.provide_power(pos, Cable, outdir, PWR_CAPA, tp1, tp2)
|
||||||
|
nvm.load = power.get_storage_load(pos, Cable, outdir, PWR_CAPA)
|
||||||
else
|
else
|
||||||
nvm.provided = 0
|
nvm.provided = 0
|
||||||
end
|
end
|
||||||
if techage.is_activeformspec(pos) then
|
if techage.is_activeformspec(pos) then
|
||||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
meta:set_string("formspec", formspec(State, pos, nvm))
|
||||||
end
|
end
|
||||||
return State:is_active(nvm)
|
return State:is_active(nvm)
|
||||||
end
|
end
|
||||||
@ -150,42 +153,12 @@ local function on_rightclick(pos, node, clicker)
|
|||||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||||
end
|
end
|
||||||
|
|
||||||
local liquid_def = {
|
local function get_generator_data(pos, tlib2)
|
||||||
fuel_cat = fuel.BT_NAPHTHA,
|
local nvm = techage.get_nvm(pos)
|
||||||
capa = fuel.CAPACITY,
|
if nvm.running then
|
||||||
peek = liquid.srv_peek,
|
return {level = (nvm.load or 0) / PWR_CAPA, perf = PWR_CAPA, capa = PWR_CAPA * 2}
|
||||||
put = function(pos, indir, name, amount)
|
|
||||||
if fuel.valid_fuel(name, fuel.BT_OIL) then
|
|
||||||
local res = liquid.srv_put(pos, indir, name, amount)
|
|
||||||
if techage.is_activeformspec(pos) then
|
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
|
||||||
end
|
|
||||||
return res
|
|
||||||
end
|
|
||||||
return amount
|
|
||||||
end,
|
|
||||||
take = function(pos, indir, name, amount)
|
|
||||||
amount, name = liquid.srv_take(pos, indir, name, amount)
|
|
||||||
if techage.is_activeformspec(pos) then
|
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
|
||||||
end
|
|
||||||
return amount, name
|
|
||||||
end
|
end
|
||||||
}
|
end
|
||||||
|
|
||||||
local net_def = {
|
|
||||||
pipe2 = {
|
|
||||||
sides = techage.networks.AllSides, -- Pipe connection sides
|
|
||||||
ntype = "tank",
|
|
||||||
},
|
|
||||||
ele1 = {
|
|
||||||
sides = {R = 1},
|
|
||||||
ntype = "gen1",
|
|
||||||
nominal = PWR_CAPA,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
minetest.register_node("techage:tiny_generator", {
|
minetest.register_node("techage:tiny_generator", {
|
||||||
description = S("TA3 Tiny Power Generator"),
|
description = S("TA3 Tiny Power Generator"),
|
||||||
@ -221,13 +194,13 @@ minetest.register_node("techage:tiny_generator", {
|
|||||||
techage.del_mem(pos)
|
techage.del_mem(pos)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
get_generator_data = get_generator_data,
|
||||||
|
ta3_formspec = techage.generator_settings("ta3", PWR_CAPA),
|
||||||
on_receive_fields = on_receive_fields,
|
on_receive_fields = on_receive_fields,
|
||||||
on_rightclick = on_rightclick,
|
on_rightclick = on_rightclick,
|
||||||
on_punch = fuel.on_punch,
|
on_punch = fuel.on_punch,
|
||||||
on_timer = node_timer,
|
on_timer = node_timer,
|
||||||
can_dig = fuel.can_dig,
|
can_dig = fuel.can_dig,
|
||||||
liquid = liquid_def,
|
|
||||||
networks = net_def,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node("techage:tiny_generator_on", {
|
minetest.register_node("techage:tiny_generator_on", {
|
||||||
@ -268,17 +241,56 @@ minetest.register_node("techage:tiny_generator_on", {
|
|||||||
on_rotate = screwdriver.disallow,
|
on_rotate = screwdriver.disallow,
|
||||||
is_ground_content = false,
|
is_ground_content = false,
|
||||||
|
|
||||||
|
get_generator_data = get_generator_data,
|
||||||
|
ta3_formspec = techage.generator_settings("ta3", PWR_CAPA),
|
||||||
on_receive_fields = on_receive_fields,
|
on_receive_fields = on_receive_fields,
|
||||||
on_rightclick = on_rightclick,
|
on_rightclick = on_rightclick,
|
||||||
on_punch = fuel.on_punch,
|
on_punch = fuel.on_punch,
|
||||||
on_timer = node_timer,
|
on_timer = node_timer,
|
||||||
can_dig = fuel.can_dig,
|
can_dig = fuel.can_dig,
|
||||||
liquid = liquid_def,
|
|
||||||
networks = net_def,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
Pipe:add_secondary_node_names({"techage:tiny_generator", "techage:tiny_generator_on"})
|
local liquid_def = {
|
||||||
Cable:add_secondary_node_names({"techage:tiny_generator", "techage:tiny_generator_on"})
|
fuel_cat = fuel.BT_GASOLINE,
|
||||||
|
capa = fuel.CAPACITY,
|
||||||
|
peek = function(pos)
|
||||||
|
local nvm = techage.get_nvm(pos)
|
||||||
|
return liquid.srv_peek(nvm)
|
||||||
|
end,
|
||||||
|
put = function(pos, indir, name, amount)
|
||||||
|
if techage.fuel.valid_fuel(name, fuel.BT_GASOLINE) then
|
||||||
|
local nvm = techage.get_nvm(pos)
|
||||||
|
local leftover = liquid.srv_put(nvm, name, amount, fuel.CAPACITY)
|
||||||
|
if techage.is_activeformspec(pos) then
|
||||||
|
local nvm = techage.get_nvm(pos)
|
||||||
|
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||||
|
end
|
||||||
|
return leftover
|
||||||
|
end
|
||||||
|
return amount
|
||||||
|
end,
|
||||||
|
take = function(pos, indir, name, amount)
|
||||||
|
local nvm = techage.get_nvm(pos)
|
||||||
|
local taken = liquid.srv_take(nvm, name, amount)
|
||||||
|
if techage.is_activeformspec(pos) then
|
||||||
|
local nvm = techage.get_nvm(pos)
|
||||||
|
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||||
|
end
|
||||||
|
return taken
|
||||||
|
end,
|
||||||
|
untake = function(pos, indir, name, amount)
|
||||||
|
local nvm = techage.get_nvm(pos)
|
||||||
|
local leftover = liquid.srv_put(nvm, name, amount, fuel.CAPACITY)
|
||||||
|
if techage.is_activeformspec(pos) then
|
||||||
|
local nvm = techage.get_nvm(pos)
|
||||||
|
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||||
|
end
|
||||||
|
return leftover
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
|
||||||
|
power.register_nodes({"techage:tiny_generator", "techage:tiny_generator_on"}, Cable, "gen", {"R"})
|
||||||
|
liquid.register_nodes({"techage:tiny_generator", "techage:tiny_generator_on"}, Pipe, "tank", nil, liquid_def)
|
||||||
|
|
||||||
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)
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 163 B After Width: | Height: | Size: 134 B |
@ -3,12 +3,11 @@
|
|||||||
TechAge
|
TechAge
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Copyright (C) 2017-2019 Joachim Stolberg
|
Copyright (C) 2017-2021 Joachim Stolberg
|
||||||
|
|
||||||
AGPL v3
|
AGPL v3
|
||||||
See LICENSE.txt for more information
|
See LICENSE.txt for more information
|
||||||
|
|
||||||
repairkit.lua:
|
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
-- for lazy programmers
|
-- for lazy programmers
|
||||||
@ -18,178 +17,23 @@ local S = techage.S
|
|||||||
local Cable1 = techage.ElectricCable
|
local Cable1 = techage.ElectricCable
|
||||||
local Cable2 = techage.TA4_Cable
|
local Cable2 = techage.TA4_Cable
|
||||||
local Pipe2 = techage.LiquidPipe
|
local Pipe2 = techage.LiquidPipe
|
||||||
local networks = techage.networks
|
local menu = dofile(minetest.get_modpath("techage") .. "/tools/submenu.lua")
|
||||||
|
|
||||||
local ListOfNodes = {
|
|
||||||
["techage:generator"] = true,
|
|
||||||
["techage:generator_on"] = true,
|
|
||||||
["techage:ta4_generator"] = true,
|
|
||||||
["techage:ta4_generator_on"] = true,
|
|
||||||
["techage:ta4_fuelcell"] = true,
|
|
||||||
["techage:ta4_fuelcell_on"] = true,
|
|
||||||
["techage:t3_pump"] = true,
|
|
||||||
["techage:t3_pump_on"] = true,
|
|
||||||
["techage:t4_pump"] = true,
|
|
||||||
["techage:t4_pump_on"] = true,
|
|
||||||
["techage:ta4_solar_inverter"] = true,
|
|
||||||
["techage:flywheel"] = true,
|
|
||||||
["techage:flywheel_on"] = true,
|
|
||||||
["techage:tiny_generator"] = true,
|
|
||||||
["techage:tiny_generator_on"] = true,
|
|
||||||
["techage:ta4_electrolyzer"] = true,
|
|
||||||
["techage:ta4_electrolyzer_on"] = true,
|
|
||||||
["techage:oilfirebox"] = true,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
local function delete_data(pos)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
local owner = meta:get_string("owner")
|
|
||||||
local number = meta:get_string("number")
|
|
||||||
local node_number = meta:get_string("node_number")
|
|
||||||
tubelib2.del_mem(pos)
|
|
||||||
meta:from_table(nil)
|
|
||||||
meta:set_string("owner", owner)
|
|
||||||
meta:set_string("number", number)
|
|
||||||
meta:set_string("node_number", node_number)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function inv_get_count(inv, listname, size)
|
|
||||||
local cnt = 0
|
|
||||||
for i = 1,size do
|
|
||||||
cnt = cnt + inv:get_stack(listname, i):get_count()
|
|
||||||
end
|
|
||||||
return cnt
|
|
||||||
end
|
|
||||||
|
|
||||||
local function inv_get_name(inv, listname, size)
|
|
||||||
for i = 1,size do
|
|
||||||
local name = inv:get_stack(listname, i):get_name()
|
|
||||||
if name ~= "" then
|
|
||||||
return name
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return ""
|
|
||||||
end
|
|
||||||
|
|
||||||
local function inv_clear(inv, listname, size)
|
|
||||||
for i = 1,size do
|
|
||||||
inv:set_stack(listname, i, nil)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function restore_inv_content(pos, listname, size)
|
|
||||||
local inv = M(pos):get_inventory()
|
|
||||||
local count = inv_get_count(inv, listname, size)
|
|
||||||
if count > 0 then
|
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
nvm.liquid = nvm.liquid or {}
|
|
||||||
nvm.liquid.amount = count
|
|
||||||
nvm.liquid.name = inv_get_name(inv, listname, size)
|
|
||||||
inv:set_stack(listname, 1, nil)
|
|
||||||
inv_clear(inv, listname, size)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
local function init_data(pos, netw)
|
|
||||||
local sides = netw.ele1 and netw.ele1.sides
|
|
||||||
if sides and sides["R"] then
|
|
||||||
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
|
|
||||||
M(pos):set_string("infotext", "repaired")
|
|
||||||
end
|
|
||||||
|
|
||||||
sides = netw.pipe2 and netw.pipe2.sides
|
|
||||||
if sides and sides["R"] then
|
|
||||||
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
|
|
||||||
M(pos):set_string("infotext", "repaired")
|
|
||||||
end
|
|
||||||
|
|
||||||
sides = netw.ele2 and netw.ele2.sides
|
|
||||||
if sides and sides["L"] then
|
|
||||||
M(pos):set_int("leftdir", networks.side_to_outdir(pos, "L"))
|
|
||||||
end
|
|
||||||
|
|
||||||
sides = netw.axle and netw.axle.sides
|
|
||||||
if sides and sides["R"] then
|
|
||||||
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
|
|
||||||
end
|
|
||||||
|
|
||||||
Cable1:after_place_node(pos)
|
|
||||||
Cable2:after_place_node(pos)
|
|
||||||
Pipe2:after_place_node(pos)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function repair(itemstack, user, pointed_thing)
|
|
||||||
local pos = pointed_thing.under
|
|
||||||
if pos and user then
|
|
||||||
if minetest.is_protected(pos, user:get_player_name()) then
|
|
||||||
return itemstack
|
|
||||||
end
|
|
||||||
|
|
||||||
local number = techage.get_node_number(pos)
|
|
||||||
local node = minetest.get_node(pos)
|
|
||||||
local ndef = minetest.registered_nodes[node.name]
|
|
||||||
if ndef then
|
|
||||||
local netw = ndef.networks
|
|
||||||
if netw and ListOfNodes[node.name] then
|
|
||||||
if node.name == "techage:tiny_generator" or node.name == "techage:tiny_generator_on" then
|
|
||||||
restore_inv_content(pos, "fuel", 1)
|
|
||||||
elseif node.name == "techage:oilfirebox" then
|
|
||||||
restore_inv_content(pos, "fuel", 1)
|
|
||||||
elseif node.name == "techage:ta4_fuelcell" or node.name == "techage:ta4_fuelcell_on" then
|
|
||||||
restore_inv_content(pos, "src", 4)
|
|
||||||
elseif node.name == "techage:ta4_electrolyzer" or node.name == "techage:ta4_electrolyzer_on" then
|
|
||||||
restore_inv_content(pos, "dst", 1)
|
|
||||||
end
|
|
||||||
delete_data(pos)
|
|
||||||
init_data(pos, netw)
|
|
||||||
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..S("repaired"))
|
|
||||||
itemstack:add_wear(65636/200)
|
|
||||||
return itemstack
|
|
||||||
end
|
|
||||||
|
|
||||||
if netw and netw.ele1 and netw.ele1.ntype == "junc" then
|
|
||||||
if ndef.after_place_node and ndef.tubelib2_on_update2 then
|
|
||||||
ndef.after_place_node(pos)
|
|
||||||
ndef.tubelib2_on_update2(pos, 0, Cable1)
|
|
||||||
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..S("repaired"))
|
|
||||||
itemstack:add_wear(65636/200)
|
|
||||||
return itemstack
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if netw and netw.ele2 and netw.ele2.ntype == "junc" then
|
|
||||||
if ndef.after_place_node and ndef.tubelib2_on_update2 then
|
|
||||||
ndef.after_place_node(pos)
|
|
||||||
ndef.tubelib2_on_update2(pos, 0, Cable2)
|
|
||||||
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..S("repaired"))
|
|
||||||
itemstack:add_wear(65636/200)
|
|
||||||
return itemstack
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return itemstack
|
|
||||||
end
|
|
||||||
|
|
||||||
local function network_check(start_pos, Cable, player_name)
|
local function network_check(start_pos, Cable, player_name)
|
||||||
local ndef = techage.networks.net_def(start_pos, Cable.tube_type)
|
-- local ndef = techage.networks.net_def(start_pos, Cable.tube_type)
|
||||||
local outdir = nil
|
-- local outdir = nil
|
||||||
local num = 0
|
-- local num = 0
|
||||||
if ndef and ndef.ntype ~= "junc" then
|
-- if ndef and ndef.ntype ~= "junc" then
|
||||||
outdir = M(start_pos):get_int("outdir")
|
-- outdir = M(start_pos):get_int("outdir")
|
||||||
end
|
-- end
|
||||||
networks.connection_walk(start_pos, outdir, Cable, function(pos, indir, node)
|
-- networks.connection_walk(start_pos, outdir, Cable, function(pos, indir, node)
|
||||||
local distance = vector.distance(start_pos, pos)
|
-- local distance = vector.distance(start_pos, pos)
|
||||||
num = num + 1
|
-- num = num + 1
|
||||||
if distance < 50 and num < 100 then
|
-- if distance < 50 and num < 100 then
|
||||||
local state = techage.power.power_available(pos, Cable) and "power" or "no power"
|
-- local state = techage.power.power_available(pos, Cable) and "power" or "no power"
|
||||||
techage.mark_position(player_name, pos, state, "#ff0000", 6)
|
-- techage.mark_position(player_name, pos, state, "#ff0000", 6)
|
||||||
end
|
-- end
|
||||||
end)
|
-- end)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function read_state(itemstack, user, pointed_thing)
|
local function read_state(itemstack, user, pointed_thing)
|
||||||
@ -233,7 +77,7 @@ local function read_state(itemstack, user, pointed_thing)
|
|||||||
local info = techage.send_single("0", number, "info", nil)
|
local info = techage.send_single("0", number, "info", nil)
|
||||||
if info and info ~= "" and info ~= "unsupported" then
|
if info and info ~= "" and info ~= "unsupported" then
|
||||||
info = dump(info)
|
info = dump(info)
|
||||||
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": Supported Commands:\n"..info.." ")
|
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..":\n"..info.." ")
|
||||||
end
|
end
|
||||||
local state = techage.send_single("0", number, "state", nil)
|
local state = techage.send_single("0", number, "state", nil)
|
||||||
if state and state ~= "" and state ~= "unsupported" then
|
if state and state ~= "" and state ~= "unsupported" then
|
||||||
@ -284,13 +128,64 @@ local function read_state(itemstack, user, pointed_thing)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local context = {}
|
||||||
|
|
||||||
|
local function settings_menu(pos, playername)
|
||||||
|
local number = techage.get_node_number(pos)
|
||||||
|
local node = minetest.get_node(pos)
|
||||||
|
local ndef = minetest.registered_nodes[node.name]
|
||||||
|
local form_def = ndef and (ndef.ta3_formspec or ndef.ta4_formspec)
|
||||||
|
|
||||||
|
context[playername] = pos
|
||||||
|
if form_def then
|
||||||
|
minetest.show_formspec(playername, "techage:ta_formspec", menu.generate_formspec(pos, ndef, form_def))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
|
if formname ~= "techage:ta_formspec" then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local playername = player:get_player_name()
|
||||||
|
local pos = context[playername]
|
||||||
|
if pos then
|
||||||
|
--context[playername] = nil
|
||||||
|
local number = techage.get_node_number(pos)
|
||||||
|
local node = minetest.get_node(pos)
|
||||||
|
local ndef = minetest.registered_nodes[node.name]
|
||||||
|
local form_def = ndef and (ndef.ta3_formspec or ndef.ta4_formspec)
|
||||||
|
|
||||||
|
if form_def then
|
||||||
|
if menu.eval_input(pos, ndef, form_def, fields) then
|
||||||
|
--context[playername] = pos
|
||||||
|
minetest.after(0.2, function()
|
||||||
|
minetest.show_formspec(playername, "techage:ta_formspec", menu.generate_formspec(pos, ndef, form_def))
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
local function on_place(itemstack, placer, pointed_thing)
|
||||||
|
if pointed_thing.type == "node" then
|
||||||
|
local pos = pointed_thing.under
|
||||||
|
local playername = placer:get_player_name()
|
||||||
|
if placer:get_player_control().sneak then
|
||||||
|
settings_menu(pos, playername)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_tool("techage:repairkit", {
|
minetest.register_tool("techage:repairkit", {
|
||||||
description = S("TechAge Repair Kit"),
|
description = S("TechAge Repair Kit"),
|
||||||
inventory_image = "techage_repairkit.png",
|
inventory_image = "techage_repairkit.png",
|
||||||
wield_image = "techage_repairkit.png^[transformR270",
|
wield_image = "techage_repairkit.png^[transformR270",
|
||||||
groups = {cracky=1, book=1},
|
groups = {cracky=1, book=1},
|
||||||
on_use = repair,
|
--on_use = repair,
|
||||||
on_place = repair,
|
--on_place = repair,
|
||||||
node_placement_prediction = "",
|
node_placement_prediction = "",
|
||||||
stack_max = 1,
|
stack_max = 1,
|
||||||
})
|
})
|
||||||
@ -302,21 +197,12 @@ minetest.register_tool("techage:end_wrench", {
|
|||||||
wield_image = "techage_end_wrench.png",
|
wield_image = "techage_end_wrench.png",
|
||||||
groups = {cracky=1, book=1},
|
groups = {cracky=1, book=1},
|
||||||
on_use = read_state,
|
on_use = read_state,
|
||||||
on_place = read_state,
|
on_place = on_place,
|
||||||
node_placement_prediction = "",
|
node_placement_prediction = "",
|
||||||
liquids_pointable = true,
|
liquids_pointable = true,
|
||||||
stack_max = 1,
|
stack_max = 1,
|
||||||
})
|
})
|
||||||
|
|
||||||
--minetest.register_craft({
|
|
||||||
-- output = "techage:repairkit",
|
|
||||||
-- recipe = {
|
|
||||||
-- {"", "basic_materials:gear_steel", ""},
|
|
||||||
-- {"", "techage:end_wrench", ""},
|
|
||||||
-- {"", "basic_materials:oil_extract", ""},
|
|
||||||
-- },
|
|
||||||
--})
|
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "techage:end_wrench",
|
output = "techage:end_wrench",
|
||||||
recipe = {
|
recipe = {
|
||||||
|
190
tools/submenu.lua
Normal file
190
tools/submenu.lua
Normal file
@ -0,0 +1,190 @@
|
|||||||
|
--[[
|
||||||
|
|
||||||
|
TechAge
|
||||||
|
=======
|
||||||
|
|
||||||
|
Copyright (C) 2019-2021 Joachim Stolberg
|
||||||
|
|
||||||
|
AGPL v3
|
||||||
|
See LICENSE.txt for more information
|
||||||
|
|
||||||
|
A formspec control to generate formspec strings for machine settings and monitoring
|
||||||
|
]]--
|
||||||
|
|
||||||
|
local S = techage.S
|
||||||
|
|
||||||
|
local menu = {}
|
||||||
|
|
||||||
|
local function index(list, x)
|
||||||
|
for idx, v in ipairs(list) do
|
||||||
|
if v == x then return idx end
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- generate the formspec string to be placed into a container frame
|
||||||
|
local function generate_formspec_substring(pos, meta, form_def)
|
||||||
|
local tbl = {}
|
||||||
|
if meta and form_def then
|
||||||
|
local nvm = techage.get_nvm(pos)
|
||||||
|
|
||||||
|
for i,elem in ipairs(form_def) do
|
||||||
|
local offs = (i - 1) * 0.9 - 0.2
|
||||||
|
tbl[#tbl+1] = "label[0," .. offs .. ";" .. minetest.formspec_escape(elem.label) .. ":]"
|
||||||
|
tbl[#tbl+1] = "tooltip[0," .. offs .. ";4,1;" .. elem.tooltip .. "]"
|
||||||
|
if elem.type == "number" then
|
||||||
|
local val = meta:get_int(elem.name)
|
||||||
|
if nvm.running then
|
||||||
|
tbl[#tbl+1] = "label[4.75," .. offs .. ";" .. val .. "]"
|
||||||
|
else
|
||||||
|
tbl[#tbl+1] = "field[5," .. (offs+0.2) .. ";5.3,1;" .. elem.name .. ";;" .. val .. "]"
|
||||||
|
end
|
||||||
|
elseif elem.type == "numbers" then
|
||||||
|
local val = meta:get_string(elem.name)
|
||||||
|
if nvm.running then
|
||||||
|
tbl[#tbl+1] = "label[4.75," .. offs .. ";" .. val .. "]"
|
||||||
|
else
|
||||||
|
tbl[#tbl+1] = "field[5," .. (offs+0.2) .. ";5.3,1;" .. elem.name .. ";;" .. val .. "]"
|
||||||
|
end
|
||||||
|
elseif elem.type == "float" then
|
||||||
|
local val = tonumber(meta:get_string(elem.name)) or 0
|
||||||
|
if nvm.running then
|
||||||
|
tbl[#tbl+1] = "label[4.75," .. offs .. ";" .. val .. "]"
|
||||||
|
else
|
||||||
|
tbl[#tbl+1] = "field[5," .. (offs+0.2) .. ";5.3,1;" .. elem.name .. ";;" .. val .. "]"
|
||||||
|
end
|
||||||
|
elseif elem.type == "ascii" then
|
||||||
|
local val = meta:get_string(elem.name)
|
||||||
|
if nvm.running then
|
||||||
|
tbl[#tbl+1] = "label[4.75," .. offs .. ";" .. minetest.formspec_escape(val) .. "]"
|
||||||
|
else
|
||||||
|
tbl[#tbl+1] = "field[5," .. (offs+0.2) .. ";5.3,1;" .. elem.name .. ";;" .. minetest.formspec_escape(val) .. "]"
|
||||||
|
end
|
||||||
|
elseif elem.type == "const" then
|
||||||
|
tbl[#tbl+1] = "label[4.75," .. offs .. ";" .. elem.value .. "]"
|
||||||
|
elseif elem.type == "output" then
|
||||||
|
local val = nvm[elem.name] or ""
|
||||||
|
if tonumber(val) then
|
||||||
|
val = techage.round(val)
|
||||||
|
end
|
||||||
|
tbl[#tbl+1] = "label[4.75," .. offs .. ";" .. val .. "]"
|
||||||
|
elseif elem.type == "dropdown" then
|
||||||
|
local l = elem.choices:split(",")
|
||||||
|
if nvm.running then
|
||||||
|
local val = meta:get_string(elem.name) or ""
|
||||||
|
tbl[#tbl+1] = "label[4.75," .. offs .. ";" .. val .. "]"
|
||||||
|
else
|
||||||
|
local val = meta:get_string(elem.name) or ""
|
||||||
|
local idx = index(l, val) or 1
|
||||||
|
tbl[#tbl+1] = "dropdown[4.72," .. (offs) .. ";5.5,1.4;" .. elem.name .. ";" .. elem.choices .. ";" .. idx .. "]"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return table.concat(tbl, "")
|
||||||
|
end
|
||||||
|
|
||||||
|
local function value_check(elem, value)
|
||||||
|
if elem.check then
|
||||||
|
return elem.check(value)
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
local function evaluate_data(pos, meta, form_def, fields)
|
||||||
|
local res = true
|
||||||
|
|
||||||
|
if meta and form_def then
|
||||||
|
local nvm = techage.get_nvm(pos)
|
||||||
|
if not nvm.running then
|
||||||
|
|
||||||
|
for idx,elem in ipairs(form_def) do
|
||||||
|
if elem.type == "number" then
|
||||||
|
if fields[elem.name] then
|
||||||
|
if fields[elem.name]:find("^[%d ]+$") then
|
||||||
|
local val = tonumber(fields[elem.name])
|
||||||
|
if value_check(elem, val) then
|
||||||
|
meta:set_int(elem.name, val)
|
||||||
|
print("set_int", elem.name, val)
|
||||||
|
else
|
||||||
|
res = false
|
||||||
|
end
|
||||||
|
else
|
||||||
|
res = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif elem.type == "numbers" then
|
||||||
|
if fields[elem.name] then
|
||||||
|
if fields[elem.name]:find("^[%d ]+$") and value_check(elem, fields[elem.name]) then
|
||||||
|
meta:set_string(elem.name, fields[elem.name])
|
||||||
|
else
|
||||||
|
res = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif elem.type == "float" then
|
||||||
|
if fields[elem.name] then
|
||||||
|
local val = tonumber(fields[elem.name])
|
||||||
|
if val and value_check(elem, val) then
|
||||||
|
meta:set_string(elem.name, val)
|
||||||
|
else
|
||||||
|
res = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif elem.type == "ascii" then
|
||||||
|
if fields[elem.name] then
|
||||||
|
if value_check(elem, fields[elem.name]) then
|
||||||
|
meta:set_string(elem.name, fields[elem.name])
|
||||||
|
else
|
||||||
|
res = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif elem.type == "dropdown" then
|
||||||
|
if fields[elem.name] ~= nil then
|
||||||
|
meta:set_string(elem.name, fields[elem.name])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return res
|
||||||
|
end
|
||||||
|
|
||||||
|
function menu.generate_formspec(pos, ndef, form_def)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local number = techage.get_node_number(pos)
|
||||||
|
local mem = techage.get_mem(pos)
|
||||||
|
mem.star = ((mem.star or 0) + 1) % 2
|
||||||
|
local star = mem.star == 1 and "*" or ""
|
||||||
|
|
||||||
|
if meta and number and ndef and form_def then
|
||||||
|
local title = ndef.description .. " (" .. number .. ")"
|
||||||
|
|
||||||
|
return "size[10,9]" ..
|
||||||
|
default.gui_bg ..
|
||||||
|
default.gui_bg_img ..
|
||||||
|
default.gui_slots ..
|
||||||
|
"box[0,-0.1;9.8,0.5;#c6e8ff]" ..
|
||||||
|
"label[0.2,-0.1;" .. minetest.colorize( "#000000", title) .. "]" ..
|
||||||
|
"label[9.5,-0.1;" .. minetest.colorize( "#000000", star) .. "]" ..
|
||||||
|
"container[0,1]" ..
|
||||||
|
generate_formspec_substring(pos, meta, form_def) ..
|
||||||
|
"container_end[]" ..
|
||||||
|
"button[0.5,8.4;3,1;refresh;" .. S("Refresh") .. "]" ..
|
||||||
|
"button_exit[3.5,8.4;3,1;cancel;" .. S("Cancel") .. "]" ..
|
||||||
|
"button[6.5,8.4;3,1;save;" .. S("Save") .. "]"
|
||||||
|
end
|
||||||
|
return ""
|
||||||
|
end
|
||||||
|
|
||||||
|
function menu.eval_input(pos, ndef, form_def, fields)
|
||||||
|
--print(dump(fields))
|
||||||
|
if fields.save then
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
evaluate_data(pos, meta, form_def, fields)
|
||||||
|
end
|
||||||
|
return fields.refresh or fields.save
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
return menu
|
Loading…
Reference in New Issue
Block a user