complete restructured

This commit is contained in:
Joachim Stolberg 2020-01-25 23:15:44 +01:00
parent 08c89b178a
commit 05f0fe64bd
74 changed files with 1917 additions and 5341 deletions

View File

@ -1,10 +1,24 @@
--[[
TechAge
=======
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
Demo for a electrical power consuming node
]]--
-- for lazy programmers
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local P = minetest.string_to_pos
local P2S = minetest.pos_to_string
local M = minetest.get_meta
local S = techage.S
local PWR_NEEDED = 5
local CYCLE_TIME = 4
local CYCLE_TIME = 2
local Cable = techage.ElectricCable
local power = techage.power
@ -18,59 +32,74 @@ local function swap_node(pos, name)
minetest.swap_node(pos, node)
end
local function on_power(pos, mem)
if mem.running then
swap_node(pos, "techage:sink_on")
minetest.get_node_timer(pos):start(CYCLE_TIME)
M(pos):set_string("infotext", "on")
end
local function on_power(pos)
print("on_power sink "..P2S(pos))
swap_node(pos, "techage:sink_on")
M(pos):set_string("infotext", "on")
end
local function on_nopower(pos, mem)
local function on_nopower(pos)
print("on_nopower sink "..P2S(pos))
swap_node(pos, "techage:sink")
M(pos):set_string("infotext", "nopower")
M(pos):set_string("infotext", "off")
end
local function node_timer(pos, elapsed)
--print("node_timer sink "..S(pos))
local mem = tubelib2.get_mem(pos)
power.consumer_alive(pos, mem)
return mem.running
--print("node_timer sink "..P2S(pos))
local nvm = techage.get_nvm(pos)
power.consumer_alive(pos, Cable, CYCLE_TIME)
-- if not techage.power.power_available(pos, Cable) then
-- nvm.running = false
-- swap_node(pos, "techage:sink")
-- power.consumer_stop(pos, Cable)
-- minetest.get_node_timer(pos):stop()
-- M(pos):set_string("infotext", "off")
-- end
return true
end
local function on_rightclick(pos, node, clicker)
local mem = tubelib2.get_mem(pos)
if not mem.running and power.power_available(pos, mem, PWR_NEEDED) then
mem.running = true
power.consumer_start(pos, mem, CYCLE_TIME, PWR_NEEDED)
local nvm = techage.get_nvm(pos)
if not nvm.running and power.power_available(pos, Cable) then
nvm.running = true
-- swap will be performed via on_power()
power.consumer_start(pos, Cable, CYCLE_TIME)
minetest.get_node_timer(pos):start(CYCLE_TIME)
M(pos):set_string("infotext", "...")
else
mem.running = false
nvm.running = false
swap_node(pos, "techage:sink")
power.consumer_stop(pos, mem)
power.consumer_stop(pos, Cable)
minetest.get_node_timer(pos):stop()
M(pos):set_string("infotext", "off")
end
end
--
-- Modul shows the usage of the power2 alternative function set
--
local function after_place_node(pos)
local mem = tubelib2.init_mem(pos)
local nvm = techage.get_nvm(pos)
M(pos):set_string("infotext", "off")
techage.power.after_place_node(pos)
Cable:after_place_node(pos)
end
local function after_dig_node(pos, oldnode)
techage.power.after_dig_node(pos, oldnode)
tubelib2.del_mem(pos)
Cable:after_dig_node(pos)
techage.del_mem(pos)
end
local function after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir)
techage.power.after_tube_update2(node, pos, out_dir, peer_pos, peer_in_dir)
local function tubelib2_on_update2(pos, outdir, tlib2, node)
power.update_network(pos, outdir, tlib2)
end
local net_def = {
ele1 = {
sides = techage.networks.AllSides, -- Cable connection sides
ntype = "con1",
on_power = on_power,
on_nopower = on_nopower,
nominal = PWR_NEEDED,
},
}
minetest.register_node("techage:sink", {
description = "Sink",
tiles = {'techage_electric_button.png'},
@ -79,13 +108,13 @@ minetest.register_node("techage:sink", {
on_rightclick = on_rightclick,
after_place_node = after_place_node,
after_dig_node = after_dig_node,
after_tube_update = after_tube_update,
tubelib2_on_update2 = tubelib2_on_update2,
networks = net_def,
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {choppy=2, cracky=2, crumbly=2},
groups = {choppy = 2, cracky = 2, crumbly = 2},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
@ -98,22 +127,18 @@ minetest.register_node("techage:sink_on", {
on_rightclick = on_rightclick,
after_place_node = after_place_node,
after_dig_node = after_dig_node,
after_tube_update = after_tube_update,
tubelib2_on_update2 = tubelib2_on_update2,
networks = net_def,
paramtype = "light",
light_source = minetest.LIGHT_MAX,
sunlight_propagates = true,
paramtype2 = "facedir",
diggable = false,
drop = "",
groups = {not_in_creative_inventory=1},
groups = {not_in_creative_inventory = 1},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
-- Alternative registration function
techage.power.enrich_node({"techage:sink", "techage:sink_on"}, {
power_network = Cable,
on_power = on_power,
on_nopower = on_nopower,
})
Cable:add_secondary_node_names({"techage:sink", "techage:sink_on"})

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -28,16 +28,17 @@ local STANDBY_TICKS = 6
local COUNTDOWN_TICKS = 4
local CYCLE_TIME = 4
local function formspec(self, pos, mem)
local function formspec(self, pos, nvm)
return "size[8,9.2]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"list[context;recipe;0,0;3,3;]"..
"image[2.9,1;1,1;techage_form_arrow.png]"..
"image[3.8,0;1,1;"..techage.get_power_image(pos, mem).."]"..
"image[3.8,0;1,1;"..techage.get_power_image(pos, nvm).."]"..
"list[context;output;3.8,1;1,1;]"..
"image_button[3.8,2;1,1;".. self:get_state_button_image(mem) ..";state_button;]"..
"image_button[3.8,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"tooltip[3.8,2;1,1;"..self:get_state_tooltip(nvm).."]"..
"list[context;src;0,3.2;8,2;]"..
"list[context;dst;5,0;3,3;]"..
"list[current_player;main;0,5.4;8,4;]" ..
@ -77,21 +78,21 @@ local function get_craft(pos, inventory, hash)
return craft
end
local function autocraft(pos, crd, mem, inv)
local function autocraft(pos, crd, nvm, inv)
local craft = get_craft(pos, inv)
if not craft then
crd.State:idle(pos, mem)
crd.State:idle(pos, nvm)
return
end
local output_item = craft.output.item
if output_item:get_name() == "" then
crd.State:idle(pos, mem)
crd.State:idle(pos, nvm)
return
end
-- check if we have enough room in dst
if not inv:room_for_item("dst", output_item) then
crd.State:blocked(pos, mem)
crd.State:blocked(pos, nvm)
return
end
local consumption = craft.consumption
@ -99,7 +100,7 @@ local function autocraft(pos, crd, mem, inv)
-- check if we have enough material available
for itemname, number in pairs(consumption) do
if (not inv_index[itemname]) or inv_index[itemname] < number then
crd.State:idle(pos, mem)
crd.State:idle(pos, nvm)
return
end
end
@ -116,27 +117,27 @@ local function autocraft(pos, crd, mem, inv)
inv:add_item("dst", craft.decremented_input.items[i])
end
crd.State:keep_running(pos, mem, COUNTDOWN_TICKS)
crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
end
local function keep_running(pos, elapsed)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
local crd = CRD(pos)
local inv = M(pos):get_inventory()
autocraft(pos, crd, mem, inv)
autocraft(pos, crd, nvm, inv)
end
-- note, that this function assumes allready being updated to virtual items
-- and doesn't handle recipes with stacksizes > 1
local function after_recipe_change(pos, inventory)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
local crd = CRD(pos)
-- if we emptied the grid, there's no point in keeping it running or cached
if inventory:is_empty("recipe") then
autocrafterCache[minetest.hash_node_position(pos)] = nil
inventory:set_stack("output", 1, "")
crd.State:stop(pos, mem)
crd.State:stop(pos, nvm)
return
end
local recipe = inventory:get_list("recipe")
@ -159,7 +160,7 @@ local function after_recipe_change(pos, inventory)
craft = craft or get_craft(pos, inventory, hash)
local output_item = craft.output.item
inventory:set_stack("output", 1, output_item)
crd.State:stop(pos, mem)
crd.State:stop(pos, nvm)
end
-- clean out unknown items and groups, which would be handled like unknown items in the crafting grid
@ -271,8 +272,8 @@ local function on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then
return
end
local mem = tubelib2.get_mem(pos)
CRD(pos).State:state_button_event(pos, mem, fields)
local nvm = techage.get_nvm(pos)
CRD(pos).State:state_button_event(pos, nvm, fields)
end
local function can_dig(pos, player)

View File

@ -122,7 +122,7 @@ local function blocking_checkbox(pos, filter)
return ""
end
local function formspec(self, pos, mem)
local function formspec(self, pos, nvm)
local filter = minetest.deserialize(M(pos):get_string("filter")) or {false,false,false,false}
local order = order_checkbox(pos, filter)
local blocking = blocking_checkbox(pos, filter)
@ -134,7 +134,8 @@ local function formspec(self, pos, mem)
order..
blocking..
"image[2,1.5;1,1;techage_form_arrow.png]"..
"image_button[2,3;1,1;"..self:get_state_button_image(mem)..";state_button;]"..
"image_button[2,3;1,1;"..self:get_state_button_image(nvm)..";state_button;]"..
"tooltip[2,3;1,1;"..self:get_state_tooltip(nvm).."]"..
"checkbox[3,0;filter1;On;"..dump(filter[1]).."]"..
"checkbox[3,1;filter2;On;"..dump(filter[2]).."]"..
"checkbox[3,2;filter3;On;"..dump(filter[3]).."]"..
@ -184,7 +185,7 @@ local function allow_metadata_inventory_move(pos, from_list, from_index, to_list
end
local function push_item(pos, filter, item_name, num_items, mem)
local function push_item(pos, filter, item_name, num_items, nvm)
local idx = 1
local num_pushed = 0
local num_ports = #filter
@ -196,7 +197,7 @@ local function push_item(pos, filter, item_name, num_items, mem)
local num_to_push = math.min(amount, num_items - num_pushed)
if techage.push_items(pos, push_dir, ItemStack(item_name.." "..num_to_push)) then
num_pushed = num_pushed + num_to_push
mem.port_counter[push_dir] = (mem.port_counter[push_dir] or 0) + num_to_push
nvm.port_counter[push_dir] = (nvm.port_counter[push_dir] or 0) + num_to_push
end
-- filter start offset
idx = idx + 1
@ -208,14 +209,14 @@ local function push_item(pos, filter, item_name, num_items, mem)
end
-- move items to output slots
local function distributing(pos, inv, crd, mem)
local function distributing(pos, inv, crd, nvm)
local item_filter, open_ports = get_filter_settings(pos)
local sum_num_pushed = 0
local num_pushed = 0
local blocking_mode = M(pos):get_int("blocking") == 1
-- start searching after last position
local offs = mem.last_index or 1
local offs = nvm.last_index or 1
for i = 1, SRC_INV_SIZE do
local idx = ((i + offs - 1) % 8) + 1
@ -227,35 +228,35 @@ local function distributing(pos, inv, crd, mem)
if item_filter[item_name] then
-- Push items based on filter
num_pushed = push_item(pos, item_filter[item_name], item_name, num_to_push, mem)
num_pushed = push_item(pos, item_filter[item_name], item_name, num_to_push, nvm)
elseif blocking_mode and #open_ports > 0 then
-- Push items based on open ports
num_pushed = push_item(pos, open_ports, item_name, num_to_push, mem)
num_pushed = push_item(pos, open_ports, item_name, num_to_push, nvm)
end
if not blocking_mode and num_pushed == 0 and #open_ports > 0 then
-- Push items based on open ports
num_pushed = push_item(pos, open_ports, item_name, num_to_push, mem)
num_pushed = push_item(pos, open_ports, item_name, num_to_push, nvm)
end
sum_num_pushed = sum_num_pushed + num_pushed
stack:take_item(num_pushed)
inv:set_stack("src", idx, stack)
if sum_num_pushed >= crd.num_items then
mem.last_index = idx
nvm.last_index = idx
break
end
end
if num_pushed == 0 then
crd.State:blocked(pos, mem)
crd.State:blocked(pos, nvm)
else
crd.State:keep_running(pos, mem, COUNTDOWN_TICKS, sum_num_pushed)
crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS, sum_num_pushed)
end
end
local function sequencing(pos, inv, crd, mem)
local function sequencing(pos, inv, crd, nvm)
local _,open_ports, filter_items = get_filter_settings(pos)
local offs = mem.last_index or 1
local offs = nvm.last_index or 1
local num_filters = 0 -- already processed
local num_pushed = 0
local push_dir = open_ports[1] or 1
@ -278,32 +279,32 @@ local function sequencing(pos, inv, crd, mem)
num_filters = num_filters + 1
end
mem.last_index = offs
nvm.last_index = offs
if blocked then
crd.State:blocked(pos, mem)
crd.State:blocked(pos, nvm)
elseif num_pushed == 0 then
crd.State:standby(pos, mem)
crd.State:standby(pos, nvm)
else
crd.State:keep_running(pos, mem, COUNTDOWN_TICKS, num_pushed)
crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS, num_pushed)
end
end
-- move items to the output slots
local function keep_running(pos, elapsed)
local mem = tubelib2.get_mem(pos)
mem.port_counter = mem.port_counter or {}
local nvm = techage.get_nvm(pos)
nvm.port_counter = nvm.port_counter or {}
local crd = CRD(pos)
local inv = M(pos):get_inventory()
if not inv:is_empty("src") then
if M(pos):get_int("order") == 1 then
sequencing(pos, inv, crd, mem)
sequencing(pos, inv, crd, nvm)
else
distributing(pos, inv, crd, mem)
distributing(pos, inv, crd, nvm)
end
else
crd.State:idle(pos, mem)
crd.State:idle(pos, nvm)
end
return crd.State:is_active(mem)
return crd.State:is_active(nvm)
end
local function on_receive_fields(pos, formname, fields, player)
@ -323,8 +324,8 @@ local function on_receive_fields(pos, formname, fields, player)
filter[4] = fields.filter4 == "true"
elseif fields.order ~= nil then
meta:set_int("order", fields.order == "true" and 1 or 0)
local mem = tubelib2.get_mem(pos)
mem.last_index = 1 -- start from the beginning
local nvm = techage.get_nvm(pos)
nvm.last_index = 1 -- start from the beginning
elseif fields.blocking ~= nil then
meta:set_int("blocking", fields.blocking == "true" and 1 or 0)
end
@ -332,11 +333,11 @@ local function on_receive_fields(pos, formname, fields, player)
filter_settings(pos)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
if fields.state_button ~= nil then
crd.State:state_button_event(pos, mem, fields)
crd.State:state_button_event(pos, nvm, fields)
else
meta:set_string("formspec", formspec(crd.State, pos, mem))
meta:set_string("formspec", formspec(crd.State, pos, nvm))
end
end
@ -353,8 +354,8 @@ local function change_filter_settings(pos, slot, val)
filter_settings(pos)
local mem = tubelib2.get_mem(pos)
meta:set_string("formspec", formspec(CRD(pos).State, pos, mem))
local nvm = techage.get_nvm(pos)
meta:set_string("formspec", formspec(CRD(pos).State, pos, nvm))
return true
end
@ -460,22 +461,22 @@ local node_name_ta2, node_name_ta3, node_name_ta4 =
on_metadata_inventory_move = function(pos, from_list, from_index, to_list)
if from_list ~= "src" or to_list ~= "src" then
filter_settings(pos)
local mem = tubelib2.get_mem(pos)
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, mem))
local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, nvm))
end
end,
on_metadata_inventory_put = function(pos, listname)
if listname ~= "src" then
filter_settings(pos)
local mem = tubelib2.get_mem(pos)
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, mem))
local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, nvm))
end
end,
on_metadata_inventory_take = function(pos, listname)
if listname ~= "src" then
filter_settings(pos)
local mem = tubelib2.get_mem(pos)
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, mem))
local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, nvm))
end
end,

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -18,7 +18,7 @@ local M = minetest.get_meta
local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).consumer end
local S = techage.S
local STANDBY_TICKS = 10
local STANDBY_TICKS = 5
local COUNTDOWN_TICKS = 6
local CYCLE_TIME = 6
@ -29,17 +29,17 @@ local RecipeType = { [2] = "ta2_electronic_fab",
[4] = "ta4_electronic_fab",
}
local function formspec(self, pos, mem)
local function formspec(self, pos, nvm)
local rtype = RecipeType[CRD(pos).stage]
return "size[8.4,8.4]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"list[context;src;0,0;2,4;]"..
recipes.formspec(2.2, 0, rtype, mem)..
recipes.formspec(2.2, 0, rtype, nvm)..
"list[context;dst;6.4,0;2,4;]"..
"image_button[3.7,3.3;1,1;".. self:get_state_button_image(mem) ..";state_button;]"..
"tooltip[3.7,3.3;1,1;"..self:get_state_tooltip(mem).."]"..
"image_button[3.7,3.3;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"tooltip[3.7,3.3;1,1;"..self:get_state_tooltip(nvm).."]"..
"list[current_player;main;0.2,4.5;8,4;]"..
"listring[context;dst]"..
"listring[current_player;main]"..
@ -74,15 +74,15 @@ local function allow_metadata_inventory_take(pos, listname, index, stack, player
return stack:get_count()
end
local function making(pos, crd, mem, inv)
local function making(pos, crd, nvm, inv)
local rtype = RecipeType[crd.stage]
local recipe = recipes.get(mem, rtype)
local recipe = recipes.get(nvm, rtype)
local output = ItemStack(recipe.output.name.." "..recipe.output.num)
if inv:room_for_item("dst", output) then
for _,item in ipairs(recipe.input) do
local input = ItemStack(item.name.." "..item.num)
if not inv:contains_item("src", input) then
crd.State:idle(pos, mem)
crd.State:idle(pos, nvm)
return
end
end
@ -91,20 +91,19 @@ local function making(pos, crd, mem, inv)
inv:remove_item("src", input)
end
inv:add_item("dst", output)
crd.State:keep_running(pos, mem, COUNTDOWN_TICKS)
crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
return
end
crd.State:idle(pos, mem)
crd.State:idle(pos, nvm)
end
local function keep_running(pos, elapsed)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
local crd = CRD(pos)
local inv = M(pos):get_inventory()
if inv then
making(pos, crd, mem, inv)
making(pos, crd, nvm, inv)
end
return crd.State:is_active(mem)
end
local function on_receive_fields(pos, formname, fields, player)
@ -112,15 +111,15 @@ local function on_receive_fields(pos, formname, fields, player)
return
end
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
local crd = CRD(pos)
if not mem.running then
if not nvm.running then
recipes.on_receive_fields(pos, formname, fields, player)
end
crd.State:state_button_event(pos, mem, fields)
M(pos):set_string("formspec", formspec(crd.State, pos, mem))
crd.State:state_button_event(pos, nvm, fields)
M(pos):set_string("formspec", formspec(crd.State, pos, nvm))
end
local function can_dig(pos, player)

View File

@ -113,7 +113,7 @@ local function formspec(name)
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"label[0,0;List of your Forceload Blocks:]"..
"label[0,0;"..S("List of your Forceload Blocks:").."]"..
"tablecolumns[text,width=1.2;text,width=12;text,width=1.6;text,width=12]"..
"table[0,0.6;6.8,8.4;output;"..table.concat(tRes, ",")..";1]"
end
@ -121,7 +121,7 @@ end
minetest.register_node("techage:forceload", {
description = "Techage Forceload Block",
description = S("Techage Forceload Block"),
tiles = {
-- up, down, right, left, back, front
'techage_filling_ta2.png^techage_frame_ta2_top.png',
@ -142,13 +142,13 @@ minetest.register_node("techage:forceload", {
if add_pos(pos, placer) then
minetest.forceload_block(pos, true)
local pos1, pos2, num, max = get_data(pos, placer)
M(pos):set_string("infotext", "Area "..P2S(pos1).." to "..P2S(pos2).." loaded!\n"..
"Punch the block to make the area visible.")
chat(placer, "Area ("..num.."/"..max..") "..P2S(pos1).." to "..P2S(pos2).." loaded!")
M(pos):set_string("infotext", "Area "..P2S(pos1).." to "..P2S(pos2).." "..S("loaded").."!\n"..
S("Punch the block to make the area visible."))
chat(placer, "Area ("..num.."/"..max..") "..P2S(pos1).." to "..P2S(pos2).." "..S("loaded").."!")
techage.mark_region(placer:get_player_name(), pos1, pos2)
M(pos):set_string("owner", placer:get_player_name())
else
chat(placer, "Area already loaded or max. number of Forceload Blocks reached!")
chat(placer, S("Area already loaded or max. number of Forceload Blocks reached!"))
minetest.remove_node(pos)
return itemstack
end
@ -220,7 +220,7 @@ end)
minetest.register_chatcommand("forceload", {
params = "",
description = "Forceloadblöcke der Umgebung 64x64x64 anzeigen",
description = S("Show all forceload blocks in a 64x64x64 range"),
func = function(name, param)
if minetest.check_player_privs(name, "superminer") then
local player = minetest.get_player_by_name(name)
@ -230,7 +230,7 @@ minetest.register_chatcommand("forceload", {
shoe_flbs(pos, name, 64)
end
else
return false, "Priv missing"
return false, S("Priv missing")
end
end,
})

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -18,16 +18,16 @@ local S = techage.S
local CYCLE_TIME = 2
local function start_node(pos, mem)
mem.running = true
local function start_node(pos, nvm)
nvm.running = true
minetest.get_node_timer(pos):start(CYCLE_TIME)
local meta = M(pos)
local own_num = meta:get_string("node_number")
meta:set_string("infotext", S("TA3 Funnel").." "..own_num.." : running")
end
local function stop_node(pos, mem)
mem.running = false
local function stop_node(pos, nvm)
nvm.running = false
minetest.get_node_timer(pos):stop()
local meta = M(pos)
local own_num = meta:get_string("node_number")
@ -48,9 +48,9 @@ local function allow_metadata_inventory_take(pos, listname, index, stack, player
return stack:get_count()
end
local function formspec(mem)
local function formspec(nvm)
local state = techage.STOPPED
if mem.running then
if nvm.running then
state = techage.RUNNING
end
return "size[9,7]"..
@ -65,8 +65,8 @@ local function formspec(mem)
end
local function scan_for_objects(pos, elapsed)
local mem = tubelib2.get_mem(pos)
if not mem.running then
local nvm = techage.get_nvm(pos)
if not nvm.running then
return false
end
local meta = minetest.get_meta(pos)
@ -125,14 +125,14 @@ minetest.register_node("techage:ta3_funnel", {
after_place_node = function(pos, placer)
local meta = M(pos)
local mem = tubelib2.init_mem(pos)
mem.running = false
local nvm = techage.get_nvm(pos)
nvm.running = false
local own_num = techage.add_node(pos, "techage:ta3_funnel")
local node = minetest.get_node(pos)
meta:set_string("node_number", own_num)
meta:set_string("owner", placer:get_player_name())
meta:set_string("infotext", S("TA3 Funnel").." "..own_num.." : stopped")
meta:set_string("formspec", formspec(mem))
meta:set_string("formspec", formspec(nvm))
meta:set_int("pull_dir", techage.side_to_indir("R", node.param2))
end,
@ -144,15 +144,15 @@ minetest.register_node("techage:ta3_funnel", {
end
local meta = M(pos)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
if fields.state_button ~= nil then
if mem.running then
stop_node(pos, mem)
if nvm.running then
stop_node(pos, nvm)
else
start_node(pos, mem)
start_node(pos, nvm)
end
end
meta:set_string("formspec", formspec(mem))
meta:set_string("formspec", formspec(nvm))
end,
can_dig = function(pos, player)
@ -165,7 +165,7 @@ minetest.register_node("techage:ta3_funnel", {
after_dig_node = function(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos)
tubelib2.del_mem(pos)
techage.del_nem(pos)
end,
allow_metadata_inventory_put = allow_metadata_inventory_put,
@ -194,28 +194,28 @@ techage.register_node({"techage:ta3_funnel"}, {
end
end,
on_recv_message = function(pos, src, topic, payload)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
if topic == "state" then
if mem.running then
if nvm.running then
return "running"
else
return "stopped"
end
elseif topic == "on" then
if not mem.running then
start_node(pos, mem)
if not nvm.running then
start_node(pos, nvm)
end
elseif topic == "off" then
if mem.running then
stop_node(pos, mem)
if nvm.running then
stop_node(pos, nvm)
end
else
return "unsupported"
end
end,
on_node_load = function(pos)
local mem = tubelib2.get_mem(pos)
if mem.running then
local nvm = techage.get_nvm(pos)
if nvm.running then
minetest.get_node_timer(pos):start(CYCLE_TIME)
end
end,

View File

@ -25,7 +25,7 @@ local CYCLE_TIME = 4
local Probability = {}
local function formspec(self, pos, mem)
local function formspec(self, pos, nvm)
return "size[8,8]"..
default.gui_bg..
default.gui_bg_img..
@ -33,9 +33,10 @@ local function formspec(self, pos, mem)
"list[context;src;0,0;3,3;]"..
"item_image[0,0;1,1;default:gravel]"..
"image[0,0;1,1;techage_form_mask.png]"..
"image[3.5,0;1,1;"..techage.get_power_image(pos, mem).."]"..
"image[3.5,0;1,1;"..techage.get_power_image(pos, nvm).."]"..
"image[3.5,1;1,1;techage_form_arrow.png]"..
"image_button[3.5,2;1,1;".. self:get_state_button_image(mem) ..";state_button;]"..
"image_button[3.5,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"tooltip[3.5,2;1,1;"..self:get_state_tooltip(nvm).."]"..
"list[context;dst;5,0;3,3;]"..
"list[current_player;main;0,4;8,4;]"..
"listring[context;dst]"..
@ -101,11 +102,13 @@ local function determine_water_dir(pos)
end
local function set_velocity(obj, pos, vel)
obj:set_acceleration({x = 0, y = 0, z = 0})
local p = obj:get_pos()
if p then
obj:set_pos({x=p.x, y=p.y-0.3, z=p.z})
obj:set_velocity(vel)
if obj then
obj:set_acceleration({x = 0, y = 0, z = 0})
local p = obj:get_pos()
if p then
obj:set_pos({x=p.x, y=p.y-0.3, z=p.z})
obj:set_velocity(vel)
end
end
end
@ -126,12 +129,12 @@ local function get_random_gravel_ore()
end
end
local function washing(pos, crd, mem, inv)
local function washing(pos, crd, nvm, inv)
-- for testing purposes
if inv:contains_item("src", ItemStack("default:stick")) then
add_object({x=pos.x, y=pos.y+1, z=pos.z}, "default:stick")
inv:remove_item("src", ItemStack("default:stick"))
crd.State:keep_running(pos, mem, COUNTDOWN_TICKS)
crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
return
end
@ -143,32 +146,32 @@ local function washing(pos, crd, mem, inv)
add_object({x=pos.x, y=pos.y+1, z=pos.z}, ore)
end
else
crd.State:idle(pos, mem)
crd.State:idle(pos, nvm)
return
end
if not inv:room_for_item("dst", dst) then
crd.State:idle(pos, mem)
crd.State:idle(pos, nvm)
return
end
inv:add_item("dst", dst)
inv:remove_item("src", src)
crd.State:keep_running(pos, mem, COUNTDOWN_TICKS)
crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
end
local function keep_running(pos, elapsed)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
local crd = CRD(pos)
local inv = M(pos):get_inventory()
washing(pos, crd, mem, inv)
return crd.State:is_active(mem)
washing(pos, crd, nvm, inv)
return crd.State:is_active(nvm)
end
local function on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then
return
end
local mem = tubelib2.get_mem(pos)
CRD(pos).State:state_button_event(pos, mem, fields)
local nvm = techage.get_nvm(pos)
CRD(pos).State:state_button_event(pos, nvm, fields)
end
local function can_dig(pos, player)
@ -346,6 +349,6 @@ minetest.register_lbm({
})
techage.add_rinser_recipe({input="techage:sieved_gravel", output="techage:usmium_nuggets", probability=40})
techage.add_rinser_recipe({input="techage:sieved_gravel", output="default:copper_lump", probability=20})
techage.add_rinser_recipe({input="techage:sieved_gravel", output="techage:usmium_nuggets", probability=30})
techage.add_rinser_recipe({input="techage:sieved_gravel", output="default:copper_lump", probability=15})

View File

@ -19,15 +19,15 @@ local S = techage.S
-- Consumer Related Data
local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).consumer end
local STANDBY_TICKS = 10
local COUNTDOWN_TICKS = 10
local STANDBY_TICKS = 6
local COUNTDOWN_TICKS = 4
local CYCLE_TIME = 4
local get_random_gravel_ore = techage.gravelsieve_get_random_gravel_ore
local get_random_basalt_ore = techage.gravelsieve_get_random_basalt_ore
local function formspec(self, pos, mem)
local function formspec(self, pos, nvm)
return "size[8,8]"..
default.gui_bg..
default.gui_bg_img..
@ -35,9 +35,10 @@ local function formspec(self, pos, mem)
"list[context;src;0,0;3,3;]"..
"item_image[0,0;1,1;default:gravel]"..
"image[0,0;1,1;techage_form_mask.png]"..
"image[3.5,0;1,1;"..techage.get_power_image(pos, mem).."]"..
"image[3.5,0;1,1;"..techage.get_power_image(pos, nvm).."]"..
"image[3.5,1;1,1;techage_form_arrow.png]"..
"image_button[3.5,2;1,1;".. self:get_state_button_image(mem) ..";state_button;]"..
"image_button[3.5,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"tooltip[3.5,2;1,1;"..self:get_state_tooltip(nvm).."]"..
"list[context;dst;5,0;3,3;]"..
"list[current_player;main;0,4;8,4;]"..
"listring[context;dst]"..
@ -60,8 +61,7 @@ local function allow_metadata_inventory_put(pos, listname, index, stack, player)
end
local function allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local inv = M(pos):get_inventory()
local stack = inv:get_stack(from_list, from_index)
return allow_metadata_inventory_put(pos, to_list, to_index, stack, player)
end
@ -73,39 +73,38 @@ local function allow_metadata_inventory_take(pos, listname, index, stack, player
return stack:get_count()
end
local function sieving(pos, crd, mem, inv)
local function sieving(pos, crd, nvm, inv)
local src, dst
if inv:contains_item("src", ItemStack("techage:basalt_gravel")) then
dst, src = get_random_basalt_ore(), ItemStack("techage:basalt_gravel")
elseif inv:contains_item("src", ItemStack("default:gravel")) then
dst, src = get_random_gravel_ore(), ItemStack("default:gravel")
else
crd.State:idle(pos, mem)
crd.State:idle(pos, nvm)
return
end
if not inv:room_for_item("dst", dst) then
crd.State:idle(pos, mem)
crd.State:idle(pos, nvm)
return
end
inv:add_item("dst", dst)
inv:remove_item("src", src)
crd.State:keep_running(pos, mem, COUNTDOWN_TICKS)
crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
end
local function keep_running(pos, elapsed)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
local crd = CRD(pos)
local inv = M(pos):get_inventory()
sieving(pos, crd, mem, inv)
return crd.State:is_active(mem)
sieving(pos, crd, nvm, inv)
end
local function on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then
return
end
local mem = tubelib2.get_mem(pos)
CRD(pos).State:state_button_event(pos, mem, fields)
local nvm = techage.get_nvm(pos)
CRD(pos).State:state_button_event(pos, nvm, fields)
end
local function can_dig(pos, player)
@ -158,7 +157,7 @@ local tubing = {
end,
on_push_item = function(pos, in_dir, stack)
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 or in_dir == 5 then
local inv = M(pos):get_inventory()
CRD(pos).State:start_if_standby(pos)
return techage.put_items(inv, "src", stack)

View File

@ -14,11 +14,11 @@
-- for lazy programmers
local M = minetest.get_meta
local S = techage.S
-- Consumer Related Data
local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).consumer end
local S = techage.S
local STANDBY_TICKS = 6
local COUNTDOWN_TICKS = 4
local CYCLE_TIME = 4
@ -27,7 +27,7 @@ local CYCLE_TIME = 4
-- Grinder recipes
local Recipes = {}
local function formspec(self, pos, mem)
local function formspec(self, pos, nvm)
return "size[8,8]"..
default.gui_bg..
default.gui_bg_img..
@ -35,9 +35,10 @@ local function formspec(self, pos, mem)
"list[context;src;0,0;3,3;]"..
"item_image[0,0;1,1;default:cobble]"..
"image[0,0;1,1;techage_form_mask.png]"..
"image[3.5,0;1,1;"..techage.get_power_image(pos, mem).."]"..
"image[3.5,0;1,1;"..techage.get_power_image(pos, nvm).."]"..
"image[3.5,1;1,1;techage_form_arrow.png]"..
"image_button[3.5,2;1,1;"..self:get_state_button_image(mem)..";state_button;]"..
"image_button[3.5,2;1,1;"..self:get_state_button_image(nvm)..";state_button;]"..
"tooltip[3.5,2;1,1;"..self:get_state_tooltip(nvm).."]"..
"list[context;dst;5,0;3,3;]"..
"item_image[5,0;1,1;default:gravel]"..
"image[5,0;1,1;techage_form_mask.png]"..
@ -84,39 +85,39 @@ local function src_to_dst(src_stack, idx, num_items, inv, dst_name)
return false
end
local function grinding(pos, crd, mem, inv)
local function grinding(pos, crd, nvm, inv)
local num_items = 0
for idx,stack in ipairs(inv:get_list("src")) do
if not stack:is_empty() then
local name = stack:get_name()
if Recipes[name] then
if src_to_dst(stack, idx, crd.num_items, inv, Recipes[name]) then
crd.State:keep_running(pos, mem, COUNTDOWN_TICKS)
crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
else
crd.State:blocked(pos, mem)
crd.State:blocked(pos, nvm)
end
else
crd.State:fault(pos, mem)
crd.State:fault(pos, nvm)
end
return
end
end
crd.State:idle(pos, mem)
crd.State:idle(pos, nvm)
end
local function keep_running(pos, elapsed)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
local crd = CRD(pos)
local inv = M(pos):get_inventory()
grinding(pos, crd, mem, inv)
grinding(pos, crd, nvm, inv)
end
local function on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then
return
end
local mem = tubelib2.get_mem(pos)
CRD(pos).State:state_button_event(pos, mem, fields)
local nvm = techage.get_nvm(pos)
CRD(pos).State:state_button_event(pos, nvm, fields)
end
local function can_dig(pos, player)
@ -183,7 +184,12 @@ local tubing = {
end
end,
on_recv_message = function(pos, src, topic, payload)
return CRD(pos).State:on_receive_message(pos, topic, payload)
local resp = CRD(pos).State:on_receive_message(pos, topic, payload)
if resp then
return resp
else
return "unsupported"
end
end,
on_node_load = function(pos)
CRD(pos).State:on_node_load(pos)
@ -294,3 +300,5 @@ techage.add_grinder_recipe({input="default:acacia_tree", output="default:acacia_
techage.add_grinder_recipe({input="default:aspen_tree", output="default:aspen_leaves 8"})
local ndef = minetest.registered_nodes["techage:ta2_grinder_pas"] or {}
print("techage:ta2_grinder_pas", dump(ndef.tubelib2_on_update2))

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -23,16 +23,17 @@ local STANDBY_TICKS = 4
local COUNTDOWN_TICKS = 2
local CYCLE_TIME = 8
local function formspec(self, pos, mem)
local function formspec(self, pos, nvm)
return "size[9,8.5]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"list[context;src;0,0;1,4;]"..
"image[0,0;1,1;bucket.png]"..
"image[1,0;1,1;"..techage.get_power_image(pos, mem).."]"..
"image[1,0;1,1;"..techage.get_power_image(pos, nvm).."]"..
"image[1,1.5;1,1;techage_form_arrow.png]"..
"image_button[1,3;1,1;".. self:get_state_button_image(mem) ..";state_button;]"..
"image_button[1,3;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"tooltip[1,3;1,1;"..self:get_state_tooltip(nvm).."]"..
"list[context;dst;2,0;7,4;]"..
"list[current_player;main;0.5,4.5;8,4;]"..
"listring[current_player;main]"..
@ -73,7 +74,7 @@ local function test_liquid(node)
end
end
local function sample_liquid(pos, crd, mem, inv)
local function sample_liquid(pos, crd, nvm, inv)
local meta = M(pos)
local water_pos = minetest.string_to_pos(meta:get_string("water_pos"))
local giving_back = test_liquid(techage.get_node_lvm(water_pos))
@ -83,29 +84,29 @@ local function sample_liquid(pos, crd, mem, inv)
minetest.remove_node(water_pos)
inv:remove_item("src", ItemStack("bucket:bucket_empty"))
inv:add_item("dst", ItemStack(giving_back))
crd.State:keep_running(pos, mem, COUNTDOWN_TICKS)
crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
else
crd.State:idle(pos, mem)
crd.State:idle(pos, nvm)
end
else
crd.State:fault(pos, mem)
crd.State:fault(pos, nvm)
end
end
local function keep_running(pos, elapsed)
--if tubelib.data_not_corrupted(pos) then
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
local crd = CRD(pos)
local inv = M(pos):get_inventory()
sample_liquid(pos, crd, mem, inv)
sample_liquid(pos, crd, nvm, inv)
end
local function on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then
return
end
local mem = tubelib2.get_mem(pos)
CRD(pos).State:state_button_event(pos, mem, fields)
local nvm = techage.get_nvm(pos)
CRD(pos).State:state_button_event(pos, nvm, fields)
end
local function can_dig(pos, player)
@ -121,7 +122,7 @@ local tiles = {}
-- '{power}' will be replaced by the power PNG
tiles.pas = {
-- up, down, right, left, back, front
"techage_filling_ta#.png^techage_appl_hole_electric.png^techage_frame_ta#_top.png",
"techage_filling_ta#.png^{power}^techage_frame_ta#_top.png",
"techage_filling_ta#.png^techage_frame_ta#.png",
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_outp.png",
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_inp.png",
@ -130,7 +131,7 @@ tiles.pas = {
}
tiles.act = {
-- up, down, right, left, back, front
"techage_filling_ta#.png^techage_appl_hole_electric.png^techage_frame_ta#_top.png",
"techage_filling_ta#.png^{power}^techage_frame_ta#_top.png",
"techage_filling_ta#.png^techage_frame_ta#.png",
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_outp.png",
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_inp.png",
@ -189,7 +190,6 @@ local node_name_ta2, node_name_ta3, node_name_ta4 =
inv:set_size("dst", 28)
local water_pos = techage.get_pos(pos, "B")
M(pos):set_string("water_pos", minetest.pos_to_string(water_pos))
techage.power.set_conn_dirs(pos, {"U"})
end,
can_dig = can_dig,
node_timer = keep_running,
@ -201,6 +201,7 @@ local node_name_ta2, node_name_ta3, node_name_ta4 =
sounds = default.node_sound_wood_defaults(),
num_items = {0,1,2,4},
power_consumption = {0,3,5,8},
power_sides = {U=1},
})
minetest.register_craft({

View File

@ -33,7 +33,7 @@ local STANDBY_TICKS = 10
local COUNTDOWN_TICKS = 10
local CYCLE_TIME = 2
local function pushing(pos, crd, meta, mem)
local function pushing(pos, crd, meta, nvm)
local pull_dir = meta:get_int("pull_dir")
local push_dir = meta:get_int("push_dir")
local items = techage.pull_items(pos, pull_dir, crd.num_items)
@ -41,29 +41,29 @@ local function pushing(pos, crd, meta, mem)
if techage.push_items(pos, push_dir, items) ~= true then
-- place item back
techage.unpull_items(pos, pull_dir, items)
crd.State:blocked(pos, mem)
crd.State:blocked(pos, nvm)
return
end
crd.State:keep_running(pos, mem, COUNTDOWN_TICKS)
crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
return
end
crd.State:idle(pos, mem)
crd.State:idle(pos, nvm)
end
local function keep_running(pos, elapsed)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
local crd = CRD(pos)
pushing(pos, crd, M(pos), mem)
crd.State:is_active(mem)
pushing(pos, crd, M(pos), nvm)
crd.State:is_active(nvm)
end
local function on_rightclick(pos, node, clicker)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
if not minetest.is_protected(pos, clicker:get_player_name()) then
if CRD(pos).State:get_state(mem) == techage.STOPPED then
CRD(pos).State:start(pos, mem)
if CRD(pos).State:get_state(nvm) == techage.STOPPED then
CRD(pos).State:start(pos, nvm)
else
CRD(pos).State:stop(pos, mem)
CRD(pos).State:stop(pos, nvm)
end
end
end

View File

@ -3,12 +3,12 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
TA2/TA3/TA4 Power Source
TA2/TA3/TA4 Power Test Source
]]--
@ -17,39 +17,74 @@ local P = minetest.string_to_pos
local M = minetest.get_meta
local S = techage.S
local TA2_Power = techage.Axle
local TA3_Power = techage.SteamPipe
local TA4_Power = techage.ElectricCable
local Axle = techage.Axle
local Pipe = techage.SteamPipe
local Cable = techage.ElectricCable
local power = techage.power
local networks = techage.networks
local STANDBY_TICKS = 4
local COUNTDOWN_TICKS = 4
local CYCLE_TIME = 2
local PWR_CAPA = 20
local function formspec(self, pos, mem)
return "size[8,7]"..
local function formspec(self, pos, nvm)
return "size[4,4]"..
"box[0,-0.1;3.8,0.5;#c6e8ff]"..
"label[1,-0.1;"..minetest.colorize( "#000000", S("Power Source")).."]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"image[6,0.5;1,2;"..techage.power.formspec_power_bar(PWR_CAPA, mem.provided).."]"..
"image_button[5,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]"..
"button[2.5,1;1.8,1;update;"..S("Update").."]"..
"list[current_player;main;0,3;8,4;]"..
default.get_hotbar_bg(0, 3)
power.formspec_label_bar(0, 0.8, S("power"), PWR_CAPA, nvm.provided)..
"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
local function start_node(pos, mem, state)
mem.generating = true
power.generator_start(pos, mem, PWR_CAPA)
techage.switch_axles(pos, true)
-- Axles texture animation
local function switch_axles(pos, on)
local outdir = M(pos):get_int("outdir")
Axle:switch_tube_line(pos, outdir, on and "on" or "off")
end
local function stop_node(pos, mem, state)
mem.generating = false
mem.provided = 0
power.generator_stop(pos, mem)
techage.switch_axles(pos, false)
local function start_node2(pos, nvm, state)
nvm.generating = true
local outdir = M(pos):get_int("outdir")
power.generator_start(pos, Axle, CYCLE_TIME, outdir)
switch_axles(pos, true)
end
local function stop_node2(pos, nvm, state)
nvm.generating = false
nvm.provided = 0
local outdir = M(pos):get_int("outdir")
power.generator_stop(pos, Axle, outdir)
switch_axles(pos, false)
end
local function start_node3(pos, nvm, state)
nvm.generating = true
local outdir = M(pos):get_int("outdir")
power.generator_start(pos, Pipe, CYCLE_TIME, outdir)
end
local function stop_node3(pos, nvm, state)
nvm.generating = false
nvm.provided = 0
local outdir = M(pos):get_int("outdir")
power.generator_stop(pos, Pipe, outdir)
end
local function start_node4(pos, nvm, state)
nvm.generating = true
local outdir = M(pos):get_int("outdir")
power.generator_start(pos, Cable, CYCLE_TIME, outdir)
end
local function stop_node4(pos, nvm, state)
nvm.generating = false
nvm.provided = 0
local outdir = M(pos):get_int("outdir")
power.generator_stop(pos, Cable, outdir)
end
local State2 = techage.NodeStates:new({
@ -57,8 +92,8 @@ local State2 = techage.NodeStates:new({
cycle_time = CYCLE_TIME,
standby_ticks = STANDBY_TICKS,
formspec_func = formspec,
start_node = start_node,
stop_node = stop_node,
start_node = start_node2,
stop_node = stop_node2,
})
local State3 = techage.NodeStates:new({
@ -66,8 +101,8 @@ local State3 = techage.NodeStates:new({
cycle_time = CYCLE_TIME,
standby_ticks = STANDBY_TICKS,
formspec_func = formspec,
start_node = start_node,
stop_node = stop_node,
start_node = start_node3,
stop_node = stop_node3,
})
local State4 = techage.NodeStates:new({
@ -75,39 +110,153 @@ local State4 = techage.NodeStates:new({
cycle_time = CYCLE_TIME,
standby_ticks = STANDBY_TICKS,
formspec_func = formspec,
start_node = start_node,
stop_node = stop_node,
start_node = start_node4,
stop_node = stop_node4,
})
local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos)
if mem.generating then
local provided = power.generator_alive(pos, mem)
local function node_timer2(pos, elapsed)
local nvm = techage.get_nvm(pos)
local outdir = M(pos):get_int("outdir")
nvm.provided = power.generator_alive(pos, Axle, CYCLE_TIME, outdir)
if techage.is_activeformspec(pos) then
M(pos):set_string("formspec", formspec(State2, pos, nvm))
end
return mem.generating
return true
end
local tStates = {0, State2, State3, State4}
local function node_timer3(pos, elapsed)
local nvm = techage.get_nvm(pos)
local outdir = M(pos):get_int("outdir")
nvm.provided = power.generator_alive(pos, Pipe, CYCLE_TIME, outdir)
if techage.is_activeformspec(pos) then
M(pos):set_string("formspec", formspec(State3, pos, nvm))
end
return true
end
local function on_receive_fields(pos, formname, fields, player)
local function node_timer4(pos, elapsed)
local nvm = techage.get_nvm(pos)
local outdir = M(pos):get_int("outdir")
nvm.provided = power.generator_alive(pos, Cable, CYCLE_TIME, outdir)
if techage.is_activeformspec(pos) then
M(pos):set_string("formspec", formspec(State4, pos, nvm))
end
return true
end
local function on_receive_fields2(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then
return
end
local mem = tubelib2.get_mem(pos)
local state = tStates[mem.state_num or 2]
state:state_button_event(pos, mem, fields)
if fields.update then
M(pos):set_string("formspec", formspec(state, pos, mem))
end
local nvm = techage.get_nvm(pos)
State2:state_button_event(pos, nvm, fields)
M(pos):set_string("formspec", formspec(State2, pos, nvm))
end
local function on_rightclick(pos)
local mem = tubelib2.get_mem(pos)
local state = tStates[mem.state_num or 2]
M(pos):set_string("formspec", formspec(state, pos, mem))
local function on_receive_fields3(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then
return
end
local nvm = techage.get_nvm(pos)
State3:state_button_event(pos, nvm, fields)
M(pos):set_string("formspec", formspec(State3, pos, nvm))
end
local function on_receive_fields4(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then
return
end
local nvm = techage.get_nvm(pos)
State4:state_button_event(pos, nvm, fields)
M(pos):set_string("formspec", formspec(State4, pos, nvm))
end
local function on_rightclick2(pos, node, clicker)
techage.set_activeformspec(pos, clicker)
local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(State2, pos, nvm))
end
local function on_rightclick3(pos, node, clicker)
techage.set_activeformspec(pos, clicker)
local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(State3, pos, nvm))
end
local function on_rightclick4(pos, node, clicker)
techage.set_activeformspec(pos, clicker)
local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(State4, pos, nvm))
end
local function after_place_node2(pos)
local nvm = techage.get_nvm(pos)
State2:node_init(pos, nvm, "")
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
M(pos):set_string("formspec", formspec(State2, pos, nvm))
Axle:after_place_node(pos)
end
local function after_place_node3(pos)
local nvm = techage.get_nvm(pos)
State3:node_init(pos, nvm, "")
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
M(pos):set_string("formspec", formspec(State3, pos, nvm))
Pipe:after_place_node(pos)
end
local function after_place_node4(pos)
local nvm = techage.get_nvm(pos)
State4:node_init(pos, nvm, "")
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
M(pos):set_string("formspec", formspec(State4, pos, nvm))
Cable:after_place_node(pos)
end
local function after_dig_node2(pos, oldnode)
Axle:after_dig_node(pos)
techage.del_mem(pos)
end
local function after_dig_node3(pos, oldnode)
Pipe:after_dig_node(pos)
techage.del_mem(pos)
end
local function after_dig_node4(pos, oldnode)
Cable:after_dig_node(pos)
techage.del_mem(pos)
end
local function tubelib2_on_update2(pos, outdir, tlib2, node)
power.update_network(pos, outdir, tlib2)
end
local net_def2 = {
axle = {
sides = {R = 1},
ntype = "gen1",
nominal = PWR_CAPA,
},
}
local net_def3 = {
pipe1 = {
sides = {R = 1},
ntype = "gen1",
nominal = PWR_CAPA,
},
}
local net_def4 = {
ele1 = {
sides = {R = 1},
ntype = "gen1",
nominal = PWR_CAPA,
},
}
minetest.register_node("techage:t2_source", {
description = S("Axle Power Source"),
tiles = {
@ -123,9 +272,13 @@ minetest.register_node("techage:t2_source", {
groups = {cracky=2, crumbly=2, choppy=2},
on_rotate = screwdriver.disallow,
is_ground_content = false,
on_receive_fields = on_receive_fields,
on_rightclick = on_rightclick,
on_timer = node_timer,
on_receive_fields = on_receive_fields2,
on_rightclick = on_rightclick2,
on_timer = node_timer2,
after_place_node = after_place_node2,
after_dig_node = after_dig_node2,
tubelib2_on_update2 = tubelib2_on_update2,
networks = net_def2,
})
minetest.register_node("techage:t3_source", {
@ -143,9 +296,13 @@ minetest.register_node("techage:t3_source", {
groups = {cracky=2, crumbly=2, choppy=2},
on_rotate = screwdriver.disallow,
is_ground_content = false,
on_receive_fields = on_receive_fields,
on_rightclick = on_rightclick,
on_timer = node_timer,
on_receive_fields = on_receive_fields3,
on_rightclick = on_rightclick3,
on_timer = node_timer3,
after_place_node = after_place_node3,
after_dig_node = after_dig_node3,
tubelib2_on_update2 = tubelib2_on_update2,
networks = net_def3,
})
minetest.register_node("techage:t4_source", {
@ -163,40 +320,15 @@ minetest.register_node("techage:t4_source", {
groups = {cracky=2, crumbly=2, choppy=2},
on_rotate = screwdriver.disallow,
is_ground_content = false,
on_receive_fields = on_receive_fields,
on_rightclick = on_rightclick,
on_timer = node_timer,
on_receive_fields = on_receive_fields4,
on_rightclick = on_rightclick4,
on_timer = node_timer4,
after_place_node = after_place_node4,
after_dig_node = after_dig_node4,
tubelib2_on_update2 = tubelib2_on_update2,
networks = net_def4,
})
techage.power.register_node({"techage:t2_source"}, {
conn_sides = {"R"},
power_network = TA2_Power,
after_place_node = function(pos, placer)
local mem = tubelib2.init_mem(pos)
State2:node_init(pos, mem, "")
mem.state_num = 2
on_rightclick(pos)
end,
})
techage.power.register_node({"techage:t3_source"}, {
conn_sides = {"R"},
power_network = TA3_Power,
after_place_node = function(pos, placer)
local mem = tubelib2.init_mem(pos)
State3:node_init(pos, mem, "")
mem.state_num = 3
on_rightclick(pos)
end,
})
techage.power.register_node({"techage:t4_source"}, {
conn_sides = {"R"},
power_network = TA4_Power,
after_place_node = function(pos, placer)
local mem = tubelib2.init_mem(pos)
State4:node_init(pos, mem, "")
mem.state_num = 4
on_rightclick(pos)
end,
})
Axle:add_secondary_node_names({"techage:t2_source"})
--Pipe:add_secondary_node_names({"techage:t3_source"})
Cable:add_secondary_node_names({"techage:t4_source"})

View File

@ -103,7 +103,7 @@ local function register_lbm(name, nodenames)
run_at_every_load = true,
action = function(pos, node)
if NodeDef[node.name] and NodeDef[node.name].on_node_load then
NodeDef[node.name].on_node_load(pos)
NodeDef[node.name].on_node_load(pos, node)
end
end
})
@ -180,6 +180,15 @@ function techage.get_node_number(pos)
return nil
end
function techage.get_pos(pos, side)
local node = techage.get_node_lvm(pos)
local dir = nil
if node.name ~= "air" and node.name ~= "ignore" then
dir = side_to_dir(side, node.param2)
end
return tubelib2.get_pos(pos, dir)
end
-- Function is used for available nodes with lost numbers, only.
function techage.get_new_number(pos, name)
-- store position

View File

@ -1,276 +0,0 @@
--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
Consumer node basis functionality.
It handles:
- up to 3 stages of nodes (TA2/TA3/TA4)
- power consumption
- node state handling
- registration of passive and active nodes
- Tube connections are on left and right side (from left to right)
- Power connection are on front and back side (front or back)
]]--
-- for lazy programmers
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local P = minetest.string_to_pos
local M = minetest.get_meta
local D = techage.Debug
-- Consumer Related Data
local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).consumer end
local CRDN = function(node) return (minetest.registered_nodes[node.name] or {}).consumer end
local power = techage.power
local function has_power(pos, mem, state)
if D.con then D.dbg("consumer has_power", state) end
if not power.power_available(pos, mem, 0) then
-- force to set to NOPOWER
local crd = CRD(pos)
techage.power.consumer_start(pos, mem, crd.cycle_time, crd.power_consumption)
return false
end
return true
end
local function start_node(pos, mem, state)
local crd = CRD(pos)
if D.con then D.dbg("consumer start_node", state) end
power.consumer_start(pos, mem, crd.cycle_time, crd.power_consumption)
end
local function stop_node(pos, mem, state)
if D.con then D.dbg("consumer stop_node", state) end
power.consumer_stop(pos, mem)
end
local function on_power(pos, mem)
if D.con then D.dbg("consumer on_power") end
local crd = CRD(pos)
crd.State:start(pos, mem)
end
local function on_nopower(pos, mem)
if D.con then D.dbg("consumer on_nopower") end
local crd = CRD(pos)
crd.State:nopower(pos, mem)
end
local function node_timer(pos, elapsed)
local crd = CRD(pos)
local mem = tubelib2.get_mem(pos)
local state = mem.techage_state
if techage.needs_power(mem) then
power.consumer_alive(pos, mem)
end
-- call the node timer routine
if techage.is_operational(mem) then
crd.node_timer(pos, crd.cycle_time)
end
return crd.State:is_active(mem)
end
local function prepare_tiles(tiles, stage, power_png)
local tbl = {}
for _,item in ipairs(tiles) do
if type(item) == "string" then
tbl[#tbl+1] = item:gsub("#", stage):gsub("{power}", power_png)
else
local temp = table.copy(item)
temp.image = temp.image:gsub("#", stage):gsub("{power}", power_png)
tbl[#tbl+1] = temp
end
end
return tbl
end
-- 'validStates' is optional and can be used to e.g. enable
-- only one TA2 node {false, true, false, false}
function techage.register_consumer(base_name, inv_name, tiles, tNode, validStates)
local names = {}
validStates = validStates or {true, true, true, true}
for stage = 2,4 do
local name_pas = "techage:ta"..stage.."_"..base_name.."_pas"
local name_act = "techage:ta"..stage.."_"..base_name.."_act"
local name_inv = "TA"..stage.." "..inv_name
names[#names+1] = name_pas
if validStates[stage] then
local on_recv_message = tNode.tubing.on_recv_message
if stage > 2 then
on_recv_message = function(pos, src, topic, payload)
return "unsupported"
end
end
local power_network
local power_png = 'techage_axle_clutch.png'
local power_used = tNode.power_consumption ~= nil
-- power needed?
if power_used then
if stage > 2 then
power_network = techage.ElectricCable
power_png = 'techage_appl_hole_electric.png'
else
power_network = techage.Axle
power_png = 'techage_axle_clutch.png'
end
power_network:add_secondary_node_names({name_pas, name_act})
end
local tState = techage.NodeStates:new({
node_name_passive = name_pas,
node_name_active = name_act,
infotext_name = name_inv,
cycle_time = tNode.cycle_time,
standby_ticks = tNode.standby_ticks,
formspec_func = tNode.formspec,
on_state_change = tNode.on_state_change,
can_start = tNode.can_start,
has_power = tNode.has_power or power_used and has_power or nil,
start_node = power_used and start_node or nil,
stop_node = power_used and stop_node or nil,
})
local tConsumer = {
stage = stage,
State = tState,
-- number of items to be processed per cycle
num_items = tNode.num_items and tNode.num_items[stage],
power_consumption = power_used and
tNode.power_consumption[stage] or 0,
node_timer = tNode.node_timer,
cycle_time = tNode.cycle_time,
}
tNode.groups.not_in_creative_inventory = 0
minetest.register_node(name_pas, {
description = name_inv,
tiles = prepare_tiles(tiles.pas, stage, power_png),
consumer = tConsumer,
drawtype = tNode.drawtype,
node_box = tNode.node_box,
selection_box = tNode.selection_box,
-- will be overwritten in case, power is used
after_place_node = function(pos, placer, itemstack, pointed_thing)
local meta = M(pos)
local mem = tubelib2.init_mem(pos)
local node = minetest.get_node(pos)
meta:set_int("push_dir", techage.side_to_indir("L", node.param2))
meta:set_int("pull_dir", techage.side_to_indir("R", node.param2))
local number = "-"
if stage > 2 then
number = techage.add_node(pos, name_pas)
end
if tNode.after_place_node then
tNode.after_place_node(pos, placer, itemstack, pointed_thing)
end
CRD(pos).State:node_init(pos, mem, number)
end,
-- will be overwritten in case, power is used
after_dig_node = function(pos, oldnode, oldmetadata, digger)
if tNode.after_dig_node then
tNode.after_dig_node(pos, oldnode, oldmetadata, digger)
end
techage.remove_node(pos)
tubelib2.del_mem(pos)
end,
can_dig = tNode.can_dig,
on_rotate = screwdriver.disallow,
on_timer = node_timer,
on_receive_fields = tNode.on_receive_fields,
on_rightclick = tNode.on_rightclick,
allow_metadata_inventory_put = tNode.allow_metadata_inventory_put,
allow_metadata_inventory_move = tNode.allow_metadata_inventory_move,
allow_metadata_inventory_take = tNode.allow_metadata_inventory_take,
on_metadata_inventory_move = tNode.on_metadata_inventory_move,
on_metadata_inventory_put = tNode.on_metadata_inventory_put,
on_metadata_inventory_take = tNode.on_metadata_inventory_take,
networks = tNode.networks,
tubelib2_on_update2 = tNode.tubelib2_on_update2,
paramtype = tNode.paramtype,
paramtype2 = "facedir",
groups = table.copy(tNode.groups),
is_ground_content = false,
sounds = tNode.sounds,
})
tNode.groups.not_in_creative_inventory = 1
minetest.register_node(name_act, {
description = name_inv,
tiles = prepare_tiles(tiles.act, stage, power_png),
consumer = tConsumer,
drawtype = tNode.drawtype,
node_box = tNode.node_box,
selection_box = tNode.selection_box,
on_rotate = screwdriver.disallow,
on_timer = node_timer,
on_receive_fields = tNode.on_receive_fields,
on_rightclick = tNode.on_rightclick,
allow_metadata_inventory_put = tNode.allow_metadata_inventory_put,
allow_metadata_inventory_move = tNode.allow_metadata_inventory_move,
allow_metadata_inventory_take = tNode.allow_metadata_inventory_take,
on_metadata_inventory_move = tNode.on_metadata_inventory_move,
on_metadata_inventory_put = tNode.on_metadata_inventory_put,
on_metadata_inventory_take = tNode.on_metadata_inventory_take,
networks = tNode.networks,
tubelib2_on_update2 = tNode.tubelib2_on_update2,
paramtype = tNode.paramtype,
paramtype2 = "facedir",
drop = "",
diggable = false,
groups = tNode.groups,
is_ground_content = false,
sounds = tNode.sounds,
})
if power_used then
techage.power.register_node({name_pas, name_act}, {
conn_sides = {"F", "B"},
power_network = power_network,
on_power = on_power,
on_nopower = on_nopower,
after_place_node = function(pos, placer, itemstack, pointed_thing)
local meta = M(pos)
local mem = tubelib2.init_mem(pos)
local node = techage.get_node_lvm(pos)
meta:set_int("push_dir", techage.side_to_indir("L", node.param2))
meta:set_int("pull_dir", techage.side_to_indir("R", node.param2))
local number = "-"
if stage > 2 then
number = techage.add_node(pos, name_pas)
end
if tNode.after_place_node then
tNode.after_place_node(pos, placer, itemstack, pointed_thing)
end
CRD(pos).State:node_init(pos, mem, number)
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
if tNode.after_dig_node then
tNode.after_dig_node(pos, oldnode, oldmetadata, digger)
end
techage.remove_node(pos)
tubelib2.del_mem(pos)
end,
})
end
techage.register_node({name_pas, name_act}, tNode.tubing)
end
end
return names[1], names[2], names[3]
end

View File

@ -46,40 +46,24 @@ local function determine_burntimes()
end
minetest.after(1, determine_burntimes)
function techage.firebox.formspec(mem)
function techage.firebox.formspec(nvm)
local fuel_percent = 0
if mem.running then
fuel_percent = ((mem.burn_cycles or 1) * 100) / (mem.burn_cycles_total or 1)
end
if mem.power_level then
return "size[8,6.5]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"list[current_name;fuel;1,0.5;1,1;]"..
"image[2,0.5;1,1;default_furnace_fire_bg.png^[lowpart:"..
fuel_percent..":default_furnace_fire_fg.png]"..
"label[4.5,0.1;"..S("Power")..":]"..
"dropdown[6,0;1.8;power_level;25%,50%,75%,100%;"..mem.power_level.."]"..
"button[1,1.5;1.8,1;update;"..S("Update").."]"..
"list[current_player;main;0,2.8;8,4;]"..
"listring[current_name;fuel]"..
"listring[current_player;main]"..
default.get_hotbar_bg(0, 2.8)
else
return "size[8,6]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"list[current_name;fuel;1,0.5;1,1;]"..
"image[3,0.5;1,1;default_furnace_fire_bg.png^[lowpart:"..
fuel_percent..":default_furnace_fire_fg.png]"..
"button[5,0.5;1.8,1;update;"..S("Update").."]"..
"list[current_player;main;0,2;8,4;]"..
"listring[current_name;fuel]"..
"listring[current_player;main]"..
default.get_hotbar_bg(0, 2)
if nvm.running then
fuel_percent = ((nvm.burn_cycles or 1) * 100) / (nvm.burn_cycles_total or 1)
end
return "size[8,6]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"box[0,-0.1;7.8,0.5;#c6e8ff]"..
"label[3,-0.1;"..minetest.colorize( "#000000", S("Firebox")).."]"..
"list[current_name;fuel;3,1;1,1;]"..
"image[4,1;1,1;default_furnace_fire_bg.png^[lowpart:"..
fuel_percent..":default_furnace_fire_fg.png]"..
"list[current_player;main;0,2.3;8,4;]"..
"listring[current_name;fuel]"..
"listring[current_player;main]"..
default.get_hotbar_bg(0, 2.3)
end
function techage.firebox.can_dig(pos, player)
@ -104,30 +88,10 @@ function techage.firebox.allow_metadata_inventory_take(pos, listname, index, sta
return stack:get_count()
end
local PowerLevel = {
["25%"] = 1,
["50%"] = 2,
["75%"] = 3,
["100%"] = 4,
}
function techage.firebox.on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then
return
end
if fields.update then
local mem = tubelib2.get_mem(pos)
M(pos):set_string("formspec", techage.firebox.formspec(mem))
end
if fields.power_level then
local mem = tubelib2.get_mem(pos)
mem.power_level = PowerLevel[fields.power_level]
end
end
function techage.firebox.on_rightclick(pos, node, clicker)
local mem = tubelib2.get_mem(pos)
M(pos):set_string("formspec", techage.firebox.formspec(mem))
local nvm = techage.get_nvm(pos)
techage.set_activeformspec(pos, clicker)
M(pos):set_string("formspec", techage.firebox.formspec(nvm))
end
function techage.firebox.swap_node(pos, name)

View File

@ -1,176 +0,0 @@
--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
Oil fuel burning lib
]]--
local S2P = minetest.string_to_pos
local P2S = minetest.pos_to_string
local M = minetest.get_meta
local S = techage.S
local ValidOilFuels = techage.firebox.ValidOilFuels
local Burntime = techage.firebox.Burntime
local CAPACITY = 50
techage.fuel = {}
techage.fuel.CAPACITY = CAPACITY
local function formspec_fuel(x, y, mem)
local itemname = ""
if mem.liquid and mem.liquid.name and mem.liquid.amount and mem.liquid.amount > 0 then
itemname = mem.liquid.name.." "..mem.liquid.amount
end
local fuel_percent = 0
if mem.running then
fuel_percent = ((mem.burn_cycles or 1) * 100) / (mem.burn_cycles_total or 1)
end
return "container["..x..","..y.."]"..
"background[0,0;3,1.05;techage_form_grey.png]"..
"list[context;fuel;0,0;1,1;]"..
techage.item_image(1, 0, itemname)..
"image[2,0;1,1;default_furnace_fire_bg.png^[lowpart:"..
fuel_percent..":default_furnace_fire_fg.png]"..
"container_end[]"
end
techage.fuel.formspec_fuel = formspec_fuel
function techage.fuel.formspec(mem)
local update = ((mem.countdown or 0) > 0 and mem.countdown) or S("Update")
return "size[8,5]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
formspec_fuel(1, 0, mem)..
"button[5,0;2,1;update;"..update.."]"..
"list[current_player;main;0,1.3;8,4;]"
end
local function fill_container(pos, inv, mem)
mem.liquid = mem.liquid or {}
mem.liquid.amount = mem.liquid.amount or 0
local empty_container = inv:get_stack("fuel", 1):get_name()
local full_container = liquid.get_full_container(empty_container, mem.liquid.name)
if empty_container and full_container then
local ldef = liquid.get_liquid_def(full_container)
if ldef and mem.liquid.amount - ldef.size >= 0 then
inv:remove_item("fuel", ItemStack(empty_container))
inv:add_item("fuel", ItemStack(full_container))
mem.liquid.amount = mem.liquid.amount - ldef.size
end
end
end
local function empty_container(pos, inv, mem)
mem.liquid = mem.liquid or {}
mem.liquid.amount = mem.liquid.amount or 0
local stack = inv:get_stack("fuel", 1)
if stack:get_count() == 1 then
local ldef = liquid.get_liquid_def(stack:get_name())
if ldef and ValidOilFuels[ldef.inv_item] then
if not mem.liquid.name or ldef.inv_item == mem.liquid.name then
if mem.liquid.amount + ldef.size <= CAPACITY then
inv:remove_item("fuel", stack)
inv:add_item("fuel", ItemStack(ldef.container))
mem.liquid.amount = mem.liquid.amount + ldef.size
mem.liquid.name = ldef.inv_item
end
end
end
end
end
local function move_item(pos, stack)
local mem = tubelib2.get_mem(pos)
local inv = M(pos):get_inventory()
if liquid.is_container_empty(stack:get_name()) then
fill_container(pos, inv, mem)
else
empty_container(pos, inv, mem)
end
M(pos):set_string("formspec", techage.fuel.formspec(mem))
end
function techage.fuel.move_item(pos, stack, formspec)
local mem = tubelib2.get_mem(pos)
local inv = M(pos):get_inventory()
if liquid.is_container_empty(stack:get_name()) then
fill_container(pos, inv, mem)
else
empty_container(pos, inv, mem)
end
M(pos):set_string("formspec", formspec(pos, mem))
end
function techage.fuel.allow_metadata_inventory_put(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
return 1
end
function techage.fuel.allow_metadata_inventory_take(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
return stack:get_count()
end
function techage.fuel.on_metadata_inventory_put(pos, listname, index, stack, player)
minetest.after(0.5, move_item, pos, stack)
end
function techage.fuel.can_dig(pos, player)
if minetest.is_protected(pos, player:get_player_name()) then
return false
end
local mem = tubelib2.get_mem(pos)
mem.liquid = mem.liquid or {}
mem.liquid.amount = mem.liquid.amount or 0
local inv = M(pos):get_inventory()
return inv:is_empty("fuel") and mem.liquid.amount == 0
end
function techage.fuel.on_rightclick(pos)
local mem = tubelib2.get_mem(pos)
mem.countdown = 10
M(pos):set_string("formspec", techage.fuel.formspec(mem))
end
function techage.fuel.on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then
return
end
local mem = tubelib2.get_mem(pos)
mem.countdown = 10
M(pos):set_string("formspec", techage.fuel.formspec(mem))
end
function techage.fuel.formspec_update(pos, mem)
if mem.countdown and mem.countdown > 0 then
mem.countdown = mem.countdown - 1
M(pos):set_string("formspec", techage.fuel.formspec(mem))
end
end
-- name is the fuel item name
-- category is 4 (all burner) to 1 (gasoline)
function techage.fuel.burntime(name, category)
if ValidOilFuels[name] and ValidOilFuels[name] <= category then
return Burntime[name] or 0.01 -- not zero !
end
return 0.01 -- not zero !
end

View File

@ -48,7 +48,7 @@ function techage.rotate_wallmounted(param2)
return offs + rot
end
function techage.range(val, min, max)
function techage.in_range(val, min, max)
val = tonumber(val)
if val < min then return min end
if val > max then return max end
@ -100,8 +100,6 @@ function techage.get_node_lvm(pos)
return node
end
--
-- Functions used to hide electric cable and biogas pipes
--
@ -167,7 +165,7 @@ local function determine_ocean_ids()
for name, _ in pairs(minetest.registered_biomes) do
if string.find(name, "ocean") then
local id = minetest.get_biome_id(name)
print(id, name)
--print(id, name)
techage.OceanIdTbl[id] = true
end
end
@ -191,3 +189,47 @@ function techage.item_image(x, y, itemname)
"tooltip["..x..","..y..";1,1;"..tooltip(itemname)..";#0C3D32;#FFFFFF]"
end
function techage.mydump(o, indent, nested, level)
local t = type(o)
if not level and t == "userdata" then
-- when userdata (e.g. player) is passed directly, print its metatable:
return "userdata metatable: " .. techage.mydump(getmetatable(o))
end
if t ~= "table" then
return basic_dump(o)
end
-- Contains table -> true/nil of currently nested tables
nested = nested or {}
if nested[o] then
return "<circular reference>"
end
nested[o] = true
indent = " "
level = level or 1
local t = {}
local dumped_indexes = {}
for i, v in ipairs(o) do
t[#t + 1] = techage.mydump(v, indent, nested, level + 1)
dumped_indexes[i] = true
end
for k, v in pairs(o) do
if not dumped_indexes[k] then
if type(k) ~= "string" or not is_valid_identifier(k) then
k = "["..techage.mydump(k, indent, nested, level + 1).."]"
end
v = techage.mydump(v, indent, nested, level + 1)
t[#t + 1] = k.." = "..v
end
end
nested[o] = nil
if indent ~= "" then
local indent_str = string.rep(indent, level)
local end_indent_str = string.rep(indent, level - 1)
return string.format("{%s%s%s}",
indent_str,
table.concat(t, ","..indent_str),
end_indent_str)
end
return "{"..table.concat(t, ", ").."}"
end

View File

@ -65,3 +65,43 @@ minetest.register_entity(":techage:position_cube", {
end,
})
function techage.mark_side(name, pos, dir, nametag, color, time)
local v = vector.multiply(tubelib2.Dir6dToVector[dir or 0], 0.7)
local pos2 = vector.add(pos, v)
local marker = minetest.add_entity(pos2, "techage:position_side")
if marker ~= nil then
marker:set_nametag_attributes({color = color, text = nametag})
marker:get_luaentity().player_name = name
if dir == 2 or dir == 4 then
marker:setyaw(math.pi / 2)
end
if not marker_region[name] then
marker_region[name] = {}
end
marker_region[name][#marker_region[name] + 1] = marker
end
minetest.after(time or 30, techage.unmark_position, name)
end
minetest.register_entity(":techage:position_side", {
initial_properties = {
visual = "upright_sprite",
textures = {"techage_side_mark.png"},
physical = false,
visual_size = {x = 1.1, y = 1.1, z = 1.1},
collisionbox = {-0.55,-0.55,-0.55, 0.55,0.55,0.55},
glow = 8,
},
on_step = function(self, dtime)
if marker_region[self.player_name] == nil then
self.object:remove()
return
end
end,
on_punch = function(self, hitter)
techage.unmark_position(self.player_name)
end,
})

View File

@ -53,15 +53,32 @@ local function output(network, valid)
--print("Network ("..valid.."): "..table.concat(tbl, ", "))
end
local function hidden_node(pos, net_name)
local name = M(pos):get_string("techage_hidden_nodename")
local ndef = minetest.registered_nodes[name]
if ndef and ndef.networks then
return ndef.networks[net_name] or {}
end
return {}
end
-- return the node definition local networks table
local function net_def(pos, net_name)
local ndef = minetest.registered_nodes[techage.get_node_lvm(pos).name]
return ndef and ndef.networks and ndef.networks[net_name] or {}
if ndef and ndef.networks then
return ndef.networks[net_name] or {}
else -- hidden junction
return hidden_node(pos, net_name)
end
end
local function net_def2(node_name, net_name)
local function net_def2(pos, node_name, net_name)
local ndef = minetest.registered_nodes[node_name]
return ndef and ndef.networks and ndef.networks[net_name] or {}
if ndef and ndef.networks then
return ndef.networks[net_name] or {}
else -- hidden junction
return hidden_node(pos, net_name)
end
end
local function connected(tlib2, pos, dir)
@ -71,6 +88,10 @@ local function connected(tlib2, pos, dir)
if not num then return end
return Flip[dir] == d1 or Flip[dir] == d2
end
-- secondary nodes allowed?
if not tlib2.force_to_use_tubes then
return tlib2:is_secondary_node(pos, dir)
end
return false
end
@ -114,25 +135,28 @@ local function get_node_connections(pos, net_name)
return tbl
end
-- determine all node sides with tube connections
-- store all node sides with tube connections as nodemeta
local function node_connections(pos, tlib2)
local node = techage.get_node_lvm(pos)
local val = 0
local sides = net_def2(node.name, tlib2.tube_type).sides
local ndef = net_def2(pos, node.name, tlib2.tube_type)
local sides = ndef.sides or ndef.get_sides and ndef.get_sides(pos, node)
print("node_connections", node.name, dump(sides))
if sides then
for dir = 1,6 do
val = val * 2
local side = DirToSide[outdir_to_dir(dir, node.param2)]
if sides[side] then
print(side, sides[side], P2S(pos), dir, connected(tlib2, pos, dir))
if connected(tlib2, pos, dir) then
techage.mark_side("singleplayer", pos, dir, "node_connections", "", 1)--------------------
val = val + 1
end
end
end
M(pos):set_int(tlib2.tube_type.."_conn", val)
else
error(pos, "sides missing")
--error(pos, "sides missing")
end
end
@ -147,14 +171,30 @@ local function pos_already_reached(pos)
end
-- check if the given pipe dir into the node is valid
local function valid_indir(indir, node, net_name)
local ndef = net_def2(node.name, net_name)
if not ndef or not ndef.sides then return false end
local function valid_indir(pos, indir, node, net_name)
local ndef = net_def2(pos, node.name, net_name)
local sides = ndef.sides or ndef.get_sides and ndef.get_sides(pos, node)
local side = DirToSide[indir_to_dir(indir, node.param2)]
if not ndef.sides[side] then return false end
if not sides or sides and not sides[side] then return false end
return true
end
local function is_junction(pos, name, tube_type)
local ndef = net_def2(pos, name, tube_type)
-- ntype can be a string or an array of strings or nil
if ndef.ntype == "junc" then
return true
end
if type(ndef.ntype) == "table" then
for _,ntype in ipairs(ndef.ntype) do
if ntype == "junc" then
return true
end
end
end
return false
end
-- do the walk through the tubelib2 network
-- indir is the direction which should not be covered by the walk
-- (coming from there)
@ -162,18 +202,20 @@ end
local function connection_walk(pos, outdirs, indir, node, tlib2, clbk)
if clbk then clbk(pos, indir, node) end
--techage.mark_position("singleplayer", pos, "walk", "", 1)
if outdirs or net_def2(node.name, tlib2.tube_type).ntype == "junc" then
--print("connection_walk", node.name, outdirs or is_junction(pos, node.name, tlib2.tube_type))
if outdirs or is_junction(pos, node.name, tlib2.tube_type) then
for _,outdir in pairs(outdirs or get_node_connections(pos, tlib2.tube_type)) do
techage.mark_side("singleplayer", pos, outdir, "connection_walk", "", 3)--------------------
--print("get_node_connections", node.name, outdir)
local pos2, indir2 = tlib2:get_connected_node_pos(pos, outdir)
local node = techage.get_node_lvm(pos2)
if pos2 and not pos_already_reached(pos2) and valid_indir(indir2, node, tlib2.tube_type) then
if pos2 and not pos_already_reached(pos2) and valid_indir(pos2, indir2, node, tlib2.tube_type) then
connection_walk(pos2, nil, indir2, node, tlib2, clbk)
end
end
end
end
local function collect_network_nodes(pos, outdir, tlib2)
Route = {}
NumNodes = 0
@ -183,17 +225,24 @@ local function collect_network_nodes(pos, outdir, tlib2)
local net_name = tlib2.tube_type
-- outdir corresponds to the indir coming from
connection_walk(pos, outdir and {outdir}, nil, node, tlib2, function(pos, indir, node)
local ntype = net_def2(node.name, net_name).ntype
if ntype then
local ndef = net_def2(pos, node.name, net_name)
-- ntype can be a string or an array of strings or nil
local ntypes = ndef.ntype or {}
if type(ntypes) == "string" then
ntypes = {ntypes}
end
for _,ntype in ipairs(ntypes) do
if not netw[ntype] then netw[ntype] = {} end
netw[ntype][#netw[ntype] + 1] = {pos = pos, indir = indir}
netw[ntype][#netw[ntype] + 1] = {pos = pos, indir = indir, nominal = ndef.nominal or 0}
end
end)
netw.best_before = minetest.get_gametime() + BEST_BEFORE
netw.num_nodes = NumNodes
return netw
end
-- keep data base small and valid
-- needed for networks without scheduler
local function remove_outdated_networks()
local to_be_deleted = {}
local t = minetest.get_gametime()
@ -230,10 +279,6 @@ techage.networks.AllSides = Sides -- table for all 6 node sides
-- techage.networks.side_to_outdir(pos, side)
techage.networks.side_to_outdir = side_to_outdir
-- check if the given pipe dir into the node is valid
-- valid_indir(pos, indir, param2, net_name)
--techage.networks.valid_indir = valid_indir
-- techage.networks.node_connections(pos, tlib2)
techage.networks.node_connections = node_connections
@ -245,44 +290,66 @@ function techage.networks.connection_walk(pos, outdir, tlib2, clbk)
NumNodes = 0
pos_already_reached(pos) -- don't consider the start pos
local node = techage.get_node_lvm(pos)
connection_walk(pos, {outdir}, Flip[outdir], node, tlib2, clbk)
connection_walk(pos, outdir and {outdir}, Flip[outdir], node, tlib2, clbk)
return NumNodes
end
function techage.networks.get_network(netID, tlib2)
if Networks[tlib2.tube_type] and Networks[tlib2.tube_type][netID] then
Networks[tlib2.tube_type][netID].best_before = minetest.get_gametime() + BEST_BEFORE
return Networks[tlib2.tube_type][netID]
function techage.networks.get_network(tube_type, netID)
if Networks[tube_type] and Networks[tube_type][netID] then
Networks[tube_type][netID].best_before = minetest.get_gametime() + BEST_BEFORE
return Networks[tube_type][netID]
end
end
function techage.networks.set_network(netID, tlib2, network)
function techage.networks.set_network(tube_type, netID, network)
if netID then
if not Networks[tlib2.tube_type] then
Networks[tlib2.tube_type] = {}
if not Networks[tube_type] then
Networks[tube_type] = {}
end
Networks[tlib2.tube_type][netID] = network
Networks[tlib2.tube_type][netID].best_before = minetest.get_gametime() + BEST_BEFORE
Networks[tube_type][netID] = network
Networks[tube_type][netID].best_before = minetest.get_gametime() + BEST_BEFORE
end
end
function techage.networks.trigger_network(netID, tlib2)
if not Networks[tlib2.tube_type] then
Networks[tlib2.tube_type] = {}
end
Networks[tlib2.tube_type][netID].best_before = minetest.get_gametime() + BEST_BEFORE
end
function techage.networks.delete_network(netID, tlib2)
if Networks[tlib2.tube_type] and Networks[tlib2.tube_type][netID] then
Networks[tlib2.tube_type][netID] = nil
--
-- Power API
--
function techage.networks.has_network(tube_type, netID)
local netw = Networks[tube_type] and Networks[tube_type][netID]
if netw then
netw.alive = 1
netw.best_before = minetest.get_gametime() + BEST_BEFORE
return netw
end
end
function techage.networks.connections(pos, tlib2)
for _,dir in ipairs(get_node_connections(pos, tlib2.tube_type)) do
print(({"North", "East", "South", "West", "Down", "Up"})[dir])
function techage.networks.build_network(pos, outdir, tlib2, netID)
local netw = collect_network_nodes(pos, outdir, tlib2)
Networks[tlib2.tube_type] = Networks[tlib2.tube_type] or {}
Networks[tlib2.tube_type][netID] = netw
netw.alive = 1
techage.schedule.start(tlib2.tube_type, netID)
end
function techage.networks.delete_network(tube_type, netID)
if Networks[tube_type] then
Networks[tube_type][netID] = nil
end
end
function techage.networks.delete_network(tube_type, netID)
if Networks[tube_type] and Networks[tube_type][netID] then
Networks[tube_type][netID] = nil
end
end
--function techage.networks.connections(pos, tlib2)
-- for _,dir in ipairs(get_node_connections(pos, tlib2.tube_type)) do
-- print(({"North", "East", "South", "West", "Down", "Up"})[dir])
-- end
--end
-- Get node tubelib2 connections as table of outdirs
-- techage.networks.get_node_connections(pos, net_name)
techage.networks.get_node_connections = get_node_connections

View File

@ -51,10 +51,10 @@ Node states:
| FAULT none no no
| STOPPED none no no
Node mem data:
Node nvm data:
"techage_state" - node state, like "RUNNING"
"techage_item_meter" - node item/runtime counter
"techage_countdown" - countdown to stadby mode
"techage_countdown" - countdown to standby mode
]]--
-- for lazy programmers
@ -95,7 +95,7 @@ function techage.state_button(state)
return "techage_inv_button_off.png"
end
function techage.get_power_image(pos, mem)
function techage.get_power_image(pos, nvm)
local node = techage.get_node_lvm(pos)
local s = "3" -- electrical power
if string.find(node.name, "techage:ta2") then
@ -124,12 +124,12 @@ local STOPPED = techage.STOPPED
techage.NodeStates = {}
local NodeStates = techage.NodeStates
local function can_start(pos, mem)
local function can_start(pos, nvm)
--if false, node goes in FAULT
return true
end
local function has_power(pos, mem)
local function has_power(pos, nvm)
--if false, node goes in NOPOWER
return true
end
@ -144,14 +144,14 @@ local function swap_node(pos, name)
end
-- true if node_timer should be executed
function techage.is_operational(mem)
local state = mem.techage_state or STOPPED
function techage.is_operational(nvm)
local state = nvm.techage_state or STOPPED
return state < NOPOWER
end
-- consumes power
function techage.needs_power(mem)
local state = mem.techage_state or STOPPED
function techage.needs_power(nvm)
local state = nvm.techage_state or STOPPED
return state < BLOCKED
end
@ -159,8 +159,8 @@ function techage.needs_power2(state)
return state < BLOCKED
end
function techage.get_state_string(mem)
return techage.StateStrings[mem.techage_state or STOPPED]
function techage.get_state_string(nvm)
return techage.StateStrings[nvm.techage_state or STOPPED]
end
function NodeStates:new(attr)
@ -184,15 +184,15 @@ function NodeStates:new(attr)
return o
end
function NodeStates:node_init(pos, mem, number)
mem.techage_state = STOPPED
function NodeStates:node_init(pos, nvm, number)
nvm.techage_state = STOPPED
M(pos):set_string("node_number", number)
if self.infotext_name then
M(pos):set_string("infotext", self.infotext_name.." "..number..": stopped")
end
mem.techage_item_meter = 0
nvm.techage_item_meter = 0
if self.formspec_func then
M(pos):set_string("formspec", self.formspec_func(self, pos, mem))
M(pos):set_string("formspec", self.formspec_func(self, pos, nvm))
end
end
@ -207,11 +207,11 @@ local function start_timer_delayed(pos, cycle_time)
end
end
function NodeStates:stop(pos, mem)
local state = mem.techage_state or STOPPED
mem.techage_state = STOPPED
function NodeStates:stop(pos, nvm)
local state = nvm.techage_state or STOPPED
nvm.techage_state = STOPPED
if self.stop_node then
self.stop_node(pos, mem, state)
self.stop_node(pos, nvm, state)
end
if self.node_name_passive then
swap_node(pos, self.node_name_passive)
@ -221,8 +221,8 @@ function NodeStates:stop(pos, mem)
M(pos):set_string("infotext", self.infotext_name.." "..number..": stopped")
end
if self.formspec_func then
mem.ta_state_tooltip = "stopped"
M(pos):set_string("formspec", self.formspec_func(self, pos, mem))
nvm.ta_state_tooltip = "stopped"
M(pos):set_string("formspec", self.formspec_func(self, pos, nvm))
end
if self.on_state_change then
self.on_state_change(pos, state, STOPPED)
@ -233,23 +233,23 @@ function NodeStates:stop(pos, mem)
return true
end
function NodeStates:start(pos, mem)
local state = mem.techage_state or STOPPED
function NodeStates:start(pos, nvm)
local state = nvm.techage_state or STOPPED
if state ~= RUNNING and state ~= FAULT then
local res = self.can_start(pos, mem, state)
local res = self.can_start(pos, nvm, state)
if res ~= true then
self:fault(pos, mem, res)
self:fault(pos, nvm, res)
return false
end
if not self.has_power(pos, mem, state) then
self:nopower(pos, mem)
if not self.has_power(pos, nvm, state) then
self:nopower(pos, nvm)
return false
end
mem.techage_state = RUNNING
nvm.techage_state = RUNNING
if self.start_node then
self.start_node(pos, mem, state)
self.start_node(pos, nvm, state)
end
mem.techage_countdown = 1
nvm.techage_countdown = 1
if self.node_name_active then
swap_node(pos, self.node_name_active)
end
@ -258,8 +258,8 @@ function NodeStates:start(pos, mem)
M(pos):set_string("infotext", self.infotext_name.." "..number..": running")
end
if self.formspec_func then
mem.ta_state_tooltip = "running"
M(pos):set_string("formspec", self.formspec_func(self, pos, mem))
nvm.ta_state_tooltip = "running"
M(pos):set_string("formspec", self.formspec_func(self, pos, nvm))
end
if minetest.get_node_timer(pos):is_started() then
minetest.get_node_timer(pos):stop()
@ -273,10 +273,10 @@ function NodeStates:start(pos, mem)
return false
end
function NodeStates:standby(pos, mem)
local state = mem.techage_state or STOPPED
function NodeStates:standby(pos, nvm)
local state = nvm.techage_state or STOPPED
if state == RUNNING then
mem.techage_state = STANDBY
nvm.techage_state = STANDBY
if self.node_name_passive then
swap_node(pos, self.node_name_passive)
end
@ -285,8 +285,8 @@ function NodeStates:standby(pos, mem)
M(pos):set_string("infotext", self.infotext_name.." "..number..": standby")
end
if self.formspec_func then
mem.ta_state_tooltip = "standby"
M(pos):set_string("formspec", self.formspec_func(self, pos, mem))
nvm.ta_state_tooltip = "standby"
M(pos):set_string("formspec", self.formspec_func(self, pos, nvm))
end
if self.on_state_change then
self.on_state_change(pos, state, STANDBY)
@ -298,10 +298,10 @@ function NodeStates:standby(pos, mem)
end
-- special case of standby for pushing nodes
function NodeStates:blocked(pos, mem)
local state = mem.techage_state or STOPPED
function NodeStates:blocked(pos, nvm)
local state = nvm.techage_state or STOPPED
if state == RUNNING then
mem.techage_state = BLOCKED
nvm.techage_state = BLOCKED
if self.node_name_passive then
swap_node(pos, self.node_name_passive)
end
@ -310,8 +310,8 @@ function NodeStates:blocked(pos, mem)
M(pos):set_string("infotext", self.infotext_name.." "..number..": blocked")
end
if self.formspec_func then
mem.ta_state_tooltip = "blocked"
M(pos):set_string("formspec", self.formspec_func(self, pos, mem))
nvm.ta_state_tooltip = "blocked"
M(pos):set_string("formspec", self.formspec_func(self, pos, nvm))
end
if self.on_state_change then
self.on_state_change(pos, state, BLOCKED)
@ -322,10 +322,10 @@ function NodeStates:blocked(pos, mem)
return false
end
function NodeStates:nopower(pos, mem, err_string)
local state = mem.techage_state or RUNNING
function NodeStates:nopower(pos, nvm, err_string)
local state = nvm.techage_state or RUNNING
if state ~= NOPOWER then
mem.techage_state = NOPOWER
nvm.techage_state = NOPOWER
if self.node_name_passive then
swap_node(pos, self.node_name_passive)
end
@ -334,8 +334,8 @@ function NodeStates:nopower(pos, mem, err_string)
M(pos):set_string("infotext", self.infotext_name.." "..number..": no power")
end
if self.formspec_func then
mem.ta_state_tooltip = err_string or "no power"
M(pos):set_string("formspec", self.formspec_func(self, pos, mem))
nvm.ta_state_tooltip = err_string or "no power"
M(pos):set_string("formspec", self.formspec_func(self, pos, nvm))
end
if self.on_state_change then
self.on_state_change(pos, state, NOPOWER)
@ -346,11 +346,11 @@ function NodeStates:nopower(pos, mem, err_string)
return false
end
function NodeStates:fault(pos, mem, err_string)
local state = mem.techage_state or STOPPED
function NodeStates:fault(pos, nvm, err_string)
local state = nvm.techage_state or STOPPED
err_string = err_string or "fault"
if state == RUNNING or state == STOPPED then
mem.techage_state = FAULT
nvm.techage_state = FAULT
if self.node_name_passive then
swap_node(pos, self.node_name_passive)
end
@ -359,8 +359,8 @@ function NodeStates:fault(pos, mem, err_string)
M(pos):set_string("infotext", self.infotext_name.." "..number..": "..err_string)
end
if self.formspec_func then
mem.ta_state_tooltip = err_string or "fault"
M(pos):set_string("formspec", self.formspec_func(self, pos, mem))
nvm.ta_state_tooltip = err_string or "fault"
M(pos):set_string("formspec", self.formspec_func(self, pos, nvm))
end
if self.on_state_change then
self.on_state_change(pos, state, FAULT)
@ -371,90 +371,90 @@ function NodeStates:fault(pos, mem, err_string)
return false
end
function NodeStates:get_state(mem)
return mem.techage_state or techage.STOPPED
function NodeStates:get_state(nvm)
return nvm.techage_state or techage.STOPPED
end
-- keep the timer running?
function NodeStates:is_active(mem)
local state = mem.techage_state or STOPPED
function NodeStates:is_active(nvm)
local state = nvm.techage_state or STOPPED
return state < FAULT
end
function NodeStates:start_if_standby(pos)
local mem = tubelib2.get_mem(pos)
if mem.techage_state == STANDBY then
self:start(pos, mem)
local nvm = techage.get_nvm(pos)
if nvm.techage_state == STANDBY then
self:start(pos, nvm)
end
end
-- To be called if node is idle.
-- If countdown reaches zero, the node is set to STANDBY.
function NodeStates:idle(pos, mem)
local countdown = (mem.techage_countdown or 0) - 1
mem.techage_countdown = countdown
function NodeStates:idle(pos, nvm)
local countdown = (nvm.techage_countdown or 0) - 1
nvm.techage_countdown = countdown
if countdown <= 0 then
self:standby(pos, mem)
self:standby(pos, nvm)
end
end
-- To be called after successful node action to raise the timer
-- and keep the node in state RUNNING
function NodeStates:keep_running(pos, mem, val, num_items)
function NodeStates:keep_running(pos, nvm, val, num_items)
-- set to RUNNING if not already done
if mem.techage_state ~= RUNNING then
self:start(pos, mem)
if nvm.techage_state ~= RUNNING then
self:start(pos, nvm)
end
mem.techage_countdown = val or 4
mem.techage_item_meter = (mem.techage_item_meter or 0) + (num_items or 1)
nvm.techage_countdown = val or 4
nvm.techage_item_meter = (nvm.techage_item_meter or 0) + (num_items or 1)
end
-- Start/stop node based on button events.
-- if function returns false, no button was pressed
function NodeStates:state_button_event(pos, mem, fields)
function NodeStates:state_button_event(pos, nvm, fields)
if fields.state_button ~= nil then
local state = mem.techage_state or STOPPED
local state = nvm.techage_state or STOPPED
if state == STOPPED or state == STANDBY or state == BLOCKED then
if not self:start(pos, mem) and (state == STANDBY or state == BLOCKED) then
self:stop(pos, mem)
if not self:start(pos, nvm) and (state == STANDBY or state == BLOCKED) then
self:stop(pos, nvm)
end
elseif state == RUNNING or state == FAULT or state == NOPOWER then
self:stop(pos, mem)
self:stop(pos, nvm)
end
return true
end
return false
end
function NodeStates:get_state_button_image(mem)
local state = mem.techage_state or STOPPED
function NodeStates:get_state_button_image(nvm)
local state = nvm.techage_state or STOPPED
return techage.state_button(state)
end
function NodeStates:get_state_tooltip(mem)
local tp = mem.ta_state_tooltip or ""
function NodeStates:get_state_tooltip(nvm)
local tp = nvm.ta_state_tooltip or ""
return tp..";#0C3D32;#FFFFFF"
end
-- command interface
function NodeStates:on_receive_message(pos, topic, payload)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
if topic == "on" then
self:start(pos, tubelib2.get_mem(pos))
self:start(pos, techage.get_nvm(pos))
return true
elseif topic == "off" then
self:stop(pos, tubelib2.get_mem(pos))
self:stop(pos, techage.get_nvm(pos))
return true
elseif topic == "state" then
local node = techage.get_node_lvm(pos)
if node.name == "ignore" then -- unloaded node?
return "unloaded"
end
return techage.get_state_string(tubelib2.get_mem(pos))
return techage.get_state_string(techage.get_nvm(pos))
elseif topic == "counter" then
return mem.techage_item_meter or 1
return nvm.techage_item_meter or 1
elseif topic == "clear_counter" then
mem.techage_item_meter = 0
nvm.techage_item_meter = 0
return true
elseif topic == "fuel" then
local inv = M(pos):get_inventory()
@ -470,7 +470,7 @@ end
-- repair corrupt node data
function NodeStates:on_node_load(pos, not_start_timer)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
-- Meta data corrupt?
local number = M(pos):get_string("node_number")
@ -478,7 +478,7 @@ function NodeStates:on_node_load(pos, not_start_timer)
minetest.log("warning", "[TA] Node at "..S(pos).." has no node_number")
local name = techage.get_node_lvm(pos).name
local number = techage.add_node(pos, name)
self:node_init(pos, mem, number)
self:node_init(pos, nvm, number)
return
end
@ -499,12 +499,12 @@ function NodeStates:on_node_load(pos, not_start_timer)
end
-- state corrupt?
local state = mem.techage_state or 0
local state = nvm.techage_state or 0
if state == 0 then
if minetest.get_node_timer(pos):is_started() then
mem.techage_state = RUNNING
nvm.techage_state = RUNNING
else
mem.techage_state = STOPPED
nvm.techage_state = STOPPED
end
elseif state == RUNNING and not not_start_timer then
minetest.get_node_timer(pos):start(self.cycle_time)
@ -515,7 +515,12 @@ function NodeStates:on_node_load(pos, not_start_timer)
end
if self.formspec_func then
M(pos):set_string("formspec", self.formspec_func(self, pos, mem))
M(pos):set_string("formspec", self.formspec_func(self, pos, nvm))
end
-- power available?
if nvm.techage_state == RUNNING and not self.has_power(pos, nvm, state) then
self:nopower(pos, nvm)
end
end

View File

@ -18,7 +18,7 @@ local M = minetest.get_meta
local Recipes = {} -- {rtype = {ouput = {....},...}}
local RecipeList = {} -- {rtype = {<output name>,...}}
local range = techage.range
local range = techage.in_range
techage.recipes = {}

View File

@ -1,186 +0,0 @@
--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
TA3 Akku Box
]]--
-- for lazy programmers
local M = minetest.get_meta
local S = techage.S
local CYCLE_TIME = 2
local PWR_PERF = 10
local PWR_CAPA = 2000
local Power = techage.ElectricCable
local power = techage.power
local function in_range(val, min, max)
if val < min then return min end
if val > max then return max end
return val
end
local function formspec(self, pos, mem)
return "size[5,3]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"image[0,0.5;1,2;"..techage.power.formspec_power_bar(PWR_CAPA, mem.capa).."]"..
"label[0.2,2.5;Load]"..
"button[1.1,1;1.8,1;update;"..S("Update").."]"..
"image_button[3,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]"..
"image[4,0.5;1,2;"..techage.power.formspec_load_bar(-(mem.delivered or 0), PWR_PERF).."]"..
"label[4.2,2.5;Flow]"
end
local function start_node(pos, mem, state)
mem.running = true
mem.delivered = 0
power.secondary_start(pos, mem, PWR_PERF, PWR_PERF)
end
local function stop_node(pos, mem, state)
mem.running = false
mem.delivered = 0
power.secondary_stop(pos, mem)
end
local State = techage.NodeStates:new({
node_name_passive = "techage:ta3_akku",
cycle_time = CYCLE_TIME,
standby_ticks = 0,
formspec_func = formspec,
start_node = start_node,
stop_node = stop_node,
})
local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos)
if mem.running then
mem.delivered = power.secondary_alive(pos, mem, mem.capa, PWR_CAPA)
mem.capa = mem.capa - mem.delivered
mem.capa = in_range(mem.capa, 0, PWR_CAPA)
end
return mem.running
end
local function on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then
return
end
local mem = tubelib2.get_mem(pos)
State:state_button_event(pos, mem, fields)
if fields.update then
local mem = tubelib2.get_mem(pos)
M(pos):set_string("formspec", formspec(State, pos, mem))
end
end
local function on_rightclick(pos)
local mem = tubelib2.get_mem(pos)
M(pos):set_string("formspec", formspec(State, pos, mem))
end
local function get_capa(itemstack)
local meta = itemstack:get_meta()
if meta then
return in_range(meta:get_int("capa") * (PWR_CAPA/100), 0, 3000)
end
return 0
end
local function set_capa(pos, oldnode, digger, capa)
local node = ItemStack(oldnode.name)
local meta = node:get_meta()
capa = techage.power.percent(PWR_CAPA, capa)
capa = (math.floor((capa or 0) / 5)) * 5
meta:set_int("capa", capa)
local text = S("TA3 Akku Box").." ("..capa.." %)"
meta:set_string("description", text)
local inv = minetest.get_inventory({type="player", name=digger:get_player_name()})
local left_over = inv:add_item("main", node)
if left_over:get_count() > 0 then
minetest.add_item(pos, node)
end
end
minetest.register_node("techage:ta3_akku", {
description = S("TA3 Akku Box"),
tiles = {
-- up, down, right, left, back, front
"techage_filling_ta3.png^techage_frame_ta3_top.png",
"techage_filling_ta3.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_hole_electric.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_source.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_source.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_source.png",
},
on_receive_fields = on_receive_fields,
on_rightclick = on_rightclick,
on_timer = node_timer,
drop = "", -- don't remove, item will be added via 'set_capa'
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2},
on_rotate = screwdriver.disallow,
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
techage.power.register_node({"techage:ta3_akku"}, {
conn_sides = {"R"},
power_network = Power,
after_place_node = function(pos, placer, itemstack)
local meta = M(pos)
local mem = tubelib2.init_mem(pos)
local own_num = techage.add_node(pos, "techage:ta3_akku")
meta:set_string("owner", placer:get_player_name())
meta:set_string("infotext", S("TA3 Akku Box").." "..own_num)
State:node_init(pos, mem, own_num)
mem.capa = get_capa(itemstack)
on_rightclick(pos)
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
local mem = tubelib2.get_mem(pos)
set_capa(pos, oldnode, digger, mem.capa)
end,
})
-- for logical communication
techage.register_node({"techage:ta3_akku"}, {
on_recv_message = function(pos, src, topic, payload)
local mem = tubelib2.get_mem(pos)
if topic == "capa" then
return techage.power.percent(PWR_CAPA, mem.capa)
else
return State:on_receive_message(pos, topic, payload)
end
end,
on_node_load = function(pos)
local meta = M(pos)
if meta:get_string("node_number") == "" then
local own_num = techage.add_node(pos, "techage:ta3_akku")
meta:set_string("node_number", own_num)
meta:set_string("infotext", S("TA3 Akku Box").." "..own_num)
end
end,
})
minetest.register_craft({
output = "techage:ta3_akku",
recipe = {
{"default:tin_ingot", "default:tin_ingot", "default:wood"},
{"default:copper_ingot", "default:copper_ingot", "techage:electric_cableS"},
{"techage:iron_ingot", "techage:iron_ingot", "default:wood"},
},
})

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -17,6 +17,15 @@ local M = minetest.get_meta
local S = techage.S
local Pipe = techage.SteamPipe
local networks = techage.networks
local function after_place_node(pos)
Pipe:after_place_node(pos)
end
local function after_dig_node(pos, oldnode)
Pipe:after_dig_node(pos)
end
minetest.register_node("techage:coalboiler_base", {
description = S("TA3 Boiler Base"),
@ -28,7 +37,8 @@ minetest.register_node("techage:coalboiler_base", {
fixed = {-13/32, -16/32, -13/32, 13/32, 16/32, 13/32},
},
on_construct = tubelib2.init_mem,
after_place_node = after_place_node,
after_dig_node = after_dig_node,
paramtype = "light",
paramtype2 = "facedir",
@ -38,21 +48,12 @@ minetest.register_node("techage:coalboiler_base", {
sounds = default.node_sound_stone_defaults(),
})
techage.power.register_node({"techage:coalboiler_base"}, {
conn_sides = {"F"},
power_network = Pipe,
})
Pipe:add_secondary_node_names({"techage:coalboiler_base"})
-- for logical communication
techage.register_node({"techage:coalboiler_base"}, {
on_transfer = function(pos, in_dir, topic, payload)
if topic == "start" then
return true
elseif topic == "stop" then
return true
elseif topic == "running" then
return true
end
return true
end
})

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -17,206 +17,40 @@ local M = minetest.get_meta
local S = techage.S
local CYCLE_TIME = 4
local STANDBY_TICKS = 2
local COUNTDOWN_TICKS = 20
local HEAT_STEP = 10
local WATER_CONSUMPTION = 0.1
local MAX_WATER = 10
local Pipe = techage.SteamPipe
local boiler = techage.boiler
local function transfer(pos, topic, payload)
return techage.transfer(pos, "F", topic, payload, Pipe,
{"techage:turbine", "techage:turbine_on"})
end
local Water = {
["bucket:bucket_river_water"] = true,
["bucket:bucket_water"] = true,
["bucket:bucket_empty"] = true,
}
local function formspec(self, pos, mem)
local temp = mem.temperature or 20
local ratio = mem.power_ratio or 0
return "size[8,7]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"image_button[0,0.2;1,1;techage_form_inventory.png;storage;;true;false;]"..
"list[context;water;1,0.2;1,1;]"..
"image_button[0,1.6;1,1;techage_form_input.png;input;;true;false;]"..
"list[context;input;1,1.6;1,1;]"..
"image[1,1.6;1,1;bucket_water.png]"..
"image[1,1.6;1,1;techage_form_mask.png]"..
"image[2,0.5;1,2;techage_form_temp_bg.png^[lowpart:"..
temp..":techage_form_temp_fg.png]"..
"image[7,0.5;1,2;"..techage.power.formspec_power_bar(1, ratio).."]"..
"image_button[6,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]"..
"button[3,1.5;2,1;update;"..S("Update").."]"..
"list[current_player;main;0,3;8,4;]"..
"listring[current_name;water]"..
"listring[current_player;main]"..
default.get_hotbar_bg(0, 3)
end
local function can_start(pos, mem, state)
return mem.temperature and mem.temperature >= 80
end
local function start_node(pos, mem, state)
mem.running = transfer(pos, "start", nil)
mem.power_ratio = 0
end
local function stop_node(pos, mem, state)
transfer(pos, "stop", nil)
mem.running = false
mem.power_ratio = 0
end
local State = techage.NodeStates:new({
node_name_passive = "techage:coalboiler_top",
cycle_time = CYCLE_TIME,
standby_ticks = STANDBY_TICKS,
has_item_meter = false,
formspec_func = formspec,
can_start = can_start,
start_node = start_node,
stop_node = stop_node,
})
local function get_water(pos)
local inv = M(pos):get_inventory()
local items = inv:get_stack("water", 1)
if items:get_count() > 0 then
local taken = items:take_item(1)
inv:set_stack("water", 1, items)
return true
end
return false
end
local function water_temperature(pos, mem)
mem.temperature = mem.temperature or 20
if mem.fire_trigger then
mem.temperature = math.min(mem.temperature + HEAT_STEP, 100)
else
mem.temperature = math.max(mem.temperature - HEAT_STEP, 20)
end
mem.fire_trigger = false
if mem.water_level == 0 then
if get_water(pos) then
mem.water_level = 100
else
mem.temperature = 20
end
end
return mem.temperature
end
local function steaming(pos, mem, temp)
local wc = WATER_CONSUMPTION * (mem.power_ratio or 1)
mem.water_level = math.max((mem.water_level or 0) - wc, 0)
mem.running = transfer(pos, "running", nil)
if not mem.running then
State:fault(pos, mem)
elseif temp > 20 then
if temp < 80 then
State:stop(pos, mem)
minetest.get_node_timer(pos):start(CYCLE_TIME)
else
State:keep_running(pos, mem, COUNTDOWN_TICKS)
end
local function steaming(pos, nvm, temp)
if temp >= 80 then
local wc = WATER_CONSUMPTION * (nvm.power_ratio or 1)
nvm.water_level = math.max((nvm.water_level or 0) - wc, 0)
end
end
local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos)
local temp = water_temperature(pos, mem)
if State:is_active(mem) then
steaming(pos, mem, temp)
local nvm = techage.get_nvm(pos)
local temp = boiler.water_temperature(pos, nvm)
steaming(pos, nvm, temp)
if techage.is_activeformspec(pos) then
M(pos):set_string("formspec", boiler.formspec(pos, nvm))
end
return mem.temperature > 20
return temp > 20
end
local function on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then
return
end
local mem = tubelib2.get_mem(pos)
mem.temperature = mem.temperature or 20
State:state_button_event(pos, mem, fields)
if fields.update then
if mem.temperature > 20 then
minetest.get_node_timer(pos):start(CYCLE_TIME)
end
M(pos):set_string("formspec", formspec(State, pos, mem))
local function after_place_node(pos)
local node = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z})
if node.name == "techage:coalboiler_base" then
local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", boiler.formspec(pos, nvm))
Pipe:after_place_node(pos)
end
end
local function on_rightclick(pos)
local mem = tubelib2.get_mem(pos)
M(pos):set_string("formspec", formspec(State, pos, mem))
if not minetest.get_node_timer(pos):is_started() then
minetest.get_node_timer(pos):start(CYCLE_TIME)
end
end
local function can_dig(pos, player)
local inv = M(pos):get_inventory()
local mem = tubelib2.get_mem(pos)
return inv:is_empty("input") and not mem.running
end
local function move_to_water(pos)
local inv = M(pos):get_inventory()
local water_stack = inv:get_stack("water", 1)
local input_stack = inv:get_stack("input", 1)
if input_stack:get_name() == "bucket:bucket_empty" then
if input_stack:get_count() == 1 then
if water_stack:get_count() > 0 then
water_stack:set_count(water_stack:get_count() - 1)
input_stack = ItemStack("bucket:bucket_water")
inv:set_stack("water", 1, water_stack)
inv:set_stack("input", 1, input_stack)
end
end
elseif water_stack:get_count() < MAX_WATER then
if water_stack:get_count() == 0 then
water_stack = ItemStack("default:water_source")
else
water_stack:set_count(water_stack:get_count() + 1)
end
input_stack = ItemStack("bucket:bucket_empty")
inv:set_stack("water", 1, water_stack)
inv:set_stack("input", 1, input_stack)
end
end
local function allow_metadata_inventory_put(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
if listname == "input" and Water[stack:get_name()] then
return stack:get_count()
end
return 0
end
local function allow_metadata_inventory_take(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
if listname == "input" then
return stack:get_count()
end
return 0
local function after_dig_node(pos, oldnode)
Pipe:after_dig_node(pos)
techage.del_mem(pos)
end
minetest.register_node("techage:coalboiler_top", {
@ -229,23 +63,12 @@ minetest.register_node("techage:coalboiler_top", {
fixed = {-13/32, -48/32, -13/32, 13/32, 16/32, 13/32},
},
can_dig = can_dig,
can_dig = boiler.can_dig,
on_timer = node_timer,
allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_take = allow_metadata_inventory_take,
allow_metadata_inventory_move = function(pos) return 0 end,
on_receive_fields = on_receive_fields,
on_rightclick = on_rightclick,
on_construct = function(pos)
local inv = M(pos):get_inventory()
inv:set_size('water', 1)
inv:set_size('input', 1)
end,
on_metadata_inventory_put = function(pos)
minetest.after(0.5, move_to_water, pos)
end,
on_rightclick = boiler.on_rightclick,
after_place_node = after_place_node,
after_dig_node = after_dig_node,
on_punch = boiler.on_punch,
paramtype = "light",
paramtype2 = "facedir",
@ -255,36 +78,28 @@ minetest.register_node("techage:coalboiler_top", {
sounds = default.node_sound_metal_defaults(),
})
techage.power.register_node({"techage:coalboiler_top"}, {
conn_sides = {"F"},
power_network = Pipe,
after_place_node = function(pos, placer)
local mem = tubelib2.init_mem(pos)
State:node_init(pos, mem, "")
local node = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z})
if node.name == "techage:coalboiler_base" then
on_rightclick(pos)
end
end,
})
Pipe:add_secondary_node_names({"techage:coalboiler_top"})
techage.register_node({"techage:coalboiler_top"}, {
on_transfer = function(pos, in_dir, topic, payload)
if topic == "trigger" then
local mem = tubelib2.get_mem(pos)
mem.fire_trigger = true
local nvm = techage.get_nvm(pos)
nvm.fire_trigger = true
if not minetest.get_node_timer(pos):is_started() then
minetest.get_node_timer(pos):start(CYCLE_TIME)
end
if mem.running then
mem.power_ratio = transfer(pos, topic, payload)
return mem.power_ratio
if (nvm.temperature or 20) > 80 then
nvm.power_ratio = techage.transfer(pos, "F", "trigger", nil, Pipe, {
"techage:turbine", "techage:turbine_on"}) or 0
return nvm.power_ratio
else
return 0
end
end
end
end,
})
minetest.register_craft({
output = "techage:coalboiler_top",
recipe = {

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -23,28 +23,47 @@ local function transfer(pos, in_dir, topic, payload)
{"techage:coalboiler_base"})
end
local function swap_node(pos, name)
local node = techage.get_node_lvm(pos)
if node.name == name then
return
end
node.name = name
minetest.swap_node(pos, node)
local function after_place_node(pos)
Pipe:after_place_node(pos)
end
local function after_dig_node(pos, oldnode)
Pipe:after_dig_node(pos)
techage.del_mem(pos)
end
minetest.register_node("techage:cooler", {
description = S("TA3 Cooler"),
tiles = {
-- up, down, right, left, back, front
"techage_filling_ta3.png^techage_appl_cooler.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_appl_cooler.png^techage_frame_ta3.png",
{
image = "techage_filling4_ta3.png^techage_appl_cooler4.png^techage_frame4_ta3.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 0.4,
},
},
{
image = "techage_filling4_ta3.png^techage_appl_cooler4.png^techage_frame4_ta3.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 0.4,
},
},
"techage_filling_ta3.png^techage_frame_ta3.png^techage_steam_hole.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_steam_hole.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_cooler.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_cooler.png",
},
on_construct = tubelib2.init_mem,
after_place_node = after_place_node,
after_dig_node = after_dig_node,
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2},
@ -53,8 +72,9 @@ minetest.register_node("techage:cooler", {
sounds = default.node_sound_wood_defaults(),
})
-- legacy node
minetest.register_node("techage:cooler_on", {
description = S("TA3 Cooler"),
tiles = {
-- up, down, right, left, back, front
{
@ -83,41 +103,23 @@ minetest.register_node("techage:cooler_on", {
"techage_filling_ta3.png^techage_frame_ta3.png^techage_cooler.png",
},
after_place_node = after_place_node,
after_dig_node = after_dig_node,
paramtype2 = "facedir",
groups = {not_in_creative_inventory=1},
diggable = false,
drop = "techage:cooler",
groups = {cracky=2, crumbly=2, choppy=2, not_in_creative_inventory=1},
on_rotate = screwdriver.disallow,
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
-- for mechanical pipe connections
techage.power.register_node({"techage:cooler", "techage:cooler_on"}, {
conn_sides = {"L", "R"},
power_network = Pipe,
after_tube_update = function(node, pos, out_dir, peer_pos, peer_in_dir)
swap_node(pos, "techage:cooler")
end,
})
Pipe:add_secondary_node_names({"techage:cooler", "techage:cooler_on"})
-- for logical communication
techage.register_node({"techage:cooler", "techage:cooler_on"}, {
on_transfer = function(pos, in_dir, topic, payload)
if topic == "start" then
if transfer(pos, in_dir, topic, nil) then
swap_node(pos, "techage:cooler_on")
return true
end
elseif topic == "stop" then
swap_node(pos, "techage:cooler")
return transfer(pos, in_dir, topic, nil)
elseif topic == "running" then
if transfer(pos, in_dir, topic, nil) then
return true
end
swap_node(pos, "techage:cooler")
end
return false
return transfer(pos, in_dir, topic, payload)
end
})

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -18,12 +18,9 @@ local M = minetest.get_meta
local S = techage.S
local firebox = techage.firebox
local fuel = techage.fuel
local Pipe = techage.LiquidPipe
local liquid = techage.liquid
local CYCLE_TIME = 2
local EFFICIENCY = 0.5
local BURN_CYCLE_FACTOR = 0.5
local function firehole(pos, on)
local param2 = techage.get_node_lvm(pos).param2
@ -38,38 +35,39 @@ local function firehole(pos, on)
end
local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos)
if mem.running then
-- trigger generator and provide power ratio 0..1
local ratio = techage.transfer(
local nvm = techage.get_nvm(pos)
if nvm.running then
local power = techage.transfer(
{x=pos.x, y=pos.y+2, z=pos.z},
nil, -- outdir
"trigger", -- topic
(mem.power_level or 4)/4.0, -- payload
nil, -- payload
nil, -- network
{"techage:coalboiler_top"} -- nodenames
)
ratio = math.max((ratio or 0.02), 0.02)
mem.burn_cycles = (mem.burn_cycles or 0) - ratio
if mem.burn_cycles <= 0 then
nvm.burn_cycles = (nvm.burn_cycles or 0) - math.max((power or 0.02), 0.02)
if nvm.burn_cycles <= 0 then
local taken = firebox.get_fuel(pos)
if taken then
mem.burn_cycles = (firebox.Burntime[taken:get_name()] or 1) * EFFICIENCY / CYCLE_TIME
mem.burn_cycles_total = mem.burn_cycles
nvm.burn_cycles = (firebox.Burntime[taken:get_name()] or 1) / CYCLE_TIME * BURN_CYCLE_FACTOR
nvm.burn_cycles_total = nvm.burn_cycles
else
mem.running = false
nvm.running = false
firehole(pos, false)
M(pos):set_string("formspec", firebox.formspec(mem))
M(pos):set_string("formspec", firebox.formspec(nvm))
return false
end
end
if techage.is_activeformspec(pos) then
M(pos):set_string("formspec", firebox.formspec(nvm))
end
return true
end
end
local function start_firebox(pos, mem)
if not mem.running then
mem.running = true
local function start_firebox(pos, nvm)
if not nvm.running then
nvm.running = true
node_timer(pos, 0)
firehole(pos, true)
minetest.get_node_timer(pos):start(CYCLE_TIME)
@ -98,17 +96,15 @@ minetest.register_node("techage:coalfirebox", {
can_dig = firebox.can_dig,
allow_metadata_inventory_put = firebox.allow_metadata_inventory_put,
allow_metadata_inventory_take = firebox.allow_metadata_inventory_take,
on_receive_fields = firebox.on_receive_fields,
on_rightclick = firebox.on_rightclick,
on_construct = function(pos)
local mem = tubelib2.init_mem(pos)
techage.add_node(pos, "techage:coalfirebox")
mem.running = false
mem.burn_cycles = 0
mem.power_level = 4
local nvm = techage.get_nvm(pos)
nvm.running = false
nvm.burn_cycles = 0
local meta = M(pos)
meta:set_string("formspec", firebox.formspec(mem))
meta:set_string("formspec", firebox.formspec(nvm))
local inv = meta:get_inventory()
inv:set_size('fuel', 1)
firehole(pos, false)
@ -119,9 +115,9 @@ minetest.register_node("techage:coalfirebox", {
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
local mem = tubelib2.get_mem(pos)
start_firebox(pos, mem)
M(pos):set_string("formspec", firebox.formspec(mem))
local nvm = techage.get_nvm(pos)
start_firebox(pos, nvm)
M(pos):set_string("formspec", firebox.formspec(nvm))
end,
})
@ -188,128 +184,6 @@ minetest.register_node("techage:coalfirehole_on", {
groups = {not_in_creative_inventory=1},
})
local function on_timer2(pos, elapsed)
local mem = tubelib2.get_mem(pos)
if mem.running then
fuel.formspec_update(pos, mem)
-- trigger generator and provide power ratio 0..1
local ratio = techage.transfer(
{x=pos.x, y=pos.y+2, z=pos.z},
nil, -- outdir
"trigger", -- topic
(mem.power_level or 4)/4.0, -- payload
nil, -- network
{"techage:coalboiler_top"} -- nodenames
)
ratio = math.max((ratio or 0.02), 0.02)
mem.burn_cycles = (mem.burn_cycles or 0) - ratio
mem.liquid = mem.liquid or {}
mem.liquid.amount = mem.liquid.amount or 0
if mem.burn_cycles <= 0 then
if mem.liquid.amount > 0 then
mem.liquid.amount = mem.liquid.amount - 1
mem.burn_cycles = fuel.burntime(mem.liquid.name) * EFFICIENCY / CYCLE_TIME
mem.burn_cycles_total = mem.burn_cycles
else
mem.running = false
mem.liquid.name = nil
firehole(pos, false)
M(pos):set_string("formspec", fuel.formspec(mem))
return false
end
end
return true
end
end
local function start_firebox2(pos, mem)
if not mem.running and mem.liquid.amount > 0 then
mem.running = true
on_timer2(pos, 0)
firehole(pos, true)
minetest.get_node_timer(pos):start(CYCLE_TIME)
M(pos):set_string("formspec", fuel.formspec(mem))
end
end
minetest.register_node("techage:oilfirebox", {
description = S("TA3 Power Station Oil Burner"),
inventory_image = "techage_oil_boiler_inv.png",
tiles = {"techage_coal_boiler_mesh_top.png"},
drawtype = "mesh",
mesh = "techage_cylinder_12.obj",
selection_box = {
type = "fixed",
fixed = {-13/32, -16/32, -13/32, 13/32, 16/32, 13/32},
},
paramtype = "light",
paramtype2 = "facedir",
on_rotate = screwdriver.disallow,
groups = {cracky=2},
is_ground_content = false,
sounds = default.node_sound_stone_defaults(),
on_timer = on_timer2,
can_dig = fuel.can_dig,
allow_metadata_inventory_take = fuel.allow_metadata_inventory_take,
allow_metadata_inventory_put = fuel.allow_metadata_inventory_put,
on_receive_fields = fuel.on_receive_fields,
on_rightclick = fuel.on_rightclick,
on_construct = function(pos)
local mem = tubelib2.init_mem(pos)
techage.add_node(pos, "techage:oilfirebox")
mem.running = false
mem.burn_cycles = 0
mem.liquid = {}
mem.liquid.amount = 0
local meta = M(pos)
meta:set_string("formspec", fuel.formspec(mem))
local inv = meta:get_inventory()
inv:set_size('fuel', 1)
firehole(pos, false)
end,
on_destruct = function(pos)
firehole(pos, nil)
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
local mem = tubelib2.get_mem(pos)
mem.liquid = mem.liquid or {}
mem.liquid.amount = mem.liquid.amount or 0
minetest.after(1, start_firebox2, pos, mem)
fuel.on_metadata_inventory_put(pos, listname, index, stack, player)
end,
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 leftover = liquid.srv_put(pos, indir, name, amount)
local mem = tubelib2.get_mem(pos)
mem.liquid = mem.liquid or {}
mem.liquid.amount = mem.liquid.amount or 0
start_firebox2(pos, mem)
return leftover
end
return amount
end,
take = liquid.srv_take,
},
networks = {
pipe = {
sides = techage.networks.AllSides, -- Pipe connection sides
ntype = "tank",
},
},
})
Pipe:add_secondary_node_names({"techage:oilfirebox"})
techage.register_node({"techage:coalfirebox"}, {
on_pull_item = function(pos, in_dir, num)
@ -321,8 +195,8 @@ techage.register_node({"techage:coalfirebox"}, {
if firebox.Burntime[stack:get_name()] then
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local mem = tubelib2.get_mem(pos)
start_firebox(pos, mem)
local nvm = techage.get_nvm(pos)
start_firebox(pos, nvm)
return techage.put_items(inv, "fuel", stack)
end
return false
@ -333,9 +207,9 @@ techage.register_node({"techage:coalfirebox"}, {
return techage.put_items(inv, "fuel", stack)
end,
on_recv_message = function(pos, src, topic, payload)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
if topic == "state" then
if mem.running then
if nvm.running then
return "running"
else
return "stopped"
@ -350,23 +224,6 @@ techage.register_node({"techage:coalfirebox"}, {
end,
})
techage.register_node({"techage:oilfirebox"}, {
on_recv_message = function(pos, src, topic, payload)
local mem = tubelib2.get_mem(pos)
if topic == "state" then
if mem.running then
return "running"
else
return "stopped"
end
elseif topic == "fuel" then
return mem.liquid and mem.liquid.amount and mem.liquid.amount
else
return "unsupported"
end
end,
})
minetest.register_craft({
output = "techage:coalfirebox",
recipe = {
@ -376,21 +233,14 @@ minetest.register_craft({
},
})
minetest.register_craft({
output = "techage:oilfirebox",
recipe = {
{'', 'techage:coalfirebox', ''},
{'', 'techage:ta3_barrel_empty', ''},
{'', '', ''},
},
})
minetest.register_lbm({
label = "[techage] Power Station firebox",
name = "techage:steam_engine",
nodenames = {"techage:coalfirebox", "techage:oilfirebox"},
name = "techage:coalfirebox",
nodenames = {"techage:coalfirebox"},
run_at_every_load = true,
action = function(pos, node)
local nvm = techage.get_nvm(pos)
nvm.running = true
minetest.get_node_timer(pos):start(CYCLE_TIME)
end
})

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -23,32 +23,42 @@ local PWR_CAPA = 80
local Cable = techage.ElectricCable
local power = techage.power
local networks = techage.networks
local function formspec(self, pos, mem)
return "size[8,7]"..
local function formspec(self, pos, nvm)
return "size[4,4]"..
"box[0,-0.1;3.8,0.5;#c6e8ff]"..
"label[1,-0.1;"..minetest.colorize( "#000000", S("Generator")).."]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"image[6,0.5;1,2;"..power.formspec_power_bar(PWR_CAPA, mem.provided).."]"..
"image_button[5,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]"..
"button[2,1.5;2,1;update;"..S("Update").."]"..
"list[current_player;main;0,3;8,4;]"..
default.get_hotbar_bg(0, 3)
power.formspec_label_bar(0, 0.8, S("power"), PWR_CAPA, nvm.provided)..
"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
local function can_start(pos, mem, state)
return (mem.firebox_trigger or 0) > 0 -- by means of firebox
local function transfer_turbine(pos, topic, payload)
return techage.transfer(pos, "L", topic, payload, nil,
{"techage:turbine", "techage:turbine_on"})
end
local function start_node(pos, mem, state)
mem.generating = true -- needed for power distribution
power.generator_start(pos, mem, PWR_CAPA)
local function can_start(pos, nvm, state)
return (nvm.firebox_trigger or 0) > 0 -- by means of firebox
end
local function stop_node(pos, mem, state)
mem.generating = false
power.generator_stop(pos, mem)
mem.provided = 0
local function start_node(pos, nvm, state)
local outdir = M(pos):get_int("outdir")
power.generator_start(pos, Cable, CYCLE_TIME, outdir)
transfer_turbine(pos, "start")
nvm.running = true
end
local function stop_node(pos, nvm, state)
local outdir = M(pos):get_int("outdir")
power.generator_stop(pos, Cable, outdir)
nvm.provided = 0
transfer_turbine(pos, "stop")
nvm.running = false
end
local State = techage.NodeStates:new({
@ -64,42 +74,63 @@ local State = techage.NodeStates:new({
})
local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos)
if mem.generating then
mem.firebox_trigger = (mem.firebox_trigger or 0) - 1
if mem.firebox_trigger <= 0 then
State:nopower(pos, mem)
mem.generating = false
power.generator_stop(pos, mem)
mem.provided = 0
else
mem.provided = power.generator_alive(pos, mem)
State:keep_running(pos, mem, COUNTDOWN_TICKS)
end
local nvm = techage.get_nvm(pos)
nvm.firebox_trigger = (nvm.firebox_trigger or 0) - 1
if nvm.firebox_trigger <= 0 then
State:nopower(pos, nvm)
stop_node(pos, nvm, State)
transfer_turbine(pos, "stop")
else
local outdir = M(pos):get_int("outdir")
nvm.provided = power.generator_alive(pos, Cable, CYCLE_TIME, outdir)
State:keep_running(pos, nvm, COUNTDOWN_TICKS)
end
return State:is_active(mem)
if techage.is_activeformspec(pos) then
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
return State:is_active(nvm)
end
local function on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then
return
end
local mem = tubelib2.get_mem(pos)
State:state_button_event(pos, mem, fields)
if fields.update then
M(pos):set_string("formspec", formspec(State, pos, mem))
end
local nvm,_ = techage.get_nvm(pos, true)
State:state_button_event(pos, nvm, fields)
end
local function on_rightclick(pos)
local mem = tubelib2.get_mem(pos)
M(pos):set_string("formspec", formspec(State, pos, mem))
if mem.generating then
minetest.get_node_timer(pos):start(CYCLE_TIME)
end
local function on_rightclick(pos, node, clicker)
local nvm = techage.get_nvm(pos)
techage.set_activeformspec(pos, clicker)
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
local function after_place_node(pos)
local nvm = techage.get_nvm(pos)
local number = techage.add_node(pos, "techage:generator")
State:node_init(pos, nvm, number)
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
M(pos):set_string("formspec", formspec(State, pos, nvm))
Cable:after_place_node(pos)
end
local function after_dig_node(pos, oldnode)
Cable:after_dig_node(pos)
techage.del_mem(pos)
end
local function tubelib2_on_update2(pos, outdir, tlib2, node)
power.update_network(pos, outdir, tlib2)
end
local net_def = {
ele1 = {
sides = {R = 1},
ntype = "gen1",
nominal = PWR_CAPA,
},
}
minetest.register_node("techage:generator", {
description = S("TA3 Generator"),
tiles = {
@ -111,9 +142,15 @@ minetest.register_node("techage:generator", {
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_generator.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_generator.png^[transformFX]",
},
on_receive_fields = on_receive_fields,
on_rightclick = on_rightclick,
on_timer = node_timer,
after_place_node = after_place_node,
after_dig_node = after_dig_node,
tubelib2_on_update2 = tubelib2_on_update2,
networks = net_def,
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2},
on_rotate = screwdriver.disallow,
@ -154,6 +191,11 @@ minetest.register_node("techage:generator_on", {
on_receive_fields = on_receive_fields,
on_rightclick = on_rightclick,
on_timer = node_timer,
after_place_node = after_place_node,
after_dig_node = after_dig_node,
tubelib2_on_update2 = tubelib2_on_update2,
networks = net_def,
drop = "",
paramtype2 = "facedir",
groups = {not_in_creative_inventory=1},
@ -163,38 +205,15 @@ minetest.register_node("techage:generator_on", {
sounds = default.node_sound_wood_defaults(),
})
minetest.register_craft({
output = "techage:generator",
recipe = {
{"basic_materials:steel_bar", "dye:green", "default:wood"},
{"", "basic_materials:gear_steel", "techage:electric_cableS"},
{"default:wood", "techage:iron_ingot", "basic_materials:steel_bar"},
},
})
Cable:add_secondary_node_names({"techage:generator", "techage:generator_on"})
techage.power.register_node({"techage:generator", "techage:generator_on"}, {
conn_sides = {"R"},
power_network = Cable,
after_place_node = function(pos, placer)
local mem = tubelib2.init_mem(pos)
local number = techage.add_node(pos, "techage:generator")
State:node_init(pos, mem, number)
on_rightclick(pos)
end,
})
-- for logical communication
techage.register_node({"techage:generator", "techage:generator_on"}, {
on_transfer = function(pos, in_dir, topic, payload)
local mem = tubelib2.get_mem(pos)
if topic == "power_level" then
local mem = tubelib2.get_mem(pos)
mem.power_level = payload
elseif topic == "trigger" then
mem.firebox_trigger = 3
mem.power_level = payload
if mem.generating then
return math.max((mem.provided or PWR_CAPA) / PWR_CAPA, 0.02)
local nvm = techage.get_nvm(pos)
if topic == "trigger" then
nvm.firebox_trigger = 3
if nvm.running then
return math.max((nvm.provided or PWR_CAPA) / PWR_CAPA, 0.1)
else
return 0
end
@ -209,7 +228,18 @@ techage.register_node({"techage:generator", "techage:generator_on"}, {
end
end,
on_node_load = function(pos)
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
State:on_node_load(pos)
end,
})
minetest.register_craft({
output = "techage:generator",
recipe = {
{"basic_materials:steel_bar", "dye:green", "default:wood"},
{"", "basic_materials:gear_steel", "techage:electric_cableS"},
{"default:wood", "techage:iron_ingot", "basic_materials:steel_bar"},
},
})

View File

@ -1,180 +0,0 @@
--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
TA3 Power Terminal
]]--
-- for lazy programmers
local S2P = minetest.string_to_pos
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local M = minetest.get_meta
local N = function(pos) return minetest.get_node(pos).name end
local S = techage.S
local CYCLE_TIME = 2
local PWR_CAPA = 0.1
local COUNTDOWN = 5
local Cable = techage.ElectricCable
local power = techage.power
local function collect_network_data(pos, mem)
local data = {
fuel = {},
wind = {},
solar = {},
akku = {},
stor = {},
elec = {},
fcel = {},
other = {},
}
local add = function(tbl, mem, nomi, real)
tbl.num = (tbl.num or 0) + 1
tbl.load = (tbl.load or 0) + (((mem.pwr_node_alive_cnt or 0) > 0) and 1 or 0)
tbl.nomi = (tbl.nomi or 0) + (nomi or 0)
tbl.real = (tbl.real or 0) + (((mem.pwr_node_alive_cnt or 0) > 0) and (real or 0) or 0)
end
local nnodes = techage.power.limited_connection_walk(pos,
function(pos, node, mem, num_hops, num_nodes)
if node.name == "techage:generator" or node.name == "techage:generator_on" then
add(data.fuel, mem, mem.pwr_available, mem.provided)
elseif node.name == "techage:ta3_akku" then
add(data.akku, mem, mem.pwr_could_provide, mem.delivered)
elseif node.name == "techage:heatexchanger1" then
add(data.stor, mem, mem.pwr_could_provide, mem.delivered)
elseif node.name == "techage:tiny_generator" or node.name == "techage:tiny_generator_on" then
add(data.fuel, mem, mem.pwr_available, mem.provided)
elseif node.name == "techage:ta4_solar_inverter" then
add(data.solar, mem, mem.pwr_available, mem.delivered)
elseif node.name == "techage:ta4_wind_turbine" then
add(data.wind, mem, mem.pwr_available, mem.delivered)
elseif node.name == "techage:ta4_fuelcell" or node.name == "techage:ta4_fuelcell_on" then
add(data.fcel, mem, mem.pwr_available, mem.provided)
elseif node.name == "techage:ta4_electrolyzer" or node.name == "techage:ta4_electrolyzer_on" then
add(data.elec, mem, -(mem.pwr_could_need or 0), -(mem.consumed or 0))
elseif mem.pwr_needed and mem.pwr_needed > 0 then
local nomi = -mem.pwr_needed
local real = (mem.pwr_node_alive_cnt or 0) > 0 and -mem.pwr_needed
add(data.other, mem, nomi, real)
end
end
)
return data, nnodes
end
local function formspec(pos, mem)
local data, nnodes = collect_network_data(pos, mem)
local get = function(kind)
return (data[kind].load or 0).." / "..(data[kind].num or 0).." : "..
(data[kind].real or 0).." / "..(data[kind].nomi or 0).. " ku"
end
local alarm = ""
if nnodes > (techage.MAX_NUM_NODES - 50) then
alarm = " (max. "..(techage.MAX_NUM_NODES).." !!!)"
end
local update = mem.countdown > 0 and mem.countdown or S("Update")
return "size[9.5,8.2]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"label[2,0.0;"..S("Network Data").."]"..
"label[1,0.7;"..S("(Num. nodes loaded / max. : Power current / max.)").."]"..
"label[0,1.4;"..S("TA3 Coal/oil")..":]".. "label[5,1.4;"..get("fuel").."]"..
"label[0,2.1;"..S("TA3 Akku")..":]".. "label[5,2.1;"..get("akku").."]"..
"label[0,2.8;"..S("TA4 Solar Inverter")..":]".. "label[5,2.8;"..get("solar").."]"..
"label[0,3.5;"..S("TA4 Wind Turbine")..":]".. "label[5,3.5;"..get("wind").."]"..
"label[0,4.2;"..S("TA4 Energy Storage")..":]".. "label[5,4.2;"..get("stor").."]"..
"label[0,4.9;"..S("TA4 Electrolyzer")..":]".. "label[5,4.9;"..get("elec").."]"..
"label[0,5.6;"..S("TA4 Fuel Cell")..":]".. "label[5,5.6;"..get("fcel").."]"..
"label[0,6.3;"..S("Other consumers")..":]".. "label[5,6.3;"..get("other").."]"..
"label[0,7;"..S("Number of nodes").." : "..nnodes..alarm.."]"..
"button[3.5,7.5;2,1;update;"..update.."]"
end
local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos)
power.generator_alive(pos, mem)
mem.countdown = mem.countdown or 0
if mem.countdown > 0 then
mem.countdown = mem.countdown - 1
M(pos):set_string("formspec", formspec(pos, mem))
end
return true
end
minetest.register_node("techage:ta3_power_terminal", {
description = S("TA3 Power Terminal"),
inventory_image = "techage_power_terminal_front.png",
tiles = {
"techage_power_terminal_top.png",
"techage_power_terminal_top.png",
"techage_power_terminal_side.png",
"techage_power_terminal_side.png",
"techage_power_terminal_back.png",
"techage_power_terminal_front.png",
},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{ -8/16, -8/16, 0/16, 8/16, 8/16, 8/16},
},
},
on_receive_fields = function(pos, formname, fields, player)
local mem = tubelib2.get_mem(pos)
mem.countdown = COUNTDOWN
end,
on_rightclick = function(pos, node, clicker)
local mem = tubelib2.get_mem(pos)
minetest.get_node_timer(pos):start(CYCLE_TIME)
power.generator_start(pos, mem, PWR_CAPA)
mem.countdown = COUNTDOWN
end,
on_timer = node_timer,
paramtype2 = "facedir",
paramtype = "light",
on_rotate = screwdriver.disallow,
sunlight_propagates = true,
is_ground_content = false,
groups = {cracky = 1, level = 2},
sounds = default.node_sound_metal_defaults(),
})
techage.power.register_node({"techage:ta3_power_terminal"}, {
power_network = Cable,
conn_sides = {"B"},
after_place_node = function(pos)
local mem = tubelib2.init_mem(pos)
minetest.get_node_timer(pos):start(CYCLE_TIME)
power.generator_start(pos, mem, PWR_CAPA)
local meta = M(pos)
mem.countdown = 0
meta:set_string("formspec", formspec(pos, mem))
end,
})
minetest.register_craft({
output = "techage:ta3_power_terminal",
recipe = {
{"", "techage:usmium_nuggets", "default:steel_ingot"},
{"", "techage:basalt_glass_thin", "default:copper_ingot"},
{"", "techage:vacuum_tube", "default:steel_ingot"},
},
})

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -20,12 +20,12 @@ local Pipe = techage.SteamPipe
local function transfer_cooler(pos, topic, payload)
return techage.transfer(pos, 6, topic, payload, Pipe,
{"techage:cooler", "techage:cooler_on"})
{"techage:cooler", "techage:cooler_on"})
end
local function transfer_generator(pos, topic, payload)
return techage.transfer(pos, "R", topic, payload, nil,
{"techage:generator", "techage:generator_on"})
{"techage:generator", "techage:generator_on"})
end
local function swap_node(pos, name)
@ -37,35 +37,41 @@ local function swap_node(pos, name)
minetest.swap_node(pos, node)
end
local function node_timer(pos)
local mem = tubelib2.get_mem(pos)
if mem.running then
mem.handle = minetest.sound_play("techage_turbine", {
pos = pos,
gain = 1,
max_hear_distance = 15})
end
return mem.running
end
local function play_sound(pos)
local mem = tubelib2.get_mem(pos)
if mem.running then
node_timer(pos)
minetest.get_node_timer(pos):start(2)
local mem = techage.get_mem(pos)
mem.handle = minetest.sound_play("techage_turbine", {
pos = pos,
gain = 1,
max_hear_distance = 15,
loop = true})
if mem.handle == -1 then
minetest.after(1, play_sound, pos)
end
end
local function stop_sound(pos)
local mem = tubelib2.get_mem(pos)
if mem.running and mem.handle then
local mem = techage.get_mem(pos)
if mem.handle then
minetest.sound_stop(mem.handle)
mem.handle = nil
minetest.get_node_timer(pos):stop(2)
end
end
local function after_place_node(pos)
Pipe:after_place_node(pos)
end
local function after_dig_node(pos, oldnode)
stop_sound(pos)
Pipe:after_dig_node(pos)
techage.del_mem(pos)
end
local function tubelib2_on_update2(pos, outdir, tlib2, node)
swap_node(pos, "techage:turbine")
stop_sound(pos)
end
minetest.register_node("techage:turbine", {
description = S("TA3 Turbine"),
tiles = {
@ -77,6 +83,11 @@ minetest.register_node("techage:turbine", {
"techage_filling_ta3.png^techage_appl_turbine.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_appl_turbine.png^techage_frame_ta3.png",
},
after_place_node = after_place_node,
after_dig_node = after_dig_node,
tubelib2_on_update2 = tubelib2_on_update2,
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2},
on_rotate = screwdriver.disallow,
@ -112,7 +123,9 @@ minetest.register_node("techage:turbine_on", {
},
},
},
on_timer = node_timer,
tubelib2_on_update2 = tubelib2_on_update2,
paramtype2 = "facedir",
groups = {not_in_creative_inventory=1},
diggable = false,
@ -121,49 +134,41 @@ minetest.register_node("techage:turbine_on", {
sounds = default.node_sound_wood_defaults(),
})
-- for mechanical pipe connections
techage.power.register_node({"techage:turbine", "techage:turbine_on"}, {
conn_sides = {"L", "U"},
power_network = Pipe,
after_tube_update = function(node, pos, out_dir, peer_pos, peer_in_dir)
local mem = tubelib2.get_mem(pos)
transfer_cooler(pos, "stop", nil)
swap_node(pos, "techage:turbine")
mem.running = false
stop_sound(pos)
end
})
Pipe:add_secondary_node_names({"techage:turbine", "techage:turbine_on"})
-- for logical communication
techage.register_node({"techage:turbine", "techage:turbine_on"}, {
on_transfer = function(pos, in_dir, topic, payload)
local mem = tubelib2.get_mem(pos)
if topic == "trigger" then
return transfer_generator(pos, topic, payload)
elseif topic == "start" then
if transfer_cooler(pos, topic, payload) then
swap_node(pos, "techage:turbine_on")
mem.running = true
play_sound(pos)
return true
end
return false
elseif topic == "running" then
local nvm = techage.get_nvm(pos)
if topic == "trigger" then -- used by boiler
if not transfer_cooler(pos, topic, payload) then
swap_node(pos, "techage:turbine")
mem.running = false
stop_sound(pos)
return false
return 0
end
local power = transfer_generator(pos, topic, payload)
if not power or power <= 0 and nvm.running then
swap_node(pos, "techage:cylinder")
stop_sound(pos)
nvm.running = false
return 0
end
return power
elseif topic == "start" then -- used by generator
swap_node(pos, "techage:turbine_on")
play_sound(pos)
nvm.running = true
return true
elseif topic == "stop" then
transfer_cooler(pos, topic, payload)
elseif topic == "stop" then -- used by generator
swap_node(pos, "techage:turbine")
mem.running = false
stop_sound(pos)
nvm.running = false
return true
end
end
end,
on_node_load = function(pos, node)
--print("on_node_load", node.name)
if node.name == "techage:turbine_on" then
play_sound(pos)
end
end,
})
minetest.register_craft({
@ -175,12 +180,3 @@ minetest.register_craft({
},
})
minetest.register_lbm({
label = "[techage] Turbine sound",
name = "techage:power_station",
nodenames = {"techage:turbine_on"},
run_at_every_load = true,
action = function(pos, node)
play_sound(pos)
end
})

View File

@ -189,7 +189,7 @@ techage.manual_DE.aText = {
"\n",
"Erdöl kann nur mit Hilfe des Explorers gefunden und mit Hilfe entsprechender TA3 Maschinen gefördert werden. Siehe TA3.\n"..
"\n",
"Bauxit wird nur im Untertagebau gewonnen. Bauxit findet man nur in Stein in einer Höhe zwischen -50 und -150 Meter.\n"..
"Bauxit wird nur im Untertagebau gewonnen. Bauxit findet man nur in Stein in einer Höhe zwischen -50 und -500 Meter.\n"..
"Es wird zur Herstellung von Aluminium benötigt\\, was vor allem in TA4 Verwendung findet.\n"..
"\n",
" - 28.09.2019: Um Solaranlage erweitert\n"..

View File

@ -360,8 +360,10 @@ Pipe:add_secondary_node_names({"techage:heatexchanger1", "techage:heatexchanger3
techage.register_node({"techage:heatexchanger1"}, {
on_recv_message = function(pos, src, topic, payload)
local mem = tubelib2.get_mem(pos)
if topic == "capa" then
if topic == "load" then
return techage.power.percent(mem.capa_max, mem.capa)
elseif topic == "size" then
return (mem.capa_max or 0) / GRVL_CAPA
else
return State:on_receive_message(pos, topic, payload)
end

View File

@ -104,7 +104,7 @@ local function start_flarestack(pos, playername)
max_hear_distance = 20,
gain = 1,
loop = true})
print("handle", handle)
--print("handle", handle)
meta:set_int("handle", handle)
end
@ -140,7 +140,7 @@ minetest.register_node("techage:gasflare", {
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
print(dump(oldmetadata))
--print(dump(oldmetadata))
stop_flarestack(pos, oldmetadata.fields.handle)
local node = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z})
if node.name == "techage:gasflare2" then

View File

@ -17,7 +17,7 @@ local P = minetest.string_to_pos
local M = minetest.get_meta
local S = techage.S
local range = techage.range
local range = techage.in_range
local Recipes = {} -- registered recipes {output = {recipe, ...},}
local Ingredients = {} -- {{input = output},

View File

@ -30,7 +30,7 @@ local num_recipes = techage.furnace.get_num_recipes
local reset_cooking = techage.furnace.reset_cooking
local get_ingredients = techage.furnace.get_ingredients
local check_if_worth_to_wakeup = techage.furnace.check_if_worth_to_wakeup
local range = techage.range
local range = techage.in_range
local function update_recipe_menu(pos, mem)

View File

@ -8,7 +8,7 @@
GPL v3
See LICENSE.txt for more information
TA4 Electrolyzer
TA4 Electrolyzer v2
]]--
@ -18,27 +18,29 @@ local S = techage.S
local Power = techage.ElectricCable
local power = techage.power
local Pipe = techage.LiquidPipe
local liquid = techage.liquid
local CYCLE_TIME = 2
local STANDBY_TICKS = 5
local PWR_NEEDED = 40
local PWR_UNITS_PER_HYDROGEN_ITEM = 320
local CAPACITY = 400
local function formspec(self, pos, mem)
local update = ((mem.countdown or 0) > 0 and mem.countdown) or S("Update")
return "size[8,6.6]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"image[0.5,0;1,2;"..power.formspec_power_bar(PWR_NEEDED, mem.consumed).."]"..
"label[0.7,1.9;"..S("\\[ku\\]").."]"..
"image[3,0;1,1;techage_form_arrow_fg.png^[transformR270]"..
"image_button[4,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]"..
"button[2.1,1;1.8,1;update;"..S("Update").."]"..
"list[context;dst;5.5,0;2,2;]"..
"image[0.0,0;1,2;"..power.formspec_power_bar(PWR_NEEDED, mem.consumed).."]"..
"label[0.2,1.9;"..S("\\[ku\\]").."]"..
"image[2.5,0;1,1;techage_form_arrow_fg.png^[transformR270]"..
"image_button[3.5,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]"..
"tooltip[3.5,1;1,1;"..self:get_state_tooltip(mem).."]"..
"button[1.6,1;1.8,1;update;"..update.."]"..
"list[current_player;main;0,2.8;8,4;]" ..
"listring[current_player;main]"..
"listring[context;dst]" ..
"listring[current_player;main]"..
liquid.formspec_liquid(5, 0, mem)..
default.get_hotbar_bg(0, 2.8)
end
@ -55,8 +57,8 @@ local function stop_node(pos, mem, state)
end
local State = techage.NodeStates:new({
node_name_passive = "techage:ta4_electrolyzer",
node_name_active = "techage:ta4_electrolyzer_on",
node_name_passive = "techage:ta4_electrolyzer2",
node_name_active = "techage:ta4_electrolyzer2_on",
cycle_time = CYCLE_TIME,
standby_ticks = STANDBY_TICKS,
formspec_func = formspec,
@ -65,47 +67,45 @@ local State = techage.NodeStates:new({
stop_node = stop_node,
})
local function add_hydrogen(pos)
local inv = M(pos):get_inventory()
local leftover = inv:add_item("dst", ItemStack("techage:hydrogen"))
return leftover:get_count() == 0
end
local function room_for_hydrogen(pos)
local inv = M(pos):get_inventory()
return inv:room_for_item("dst", ItemStack("techage:hydrogen"))
end
-- converts power into hydrogen
local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos)
mem.num_pwr_units = mem.num_pwr_units or 0
--print("electrolyzer", mem.running, mem.consumed, mem.num_pwr_units, techage.get_state_string(mem))
mem.countdown = mem.countdown or 0
mem.liquid = mem.liquid or {}
mem.liquid.amount = mem.liquid.amount or 0
print("electrolyzer", mem.running, mem.consumed, mem.num_pwr_units, mem.liquid.amount)
if mem.running then
if techage.needs_power(mem) then
mem.consumed = -power.secondary_alive(pos, mem, 0, 1)
--print("mem.consumed", mem.consumed)
if mem.consumed > 0 then
mem.num_pwr_units = mem.num_pwr_units + mem.consumed
if mem.num_pwr_units >= PWR_UNITS_PER_HYDROGEN_ITEM then
if add_hydrogen(pos) then
if mem.liquid.amount < CAPACITY then
mem.num_pwr_units = mem.num_pwr_units + mem.consumed
if mem.num_pwr_units >= PWR_UNITS_PER_HYDROGEN_ITEM then
mem.liquid.amount = mem.liquid.amount + 1
mem.liquid.name = "techage:hydrogen"
mem.num_pwr_units = mem.num_pwr_units - PWR_UNITS_PER_HYDROGEN_ITEM
State:keep_running(pos, mem, 1, 0) -- count items
else
State:blocked(pos, mem)
power.secondary_stop(pos, mem)
end
else
State:blocked(pos, mem)
power.secondary_stop(pos, mem)
end
end
else
mem.consumed = -power.secondary_alive(pos, mem, 1, 1)
if room_for_hydrogen(pos) then
if mem.liquid.amount < CAPACITY then
State:start(pos, mem)
power.secondary_start(pos, mem, PWR_NEEDED, PWR_NEEDED)
end
end
end
return mem.running
if mem.countdown > 0 then
mem.countdown = mem.countdown - 1
M(pos):set_string("formspec", formspec(State, pos, mem))
end
return mem.running or mem.countdown > 0
end
local function on_receive_fields(pos, formname, fields, player)
@ -115,9 +115,9 @@ local function on_receive_fields(pos, formname, fields, player)
local mem = tubelib2.get_mem(pos)
State:state_button_event(pos, mem, fields)
if fields.update then
M(pos):set_string("formspec", formspec(State, pos, mem))
end
mem.countdown = 10
M(pos):set_string("formspec", formspec(State, pos, mem))
minetest.get_node_timer(pos):start(CYCLE_TIME)
end
local function allow_metadata_inventory(pos, listname, index, stack, player)
@ -132,10 +132,12 @@ end
local function on_rightclick(pos)
local mem = tubelib2.get_mem(pos)
mem.countdown = 10
M(pos):set_string("formspec", formspec(State, pos, mem))
minetest.get_node_timer(pos):start(CYCLE_TIME)
end
minetest.register_node("techage:ta4_electrolyzer", {
minetest.register_node("techage:ta4_electrolyzer2", {
description = S("TA4 Electrolyzer"),
tiles = {
-- up, down, right, left, back, front
@ -149,21 +151,46 @@ minetest.register_node("techage:ta4_electrolyzer", {
on_construct = function(pos)
local mem = tubelib2.init_mem(pos)
local number = techage.add_node(pos, "techage:ta4_electrolyzer")
local number = techage.add_node(pos, "techage:ta4_electrolyzer2")
mem.running = false
mem.num_pwr_units = 0
State:node_init(pos, mem, number)
local meta = M(pos)
meta:set_string("formspec", formspec(State, pos, mem))
local inv = meta:get_inventory()
inv:set_size('dst', 4)
inv:set_size('src', 1)
inv:set_size('dst', 1)
end,
tubelib2_on_update2 = function(pos, outdir, tlib2, node)
liquid.update_network(pos, outdir)
end,
can_dig = function(pos, player)
local inv = M(pos):get_inventory()
return inv:is_empty("dst")
end,
liquid = {
capa = CAPACITY,
peek = liquid.srv_peek,
put = function(pos, indir, name, amount)
local leftover = liquid.srv_put(pos, indir, name, amount)
local inv = M(pos):get_inventory()
if not inv:is_empty("src") and inv:is_empty("dst") then
liquid.fill_container(pos, inv)
end
return leftover
end,
take = liquid.srv_take,
},
networks = {
pipe = {
sides = {R = 1}, -- Pipe connection sides
ntype = "tank",
},
},
allow_metadata_inventory_put = allow_metadata_inventory,
allow_metadata_inventory_take = allow_metadata_inventory,
on_receive_fields = on_receive_fields,
@ -176,7 +203,7 @@ minetest.register_node("techage:ta4_electrolyzer", {
is_ground_content = false,
})
minetest.register_node("techage:ta4_electrolyzer_on", {
minetest.register_node("techage:ta4_electrolyzer2_on", {
description = S("TA4 Electrolyzer"),
tiles = {
-- up, down, right, left, back, front
@ -206,6 +233,30 @@ minetest.register_node("techage:ta4_electrolyzer_on", {
},
},
tubelib2_on_update2 = function(pos, outdir, tlib2, node)
liquid.update_network(pos, outdir)
end,
liquid = {
capa = CAPACITY,
peek = liquid.srv_peek,
put = function(pos, indir, name, amount)
local leftover = liquid.srv_put(pos, indir, name, amount)
local inv = M(pos):get_inventory()
if not inv:is_empty("src") and inv:is_empty("dst") then
liquid.fill_container(pos, inv)
end
return leftover
end,
take = liquid.srv_take,
},
networks = {
pipe = {
sides = {R = 1}, -- Pipe connection sides
ntype = "tank",
},
},
allow_metadata_inventory_put = allow_metadata_inventory,
allow_metadata_inventory_take = allow_metadata_inventory,
on_receive_fields = on_receive_fields,
@ -221,46 +272,29 @@ minetest.register_node("techage:ta4_electrolyzer_on", {
light_source = 6,
})
techage.power.register_node({"techage:ta4_electrolyzer", "techage:ta4_electrolyzer_on"}, {
-- Register for power
techage.power.register_node({"techage:ta4_electrolyzer2", "techage:ta4_electrolyzer2_on"}, {
conn_sides = {"L"},
power_network = Power,
after_place_node = function(pos)
local node = minetest.get_node(pos)
local indir = techage.side_to_indir("R", node.param2)
M(pos):set_int("in_dir", indir)
Pipe:after_place_node(pos)
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
Pipe:after_dig_node(pos)
end,
})
techage.register_node({"techage:ta4_electrolyzer", "techage:ta4_electrolyzer_on"}, {
on_pull_item = function(pos, in_dir, num)
local meta = minetest.get_meta(pos)
if meta:get_int("in_dir") == in_dir then
local inv = M(pos):get_inventory()
return techage.get_items(inv, "dst", num)
end
end,
on_push_item = function(pos, in_dir, stack)
local meta = minetest.get_meta(pos)
if meta:get_int("in_dir") == in_dir then
local inv = M(pos):get_inventory()
State:start_if_standby(pos)
return techage.put_items(inv, "dst", stack)
end
end,
on_unpull_item = function(pos, in_dir, stack)
local meta = minetest.get_meta(pos)
if meta:get_int("in_dir") == in_dir then
local inv = M(pos):get_inventory()
return techage.put_items(inv, "dst", stack)
end
end,
on_recv_message = function(pos, src, topic, payload)
return State:on_receive_message(pos, topic, payload)
end,
})
-- Register for tubes
techage.register_node({"techage:ta4_electrolyzer2", "techage:ta4_electrolyzer2_on"}, liquid.tubing)
-- Register for pipes
Pipe:add_secondary_node_names({"techage:ta3_tank", "techage:ta4_tank", "techage:oiltank"})
minetest.register_craft({
output = "techage:ta4_electrolyzer",
output = "techage:ta4_electrolyzer2",
recipe = {
{'default:steel_ingot', 'dye:blue', 'default:steel_ingot'},
{'techage:electric_cableS', 'default:glass', 'techage:tubeS'},

View File

@ -1,34 +0,0 @@
--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
TA4 Hydrogen
]]--
local S = techage.S
minetest.register_craftitem("techage:hydrogen", {
description = S("TA4 Hydrogen"),
inventory_image = "techage_hydrogen_inv.png",
})
minetest.register_craftitem("techage:ta4_fuelcellstack", {
description = S("TA4 Fuel Cell Stack"),
inventory_image = "techage_fc_stack_inv.png",
})
minetest.register_craft({
output = "techage:ta4_fuelcellstack",
recipe = {
{'techage:baborium_ingot', 'techage:ta4_carbon_fiber', 'default:copper_ingot'},
{'default:gold_ingot', 'techage:ta4_carbon_fiber', 'default:tin_ingot'},
{"techage:baborium_ingot", 'techage:ta4_carbon_fiber', 'default:copper_ingot'},
},
})

228
init.lua
View File

@ -11,45 +11,31 @@ else
techage = {
NodeDef = {}, -- node registration info
}
techage.max_num_forceload_blocks = tonumber(minetest.setting_get("techage_max_num_forceload_blocks")) or 24
techage.basalt_stone_enabled = minetest.setting_get("techage_basalt_stone_enabled") == "true"
techage.ore_rarity = tonumber(minetest.setting_get("techage_ore_rarity")) or 1
techage.modified_recipes_enabled = minetest.setting_get("techage_modified_recipes_enabled") == "true"
techage.max_num_forceload_blocks = tonumber(minetest.settings:get("techage_max_num_forceload_blocks")) or 24
techage.basalt_stone_enabled = minetest.settings:get_bool("techage_basalt_stone_enabled") ~= false
techage.ore_rarity = tonumber(minetest.settings:get("techage_ore_rarity")) or 1
techage.modified_recipes_enabled = minetest.settings:get_bool("techage_modified_recipes_enabled") ~= false
-- Load support for I18n.
techage.S = minetest.get_translator("techage")
-- Debugging via "techage.Debug.dbg(text)"
techage.Debug = {
dbg = function(text, ...)
local t = string.format("%.4f: ", minetest.get_us_time() / 1000000.0)
if type(text) ~= "string" then
text = dump(text)
end
print(t..text, unpack({...}))
end,
--con = true, -- consumer modell
--pwr = true, -- power distribution
--sts = true, -- status plots
--dbg2 = true,
--tst = true,
--bot = true -- Signs Bot
--slr = true,
}
-- Basis features
local MP = minetest.get_modpath("techage")
dofile(MP.."/basis/lib.lua") -- helper functions
dofile(MP.."/basis/gravel_lib.lua") -- ore probability
dofile(MP.."/basis/node_states.lua") -- state model
dofile(MP.."/basis/tubes.lua") -- tubelib replacement
dofile(MP.."/basis/command.lua") -- tubelib replacement
dofile(MP.."/basis/tubes.lua") -- tubes for item transport
dofile(MP.."/basis/command.lua") -- command API
dofile(MP.."/basis/firebox_lib.lua") -- common firebox functions
dofile(MP.."/basis/boiler_lib.lua") -- common boiler functions
dofile(MP.."/basis/mark.lua")
dofile(MP.."/basis/mark2.lua")
dofile(MP.."/basis/assemble.lua")
dofile(MP.."/basis/networks.lua")
dofile(MP.."/basis/recipe_lib.lua")
dofile(MP.."/basis/formspec_update.lua")
dofile(MP.."/basis/storage.lua")
-- Main doc
dofile(MP.."/doc/manual_DE.lua")
@ -59,20 +45,30 @@ else
dofile(MP.."/doc/guide.lua") -- construction guides
-- Power networks
dofile(MP.."/power/schedule.lua")
--dofile(MP.."/power/distribute.lua")
--dofile(MP.."/power/test.lua")
dofile(MP.."/power/power.lua")
dofile(MP.."/power/power2.lua")
dofile(MP.."/power/node_api.lua")
dofile(MP.."/power/junction.lua")
dofile(MP.."/power/distribution.lua")
dofile(MP.."/power/schedule.lua")
dofile(MP.."/power/formspecs.lua")
dofile(MP.."/power/drive_axle.lua")
dofile(MP.."/power/gearbox.lua")
dofile(MP.."/power/steam_pipe.lua")
dofile(MP.."/power/electric_cable.lua")
dofile(MP.."/power/power_line.lua")
dofile(MP.."/power/junctionbox.lua")
dofile(MP.."/power/powerswitch.lua")
dofile(MP.."/power/power_terminal.lua")
dofile(MP.."/power/powerswitchbox.lua")
dofile(MP.."/power/protection.lua")
dofile(MP.."/power/ta4_cable.lua")
dofile(MP.."/power/power_line.lua")
--dofile(MP.."/power/test.lua")
--dofile(MP.."/power/power.lua")
--dofile(MP.."/power/power2.lua")
--dofile(MP.."/power/junction.lua")
--dofile(MP.."/power/junctionbox.lua")
--dofile(MP.."/power/powerswitch.lua")
--dofile(MP.."/power/ta4_cable.lua")
-- Iron Age
dofile(MP.."/iron_age/main.lua")
@ -96,10 +92,9 @@ else
dofile(MP.."/steam_engine/boiler.lua")
dofile(MP.."/steam_engine/cylinder.lua")
dofile(MP.."/steam_engine/flywheel.lua")
dofile(MP.."/steam_engine/gearbox.lua")
-- Basic Machines
dofile(MP.."/basis/consumer.lua") -- consumer base model
dofile(MP.."/basic_machines/consumer.lua") -- consumer base model
dofile(MP.."/basic_machines/source.lua")
dofile(MP.."/basic_machines/pusher.lua")
dofile(MP.."/basic_machines/legacy_nodes.lua")
@ -113,13 +108,14 @@ else
dofile(MP.."/basic_machines/funnel.lua")
dofile(MP.."/basic_machines/liquidsampler.lua")
-- Liquids
dofile(MP.."/liquids/liquid_pipe.lua")
dofile(MP.."/liquids/liquid.lua")
dofile(MP.."/liquids/tank.lua")
dofile(MP.."/liquids/silo.lua")
dofile(MP.."/liquids/pump.lua")
dofile(MP.."/liquids/fuel_lib.lua")
-- -- Liquids
-- dofile(MP.."/liquids/liquid_pipe.lua")
-- dofile(MP.."/liquids/liquid.lua")
-- dofile(MP.."/liquids/liquid_lib.lua")
-- dofile(MP.."/liquids/tank.lua")
-- dofile(MP.."/liquids/silo.lua")
-- dofile(MP.."/liquids/pump.lua")
-- dofile(MP.."/liquids/fuel_lib.lua")
-- Coal power station
dofile(MP.."/coal_power_station/firebox.lua")
@ -128,16 +124,14 @@ else
dofile(MP.."/coal_power_station/generator.lua")
dofile(MP.."/coal_power_station/turbine.lua")
dofile(MP.."/coal_power_station/cooler.lua")
dofile(MP.."/coal_power_station/akkubox.lua")
dofile(MP.."/coal_power_station/power_terminal.lua")
-- Industrial Furnace
dofile(MP.."/furnace/firebox.lua")
dofile(MP.."/furnace/cooking.lua")
dofile(MP.."/furnace/furnace_top.lua")
dofile(MP.."/furnace/booster.lua")
dofile(MP.."/furnace/heater.lua")
dofile(MP.."/furnace/recipes.lua")
-- -- Industrial Furnace
-- dofile(MP.."/furnace/firebox.lua")
-- dofile(MP.."/furnace/cooking.lua")
-- dofile(MP.."/furnace/furnace_top.lua")
-- dofile(MP.."/furnace/booster.lua")
-- dofile(MP.."/furnace/heater.lua")
-- dofile(MP.."/furnace/recipes.lua")
-- Tools
dofile(MP.."/tools/trowel.lua")
@ -145,24 +139,27 @@ else
dofile(MP.."/basic_machines/blackhole.lua")
dofile(MP.."/basic_machines/forceload.lua")
-- Lamps
dofile(MP.."/lamps/lib.lua")
dofile(MP.."/lamps/simplelamp.lua")
dofile(MP.."/lamps/streetlamp.lua")
dofile(MP.."/lamps/ceilinglamp.lua")
dofile(MP.."/lamps/industriallamp1.lua")
dofile(MP.."/lamps/industriallamp2.lua")
dofile(MP.."/lamps/industriallamp3.lua")
-- -- Lamps
-- dofile(MP.."/lamps/lib.lua")
-- dofile(MP.."/lamps/simplelamp.lua")
-- dofile(MP.."/lamps/streetlamp.lua")
-- dofile(MP.."/lamps/ceilinglamp.lua")
-- dofile(MP.."/lamps/industriallamp1.lua")
-- dofile(MP.."/lamps/industriallamp2.lua")
-- dofile(MP.."/lamps/industriallamp3.lua")
-- Oil
dofile(MP.."/oil/explore.lua")
dofile(MP.."/oil/tower.lua")
dofile(MP.."/oil/drillbox.lua")
dofile(MP.."/oil/pumpjack.lua")
dofile(MP.."/oil/generator.lua")
dofile(MP.."/oil/distiller.lua")
dofile(MP.."/oil/reboiler.lua")
dofile(MP.."/oil/gasflare.lua")
-- -- Oil
-- dofile(MP.."/oil/explore.lua")
-- dofile(MP.."/oil/tower.lua")
-- dofile(MP.."/oil/drillbox.lua")
-- dofile(MP.."/oil/pumpjack.lua")
-- dofile(MP.."/oil/distiller.lua")
-- dofile(MP.."/oil/reboiler.lua")
-- dofile(MP.."/oil/gasflare.lua")
-- TA3 power based
--dofile(MP.."/ta3_power/tiny_generator.lua")
--dofile(MP.."/ta3_power/akkubox.lua")
-- Logic
dofile(MP.."/logic/lib.lua")
@ -183,54 +180,71 @@ else
-- Test
dofile(MP.."/recipe_checker.lua")
--dofile(MP.."/.test/sink.lua")
dofile(MP.."/.test/source.lua")
--dofile(MP.."/.test/akku.lua")
--dofile(MP.."/.test/switch.lua")
dofile(MP.."/.test/sink.lua")
--dofile(MP.."/.test/source.lua")
--dofile(MP.."/.test/accu.lua")
-- Solar
dofile(MP.."/solar/minicell.lua")
dofile(MP.."/solar/solarcell.lua")
dofile(MP.."/solar/inverter.lua")
-- dofile(MP.."/solar/minicell.lua")
-- dofile(MP.."/solar/solarcell.lua")
-- dofile(MP.."/solar/inverter.lua")
-- Wind
dofile(MP.."/wind_turbine/rotor.lua")
dofile(MP.."/wind_turbine/pillar.lua")
dofile(MP.."/wind_turbine/signallamp.lua")
-- -- Wind
-- dofile(MP.."/wind_turbine/rotor.lua")
-- dofile(MP.."/wind_turbine/pillar.lua")
-- dofile(MP.."/wind_turbine/signallamp.lua")
-- TA4 Energy Storage
dofile(MP.."/energy_storage/heatexchanger.lua")
dofile(MP.."/energy_storage/generator.lua")
dofile(MP.."/energy_storage/turbine.lua")
dofile(MP.."/energy_storage/inlet.lua")
dofile(MP.."/energy_storage/nodes.lua")
-- -- TA4 Energy Storage
-- dofile(MP.."/energy_storage/heatexchanger.lua")
-- dofile(MP.."/energy_storage/generator.lua")
-- dofile(MP.."/energy_storage/turbine.lua")
-- dofile(MP.."/energy_storage/inlet.lua")
-- dofile(MP.."/energy_storage/nodes.lua")
-- Chemistry
dofile(MP.."/chemistry/ta4_reactor.lua")
dofile(MP.."/chemistry/ta4_stand.lua")
dofile(MP.."/chemistry/ta4_doser.lua")
-- -- Chemistry
-- dofile(MP.."/chemistry/ta4_reactor.lua")
-- dofile(MP.."/chemistry/ta4_stand.lua")
-- dofile(MP.."/chemistry/ta4_doser.lua")
-- Hydrogen
dofile(MP.."/hydrogen/hydrogen.lua")
dofile(MP.."/hydrogen/electrolyzer.lua")
dofile(MP.."/hydrogen/fuelcell.lua")
-- -- Hydrogen
-- dofile(MP.."/hydrogen/fuelcellstack.lua")
-- dofile(MP.."/hydrogen/electrolyzer.lua")
-- dofile(MP.."/hydrogen/fuelcell.lua")
-- dofile(MP.."/hydrogen/legacy.lua")
-- Items
dofile(MP.."/items/barrel.lua")
-- dofile(MP.."/items/barrel.lua")
dofile(MP.."/items/baborium.lua")
dofile(MP.."/items/usmium.lua")
dofile(MP.."/items/lye.lua")
dofile(MP.."/items/oil.lua")
dofile(MP.."/items/petroleum.lua")
dofile(MP.."/items/bauxit.lua")
dofile(MP.."/items/silicon.lua")
dofile(MP.."/items/steelmat.lua")
dofile(MP.."/items/powder.lua")
dofile(MP.."/items/epoxy.lua")
dofile(MP.."/items/aluminium.lua")
dofile(MP.."/items/plastic.lua")
-- dofile(MP.."/items/lye.lua")
-- dofile(MP.."/items/oil.lua")
-- dofile(MP.."/items/petroleum.lua")
-- dofile(MP.."/items/bauxit.lua")
-- dofile(MP.."/items/silicon.lua")
-- dofile(MP.."/items/steelmat.lua")
-- dofile(MP.."/items/powder.lua")
-- dofile(MP.."/items/epoxy.lua")
-- dofile(MP.."/items/aluminium.lua")
-- dofile(MP.."/items/plastic.lua")
-- dofile(MP.."/items/hydrogen.lua")
if techage.basalt_stone_enabled then
dofile(MP.."/items/basalt.lua")
end
end
-- if techage.basalt_stone_enabled then
-- dofile(MP.."/items/basalt.lua")
-- end
-- dofile(MP.."/power3/electric_cable.lua")
-- dofile(MP.."/power3/node_api.lua")
-- dofile(MP.."/power3/distribution.lua")
-- dofile(MP.."/power3/schedule.lua")
-- dofile(MP.."/power3/hud_debug.lua")
-- dofile(MP.."/power3/junctionbox.lua")
-- dofile(MP.."/power3/ele3_sink.lua")
-- dofile(MP.."/power3/ele3_source.lua")
-- dofile(MP.."/power3/accu.lua")
-- dofile(MP.."/power3/power_terminal.lua")
-- dofile(MP.."/power3/powerswitchbox.lua")
-- dofile(MP.."/power3/drive_axle.lua")
-- dofile(MP.."/power3/gearbox.lua")
-- dofile(MP.."/power3/axle_sink.lua")
-- dofile(MP.."/power3/axle_source.lua")
end

View File

@ -234,11 +234,15 @@ function techage.keep_running_burner(pos)
else
minetest.swap_node(pos, {name="techage:ash"})
remove_coal(pos, height)
local handle = meta:get_int("handle")
minetest.sound_stop(handle)
return false
end
else
minetest.swap_node(pos, {name="techage:ash"})
remove_coal(pos, height)
local handle = meta:get_int("handle")
minetest.sound_stop(handle)
return false
end
else

View File

@ -32,7 +32,7 @@ minetest.register_node("techage:lighter_burn", {
drop = "",
light_source = 10,
is_ground_content = false,
groups = {crumbly = 1, not_in_creative_inventory=1},
groups = {crumbly = 3, snappy = 3, oddly_breakable_by_hand = 1, not_in_creative_inventory=1},
sounds = default.node_sound_dirt_defaults(),
})
@ -56,7 +56,7 @@ minetest.register_node("techage:coal_lighter_burn", {
drop = "",
light_source = 10,
is_ground_content = false,
groups = {crumbly = 1, not_in_creative_inventory=1},
groups = {crumbly = 3, snappy = 3, oddly_breakable_by_hand = 1, not_in_creative_inventory=1},
sounds = default.node_sound_dirt_defaults(),
})
@ -75,7 +75,7 @@ minetest.register_node("techage:lighter", {
meta:set_string("playername", placer:get_player_name())
end,
is_ground_content = false,
groups = {crumbly = 1, flammable = 2},
groups = {crumbly = 3, snappy = 3, oddly_breakable_by_hand = 1, flammable = 2},
sounds = default.node_sound_dirt_defaults(),
})

View File

@ -40,7 +40,7 @@ minetest.register_ore({
clust_num_ores = 5,
clust_size = 3,
y_min = -340,
y_max = -260,
y_max = -250,
})
minetest.register_craft({

View File

@ -56,6 +56,16 @@ minetest.register_craftitem("techage:ta3_canister_empty", {
inventory_image = "techage_canister_filling.png^[colorize:#BFBFBF:180^techage_canister_frame.png",
})
minetest.register_craftitem("techage:ta3_cylinder_small", {
description = S("Gas Cylinder Small"),
inventory_image = "techage_gas_cylinder_small.png^[colorize:#4D7481:100",
})
minetest.register_craftitem("techage:ta3_cylinder_large", {
description = S("Gas Cylinder Large"),
inventory_image = "techage_gas_cylinder_large.png^[colorize:#4D7481:100",
})
minetest.register_craft({
output = 'techage:ta3_barrel_empty 6',
@ -75,6 +85,26 @@ minetest.register_craft({
}
})
minetest.register_craft({
output = 'techage:ta3_cylinder_small 8',
recipe = {
{'', 'techage:iron_ingot', ''},
{'techage:iron_ingot', '', 'techage:iron_ingot'},
{'techage:iron_ingot', 'techage:iron_ingot', 'techage:iron_ingot'},
}
})
minetest.register_craft({
output = 'techage:ta3_cylinder_large',
recipe = {
{'', 'techage:ta3_cylinder_small', ''},
{'', 'techage:ta3_cylinder_small', ''},
{'', 'techage:ta3_cylinder_small', ''},
}
})
techage.register_liquid("bucket:bucket_water", "bucket:bucket_empty", 1, "techage:water")
techage.register_liquid("bucket:bucket_river_water", "bucket:bucket_empty", 1, "techage:river_water")

View File

@ -33,6 +33,17 @@ minetest.register_node("techage:basalt_stone", {
sounds = default.node_sound_stone_defaults(),
})
stairs.register_stair_and_slab(
"basalt_stone",
"techage:basalt_stone",
{cracky = 3, stone = 1},
{"default_stone.png^[brighten"},
"Basalt Stone Stair",
"Basalt Stone Slab",
default.node_sound_stone_defaults(),
false
)
minetest.register_node("techage:basalt_cobble", {
description = S("Basalt Cobble"),
tiles = {"default_cobble.png^[brighten"},
@ -40,6 +51,17 @@ minetest.register_node("techage:basalt_cobble", {
sounds = default.node_sound_stone_defaults(),
})
stairs.register_stair_and_slab(
"basalt_cobble",
"techage:basalt_cobble",
{cracky = 3, stone = 2},
{"default_cobble.png^[brighten"},
"Basalt Cobble Stair",
"Basalt Cobble Slab",
default.node_sound_stone_defaults(),
false
)
minetest.register_node("techage:basalt_stone_brick", {
description = S("Basalt Stone Brick"),
paramtype2 = "facedir",
@ -50,6 +72,17 @@ minetest.register_node("techage:basalt_stone_brick", {
sounds = default.node_sound_stone_defaults(),
})
stairs.register_stair_and_slab(
"basalt_stone_brick",
"techage:basalt_stone_brick",
{cracky = 2, stone = 1},
{"default_stone_brick.png^[brighten"},
"Basalt Brick Stair",
"Basalt Brick Slab",
default.node_sound_stone_defaults(),
false
)
minetest.register_node("techage:basalt_stone_block", {
description = S("Basalt Stone Block"),
tiles = {"default_stone_block.png^[brighten"},
@ -58,6 +91,17 @@ minetest.register_node("techage:basalt_stone_block", {
sounds = default.node_sound_stone_defaults(),
})
stairs.register_stair_and_slab(
"basalt_stone_block",
"techage:basalt_stone_block",
{cracky = 2, stone = 1},
{"default_stone_block.png^[brighten"},
"Basalt Stone Block Stair",
"Basalt Stone Block Slab",
default.node_sound_stone_defaults(),
false
)
minetest.register_node("techage:basalt_gravel", {
description = S("Basalt Gravel"),
tiles = {"default_gravel.png^[brighten"},
@ -65,6 +109,17 @@ minetest.register_node("techage:basalt_gravel", {
sounds = default.node_sound_gravel_defaults(),
})
stairs.register_stair_and_slab(
"sieved_basalt_gravel",
"techage:sieved_basalt_gravel",
{crumbly = 2, falling_node = 1},
{"default_gravel.png^[brighten"},
"Basalt Gravel Stair",
"Basalt Gravel Slab",
default.node_sound_gravel_defaults(),
false
)
minetest.register_node("techage:sieved_basalt_gravel", {
description = S("Sieved Basalt Gravel"),
tiles = {"default_gravel.png^[brighten"},
@ -85,6 +140,17 @@ minetest.register_node("techage:basalt_glass", {
sounds = default.node_sound_glass_defaults(),
})
stairs.register_stair_and_slab(
"basalt_glass",
"techage:basalt_glass",
{cracky = 3, oddly_breakable_by_hand = 3},
{"techage_basalt_glass.png"},
"Basalt Glass Stair",
"Basalt Glass Slab",
default.node_sound_glass_defaults(),
false
)
minetest.register_node("techage:basalt_glass2", {
description = S("Basalt Glass 2"),
drawtype = "glasslike_framed_optional",
@ -98,6 +164,17 @@ minetest.register_node("techage:basalt_glass2", {
sounds = default.node_sound_glass_defaults(),
})
stairs.register_stair_and_slab(
"basalt_glass2",
"techage:basalt_glass2",
{cracky = 3, oddly_breakable_by_hand = 3},
{"techage_basalt_glass2.png"},
"Basalt Glass 2 Stair",
"Basalt Glass 2 Slab",
default.node_sound_glass_defaults(),
false
)
minetest.register_node("techage:basalt_glass_thin", {
description = S("Basalt Glass Thin"),
drawtype = "nodebox",
@ -174,50 +251,6 @@ minetest.register_node("techage:basalt_glass_thin_xl2", {
sounds = default.node_sound_glass_defaults(),
})
stairs.register_stair_and_slab(
"basalt_stone",
"techage:basalt_stone",
{cracky = 3, stone = 1},
{"default_stone.png^[brighten"},
"Basalt Stone Stair",
"Basalt Stone Slab",
default.node_sound_stone_defaults(),
false
)
stairs.register_stair_and_slab(
"basalt_stone_brick",
"techage:basalt_stone_brick",
{cracky = 2, stone = 1},
{"default_stone_brick.png^[brighten"},
"Basalt Brick Stair",
"Basalt Brick Slab",
default.node_sound_stone_defaults(),
false
)
stairs.register_stair_and_slab(
"basalt_stone_block",
"techage:basalt_stone_block",
{cracky = 2, stone = 1},
{"default_stone_block.png^[brighten"},
"Basalt Block Stair",
"Basalt Block Slab",
default.node_sound_stone_defaults(),
false
)
stairs.register_stair_and_slab(
"sieved_basalt_gravel",
"techage:sieved_basalt_gravel",
{crumbly = 2, falling_node = 1},
{"default_gravel.png^[brighten"},
"Basalt Gravel Stair",
"Basalt Gravel Slab",
default.node_sound_gravel_defaults(),
false
)
minetest.register_craft({
output = "techage:basalt_stone_brick 4",
recipe = {

View File

@ -38,9 +38,19 @@ minetest.register_craftitem("techage:gasoline", {
minetest.register_craftitem("techage:gas", {
description = S("TA3 Gas"),
inventory_image = "techage_gas_inv.png",
groups = {not_in_creative_inventory=1},
})
minetest.register_craftitem("techage:ta3_cylinder_small_gas", {
description = S("Gas Cylinder Small"),
inventory_image = "techage_gas_cylinder_small.png^[colorize:#e51818:120",
stack_max = 1,
})
minetest.register_craftitem("techage:ta3_cylinder_large_gas", {
description = S("Gas Cylinder Large"),
inventory_image = "techage_gas_cylinder_large.png^[colorize:#e51818:120",
stack_max = 1,
})
minetest.register_craftitem("techage:ta3_barrel_bitumen", {
description = S("TA3 Bitumen Barrel"),
@ -122,10 +132,12 @@ techage.register_liquid("techage:ta3_barrel_bitumen", "techage:ta3_barrel_empty"
techage.register_liquid("techage:ta3_barrel_fueloil", "techage:ta3_barrel_empty", 10, "techage:fueloil")
techage.register_liquid("techage:ta3_barrel_naphtha", "techage:ta3_barrel_empty", 10, "techage:naphtha")
techage.register_liquid("techage:ta3_barrel_gasoline", "techage:ta3_barrel_empty", 10, "techage:gasoline")
techage.register_liquid("techage:ta3_cylinder_large_gas", "techage:ta3_cylinder_large", 6, "techage:gas")
techage.register_liquid("techage:ta3_canister_oil", "techage:ta3_canister_empty", 1, "techage:oil_source")
techage.register_liquid("techage:ta3_canister_bitumen", "techage:ta3_canister_empty", 1, "techage:bitumen")
techage.register_liquid("techage:ta3_canister_fueloil", "techage:ta3_canister_empty", 1, "techage:fueloil")
techage.register_liquid("techage:ta3_canister_naphtha", "techage:ta3_canister_empty", 1, "techage:naphtha")
techage.register_liquid("techage:ta3_canister_gasoline", "techage:ta3_canister_empty", 1, "techage:gasoline")
techage.register_liquid("techage:ta3_cylinder_small_gas", "techage:ta3_cylinder_small", 1, "techage:gas")

View File

@ -89,10 +89,10 @@ end
local function get_network_table(pos, outdir, ntype)
local netID = get_netID(pos, outdir)
if netID then
local netw = networks.get_network(netID, Pipe)
local netw = networks.get_network("pipe", netID)
if not netw then
netw = networks.collect_network_nodes(pos, outdir, Pipe)
networks.set_network(netID, Pipe, netw)
networks.set_network("pipe", netID, netw)
end
local s = minetest.pos_to_string(minetest.get_position_from_hash(netID))
--print("netw", string.format("%012X", netID), s, dump(netw))

View File

@ -16,93 +16,22 @@ local S2P = minetest.string_to_pos
local P2S = minetest.pos_to_string
local M = minetest.get_meta
local S = techage.S
local LQD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).liquid end
local Pipe = techage.LiquidPipe
local liquid = techage.liquid
local CAPACITY = 500
local function formspec_tank(x, y, mem)
local itemname = "techage:liquid"
if mem.liquid and mem.liquid.amount and mem.liquid.amount > 0 and mem.liquid.name then
itemname = mem.liquid.name.." "..mem.liquid.amount
end
return "container["..x..","..y.."]"..
"background[0,0;3,2.05;techage_form_grey.png]"..
"image[0,0;1,1;techage_form_input_arrow.png]"..
techage.item_image(1, 0, itemname)..
"image[2,0;1,1;techage_form_output_arrow.png]"..
"image[1,1;1,1;techage_form_arrow.png]"..
"list[context;src;0,1;1,1;]"..
"list[context;dst;2,1;1,1;]"..
--"listring[]"..
"container_end[]"
end
local function formspec(mem)
local function formspec(pos, mem)
local update = ((mem.countdown or 0) > 0 and mem.countdown) or S("Update")
return "size[8,6]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
formspec_tank(2, 0, mem)..
liquid.formspec_liquid(2, 0, mem)..
"button[5.5,0.5;2,1;update;"..update.."]"..
"list[current_player;main;0,2.3;8,4;]"
end
local function fill_container(pos, inv)
local mem = tubelib2.get_mem(pos)
mem.liquid = mem.liquid or {}
mem.liquid.amount = mem.liquid.amount or 0
local empty_container = inv:get_stack("src", 1):get_name()
local full_container = liquid.get_full_container(empty_container, mem.liquid.name)
if empty_container and full_container then
local ldef = liquid.get_liquid_def(full_container)
if ldef and mem.liquid.amount - ldef.size >= 0 then
if inv:room_for_item("dst", ItemStack(full_container)) then
inv:remove_item("src", ItemStack(empty_container))
inv:add_item("dst", ItemStack(full_container))
mem.liquid.amount = mem.liquid.amount - ldef.size
if mem.liquid.amount == 0 then
mem.liquid.name = nil
end
end
end
end
end
local function empty_container(pos, inv)
local mem = tubelib2.get_mem(pos)
mem.liquid = mem.liquid or {}
mem.liquid.amount = mem.liquid.amount or 0
local stack = inv:get_stack("src", 1)
local ldef = liquid.get_liquid_def(stack:get_name())
if ldef and (not mem.liquid.name or ldef.inv_item == mem.liquid.name) then
local capa = LQD(pos).capa
local amount = stack:get_count() * ldef.size
if mem.liquid.amount + amount <= capa then
if inv:room_for_item("dst", ItemStack(ldef.container)) then
inv:remove_item("src", stack)
inv:add_item("dst", ItemStack(ldef.container))
mem.liquid.amount = mem.liquid.amount + amount
mem.liquid.name = ldef.inv_item
end
end
end
end
local function move_item(pos, stack)
local mem = tubelib2.get_mem(pos)
local inv = M(pos):get_inventory()
if liquid.is_container_empty(stack:get_name()) then
fill_container(pos, inv)
else
empty_container(pos, inv)
end
M(pos):set_string("formspec", formspec(mem))
end
local function allow_metadata_inventory_put(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
@ -122,13 +51,13 @@ local function allow_metadata_inventory_move()
end
local function on_metadata_inventory_put(pos, listname, index, stack, player)
minetest.after(0.5, move_item, pos, stack)
minetest.after(0.5, liquid.move_item, pos, stack, CAPACITY, formspec)
end
local function on_rightclick(pos)
local mem = tubelib2.get_mem(pos)
mem.countdown = 10
M(pos):set_string("formspec", formspec(mem))
M(pos):set_string("formspec", formspec(pos, mem))
minetest.get_node_timer(pos):start(2)
end
@ -138,7 +67,7 @@ local function on_receive_fields(pos, formname, fields, player)
end
local mem = tubelib2.get_mem(pos)
mem.countdown = 10
M(pos):set_string("formspec", formspec(mem))
M(pos):set_string("formspec", formspec(pos, mem))
minetest.get_node_timer(pos):start(2)
end
@ -146,9 +75,7 @@ local function can_dig(pos, player)
if minetest.is_protected(pos, player:get_player_name()) then
return false
end
local mem = tubelib2.get_mem(pos)
local inv = minetest.get_meta(pos):get_inventory()
return inv:is_empty("src") and inv:is_empty("dst") and (not mem.liquid or (mem.liquid.amount or 0) == 0)
return liquid.is_empty(pos)
end
@ -176,7 +103,7 @@ minetest.register_node("techage:ta3_tank", {
local number = techage.add_node(pos, "techage:ta3_tank")
meta:set_string("node_number", number)
meta:set_string("owner", placer:get_player_name())
meta:set_string("formspec", formspec(mem))
meta:set_string("formspec", formspec(pos, mem))
meta:set_string("infotext", S("TA3 Tank").." "..number)
Pipe:after_place_node(pos)
end,
@ -187,7 +114,7 @@ minetest.register_node("techage:ta3_tank", {
local mem = tubelib2.get_mem(pos)
if mem.countdown then
mem.countdown = mem.countdown - 1
M(pos):set_string("formspec", formspec(mem))
M(pos):set_string("formspec", formspec(pos, mem))
return mem.countdown > 0
end
end,
@ -202,7 +129,7 @@ minetest.register_node("techage:ta3_tank", {
local leftover = liquid.srv_put(pos, indir, name, amount)
local inv = M(pos):get_inventory()
if not inv:is_empty("src") and inv:is_empty("dst") then
fill_container(pos, inv)
liquid.fill_container(pos, inv)
end
return leftover
end,
@ -263,7 +190,7 @@ minetest.register_node("techage:oiltank", {
local number = techage.add_node(pos, "techage:oiltank")
meta:set_string("node_number", number)
meta:set_string("owner", placer:get_player_name())
meta:set_string("formspec", formspec(mem))
meta:set_string("formspec", formspec(pos, mem))
meta:set_string("infotext", S("Oil Tank").." "..number)
Pipe:after_place_node(pos)
end,
@ -274,7 +201,7 @@ minetest.register_node("techage:oiltank", {
local mem = tubelib2.get_mem(pos)
if mem.countdown then
mem.countdown = mem.countdown - 1
M(pos):set_string("formspec", formspec(mem))
M(pos):set_string("formspec", formspec(pos, mem))
return mem.countdown > 0
end
end,
@ -289,7 +216,7 @@ minetest.register_node("techage:oiltank", {
local leftover = liquid.srv_put(pos, indir, name, amount)
local inv = M(pos):get_inventory()
if not inv:is_empty("src") and inv:is_empty("dst") then
fill_container(pos, inv)
liquid.fill_container(pos, inv)
end
return leftover
end,
@ -340,7 +267,7 @@ minetest.register_node("techage:ta4_tank", {
local number = techage.add_node(pos, "techage:ta4_tank")
meta:set_string("node_number", number)
meta:set_string("owner", placer:get_player_name())
meta:set_string("formspec", formspec(mem))
meta:set_string("formspec", formspec(pos, mem))
meta:set_string("infotext", S("TA4 Tank").." "..number)
Pipe:after_place_node(pos)
end,
@ -351,7 +278,7 @@ minetest.register_node("techage:ta4_tank", {
local mem = tubelib2.get_mem(pos)
if mem.countdown then
mem.countdown = mem.countdown - 1
M(pos):set_string("formspec", formspec(mem))
M(pos):set_string("formspec", formspec(pos, mem))
return mem.countdown > 0
end
end,
@ -366,7 +293,7 @@ minetest.register_node("techage:ta4_tank", {
local leftover = liquid.srv_put(pos, indir, name, amount)
local inv = M(pos):get_inventory()
if not inv:is_empty("src") and inv:is_empty("dst") then
fill_container(pos, inv)
liquid.fill_container(pos, inv)
end
return leftover
end,
@ -392,45 +319,7 @@ minetest.register_node("techage:ta4_tank", {
sounds = default.node_sound_metal_defaults(),
})
techage.register_node({"techage:ta3_tank", "techage:ta4_tank", "techage:oiltank"}, {
on_pull_item = function(pos, in_dir, num)
local inv = M(pos):get_inventory()
if not inv:is_empty("dst") then
local taken = techage.get_items(inv, "dst", num)
if not inv:is_empty("src") then
fill_container(pos, inv)
end
return taken
end
end,
on_push_item = function(pos, in_dir, stack)
local inv = M(pos):get_inventory()
if inv:room_for_item("src", stack) then
inv:add_item("src", stack)
if liquid.is_container_empty(stack:get_name()) then
fill_container(pos, inv)
else
empty_container(pos, inv)
end
return true
end
return false
end,
on_unpull_item = function(pos, in_dir, stack)
local meta = M(pos)
local inv = meta:get_inventory()
return techage.put_items(inv, "dst", stack)
end,
on_recv_message = function(pos, src, topic, payload)
if topic == "state" then
local meta = M(pos)
local inv = meta:get_inventory()
return techage.get_inv_state(inv, "main")
else
return "unsupported"
end
end,
})
techage.register_node({"techage:ta3_tank", "techage:ta4_tank", "techage:oiltank"}, liquid.tubing)
Pipe:add_secondary_node_names({"techage:ta3_tank", "techage:ta4_tank", "techage:oiltank"})

View File

@ -21,7 +21,7 @@ Bei allen Blöcken beim Setzen immer auch die Ausrichtung achten:
Der Boiler muss mit Wasser gefüllt werden. Dazu bis zu 10 Eimer Wasser in den Boiler füllen.
Die Feuerbox muss mit Kohle oder Holzkohle gefüllt werden.
Wenn das Wasser heiß ist, kann das Ventil am Boiler geöffnet und anschließend die Dampfmaschine am Schwungrad gestartet werden.
Wenn das Wasser heiß ist (Temperaturanzeige ganz oben), kann die Dampfmaschine am Schwungrad gestartet werden.
Die Dampfmaschine leistet 25 ku, kann damit mehrere Maschinen gleichzeitig antreiben.
@ -39,7 +39,7 @@ Die Feuerbox muss mit Kohle oder Holzkohle gefüllt werden. Die Brenndauer ist a
### TA2 Boiler
Teil der Dampfmaschine. Muss mit Wasser gefüllt werden. Wem kein Wasser mehr vorhanden ist oder die Temperatur zu weit absinkt, schaltet sich der Boiler ab.
Teil der Dampfmaschine. Muss mit Wasser gefüllt werden. Wem kein Wasser mehr vorhanden ist oder die Temperatur zu weit absinkt, schaltet sich die Dampfmaschine ab.
[ta2_boiler|image]

View File

@ -1,549 +0,0 @@
minetest.register_node("techage:block1", {
description = "block1",
tiles = {"techage_filling_ta2.png^techage_frame_ta2.png"},
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2},
is_ground_content = false,
--sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("techage:block2", {
description = "block2",
tiles = {"techage_filling_ta3.png^techage_frame_ta3.png"},
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2},
is_ground_content = false,
--sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("techage:block3", {
description = "block3",
tiles = {
"techage_top_ta4.png",
"techage_filling_ta4.png^techage_frame_ta4.png",
},
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2},
is_ground_content = false,
--sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("techage:block4", {
description = "block4",
tiles = {
-- up, down, right, left, back, front
'techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_arrow.png',
'techage_filling_ta2.png^techage_frame_ta2.png',
'techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_outp.png',
'techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_inp.png',
{
image = "techage_pusher14.png^[transformR180]^techage_frame14_ta2.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 2.0,
},
},
{
image = "techage_pusher14.png^techage_frame14_ta2.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 2.0,
},
},
},
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2},
is_ground_content = false,
--sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("techage:block5", {
description = "block5",
tiles = {
-- up, down, right, left, back, front
'techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_arrow.png',
'techage_filling_ta3.png^techage_frame_ta3.png',
'techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_outp.png',
'techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_inp.png',
{
image = "techage_pusher14.png^[transformR180]^techage_frame14_ta3.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 2.0,
},
},
{
image = "techage_pusher14.png^techage_frame14_ta3.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 2.0,
},
},
},
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2},
is_ground_content = false,
--sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("techage:block6", {
description = "block6",
tiles = {
-- up, down, right, left, back, front
'techage_filling_ta4.png^techage_top_ta4.png^techage_appl_arrow.png',
'techage_filling_ta4.png^techage_frame_ta4.png',
'techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_outp.png',
'techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_inp.png',
{
image = "tubelib_pusher.png^[transformR180]^techage_frame14_ta4.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 2.0,
},
},
{
image = "tubelib_pusher.png^techage_frame14_ta4.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 2.0,
},
},
},
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2},
is_ground_content = false,
--sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("techage:block7", {
description = "block7",
tiles = {
-- up, down, right, left, back, front
"techage_filling_ta2.png^techage_frame_ta2.png",
"techage_filling_ta2.png^techage_frame_ta2.png",
"techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_chest_back_ta3.png",
"techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_chest_back_ta3.png",
"techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_chest_back_ta3.png",
"techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_chest_front_ta3.png",
},
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2},
is_ground_content = false,
--sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("techage:block8", {
description = "block8",
tiles = {
-- up, down, right, left, back, front
"techage_filling_ta3.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_chest_back_ta3.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_chest_back_ta3.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_chest_back_ta3.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_chest_front_ta3.png",
},
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2},
is_ground_content = false,
--sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("techage:block9", {
description = "block9",
tiles = {
-- up, down, right, left, back, front
"techage_filling_ta4.png^techage_top_ta4.png",
"techage_filling_ta4.png^techage_frame_ta4.png",
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_chest_back_ta4.png",
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_chest_back_ta4.png",
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_chest_back_ta4.png",
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_chest_front_ta4.png",
},
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2},
is_ground_content = false,
--sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("techage:sieve", {
description = "sieve",
drawtype = "nodebox",
tiles = {
-- up, down, right, left, back, front
'techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_inp.png',
'techage_filling_ta2.png^techage_frame_ta2.png',
'techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_outp.png',
'techage_filling_ta2.png^techage_frame_ta2.png',
{
image = "techage_filling4_ta2.png^techage_appl_sieve4.png^techage_frame4_ta2.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 2,
},
},
{
image = "techage_filling4_ta2.png^techage_appl_sieve4.png^techage_frame4_ta2.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 2,
},
},
},
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2},
is_ground_content = false,
--sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("techage:sieve2", {
description = "sieve",
drawtype = "nodebox",
tiles = {
-- up, down, right, left, back, front
'techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_inp.png',
'techage_filling_ta3.png^techage_frame_ta3.png',
'techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_outp.png',
'techage_filling_ta3.png^techage_frame_ta3.png',
{
image = "techage_filling4_ta3.png^techage_appl_sieve4.png^techage_frame4_ta3.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 2,
},
},
{
image = "techage_filling4_ta3.png^techage_appl_sieve4.png^techage_frame4_ta3.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 2,
},
},
},
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2},
is_ground_content = false,
--sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("techage:sieve3", {
description = "sieve",
drawtype = "nodebox",
tiles = {
-- up, down, right, left, back, front
'techage_filling_ta4.png^techage_top_ta4.png^techage_appl_inp.png',
'techage_filling_ta4.png^techage_frame_ta4.png',
'techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_outp.png',
'techage_filling_ta4.png^techage_frame_ta4.png',
{
image = "techage_filling4_ta4.png^techage_appl_sieve4.png^techage_frame4_ta4.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 2,
},
},
{
image = "techage_filling4_ta4.png^techage_appl_sieve4.png^techage_frame4_ta4.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 2,
},
},
},
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2},
is_ground_content = false,
--sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("techage:filler", {
description = "filler",
tiles = {
-- up, down, right, left, back, front
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_arrow.png",
"techage_filling_ta3.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_hole2.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_inp.png",
--"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_filler.png",
--"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_filler.png",
{
image = "techage_filling4_ta3.png^techage_appl_filler4.png^techage_frame4_ta3.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 2.0,
},
},
{
image = "techage_filling4_ta3.png^techage_appl_filler4.png^techage_frame4_ta3.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 2.0,
},
},
},
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2},
is_ground_content = false,
--sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("techage:compressor", {
description = "compressor",
tiles = {
-- up, down, right, left, back, front
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_arrow.png",
"techage_filling_ta3.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_hole2.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_hole2.png",
--"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_compressor.png",
--"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_compressor.png^[transformFX]",
{
image = "techage_filling4_ta3.png^techage_appl_compressor4.png^techage_frame4_ta3.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 0.2,
},
},
{
image = "techage_filling4_ta3.png^techage_appl_compressor4.png^[transformFX]^techage_frame4_ta3.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 0.2,
},
},
},
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2},
is_ground_content = false,
--sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("techage:fermenter", {
description = "fermenter",
tiles = {"techage_fermenter.png"},
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2},
is_ground_content = false,
--sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("techage:fermenter_foil", {
description = "fermenter_foil",
tiles = {"techage_fermenter_foil.png"},
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2},
is_ground_content = false,
--sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("techage:biomass", {
description = "biomass",
drawtype = "liquid",
tiles = {
{
name = "techage_biomass.png",
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 4.0,
},
},
},
special_tiles = {
-- New-style water source material (mostly unused)
{
name = "techage_biomass.png",
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 4.0,
},
backface_culling = false,
},
},
on_timer = function(pos)
minetest.remove_node(pos)
return false
end,
after_place_node = function(pos, placer)
minetest.get_node_timer(pos):start(5)
end,
--alpha = 160,
paramtype = "light",
walkable = false,
pointable = false,
diggable = false,
buildable_to = true,
is_ground_content = false,
drop = "",
drowning = 1,
liquidtype = "source",
liquid_alternative_flowing = "techage:biomass_flowing",
liquid_alternative_source = "techage:biomass",
liquid_viscosity = 1,
post_effect_color = {a = 103, r = 30, g = 60, b = 90},
groups = {water = 3, liquid = 3, puts_out_fire = 1, cools_lava = 1},
sounds = default.node_sound_water_defaults(),
})
minetest.register_node("techage:biomass_flowing", {
description = "biomass",
drawtype = "flowingliquid",
tiles = {"default_water.png"},
special_tiles = {
{
name = "techage_biomass.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 4,
},
},
{
name = "techage_biomass.png",
backface_culling = true,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 4,
},
},
},
--alpha = 220,
paramtype = "light",
paramtype2 = "flowingliquid",
walkable = false,
pointable = false,
diggable = false,
buildable_to = true,
is_ground_content = false,
drop = "",
drowning = 1,
liquidtype = "flowing",
liquid_alternative_flowing = "techage:biomass_flowing",
liquid_alternative_source = "techage:biomass",
liquid_viscosity = 1,
post_effect_color = {a = 103, r = 30, g = 60, b = 90},
groups = {water = 3, liquid = 3, puts_out_fire = 1,
not_in_creative_inventory = 0, cools_lava = 1},
sounds = default.node_sound_water_defaults(),
})

View File

@ -104,7 +104,7 @@ local function start_flarestack(pos, playername)
max_hear_distance = 20,
gain = 1,
loop = true})
print("handle", handle)
--print("handle", handle)
meta:set_int("handle", handle)
end
@ -140,7 +140,7 @@ minetest.register_node("techage:gasflare", {
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
print(dump(oldmetadata))
--print(dump(oldmetadata))
stop_flarestack(pos, oldmetadata.fields.handle)
local node = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z})
if node.name == "techage:gasflare2" then

View File

@ -1,280 +0,0 @@
--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
TA3 Tiny Oil Power Generator
]]--
-- for lazy programmers
local M = minetest.get_meta
local S = techage.S
local Power = techage.ElectricCable
local firebox = techage.firebox
local power = techage.power
local fuel = techage.fuel
local Pipe = techage.LiquidPipe
local liquid = techage.liquid
local CYCLE_TIME = 2
local PWR_CAPA = 12
local EFFICIENCY = 2.5
local function formspec(self, pos, mem)
local fuel_percent = 0
if mem.running then
fuel_percent = ((mem.burn_cycles or 1) * 100) / (mem.burn_cycles_total or 1)
end
return "size[8,6]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
fuel.formspec_fuel(1, 0, mem)..
"button[1.6,1;1.8,1;update;"..S("Update").."]"..
"image_button[5.5,0.5;1,1;".. self:get_state_button_image(mem) ..";state_button;]"..
"image[6.5,0;1,2;"..power.formspec_power_bar(PWR_CAPA, mem.provided).."]"..
"list[current_player;main;0,2.3;8,4;]"..
default.get_hotbar_bg(0, 3)
end
local function can_start(pos, mem, state)
if mem.burn_cycles > 0 or (mem.liquid and mem.liquid.amount and mem.liquid.amount > 0) then
return true
end
return false
end
local function start_node(pos, mem, state)
mem.running = true
power.generator_start(pos, mem, PWR_CAPA)
minetest.sound_play("techage_generator", {
pos = pos,
gain = 1,
max_hear_distance = 10})
end
local function stop_node(pos, mem, state)
mem.running = false
mem.provided = 0
power.generator_stop(pos, mem)
end
local State = techage.NodeStates:new({
node_name_passive = "techage:tiny_generator",
node_name_active = "techage:tiny_generator_on",
cycle_time = CYCLE_TIME,
standby_ticks = 0,
formspec_func = formspec,
infotext_name = "TA3 Tiny Power Generator",
can_start = can_start,
start_node = start_node,
stop_node = stop_node,
})
local function burning(pos, mem)
local ratio = math.max((mem.provided or PWR_CAPA) / PWR_CAPA, 0.02)
mem.liquid = mem.liquid or {}
mem.liquid.amount = mem.liquid.amount or 0
mem.burn_cycles = (mem.burn_cycles or 0) - ratio
if mem.burn_cycles <= 0 then
if mem.liquid.amount > 0 then
mem.liquid.amount = mem.liquid.amount - 1
mem.burn_cycles = fuel.burntime(mem.liquid.name) * EFFICIENCY / CYCLE_TIME
mem.burn_cycles_total = mem.burn_cycles
return true
else
mem.liquid.name = nil
State:fault(pos, mem)
return false
end
else
return true
end
end
local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos)
if mem.running and burning(pos, mem) then
mem.provided = power.generator_alive(pos, mem)
minetest.sound_play("techage_generator", {
pos = pos,
gain = 1,
max_hear_distance = 10})
return true
else
mem.provided = 0
end
return false
end
local function on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then
return
end
local mem = tubelib2.get_mem(pos)
State:state_button_event(pos, mem, fields)
M(pos):set_string("formspec", formspec(State, pos, mem))
end
local function formspec_clbk(pos, mem)
return formspec(State, pos, mem)
end
local function on_metadata_inventory_put(pos, listname, index, stack, player)
minetest.after(0.5, fuel.move_item, pos, stack, formspec_clbk)
end
local function on_rightclick(pos)
local mem = tubelib2.get_mem(pos)
M(pos):set_string("formspec", formspec(State, pos, mem))
end
local _liquid = {
fuel_cat = fuel.BT_NAPHTHA,
capa = fuel.CAPACITY,
peek = liquid.srv_peek,
put = function(pos, indir, name, amount)
if fuel.valid_fuel(name, fuel.BT_NAPHTHA) then
return liquid.srv_put(pos, indir, name, amount)
end
return amount
end,
take = liquid.srv_take,
}
local _networks = {
pipe = {
sides = techage.networks.AllSides, -- Pipe connection sides
ntype = "tank",
},
}
minetest.register_node("techage:tiny_generator", {
description = S("TA3 Tiny Power Generator"),
tiles = {
-- up, down, right, left, back, front
"techage_appl_electric_gen_top.png^techage_frame_ta3_top.png",
"techage_appl_electric_gen_top.png^techage_frame_ta3.png",
"techage_appl_electric_gen_side.png^techage_appl_hole_electric.png^techage_frame_ta3.png",
"techage_appl_electric_gen_side.png^techage_frame_ta3.png",
"techage_appl_electric_gen_front.png^[transformFX]^techage_frame_ta3.png",
"techage_appl_electric_gen_front.png^techage_frame_ta3.png",
},
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2},
on_rotate = screwdriver.disallow,
is_ground_content = false,
on_construct = function(pos)
local mem = tubelib2.init_mem(pos)
local number = techage.add_node(pos, "techage:tiny_generator")
mem.running = false
mem.burn_cycles = 0
State:node_init(pos, mem, number)
local meta = M(pos)
meta:set_string("formspec", formspec(State, pos, mem))
local inv = meta:get_inventory()
inv:set_size('fuel', 1)
end,
allow_metadata_inventory_put = fuel.allow_metadata_inventory_put,
allow_metadata_inventory_take = fuel.allow_metadata_inventory_take,
on_metadata_inventory_put = on_metadata_inventory_put,
on_receive_fields = on_receive_fields,
on_rightclick = on_rightclick,
on_timer = node_timer,
can_dig = fuel.can_dig,
liquid = _liquid,
networks = _networks,
})
minetest.register_node("techage:tiny_generator_on", {
description = S("TA3 Tiny Power Generator"),
tiles = {
-- up, down, right, left, back, front
"techage_appl_electric_gen_top.png^techage_frame_ta3_top.png",
"techage_appl_electric_gen_top.png^techage_frame_ta3.png",
"techage_appl_electric_gen_side.png^techage_appl_hole_electric.png^techage_frame_ta3.png",
"techage_appl_electric_gen_side.png^techage_frame_ta3.png",
{
image = "techage_appl_electric_gen_front4.png^[transformFX]^techage_frame4_ta3.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 0.8,
},
},
{
image = "techage_appl_electric_gen_front4.png^techage_frame4_ta3.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 0.8,
},
},
},
paramtype = "light",
paramtype2 = "facedir",
groups = {not_in_creative_inventory=1},
diggable = false,
light_source = 4,
on_rotate = screwdriver.disallow,
is_ground_content = false,
allow_metadata_inventory_put = fuel.allow_metadata_inventory_put,
allow_metadata_inventory_take = fuel.allow_metadata_inventory_take,
on_metadata_inventory_put = on_metadata_inventory_put,
on_receive_fields = on_receive_fields,
on_rightclick = on_rightclick,
on_timer = node_timer,
can_dig = fuel.can_dig,
liquid = _liquid,
networks = _networks,
})
Pipe:add_secondary_node_names({"techage:tiny_generator", "techage:tiny_generator_on"})
techage.power.register_node({"techage:tiny_generator", "techage:tiny_generator_on"}, {
conn_sides = {"R"},
power_network = Power,
})
techage.register_node({"techage:tiny_generator", "techage:tiny_generator_on"}, {
on_recv_message = function(pos, src, topic, payload)
local mem = tubelib2.get_mem(pos)
if topic == "load" then
return power.percent(PWR_CAPA, mem.provided)
else
return State:on_receive_message(pos, topic, payload)
end
end,
on_node_load = function(pos)
State:on_node_load(pos)
end,
})
minetest.register_craft({
output = "techage:tiny_generator",
recipe = {
{'default:steel_ingot', 'techage:usmium_nuggets', 'default:steel_ingot'},
{'dye:red', 'basic_materials:gear_steel', 'techage:electric_cableS'},
{'default:steel_ingot', 'techage:vacuum_tube', 'default:steel_ingot'},
},
})

View File

@ -1,65 +0,0 @@
# Power Distribution API
The module power supports 3 kinds of devices:
- Generators: Provide power, can be turned on/off
- Consumers: Need power, like machines or lamps, can be turned on/off
- Akkus: Can provide stored power, combination of generator and consumer
### Possible connection sides
```
U(p) B(ack)
| /
| /
+--|-----+
/ o /|
+--------+ |
L(eft) ----| |o---- R(ight)
| o | +
| / |/
+--/-----+
/ |
F(ront) |
|
D(own)
```
All 3 kinds of nodes use the same registration function to enrich the nodes functionality for power distribution.
techage.power.register_nodes(names, definition)
-- names is a list of node names
-- definition is a table according to:
{
conn_sides = <list>, -- allowed connection sides for power cables
-- one or several of {"L", "R", "U", "D", "F", "B"}
power_network = <tubelib2-instance>,
}
tbd..........
techage.power.power_distribution(pos)
-- Trigger the recalculation or the power distribution in case of
-- a turn on/off request
techage.power.formspec_power_bar(max_power, current_power)
-- returns the formspec PGN with a bar according the the ratio `current_power/max_power`
techage.power.formspec_load_bar(charging)
-- returns the formspec PGN with the charging/uncharging symbol
-- charging can be:
-- true => charging
-- false => uncharging
-- nil => turned off
### Internas
The function `techage.power.register_nodes`:
- adds a wrapper to `after_place_node` (needed to maintain tubelib2 data base)
- adds a wrapper to `after_dig_node` (needed to maintain tubelib2 data base)
- adds the function `after_tube_update` (needed to maintain tubelib2 data base)
- adds the table `power` to the node definition with the provided attributes
- adds `power_dirs` to the node meta table with the `conn_sides` information converted to node specific dirs
- adds `mem.connections` for the available power connections with consideration of valid `power_dirs`

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -33,11 +33,6 @@ local Axle = tubelib2.Tube:new({
end,
})
Axle:register_on_tube_update(function(node, pos, out_dir, peer_pos, peer_in_dir)
minetest.registered_nodes[node.name].after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir)
end)
techage.Axle = Axle
minetest.register_node("techage:axle", {
description = S("TA2 Drive Axle"),
@ -182,17 +177,4 @@ minetest.register_craft({
})
-- Axles PNG animation
function techage.switch_axles(pos, on)
local s = M(pos):get_string("power_dirs")
if s ~= "" then
for _,indir in ipairs(minetest.deserialize(s)) do
local out_dir = tubelib2.Turn180Deg[indir]
if on then
Axle:switch_tube_line(pos, out_dir, "on")
else
Axle:switch_tube_line(pos, out_dir, "off")
end
end
end
end
techage.Axle = Axle

View File

@ -3,12 +3,12 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
TA3/TA4 Cable for electrical power distribution
TA3 Electric Cables (AC)
]]--
@ -18,13 +18,16 @@ local P2S = minetest.pos_to_string
local M = minetest.get_meta
local S = techage.S
local ELE1_MAX_CABLE_LENGHT = 1000
local Cable = tubelib2.Tube:new({
dirs_to_check = {1,2,3,4,5,6},
max_tube_length = 1000,
max_tube_length = ELE1_MAX_CABLE_LENGHT,
show_infotext = false,
tube_type = "electric_cable",
primary_node_names = {"techage:electric_cableS", "techage:electric_cableA",
"techage:power_line", "techage:power_lineS", "techage:power_lineA", "techage:power_pole2"},
tube_type = "ele1",
primary_node_names = {"techage:electric_cableS", "techage:electric_cableA",
"techage:power_line", "techage:power_lineS", "techage:power_lineA",
"techage:power_pole2"},
secondary_node_names = {},
after_place_tube = function(pos, param2, tube_type, num_tubes)
-- Handle "power line" nodes
@ -154,14 +157,6 @@ minetest.register_node("techage:electric_cableA", {
drop = "techage:electric_cableS",
})
Cable:register_on_tube_update(function(node, pos, out_dir, peer_pos, peer_in_dir)
if minetest.registered_nodes[node.name].after_tube_update then -- primay/secondary nodes
minetest.registered_nodes[node.name].after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir)
else -- all kind of nodes, used as cable filler/grout
techage.power.after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir, Cable)
end
end)
minetest.register_craft({
output = "techage:electric_cableS 6",
recipe = {
@ -171,3 +166,5 @@ minetest.register_craft({
},
})
techage.ElectricCable = Cable
techage.ELE1_MAX_CABLE_LENGHT = ELE1_MAX_CABLE_LENGHT

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -48,10 +48,10 @@ end
-- 'size' is the size of the junction cube without any connection, e.g. 1/8
-- 'boxes' is a table with 6 table elements for the 6 possible connection arms
-- 'network' is the power (tubelib2) instance or nil
-- 'tlib2' is the tubelib2 instance
-- 'node' is the node definition with tiles, callback functions, and so on
-- 'index' number for the inventory node (default 0)
function techage.register_junction(name, size, boxes, network, node, index)
function techage.register_junction(name, size, boxes, tlib2, node, index)
for idx = 0,63 do
local ndef = table.copy(node)
if idx == (index or 0) then
@ -69,21 +69,21 @@ function techage.register_junction(name, size, boxes, network, node, index)
ndef.is_ground_content = false
ndef.drop = name..(index or "0")
minetest.register_node(name..idx, ndef)
-- Register in addition for power distribution
if network then
techage.power.register_node({name..idx}, {
power_network = network,
after_tube_update = ndef.after_tube_update,
})
end
tlib2:add_secondary_node_names({name..idx})
end
end
function techage.junction_type(pos, network)
local val = 0
for dir = 1,6 do
if network:connected(pos, dir) then
val = setbit(val, bit(dir))
if network.force_to_use_tubes then
if network:friendly_primary_node(pos, dir) then
val = setbit(val, bit(dir))
end
else
if network:connected(pos, dir) then
val = setbit(val, bit(dir))
end
end
end
return val

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -16,6 +16,7 @@
local M = minetest.get_meta
local S = techage.S
local networks = techage.networks
local Cable = techage.ElectricCable
local power = techage.power
@ -35,22 +36,23 @@ techage.register_junction("techage:electric_junction", 2/8, Boxes, Cable, {
groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 3, techage_trowel = 1},
sounds = default.node_sound_defaults(),
on_construct = tubelib2.init_mem,
after_tube_update = function(node, pos, out_dir, peer_pos, peer_in_dir)
after_place_node = function(pos, placer, itemstack, pointed_thing)
local name = "techage:electric_junction"..techage.junction_type(pos, Cable)
minetest.swap_node(pos, {name = name, param2 = 0})
power.network_changed(pos, tubelib2.get_mem(pos))
Cable:after_place_node(pos)
end,
is_power_available = function(pos)
return techage.power.power_accounting(pos, tubelib2.get_mem(pos))
tubelib2_on_update2 = function(pos, dir1, tlib2, node)
local name = "techage:electric_junction"..techage.junction_type(pos, Cable)
minetest.swap_node(pos, {name = name, param2 = 0})
power.update_network(pos, nil, tlib2)
end,
})
minetest.register_craft({
output = "techage:electric_junction0 2",
recipe = {
{"", "basic_materials:plastic_sheet", ""},
{"basic_materials:plastic_sheet", "default:copper_ingot", "basic_materials:plastic_sheet"},
{"", "basic_materials:plastic_sheet", ""},
after_dig_node = function(pos, oldnode, oldmetadata, digger)
Cable:after_dig_node(pos)
end,
networks = {
ele1 = {
sides = networks.AllSides, -- connection sides for cables
ntype = "junc",
},
},
})
})

View File

@ -1,678 +0,0 @@
--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
Power distribution and consumption calculation
for any kind of power distribution network
]]--
-- for lazy programmers
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local P = minetest.string_to_pos
local M = minetest.get_meta
local N = function(pos) return minetest.get_node(pos).name end
local D = techage.Debug
-- Techage Related Data
local PWR = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).power end
-- Used to determine the already passed nodes while power distribution
local Route = {}
local NumNodes = 0
techage.power = {}
local MAX_NUM_NODES = 1000
techage.MAX_NUM_NODES = MAX_NUM_NODES
-- Consumer States
local STOPPED = 1
local NOPOWER = 2
local RUNNING = 3
-------------------------------------------------- Migrate
local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).consumer end
local Consumer = {
["techage:streetlamp_off"] = 0,
["techage:streetlamp_on"] = 0.5,
["techage:industriallamp1_off"] = 0,
["techage:industriallamp1_on"] = 0.5,
["techage:industriallamp2_off"] = 0,
["techage:industriallamp2_on"] = 0.5,
["techage:industriallamp3_off"] = 0,
["techage:industriallamp3_on"] = 0.5,
["techage:simplelamp_off"] = 0,
["techage:simplelamp_on"] = 0.5,
["techage:ceilinglamp_off"] = 0,
["techage:ceilinglamp_on"] = 0.5,
["techage:ta2_autocrafter_pas"] = 0,
["techage:ta2_autocrafter_act"] = 4,
["techage:ta3_autocrafter_pas"] = 0,
["techage:ta3_autocrafter_act"] = 6,
["techage:ta2_electronic_fab_pas"] = 0,
["techage:ta2_electronic_fab_act"] = 8,
["techage:ta3_electronic_fab_pas"] = 0,
["techage:ta3_electronic_fab_act"] = 12,
["techage:ta2_gravelsieve_pas"] = 0,
["techage:ta2_gravelsieve_act"] = 3,
["techage:ta3_gravelsieve_pas"] = 0,
["techage:ta3_gravelsieve_act"] = 4,
["techage:ta2_grinder_pas"] = 0,
["techage:ta2_grinder_act"] = 4,
["techage:ta3_grinder_pas"] = 0,
["techage:ta3_grinder_act"] = 6,
["techage:ta2_rinser_pas"] = 0,
["techage:ta2_rinser_act"] = 3,
["techage:ta3_booster"] = 0,
["techage:ta3_booster_on"] = 3,
["techage:ta3_drillbox_pas"] = 0,
["techage:ta3_drillbox_act"] = 16,
["techage:ta3_pumpjack_pas"] = 0,
["techage:ta3_pumpjack_act"] = 16,
["techage:gearbox"] = 0,
["techage:gearbox_on"] = 1,
}
local Generator = {
["techage:t2_source"] = 20,
["techage:t3_source"] = 20,
["techage:t4_source"] = 20,
["techage:flywheel"] = 0,
["techage:flywheel_on"] = 25,
["techage:generator"] = 0,
["techage:generator_on"] = 80,
["techage:tiny_generator"] = 0,
["techage:tiny_generator_on"] = 12,
}
local Akku = {
["techage:ta3_akku"] = 10
}
local function migrate(pos, mem, node)
if mem.master_pos or mem.is_master ~= nil then
print("migrate", S(pos), node.name)
if mem.master_pos then
mem.pwr_master_pos = table.copy(mem.master_pos)
mem.master_pos = nil
end
mem.pwr_is_master = mem.is_master; mem.is_master = nil
mem.available1 = nil
mem.available2 = nil
mem.supply1 = nil
mem.supply2 = nil
mem.needed1 = nil
mem.needed2 = nil
mem.demand1 = nil
mem.demand2 = nil
mem.reserve = nil
mem.could_be_master = nil
mem.node_loaded = nil
mem.pwr_power_provided_cnt = 2
mem.pwr_node_alive_cnt = 4
local name = techage.get_node_lvm(pos).name
mem.pwr_needed = Consumer[name]
mem.pwr_available = Generator[name]
mem.pwr_could_provide = Akku[name]
mem.pwr_could_need = Akku[name]
if Consumer[name] then
if mem.techage_state then
if mem.techage_state == techage.STOPPED then
mem.pwr_state = STOPPED
elseif mem.techage_state == techage.NOPOWER or mem.techage_state == techage.RUNNING then
local crd = CRD(pos)
techage.power.consumer_start(pos, mem, crd.cycle_time, crd.power_consumption)
end
elseif mem.turned_on then
mem.pwr_state = RUNNING
elseif mem.pwr_needed then
mem.pwr_state = RUNNING
else
mem.pwr_state = STOPPED
end
if techage.in_list({"techage:ta2_electronic_fab_pas", "techage:ta2_electronic_fab_act", "techage:ta3_electronic_fab_pas", "techage:ta3_electronic_fab_act"}, name) then
mem.pwr_cycle_time = 6
elseif techage.in_list({"techage:ta3_drillbox_pas", "techage:ta3_drillbox_act"}, name) then
mem.pwr_cycle_time = 16
elseif techage.in_list({"techage:ta3_pumpjack_pas", "techage:ta3_pumpjack_act"}, name) then
mem.pwr_cycle_time = 8
else
mem.pwr_cycle_time = 4
end
elseif Generator[name] then
mem.pwr_cycle_time = 2
if mem.generating then
techage.power.generator_start(pos, mem, Generator[name])
else
techage.power.generator_stop(pos, mem)
end
elseif Akku[name] then
mem.pwr_cycle_time = 2
if mem.techage_state and mem.techage_state == techage.RUNNING then
mem.running = true
minetest.get_node_timer(pos):start(2)
techage.power.secondary_start(pos, mem, mem.pwr_could_provide, mem.pwr_could_need)
end
end
end
end
local Nodenames={}
local n=0
for k,v in pairs(Consumer) do
n=n+1
Nodenames[n]=k
end
for k,v in pairs(Generator) do
n=n+1
Nodenames[n]=k
end
for k,v in pairs(Akku) do
n=n+1
Nodenames[n]=k
end
minetest.register_lbm({
label = "[techage] Power Conversion",
name = "techage:power",
nodenames = Nodenames,
run_at_every_load = true,
action = function(pos, node)
local mem = tubelib2.get_mem(pos)
migrate(pos, mem, node)
end
})
-------------------------------------------------- Migrate
local function connection_color(t)
local count = 0
for _ in pairs(t) do count = count + 1 end
if count == 0 then return count, "#FF0000" end
if count == 1 then return count, "#FFFF00" end
return count, "#00FF00"
end
local function pos_already_reached(pos)
local key = minetest.hash_node_position(pos)
if not Route[key] and NumNodes < MAX_NUM_NODES then
Route[key] = true
NumNodes = NumNodes + 1
return false
end
return true
end
local function min(val, max)
if val < 0 then return 0 end
if val > max then return max end
return val
end
local function accounting(pos, mem)
-- calculate the primary and secondary supply and demand
mem.mst_supply1 = min(mem.mst_needed1 + mem.mst_needed2, mem.mst_available1)
mem.mst_demand1 = min(mem.mst_needed1, mem.mst_available1 + mem.mst_available2)
mem.mst_supply2 = min(mem.mst_demand1 - mem.mst_supply1, mem.mst_available2)
mem.mst_demand2 = min(mem.mst_supply1 - mem.mst_demand1, mem.mst_available1)
mem.mst_reserve = (mem.mst_available1 + mem.mst_available2) - mem.mst_needed1
if D.sts then D.dbg("needed = "..mem.mst_needed1.."/"..mem.mst_needed2..", available = "..mem.mst_available1.."/"..mem.mst_available2) end
if D.sts then D.dbg("supply = "..mem.mst_supply1.."/"..mem.mst_supply2..", demand = "..mem.mst_demand1.."/"..mem.mst_demand2..", reserve = "..mem.mst_reserve) end
end
local function connection_walk(pos, clbk)
local mem = tubelib2.get_mem(pos)
mem.interrupted_dirs = mem.interrupted_dirs or {}
if clbk then
clbk(pos, mem)
end
for out_dir,item in pairs(mem.connections or {}) do
if item.pos and not pos_already_reached(item.pos) and
not mem.interrupted_dirs[out_dir] then
connection_walk(item.pos, clbk)
end
end
end
-- Comfort walk with abort condition and additional info
-- num_hops is for internal use only
-- clbk(pos, node, mem, num_hops, num_nodes)
local function limited_connection_walk(pos, clbk, num_hops)
num_hops = num_hops or 1
local mem = tubelib2.get_mem(pos)
mem.interrupted_dirs = mem.interrupted_dirs or {}
if clbk then
local node = techage.get_node_lvm(pos)
if clbk(pos, node, mem, num_hops, NumNodes) then return true end
end
num_hops = num_hops + 1
for out_dir,item in pairs(mem.connections or {}) do
if item.pos and not pos_already_reached(item.pos) and
not mem.interrupted_dirs[out_dir] then
limited_connection_walk(item.pos, clbk, num_hops)
end
end
return false
end
-- if no power available
local function consumer_turn_off(pos, mem)
local pwr = PWR(pos)
if D.pwr then D.dbg("consumer_turn_off") end
if pwr and pwr.on_nopower then
pwr.on_nopower(pos, mem)
end
mem.pwr_state = NOPOWER
mem.pwr_power_provided_cnt = -1
end
local function consumer_turn_on(pos, mem)
local pwr = PWR(pos)
if D.pwr then D.dbg("consumer_turn_on") end
if pwr and pwr.on_power then
pwr.on_power(pos, mem)
end
mem.pwr_state = RUNNING
-- to avoid consumer starvation
mem.pwr_node_alive_cnt = (mem.pwr_cycle_time or 2)/2 + 1
end
-- determine one "generating" node as master (largest hash number)
local function determine_master(pos)
Route = {}
NumNodes = 0
pos_already_reached(pos)
local hash = 0
local master = nil
connection_walk(pos, function(pos, mem)
if (mem.pwr_node_alive_cnt or 0) >= 0 and
((mem.pwr_available or 0) > 0 or
(mem.pwr_available2 or 0) > 0) then -- active generator?
local new = minetest.hash_node_position(pos)
if hash <= new then
hash = new
master = pos
end
end
end)
return master
end
-- store master position on all network nodes
local function store_master(pos, master_pos)
Route = {}
NumNodes = 0
pos_already_reached(pos)
connection_walk(pos, function(pos, mem)
mem.pwr_master_pos = master_pos
end)
end
local function master_mem(mem)
if mem.pwr_master_pos then
local netkey = minetest.hash_node_position(mem.pwr_master_pos)
return techage.schedule.get_network(netkey)
end
end
local function handle_generator(mst_mem, mem, pos, power_available)
-- for next cycle
mst_mem.mst_available1 = (mst_mem.mst_available1 or 0) + power_available
-- current cycle
mst_mem.mst_supply1 = mst_mem.mst_supply1 or 0
if mst_mem.mst_supply1 < power_available then
mem.pwr_provided = mst_mem.mst_supply1
mst_mem.mst_supply1 = 0
else
mst_mem.mst_supply1 = mst_mem.mst_supply1 - power_available
mem.pwr_provided = power_available
end
end
local function handle_consumer(mst_mem, mem, pos, power_needed)
if mem.pwr_state == NOPOWER then
-- for next cycle
mst_mem.mst_needed1 = (mst_mem.mst_needed1 or 0) + power_needed
-- current cycle
if (mst_mem.mst_demand1 or 0) >= power_needed then
mst_mem.mst_demand1 = (mst_mem.mst_demand1 or 0) - power_needed
if D.sts then D.dbg("consumer_turn_on: mst_demand = "..mst_mem.mst_demand1..", node = "..minetest.get_node(pos).name) end
consumer_turn_on(pos, mem)
end
elseif mem.pwr_state == RUNNING then
-- for next cycle
mst_mem.mst_needed1 = (mst_mem.mst_needed1 or 0) + power_needed
-- current cycle
if (mst_mem.mst_demand1 or 0) >= power_needed then
mst_mem.mst_demand1 = (mst_mem.mst_demand1 or 0) - power_needed
-- small consumer like lamps are allowed to "use" the reserve
elseif power_needed <= 2 and (mst_mem.mst_reserve or 0) >= power_needed then
mst_mem.mst_reserve = (mst_mem.mst_reserve or 0) - power_needed
else -- no power available
mst_mem.mst_demand1 = 0
if D.sts then D.dbg("consumer_turn_off: mst_demand = "..mst_mem.mst_demand1..", node = "..minetest.get_node(pos).name) end
consumer_turn_off(pos, mem)
end
end
end
local function handle_secondary(mst_mem, mem, pos, provides, needed)
-- for next cycle
mst_mem.mst_available2 = (mst_mem.mst_available2 or 0) + provides
mst_mem.mst_needed2 = (mst_mem.mst_needed2 or 0) + needed
-- check as generator
mst_mem.mst_supply2 = mst_mem.mst_supply2 or 0
mst_mem.mst_demand2 = mst_mem.mst_demand2 or 0
if mst_mem.mst_supply2 > 0 then
local val = math.min(provides, mst_mem.mst_supply2)
mst_mem.mst_supply2 = mst_mem.mst_supply2 - val
mem.pwr_provided = val
-- check as consumer
elseif mst_mem.mst_demand2 > 0 then
local val = math.min(needed, mst_mem.mst_demand2)
mst_mem.mst_demand2 = mst_mem.mst_demand2 - val
mem.pwr_provided = -val
else
mem.pwr_provided = 0
end
end
local function trigger_nodes(mst_pos, mst_mem, dec)
Route = {}
NumNodes = 0
pos_already_reached(mst_pos)
connection_walk(mst_pos, function(pos, mem)
mem.pwr_node_alive_cnt = (mem.pwr_node_alive_cnt or 1) - dec
mem.pwr_power_provided_cnt = 2
if D.pwr then D.dbg("trigger_nodes", minetest.get_node(pos).name, mem.pwr_node_alive_cnt, mem.pwr_available2 or mem.pwr_available or mem.pwr_needed) end
if mem.pwr_node_alive_cnt >= 0 or mem.pwr_state == NOPOWER then
if mem.pwr_available then
handle_generator(mst_mem, mem, pos, mem.pwr_available)
elseif mem.pwr_needed then
handle_consumer(mst_mem, mem, pos, mem.pwr_needed)
elseif mem.pwr_available2 then
handle_secondary(mst_mem, mem, pos, mem.pwr_available2, mem.pwr_needed2)
end
end
end)
end
local function turn_off_nodes(mst_pos)
Route = {}
NumNodes = 0
pos_already_reached(mst_pos)
if D.pwr then D.dbg("turn_off_nodes") end
connection_walk(mst_pos, function(pos, mem)
if (mem.pwr_node_alive_cnt or -1) >= 0 then
if mem.pwr_needed then
consumer_turn_off(pos, mem)
end
end
end)
end
local function determine_new_master(pos, mem)
local mpos = determine_master(pos)
store_master(pos, mpos)
mem.pwr_master_pos = mpos
return true
end
-- called from all nodes
local function trigger_network(pos, mem)
if mem.pwr_master_pos then
local netkey = minetest.hash_node_position(mem.pwr_master_pos)
local network = techage.schedule.get_network(netkey) or
techage.schedule.add_network(netkey, {mst_pos = mem.pwr_master_pos})
network.alive = 10
else
print("node without master_pos "..N(pos).." at "..S(pos))
end
end
-- called from global timer
function techage.power.power_distribution(time, pos, mem)
if D.pwr then D.dbg("power_distribution"..math.floor(time).." "..N(pos)) end
mem.mst_needed1 = 0
mem.mst_needed2 = 0
mem.mst_available1 = 0
mem.mst_available2 = 0
trigger_nodes(pos, mem, 1)
accounting(pos, mem)
end
--
-- Power API functions
--
-- To be called for each network change from any node
function techage.power.network_changed(pos, mem)
if D.pwr then D.dbg("network_changed") end
mem.pwr_node_alive_cnt = (mem.pwr_cycle_time or 2)/2 + 1
if determine_new_master(pos, mem) then -- new master
trigger_network(pos, mem)
end
end
--
-- Generator related functions
--
function techage.power.generator_start(pos, mem, available)
mem.pwr_node_alive_cnt = 2
mem.pwr_cycle_time = 2
mem.pwr_available = available
if determine_new_master(pos, mem) then -- new master
trigger_network(pos, mem)
end
end
function techage.power.generator_update(pos, mem, available)
mem.pwr_available = available
end
function techage.power.generator_stop(pos, mem)
mem.pwr_node_alive_cnt = 0
mem.pwr_available = 0
if determine_new_master(pos, mem) then -- last available master
trigger_network(pos, mem)
end
end
function techage.power.generator_alive(pos, mem)
mem.pwr_node_alive_cnt = 2
trigger_network(pos, mem)
return mem.pwr_provided or 0
end
--
-- Consumer related functions
--
-- this is more a try to start, the start will be performed by consumer_turn_on()
function techage.power.consumer_start(pos, mem, cycle_time, needed)
mem.pwr_cycle_time = cycle_time
mem.pwr_power_provided_cnt = 0 -- must be zero!
mem.pwr_node_alive_cnt = 2
mem.pwr_needed = needed
mem.pwr_state = NOPOWER
end
function techage.power.consumer_stop(pos, mem)
mem.pwr_node_alive_cnt = 0
mem.pwr_needed = 0
mem.pwr_state = STOPPED
end
function techage.power.consumer_alive(pos, mem)
if D.pwr then D.dbg("consumer_alive", mem.pwr_power_provided_cnt, mem.pwr_cycle_time) end
mem.pwr_node_alive_cnt = (mem.pwr_cycle_time or 2)/2 + 1
mem.pwr_power_provided_cnt = (mem.pwr_power_provided_cnt or 0) - 1
if mem.pwr_power_provided_cnt < 0 and mem.pwr_state == RUNNING then
consumer_turn_off(pos, mem)
end
end
-- Lamp related function to speed up the turn on
function techage.power.power_available(pos, mem, needed)
if mem.pwr_master_pos and (mem.pwr_power_provided_cnt or 0) > 0 then
mem = master_mem(mem)
if mem and (mem.mst_reserve or 0) >= needed then
mem.mst_reserve = (mem.mst_reserve or 0) - needed
return true
end
end
return false
end
-- Debug info, used by junction boxes
function techage.power.power_accounting(pos, mem)
if mem.pwr_master_pos and (mem.pwr_power_provided_cnt or 0) > 0 then
mem.pwr_power_provided_cnt = (mem.pwr_power_provided_cnt or 0) - 1
mem = master_mem(mem)
if mem then
return {
prim_available = mem.mst_available1 or 0,
sec_available = mem.mst_available2 or 0,
prim_needed = mem.mst_needed1 or 0,
sec_needed = mem.mst_needed2 or 0,
num_nodes = mem.mst_num_nodes or 0,
}
end
end
return {
prim_available = 0,
sec_available = 0,
prim_needed = 0,
sec_needed = 0,
num_nodes = 0,
}
end
--
-- Akku related functions
--
function techage.power.secondary_start(pos, mem, available, needed)
mem.pwr_node_alive_cnt = 2
mem.pwr_could_provide = available
mem.pwr_could_need = needed
if determine_new_master(pos, mem) then -- new master
trigger_network(pos, mem)
end
end
function techage.power.secondary_stop(pos, mem)
mem.pwr_node_alive_cnt = 0
mem.pwr_could_provide = 0
mem.pwr_could_need = 0
mem.pwr_needed2 = 0
if determine_new_master(pos, mem) then -- last available master
trigger_network(pos, mem)
end
end
function techage.power.secondary_alive(pos, mem, capa_curr, capa_max)
if D.pwr then D.dbg("secondary_alive") end
if capa_curr >= capa_max then
mem.pwr_available2, mem.pwr_needed2 = mem.pwr_could_provide, 0 -- can provide only
elseif capa_curr <= 0 then
mem.pwr_available2, mem.pwr_needed2 = 0, mem.pwr_could_need -- can deliver only
else
mem.pwr_available2, mem.pwr_needed2 = mem.pwr_could_provide, mem.pwr_could_need
end
mem.pwr_node_alive_cnt = 2
if mem.pwr_is_master then
if D.pwr then D.dbg("secondary_alive is master") end
trigger_network(pos, mem)
end
if mem.pwr_master_pos then
return mem.pwr_provided or 0
end
return 0
end
--
-- Read the current power value from all connected devices (used for solar cells)
-- Only used by the solar inverter to collect the power of all solar cells.
-- Only one inverter per network is allowed. Therefore, we have to check,
-- if additional inverters are in the network.
-- Function returns in addition the number of found inverters.
function techage.power.get_power(start_pos, inverter)
Route = {}
NumNodes = 0
pos_already_reached(start_pos)
local sum = 0
local num_inverter = 0
connection_walk(start_pos, function(pos, mem)
local pwr = PWR(pos)
if pwr and pwr.on_getpower then
sum = sum + pwr.on_getpower(pos, mem)
else
local node = techage.get_node_lvm(pos)
if node.name == inverter then
num_inverter = num_inverter + 1
end
end
end)
return sum, num_inverter
end
function techage.power.power_network_available(start_pos)
Route = {}
NumNodes = 0
pos_already_reached(start_pos)
limited_connection_walk(start_pos, function(pos, node, mem, _, num_nodes)
return num_nodes > 2
end)
return NumNodes > 2
end
function techage.power.mark_nodes(name, start_pos)
Route = {}
NumNodes = 0
pos_already_reached(start_pos)
techage.unmark_position(name)
limited_connection_walk(start_pos, function(pos, node, mem, num_hops, num_nodes)
local num, color = connection_color(mem.connections or {})
techage.mark_position(name, pos, S(pos).." : "..num, color)
return num_hops >= 3 or num_nodes >= 100
end)
end
-- Network walk with callback for each node:
--
-- limited_connection_walk(pos, clbk) --> num_hops, num_nodes
--
-- called function: clbk(pos, node, mem, num_hops, num_nodes)
-- walk will be arborted if function returns true
function techage.power.limited_connection_walk(pos, clbk)
Route = {}
NumNodes = 0
pos_already_reached(pos)
limited_connection_walk(pos, clbk)
return NumNodes
end
--local function test()
-- print("test")
-- local cnt = 0
-- tubelib2.walk_over_all(function(pos, mem)
-- local node = techage.get_node_lvm(pos)
-- print(S(pos), node.name)
-- cnt = cnt + 1
-- end)
-- print("cnt = "..cnt)
--end
--minetest.after(1, test)

View File

@ -1,270 +0,0 @@
--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
Power helper functions
]]--
-- for lazy programmers
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local P = minetest.string_to_pos
local M = minetest.get_meta
local N = function(pos) return minetest.get_node(pos).name end
-- Techage Related Data
local PWR = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).power end
local PWRN = function(node) return (minetest.registered_nodes[node.name] or {}).power end
local network_changed = techage.power.network_changed
local SideToDir = {B=1, R=2, F=3, L=4, D=5, U=6}
local function side_to_dir(param2, side)
local dir = SideToDir[side]
if dir < 5 then
dir = (((dir - 1) + (param2 % 4)) % 4) + 1
end
return dir
end
local function set_conn_dirs(pos, sides)
local tbl = {}
local node = minetest.get_node(pos)
if type(sides) == "function" then
tbl = sides(pos, node)
else
for _,side in ipairs(sides) do
tbl[#tbl+1] = tubelib2.Turn180Deg[side_to_dir(node.param2, side)]
end
end
M(pos):set_string("power_dirs", minetest.serialize(tbl))
end
techage.power.side_to_dir = side_to_dir
techage.power.set_conn_dirs = set_conn_dirs
local function valid_indir(pos, in_dir)
local s = M(pos):get_string("power_dirs")
if s == "" then
local pwr = PWR(pos)
if pwr then
set_conn_dirs(pos, pwr.conn_sides)
end
end
if s ~= "" then
for _,dir in ipairs(minetest.deserialize(s)) do
if dir == in_dir then
return true
end
end
end
return false
end
local function valid_outdir(pos, out_dir)
return valid_indir(pos, tubelib2.Turn180Deg[out_dir])
end
-- Both nodes are from the same power network type?
local function matching_nodes(pos, peer_pos)
local tube_type1 = pos and PWR(pos) and PWR(pos).power_network.tube_type
local tube_type2 = peer_pos and PWR(peer_pos) and PWR(peer_pos).power_network.tube_type
return not tube_type1 or not tube_type2 or tube_type1 == tube_type2
end
function techage.get_pos(pos, side)
local node = techage.get_node_lvm(pos)
local dir = nil
if node.name ~= "air" and node.name ~= "ignore" then
dir = side_to_dir(node.param2, side)
end
return tubelib2.get_pos(pos, dir)
end
-- only for nodes with own 'conn_sides' and rotate function
function techage.power.after_rotate_node(pos, cable)
cable:after_dig_node(pos)
set_conn_dirs(pos, PWR(pos).conn_sides)
cable:after_place_node(pos)
end
local function add_connection(mem, pos, out_dir, peer_pos, peer_in_dir, power)
mem.connections = mem.connections or {}
if not peer_pos or not valid_indir(peer_pos, peer_in_dir)
or not valid_outdir(pos, out_dir)
or not matching_nodes(pos, peer_pos) then
mem.connections[out_dir] = nil -- del connection
else
mem.connections[out_dir] = {pos = peer_pos, in_dir = peer_in_dir}
end
-- update network for power scheduling
techage.power.network_changed(pos, mem)
end
function techage.power.register_node(names, pwr_def)
for _,name in ipairs(names) do
local ndef = minetest.registered_nodes[name]
if ndef then
minetest.override_item(name, {
power = {
conn_sides = pwr_def.conn_sides or {"L", "R", "U", "D", "F", "B"},
on_power = pwr_def.on_power,
on_nopower = pwr_def.on_nopower,
on_getpower = pwr_def.on_getpower,
power_network = pwr_def.power_network,
after_place_node = pwr_def.after_place_node,
after_dig_node = pwr_def.after_dig_node,
after_tube_update = pwr_def.after_tube_update,
},
-- after_place_node decorator
after_place_node = function(pos, placer, itemstack, pointed_thing)
local res
local pwr = PWR(pos)
set_conn_dirs(pos, pwr.conn_sides)
if pwr.after_place_node then
res = pwr.after_place_node(pos, placer, itemstack, pointed_thing)
end
pwr.power_network:after_place_node(pos)
return res
end,
-- after_dig_node decorator
after_dig_node = function(pos, oldnode, oldmetadata, digger)
local pwr = PWRN(oldnode)
pwr.power_network:after_dig_node(pos)
minetest.after(0.1, tubelib2.del_mem, pos) -- At latest...
if pwr.after_dig_node then
return pwr.after_dig_node(pos, oldnode, oldmetadata, digger)
end
end,
-- tubelib2->Cable:register_on_tube_update callback, called after any connection change
after_tube_update = function(node, pos, out_dir, peer_pos, peer_in_dir)
local pwr = PWR(pos)
local mem = tubelib2.get_mem(pos)
add_connection(mem, pos, out_dir, peer_pos, peer_in_dir, pwr)
if pwr.after_tube_update then
return pwr.after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir)
end
end,
})
pwr_def.power_network:add_secondary_node_names({name})
end
end
end
--
-- API function set for nodes, which don't (what to) call techage.power.register_node()
--
function techage.power.enrich_node(names, pwr_def)
for _,name in ipairs(names) do
minetest.override_item(name, {
power = {
conn_sides = pwr_def.conn_sides or {"L", "R", "U", "D", "F", "B"},
on_power = pwr_def.on_power,
on_nopower = pwr_def.on_nopower,
on_getpower = pwr_def.on_getpower,
power_network = pwr_def.power_network,
}
})
pwr_def.power_network:add_secondary_node_names({name})
end
end
function techage.power.after_place_node(pos)
local pwr = PWR(pos)
set_conn_dirs(pos, pwr.conn_sides)
pwr.power_network:after_place_node(pos)
end
function techage.power.after_dig_node(pos, oldnode)
local pwr = PWRN(oldnode)
pwr.power_network:after_dig_node(pos)
end
function techage.power.after_tube_update2(node, pos, out_dir, peer_pos, peer_in_dir)
local pwr = PWR(pos)
local mem = tubelib2.get_mem(pos)
add_connection(mem, pos, out_dir, peer_pos, peer_in_dir, pwr)
end
--
-- Further helper functions
--
-- Called from tubelib2 via Cable:register_on_tube_update()
-- For all kind of nodes, used as cable filler/grout
function techage.power.after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir, power)
local mem = tubelib2.get_mem(pos)
add_connection(mem, pos, out_dir, peer_pos, peer_in_dir, power)
if power.after_tube_update then
return power.after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir)
end
end
function techage.power.percent(max_val, curr_val)
return math.min(math.ceil(((curr_val or 0) * 100.0) / (max_val or 1.0)), 100)
end
function techage.power.formspec_load_bar(charging, max_val)
local percent
charging = charging or 0
max_val = max_val or 1
if charging ~= 0 then
percent = 50 + math.ceil((charging * 50.0) / max_val)
end
if charging > 0 then
return "techage_form_level_off.png^[lowpart:"..percent..":techage_form_level_charge.png"
elseif charging < 0 then
return "techage_form_level_unload.png^[lowpart:"..percent..":techage_form_level_off.png"
else
return "techage_form_level_off.png"
end
end
function techage.power.formspec_power_bar(max_power, current_power)
if (current_power or 0) == 0 then
return "techage_form_level_bg.png"
end
local percent = techage.power.percent(max_power, current_power)
percent = (percent + 5) / 1.22 -- texture correction
return "techage_form_level_bg.png^[lowpart:"..percent..":techage_form_level_fg.png"
end
function techage.power.side_to_outdir(pos, side)
local node = techage.get_node_lvm(pos)
return side_to_dir(node.param2, side)
end
-- Used to turn on/off the power by means of a power switch
function techage.power.power_cut(pos, dir, cable, cut)
local npos = vector.add(pos, tubelib2.Dir6dToVector[dir or 0])
local node = techage.get_node_lvm(npos)
if node.name ~= "techage:powerswitch_box" and
M(npos):get_string("techage_hidden_nodename") ~= "techage:powerswitch_box" then
return
end
local mem = tubelib2.get_mem(npos)
mem.interrupted_dirs = mem.interrupted_dirs or {}
if cut then
mem.interrupted_dirs = {true, true, true, true, true, true}
for dir,_ in pairs(mem.connections) do
mem.interrupted_dirs[dir] = false -- open the port
techage.power.network_changed(npos, mem)
mem.interrupted_dirs[dir] = true
end
else
mem.interrupted_dirs = {}
techage.power.network_changed(npos, mem)
end
end

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -16,7 +16,9 @@ local P = minetest.string_to_pos
local M = minetest.get_meta
local S = techage.S
local networks = techage.networks
local Cable = techage.ElectricCable
local power = techage.power
-- Primary techage.ElectricCable node
minetest.register_node("techage:power_line", {
@ -162,81 +164,6 @@ minetest.register_node("techage:power_lineA", {
sounds = default.node_sound_defaults(),
})
minetest.register_node("techage:power_pole", {
description = S("TA Power Pole Top (for up to 6 connections)"),
tiles = {
"default_wood.png^techage_power_pole_top.png",
"default_wood.png^techage_power_pole_top.png",
"default_wood.png^techage_power_pole.png"
},
paramtype2 = "facedir", -- important!
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{ -4/32, -16/32, -4/32, 4/32, 16/32, 4/32},
{-16/32, -6/32, -1/32, 16/32, -4/32, 1/32},
{ -1/32, -6/32, -16/32, 1/32, -4/32, 16/32},
{-16/32, -4/32, -2/32, -12/32, 4/32, 2/32},
{ 12/32, -4/32, -2/32, 16/32, 4/32, 2/32},
{ -2/32, -4/32, -16/32, 2/32, 4/32, -12/32},
{ -2/32, -4/32, 12/32, 2/32, 4/32, 16/32},
},
},
on_rotate = screwdriver.disallow, -- important!
paramtype = "light",
sunlight_propagates = true,
is_ground_content = false,
groups = {cracky=2, crumbly=2, choppy=2},
})
minetest.register_node("techage:power_pole_conn", {
description = "TA Power Pole Top (for up to 6 connections)",
tiles = {
"default_wood.png^techage_power_pole_top.png",
"default_wood.png^techage_power_pole_top.png",
"default_wood.png^techage_power_pole.png"
},
paramtype2 = "facedir", -- important!
drawtype = "nodebox",
node_box = {
type = "connected",
fixed = {{ -4/32, -16/32, -4/32, 4/32, 16/32, 4/32}},
connect_left = {{-16/32, -6/32, -1/32, 1/32, -4/32, 1/32},
{-16/32, -4/32, -2/32, -12/32, 4/32, 2/32}},
connect_right = {{ -1/32, -6/32, -1/32, 16/32, -4/32, 1/32},
{12/32, -4/32, -2/32, 16/32, 4/32, 2/32}},
connect_back = {{-1/32, -6/32, -1/32, 1/32, -4/32, 16/32},
{-2/32, -4/32, 12/32, 2/32, 4/32, 16/32}},
connect_front = {{-1/32, -6/32, -16/32, 1/32, -4/32, 1/32},
{-2/32, -4/32, -16/32, 2/32, 4/32, -12/32}},
},
connects_to = {"techage:power_line", "techage:power_lineS", "techage:power_lineA"},
can_dig = function(pos, digger)
local meta = minetest.get_meta(pos)
if meta:get_string("owner") == digger:get_player_name() then
return true
end
if minetest.check_player_privs(digger:get_player_name(), "powerline") then
return true
end
return false
end,
drop = "techage:power_pole",
on_rotate = screwdriver.disallow, -- important!
paramtype = "light",
sunlight_propagates = true,
is_ground_content = false,
groups = {cracky=2, crumbly=2, choppy=2, not_in_creative_inventory = 1},
sounds = default.node_sound_defaults(),
})
minetest.register_node("techage:power_pole2", {
description = S("TA Power Pole Top 2 (for landlines)"),
tiles = {
@ -256,8 +183,6 @@ minetest.register_node("techage:power_pole2", {
{ -2/32, -4/32, 12/32, 2/32, 4/32, 16/32},
},
},
after_place_node = function(pos, placer, itemstack, pointed_thing)
end,
after_place_node = function(pos, placer, itemstack, pointed_thing)
M(pos):set_string("owner", placer:get_player_name())
@ -296,9 +221,113 @@ minetest.register_node("techage:power_pole2", {
sounds = default.node_sound_defaults(),
})
-- dummy node for the inventory and to be placed and imediately replaced
minetest.register_node("techage:power_pole", {
description = S("TA Power Pole Top (for up to 6 connections)"),
tiles = {
"default_wood.png^techage_power_pole_top.png",
"default_wood.png^techage_power_pole_top.png",
"default_wood.png^techage_power_pole.png"
},
paramtype2 = "facedir", -- important!
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{ -4/32, -16/32, -4/32, 4/32, 16/32, 4/32},
{-16/32, -6/32, -1/32, 16/32, -4/32, 1/32},
{ -1/32, -6/32, -16/32, 1/32, -4/32, 16/32},
{-16/32, -4/32, -2/32, -12/32, 4/32, 2/32},
{ 12/32, -4/32, -2/32, 16/32, 4/32, 2/32},
{ -2/32, -4/32, -16/32, 2/32, 4/32, -12/32},
{ -2/32, -4/32, 12/32, 2/32, 4/32, 16/32},
},
},
after_place_node = function(pos, placer, itemstack, pointed_thing)
M(pos):set_string("owner", placer:get_player_name())
if techage.is_protected(pos, placer:get_player_name()) then
minetest.remove_node(pos)
return true
end
local node = minetest.get_node(pos)
node.name = "techage:power_pole_conn"
minetest.swap_node(pos, node)
Cable:after_place_node(pos)
end,
on_rotate = screwdriver.disallow, -- important!
paramtype = "light",
sunlight_propagates = true,
is_ground_content = false,
groups = {cracky=2, crumbly=2, choppy=2},
})
-- secondary node like a junction
minetest.register_node("techage:power_pole_conn", {
description = "TA Power Pole Top (for up to 6 connections)",
tiles = {
"default_wood.png^techage_power_pole_top.png",
"default_wood.png^techage_power_pole_top.png",
"default_wood.png^techage_power_pole.png"
},
paramtype2 = "facedir", -- important!
drawtype = "nodebox",
node_box = {
type = "connected",
fixed = {{ -4/32, -16/32, -4/32, 4/32, 16/32, 4/32}},
connect_left = {{-16/32, -6/32, -1/32, 1/32, -4/32, 1/32},
{-16/32, -4/32, -2/32, -12/32, 4/32, 2/32}},
connect_right = {{ -1/32, -6/32, -1/32, 16/32, -4/32, 1/32},
{12/32, -4/32, -2/32, 16/32, 4/32, 2/32}},
connect_back = {{-1/32, -6/32, -1/32, 1/32, -4/32, 16/32},
{-2/32, -4/32, 12/32, 2/32, 4/32, 16/32}},
connect_front = {{-1/32, -6/32, -16/32, 1/32, -4/32, 1/32},
{-2/32, -4/32, -16/32, 2/32, 4/32, -12/32}},
},
connects_to = {"techage:power_line", "techage:power_lineS", "techage:power_lineA"},
tubelib2_on_update2 = function(pos, dir1, tlib2, node)
power.update_network(pos, nil, tlib2)
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
Cable:after_dig_node(pos)
end,
can_dig = function(pos, digger)
local meta = minetest.get_meta(pos)
if meta:get_string("owner") == digger:get_player_name() then
return true
end
if minetest.check_player_privs(digger:get_player_name(), "powerline") then
return true
end
return false
end,
networks = {
ele1 = {
sides = networks.AllSides, -- connection sides for cables
ntype = "junc",
},
},
drop = "techage:power_pole",
on_rotate = screwdriver.disallow, -- important!
paramtype = "light",
sunlight_propagates = true,
is_ground_content = false,
groups = {cracky=2, crumbly=2, choppy=2, not_in_creative_inventory = 1},
sounds = default.node_sound_defaults(),
})
Cable:add_secondary_node_names({"techage:power_pole_conn"})
minetest.register_node("techage:power_pole3", {
description = S("TA Power Pole"),
--tiles = {"techage_power_pole.png"},
tiles = {
"default_wood.png",
"default_wood.png",
@ -321,24 +350,6 @@ minetest.register_node("techage:power_pole3", {
sounds = default.node_sound_defaults(),
})
techage.power.register_node({"techage:power_pole"}, {
power_network = Cable,
after_place_node = function(pos, placer, itemstack, pointed_thing)
M(pos):set_string("owner", placer:get_player_name())
if techage.is_protected(pos, placer:get_player_name()) then
minetest.remove_node(pos)
return true
end
local node = minetest.get_node(pos)
node.name = "techage:power_pole_conn"
minetest.swap_node(pos, node)
end,
})
techage.power.register_node({"techage:power_pole_conn"}, {
power_network = Cable,
})
minetest.register_craft({
output = "techage:power_lineS 24",
recipe = {

View File

@ -1,323 +0,0 @@
--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
TA3 Power Switch (large and small)
]]--
-- for lazy programmers
local P = minetest.string_to_pos
local M = minetest.get_meta
local S = techage.S
local Cable = techage.ElectricCable
local power_cut = techage.power.power_cut
local after_rotate_node = techage.power.after_rotate_node
local Param2ToDir = {
[0] = 6,
[1] = 5,
[2] = 2,
[3] = 4,
[4] = 1,
[5] = 3,
}
local function switch_on(pos, node, clicker, name)
if clicker and minetest.is_protected(pos, clicker:get_player_name()) then
return
end
node.name = name
minetest.swap_node(pos, node)
minetest.sound_play("techage_button", {
pos = pos,
gain = 0.5,
max_hear_distance = 5,
})
local dir = Param2ToDir[node.param2]
power_cut(pos, dir, Cable, false)
end
local function switch_off(pos, node, clicker, name)
if clicker and minetest.is_protected(pos, clicker:get_player_name()) then
return
end
node.name = name
minetest.swap_node(pos, node)
minetest.get_node_timer(pos):stop()
minetest.sound_play("techage_button", {
pos = pos,
gain = 0.5,
max_hear_distance = 5,
})
local dir = Param2ToDir[node.param2]
power_cut(pos, dir, Cable, true)
end
minetest.register_node("techage:powerswitch", {
description = S("TA Power Switch"),
inventory_image = "techage_appl_switch_inv.png",
tiles = {
'techage_appl_switch_off.png',
},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{ -1/4, -8/16, -1/4, 1/4, -7/16, 1/4},
{ -1/6, -12/16, -1/6, 1/6, -8/16, 1/6},
},
},
after_place_node = function(pos, placer)
local meta = M(pos)
local number = techage.add_node(pos, "techage:powerswitch")
meta:set_string("node_number", number)
meta:set_string("owner", placer:get_player_name())
meta:set_string("infotext", S("TA Power Switch").." "..number)
end,
on_rightclick = function(pos, node, clicker)
switch_on(pos, node, clicker, "techage:powerswitch_on")
end,
on_rotate = screwdriver.disallow,
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "wallmounted",
groups = {choppy=2, cracky=2, crumbly=2},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
minetest.register_node("techage:powerswitch_on", {
description = S("TA Power Switch"),
inventory_image = "techage_appl_switch_inv.png",
tiles = {
'techage_appl_switch_on.png',
},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{ -1/4, -8/16, -1/4, 1/4, -7/16, 1/4},
{ -1/6, -12/16, -1/6, 1/6, -8/16, 1/6},
},
},
on_rightclick = function(pos, node, clicker)
switch_off(pos, node, clicker, "techage:powerswitch")
end,
drop = "techage:powerswitch",
on_rotate = screwdriver.disallow,
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "wallmounted",
groups = {choppy=2, cracky=2, crumbly=2, not_in_creative_inventory = 1},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
minetest.register_node("techage:powerswitchsmall", {
description = S("TA Power Switch Small"),
inventory_image = "techage_smart_button_inventory.png",
tiles = {
'techage_smart_button_off.png',
},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{ -5/32, -16/32, -5/32, 5/32, -15/32, 5/32},
{ -2/16, -12/16, -2/16, 2/16, -8/16, 2/16},
},
},
after_place_node = function(pos, placer)
local meta = M(pos)
local number = techage.add_node(pos, "techage:powerswitchsmall")
meta:set_string("node_number", number)
meta:set_string("owner", placer:get_player_name())
meta:set_string("infotext", S("TA Power Switch Small").." "..number)
end,
on_rightclick = function(pos, node, clicker)
switch_on(pos, node, clicker, "techage:powerswitchsmall_on")
end,
on_rotate = screwdriver.disallow,
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "wallmounted",
groups = {choppy=2, cracky=2, crumbly=2},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
minetest.register_node("techage:powerswitchsmall_on", {
description = S("TA Power Switch Small"),
inventory_image = "techage_appl_switch_inv.png",
tiles = {
'techage_smart_button_on.png',
},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{ -5/32, -16/32, -5/32, 5/32, -15/32, 5/32},
{ -2/16, -12/16, -2/16, 2/16, -8/16, 2/16},
},
},
on_rightclick = function(pos, node, clicker)
switch_off(pos, node, clicker, "techage:powerswitchsmall")
end,
drop = "techage:powerswitchsmall",
on_rotate = screwdriver.disallow,
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "wallmounted",
groups = {choppy=2, cracky=2, crumbly=2, not_in_creative_inventory = 1},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
local function get_conn_dirs(pos, node)
local tbl = {[0]=
{2,4}, {1,3}, {2,4}, {1,3},
{2,4}, {5,6}, {2,4}, {5,6},
{2,4}, {5,6}, {2,4}, {5,6},
{5,6}, {1,3}, {5,6}, {1,3},
{5,6}, {1,3}, {5,6}, {1,3},
{2,4}, {1,3}, {2,4}, {1,3},
}
return tbl[node.param2]
end
local function on_place(itemstack, placer, pointed_thing)
if pointed_thing.type ~= "node" then
return itemstack
end
return minetest.rotate_and_place(itemstack, placer, pointed_thing)
end
local function on_rotate(pos, node, user, mode, new_param2)
if minetest.is_protected(pos, user:get_player_name()) then
return false
end
node.param2 = techage.rotate_wallmounted(node.param2)
minetest.swap_node(pos, node)
after_rotate_node(pos, Cable)
return true
end
minetest.register_node("techage:powerswitch_box", {
description = S("TA Power Switch Box"),
tiles = {
-- up, down, right, left, back, front
'techage_electric_switch.png',
'techage_electric_switch.png',
'techage_electric_junction.png',
'techage_electric_junction.png',
'techage_electric_switch.png',
'techage_electric_switch.png',
},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{ -2/4, -1/4, -1/4, 2/4, 1/4, 1/4},
},
},
paramtype = "light",
sunlight_propagates = true,
on_place = on_place,
on_rotate = on_rotate,
paramtype2 = "facedir",
groups = {choppy=2, cracky=2, crumbly=2, techage_trowel = 1},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
techage.power.register_node({"techage:powerswitch_box"}, {
power_network = Cable,
conn_sides = get_conn_dirs,
})
techage.register_node({"techage:powerswitch", "techage:powerswitch_on"}, {
on_recv_message = function(pos, src, topic, payload)
local node = techage.get_node_lvm(pos)
if topic == "on" and node.name == "techage:powerswitch" then
switch_on(pos, node, nil, "techage:powerswitch_on")
return true
elseif topic == "on" and node.name == "techage:powerswitchsmall" then
switch_on(pos, node, nil, "techage:powerswitchsmall_on")
return true
elseif topic == "off" and node.name == "techage:powerswitch_on" then
switch_off(pos, node, nil, "techage:powerswitch")
return true
elseif topic == "off" and node.name == "techage:powerswitchsmall_on" then
switch_off(pos, node, nil, "techage:powerswitchsmall")
return true
elseif topic == "state" then
if node.name == "techage:powerswitch_on" or node.name == "techage:powerswitchsmall_on"then
return "on"
end
return "off"
else
return "unsupported"
end
end,
on_node_load = function(pos)
local meta = M(pos)
local number = meta:get_string("number") or ""
if number ~= "" then
meta:set_string("node_number", number)
meta:set_string("number", nil)
end
end,
})
minetest.register_craft({
output = "techage:powerswitch 2",
recipe = {
{"", "", ""},
{"dye:yellow", "dye:red", "dye:yellow"},
{"basic_materials:plastic_sheet", "basic_materials:copper_wire", "basic_materials:plastic_sheet"},
},
})
minetest.register_craft({
type = "shapeless",
output = "techage:powerswitchsmall",
recipe = {"techage:powerswitch"},
})
minetest.register_craft({
output = "techage:powerswitch_box",
recipe = {
{"", "basic_materials:plastic_sheet", ""},
{"techage:electric_cableS", "basic_materials:copper_wire", "techage:electric_cableS"},
{"", "basic_materials:plastic_sheet", ""},
},
})

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -18,70 +18,64 @@ local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local M = minetest.get_meta
local N = function(pos) return minetest.get_node(pos).name end
local CYCLE_TIME = 2.0
local power = techage.power
local networks = techage.networks
local CYCLE_TIME = 2
techage.schedule = {}
local NetList = {}
local JobTable = {}
local JobQueue = {}
local first = 0
local last = -1
local LocalTime = 0
techage.SystemTime = 0
local function push(item)
last = last + 1
item.time = LocalTime + CYCLE_TIME
item.time = techage.SystemTime + CYCLE_TIME
JobQueue[last] = item
end
local function pop()
if first > last then return end
local item = JobQueue[first]
if item.time <= LocalTime then
if item.time <= techage.SystemTime then
JobQueue[first] = nil -- to allow garbage collection
first = first + 1
return item
end
end
local function power_distribution(network, tlib_type)
local t = minetest.get_us_time()
power.power_distribution(network, tlib_type, techage.SystemTime)
t = minetest.get_us_time() - t
--print("t = "..t..", #jobs = "..(last + 1 - first))
end
-- Scheduler
minetest.register_globalstep(function(dtime)
LocalTime = LocalTime + dtime
techage.SystemTime = techage.SystemTime + dtime
local item = pop()
while item do
local network = NetList[item.netkey]
local network = networks.get_network(item.tube_type, item.netID)
if network and network.alive and network.alive >= 0 then
--techage.distribute.power_distribution(LocalTime, network)
techage.power.power_distribution(LocalTime, network.mst_pos, network)
power_distribution(network, item.tube_type)
network.alive = network.alive - 1
push(item)
else
NetList[item.netkey] = nil
JobTable[item.netID] = nil
networks.delete_network(item.tube_type, item.netID)
end
item = pop()
end
end)
function techage.schedule.add_network(netkey, network)
if netkey then
if NetList[netkey] then -- already scheduled
NetList[netkey] = network
else
NetList[netkey] = network
push({netkey = netkey})
end
return NetList[netkey]
end
end
function techage.schedule.has_network(netkey)
if netkey then
return NetList[netkey] ~= nil
end
end
function techage.schedule.get_network(netkey)
if netkey then
return NetList[netkey]
function techage.schedule.start(tube_type, netID)
if not JobTable[netID] then
push({tube_type = tube_type, netID = netID})
JobTable[netID] = true
end
end

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -22,7 +22,7 @@ local Pipe = tubelib2.Tube:new({
max_tube_length = 12,
show_infotext = false,
force_to_use_tubes = true,
tube_type = "steam_pipe",
tube_type = "pipe1",
primary_node_names = {"techage:steam_pipeS", "techage:steam_pipeA"},
secondary_node_names = {"techage:cylinder", "techage:cylinder_on", "techage:boiler2"},
after_place_tube = function(pos, param2, tube_type, num_tubes)
@ -30,13 +30,6 @@ local Pipe = tubelib2.Tube:new({
end,
})
Pipe:register_on_tube_update(function(node, pos, out_dir, peer_pos, peer_in_dir)
minetest.registered_nodes[node.name].after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir)
end)
techage.SteamPipe = Pipe
minetest.register_node("techage:steam_pipeS", {
description = S("TA2 Steam Pipe"),
tiles = {
@ -57,7 +50,7 @@ minetest.register_node("techage:steam_pipeS", {
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
Pipe:after_dig_tube(pos, oldnode)
Pipe:after_dig_tube(pos, oldnode, oldmetadata)
end,
paramtype2 = "facedir", -- important!
@ -88,7 +81,7 @@ minetest.register_node("techage:steam_pipeA", {
},
after_dig_node = function(pos, oldnode, oldmetadata, digger)
Pipe:after_dig_tube(pos, oldnode)
Pipe:after_dig_tube(pos, oldnode, oldmetadata)
end,
paramtype2 = "facedir", -- important!
@ -117,3 +110,5 @@ minetest.register_craft({
{"default:bronze_ingot", '', ''},
},
})
techage.SteamPipe = Pipe

View File

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

Binary file not shown.

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -13,202 +13,91 @@
]]--
-- for lazy programmers
local P = minetest.string_to_pos
local M = minetest.get_meta
local S = techage.S
local CYCLE_TIME = 4
local STANDBY_TICKS = 2
local COUNTDOWN_TICKS = 2
local HEAT_STEP = 10
local WATER_CONSUMPTION = 0.5
local MAX_WATER = 10
local Pipe = techage.SteamPipe
local boiler = techage.boiler
local Water = {
["bucket:bucket_river_water"] = true,
["bucket:bucket_water"] = true,
["bucket:bucket_empty"] = true,
}
local function formspec(self, pos, mem)
local temp = mem.temperature or 20
local ratio = mem.power_ratio or 0
return "size[8,7]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"image_button[0,0.2;1,1;techage_form_inventory.png;storage;;true;false;]"..
"list[context;water;1,0.2;1,1;]"..
"image_button[0,1.6;1,1;techage_form_input.png;input;;true;false;]"..
"list[context;input;1,1.6;1,1;]"..
"image[1,1.6;1,1;bucket_water.png]"..
"image[1,1.6;1,1;techage_form_mask.png]"..
"image[2,0.5;1,2;techage_form_temp_bg.png^[lowpart:"..
temp..":techage_form_temp_fg.png]"..
"image[7,0.5;1,2;"..techage.power.formspec_power_bar(1, ratio).."]"..
"image_button[6,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]"..
"button[3,1.5;2,1;update;"..S("Update").."]"..
"list[current_player;main;0,3;8,4;]"..
"listring[current_name;water]"..
"listring[current_player;main]"..
default.get_hotbar_bg(0, 3)
end
local function can_start(pos, mem, state)
return mem.temperature and mem.temperature > 80
end
local function start_node(pos, mem, state)
mem.running = true
mem.power_ratio = 0
end
local function stop_node(pos, mem, state)
mem.running = false
mem.power_ratio = 0
end
local State = techage.NodeStates:new({
node_name_passive = "techage:boiler2",
cycle_time = CYCLE_TIME,
standby_ticks = STANDBY_TICKS,
has_item_meter = false,
formspec_func = formspec,
can_start = can_start,
start_node = start_node,
stop_node = stop_node,
})
local function get_water(pos)
local inv = M(pos):get_inventory()
local items = inv:get_stack("water", 1)
if items:get_count() > 0 then
local taken = items:take_item(1)
inv:set_stack("water", 1, items)
return true
end
return false
end
local function water_temperature(pos, mem)
mem.temperature = mem.temperature or 20
if mem.fire_trigger then
mem.temperature = math.min(mem.temperature + HEAT_STEP, 100)
else
mem.temperature = math.max(mem.temperature - HEAT_STEP, 20)
end
mem.fire_trigger = false
if mem.water_level == 0 then
if get_water(pos) then
mem.water_level = 100
else
mem.temperature = 20
end
end
return mem.temperature
end
local function steaming(pos, mem, temp)
local wc = WATER_CONSUMPTION * (mem.power_ratio or 1)
mem.water_level = math.max((mem.water_level or 0) - wc, 0)
local function steaming(pos, nvm, temp)
if temp >= 80 then
if mem.running then
State:keep_running(pos, mem, COUNTDOWN_TICKS)
else
State:fault(pos, mem)
end
else
State:stop(pos, mem)
minetest.get_node_timer(pos):start(CYCLE_TIME)
local wc = WATER_CONSUMPTION * (nvm.power_ratio or 1)
nvm.water_level = math.max((nvm.water_level or 0) - wc, 0)
end
end
local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos)
local temp = water_temperature(pos, mem)
if State:is_active(mem) then
steaming(pos, mem, temp)
local nvm = techage.get_nvm(pos)
local temp = boiler.water_temperature(pos, nvm)
steaming(pos, nvm, temp)
if techage.is_activeformspec(pos) then
M(pos):set_string("formspec", boiler.formspec(pos, nvm))
end
return mem.temperature > 20
return temp > 20
end
local function on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then
return
local function after_place_node(pos)
local node = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z})
if node.name == "techage:boiler1" then
local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", boiler.formspec(pos, nvm))
Pipe:after_place_node(pos)
end
local mem = tubelib2.get_mem(pos)
mem.temperature = mem.temperature or 20
State:state_button_event(pos, mem, fields)
end
local function after_dig_node(pos, oldnode)
Pipe:after_dig_node(pos)
techage.del_mem(pos)
end
-- boiler2: Main part, needed as generator
minetest.register_node("techage:boiler2", {
description = S("TA2 Boiler Top"),
tiles = {"techage_boiler2.png"},
drawtype = "mesh",
mesh = "techage_cylinder_09.obj",
selection_box = {
type = "fixed",
fixed = {-10/32, -48/32, -10/32, 10/32, 16/32, 10/32},
},
if fields.update then
if mem.temperature > 20 then
minetest.get_node_timer(pos):start(CYCLE_TIME)
end
M(pos):set_string("formspec", formspec(State, pos, mem))
end
end
local function on_rightclick(pos)
local mem = tubelib2.get_mem(pos)
M(pos):set_string("formspec", formspec(State, pos, mem))
end
local function can_dig(pos, player)
local inv = M(pos):get_inventory()
local mem = tubelib2.get_mem(pos)
return inv:is_empty("input") and not mem.running
end
local function move_to_water(pos)
local inv = M(pos):get_inventory()
local water_stack = inv:get_stack("water", 1)
local input_stack = inv:get_stack("input", 1)
can_dig = boiler.can_dig,
on_timer = node_timer,
on_rightclick = boiler.on_rightclick,
after_place_node = after_place_node,
after_dig_node = after_dig_node,
on_punch = boiler.on_punch,
if input_stack:get_name() == "bucket:bucket_empty" then
if input_stack:get_count() == 1 then
if water_stack:get_count() > 0 then
water_stack:set_count(water_stack:get_count() - 1)
input_stack = ItemStack("bucket:bucket_water")
inv:set_stack("water", 1, water_stack)
inv:set_stack("input", 1, input_stack)
paramtype = "light",
groups = {cracky=1},
on_rotate = screwdriver.disallow,
is_ground_content = false,
sounds = default.node_sound_metal_defaults(),
})
Pipe:add_secondary_node_names({"techage:boiler2"})
techage.register_node({"techage:boiler2"}, {
on_transfer = function(pos, in_dir, topic, payload)
if topic == "trigger" then
local nvm = techage.get_nvm(pos)
nvm.fire_trigger = true
if not minetest.get_node_timer(pos):is_started() then
minetest.get_node_timer(pos):start(CYCLE_TIME)
end
if (nvm.temperature or 20) > 80 then
nvm.power_ratio = techage.transfer(pos, 6, "trigger", nil, Pipe, {
"techage:cylinder", "techage:cylinder_on"}) or 0
return nvm.power_ratio
else
return 0
end
end
elseif water_stack:get_count() < MAX_WATER then
if water_stack:get_count() == 0 then
water_stack = ItemStack("default:water_source")
else
water_stack:set_count(water_stack:get_count() + 1)
end
input_stack = ItemStack("bucket:bucket_empty")
inv:set_stack("water", 1, water_stack)
inv:set_stack("input", 1, input_stack)
end
end
local function allow_metadata_inventory_put(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
if listname == "input" and Water[stack:get_name()] then
return stack:get_count()
end
return 0
end
local function allow_metadata_inventory_take(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
if listname == "input" then
return stack:get_count()
end
return 0
end
end,
})
minetest.register_node("techage:boiler1", {
description = S("TA2 Boiler Base"),
@ -227,73 +116,7 @@ minetest.register_node("techage:boiler1", {
sounds = default.node_sound_metal_defaults(),
})
-- boiler2: Main part, needed as generator
minetest.register_node("techage:boiler2", {
description = S("TA2 Boiler Top"),
tiles = {"techage_boiler2.png"},
drawtype = "mesh",
mesh = "techage_cylinder_09.obj",
selection_box = {
type = "fixed",
fixed = {-10/32, -48/32, -10/32, 10/32, 16/32, 10/32},
},
can_dig = can_dig,
on_timer = node_timer,
allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_take = allow_metadata_inventory_take,
allow_metadata_inventory_move = function(pos) return 0 end,
on_receive_fields = on_receive_fields,
on_rightclick = on_rightclick,
on_construct = function(pos)
local inv = M(pos):get_inventory()
inv:set_size('water', 1)
inv:set_size('input', 1)
end,
on_metadata_inventory_put = function(pos)
minetest.after(0.5, move_to_water, pos)
end,
paramtype = "light",
groups = {cracky=1},
on_rotate = screwdriver.disallow,
is_ground_content = false,
sounds = default.node_sound_metal_defaults(),
})
techage.power.register_node({"techage:boiler2"}, {
conn_sides = {"U"},
power_network = Pipe,
after_place_node = function(pos, placer)
local mem = tubelib2.init_mem(pos)
State:node_init(pos, mem, "")
local node = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z})
if node.name == "techage:boiler1" then
on_rightclick(pos)
end
end,
})
techage.register_node({"techage:boiler2"}, {
on_transfer = function(pos, in_dir, topic, payload)
if topic == "trigger" then
local mem = tubelib2.get_mem(pos)
mem.fire_trigger = true
if not minetest.get_node_timer(pos):is_started() then
minetest.get_node_timer(pos):start(CYCLE_TIME)
end
if mem.running then
mem.power_ratio = techage.transfer(pos, 6, "trigger", nil, Pipe, {
"techage:cylinder", "techage:cylinder_on"}) or 0
return mem.power_ratio
else
return 0
end
end
end
})
minetest.register_craft({
output = "techage:boiler1",

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -13,12 +13,16 @@
]]--
-- for lazy programmers
local P = minetest.string_to_pos
local M = minetest.get_meta
local S = techage.S
local Pipe = techage.SteamPipe
local function transfer_flywheel(pos, topic, payload)
return techage.transfer(pos, "R", topic, payload, nil,
{"techage:flywheel", "techage:flywheel_on"})
end
local function swap_node(pos, name)
local node = techage.get_node_lvm(pos)
if node.name == name then
@ -28,6 +32,41 @@ local function swap_node(pos, name)
minetest.swap_node(pos, node)
end
local function play_sound(pos)
local mem = techage.get_mem(pos)
mem.handle = minetest.sound_play("techage_steamengine", {
pos = pos,
gain = 0.5,
max_hear_distance = 10,
loop = true})
if mem.handle == -1 then
minetest.after(1, play_sound, pos)
end
end
local function stop_sound(pos)
local mem = techage.get_mem(pos)
if mem.handle then
minetest.sound_stop(mem.handle)
mem.handle = nil
end
end
local function after_place_node(pos)
Pipe:after_place_node(pos)
end
local function after_dig_node(pos, oldnode)
stop_sound(pos)
Pipe:after_dig_node(pos)
techage.del_mem(pos)
end
local function tubelib2_on_update2(pos, outdir, tlib2, node)
swap_node(pos, "techage:cylinder")
stop_sound(pos)
end
minetest.register_node("techage:cylinder", {
description = S("TA2 Cylinder"),
tiles = {
@ -40,6 +79,10 @@ minetest.register_node("techage:cylinder", {
"techage_filling_ta2.png^techage_cylinder.png^techage_frame_ta2.png",
},
after_place_node = after_place_node,
after_dig_node = after_dig_node,
tubelib2_on_update2 = tubelib2_on_update2,
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2},
on_rotate = screwdriver.disallow,
@ -77,6 +120,8 @@ minetest.register_node("techage:cylinder_on", {
},
},
tubelib2_on_update2 = tubelib2_on_update2,
paramtype2 = "facedir",
groups = {not_in_creative_inventory=1},
diggable = false,
@ -85,42 +130,38 @@ minetest.register_node("techage:cylinder_on", {
sounds = default.node_sound_wood_defaults(),
})
techage.power.register_node({"techage:cylinder", "techage:cylinder_on"}, {
conn_sides = {"L"},
power_network = Pipe,
after_tube_update = function(node, pos, out_dir, peer_pos, peer_in_dir)
local mem = tubelib2.get_mem(pos)
mem.running = false
swap_node(pos, "techage:cylinder")
end,
})
Pipe:add_secondary_node_names({"techage:cylinder", "techage:cylinder_on"})
-- used by firebox
techage.register_node({"techage:cylinder", "techage:cylinder_on"}, {
on_transfer = function(pos, in_dir, topic, payload)
local mem = tubelib2.get_mem(pos)
if topic == "trigger" then
local power = techage.transfer(pos, "R", "trigger", nil, nil, {
"techage:flywheel", "techage:flywheel_on"}) or 0
if not power then
return 0
elseif power > 0 and not mem.running then
swap_node(pos, "techage:cylinder_on")
mem.running = true
return power
elseif power <= 0 and mem.running then
local nvm = techage.get_nvm(pos)
if topic == "trigger" then -- used by firebox
local power = transfer_flywheel(pos, topic, payload)
if not power or power <= 0 and nvm.running then
swap_node(pos, "techage:cylinder")
mem.running = false
stop_sound(pos)
nvm.running = false
return 0
else
return power
end
elseif topic == "stop" then
return power
elseif topic == "start" then -- used by flywheel
swap_node(pos, "techage:cylinder_on")
play_sound(pos)
nvm.running = true
return true
elseif topic == "stop" then -- used by flywheel
swap_node(pos, "techage:cylinder")
mem.running = false
stop_sound(pos)
nvm.running = false
return true
end
end
end,
on_node_load = function(pos, node)
--print("on_node_load", node.name)
if node.name == "techage:cylinder_on" then
play_sound(pos)
end
end,
})
minetest.register_craft({

View File

@ -23,8 +23,8 @@ local CYCLE_TIME = 2
local BURN_CYCLE_FACTOR = 0.8
local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos)
if mem.running then
local nvm = techage.get_nvm(pos)
if nvm.running then
local power = techage.transfer(
{x=pos.x, y=pos.y+2, z=pos.z},
nil, -- outdir
@ -33,19 +33,22 @@ local function node_timer(pos, elapsed)
nil, -- network
{"techage:boiler2"} -- nodenames
)
mem.burn_cycles = (mem.burn_cycles or 0) - math.max((power or 0.1), 0.1)
if mem.burn_cycles <= 0 then
nvm.burn_cycles = (nvm.burn_cycles or 0) - math.max((power or 0.1), 0.1)
if nvm.burn_cycles <= 0 then
local taken = firebox.get_fuel(pos)
if taken then
mem.burn_cycles = (firebox.Burntime[taken:get_name()] or 1) / CYCLE_TIME * BURN_CYCLE_FACTOR
mem.burn_cycles_total = mem.burn_cycles
nvm.burn_cycles = (firebox.Burntime[taken:get_name()] or 1) / CYCLE_TIME * BURN_CYCLE_FACTOR
nvm.burn_cycles_total = nvm.burn_cycles
else
mem.running = false
nvm.running = false
firebox.swap_node(pos, "techage:firebox")
M(pos):set_string("formspec", firebox.formspec(mem))
M(pos):set_string("formspec", firebox.formspec(nvm))
return false
end
end
if techage.is_activeformspec(pos) then
M(pos):set_string("formspec", firebox.formspec(nvm))
end
return true
end
end
@ -71,27 +74,26 @@ minetest.register_node("techage:firebox", {
can_dig = firebox.can_dig,
allow_metadata_inventory_put = firebox.allow_metadata_inventory_put,
allow_metadata_inventory_take = firebox.allow_metadata_inventory_take,
on_receive_fields = firebox.on_receive_fields,
on_rightclick = firebox.on_rightclick,
on_construct = function(pos)
local mem = tubelib2.init_mem(pos)
mem.running = false
mem.burn_cycles = 0
local nvm = techage.get_nvm(pos)
nvm.running = false
nvm.burn_cycles = 0
local meta = M(pos)
meta:set_string("formspec", firebox.formspec(mem))
meta:set_string("formspec", firebox.formspec(nvm))
local inv = meta:get_inventory()
inv:set_size('fuel', 1)
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
local mem = tubelib2.init_mem(pos)
mem.running = true
local nvm = techage.get_nvm(pos)
nvm.running = true
-- activate the formspec fire temporarily
mem.burn_cycles = firebox.Burntime[stack:get_name()] / CYCLE_TIME
mem.burn_cycles_total = mem.burn_cycles
M(pos):set_string("formspec", firebox.formspec(mem))
mem.burn_cycles = 0
nvm.burn_cycles = firebox.Burntime[stack:get_name()] / CYCLE_TIME
nvm.burn_cycles_total = nvm.burn_cycles
M(pos):set_string("formspec", firebox.formspec(nvm))
nvm.burn_cycles = 0
firebox.swap_node(pos, "techage:firebox_on")
minetest.get_node_timer(pos):start(CYCLE_TIME)
end,
@ -163,9 +165,9 @@ minetest.register_lbm({
nodenames = {"techage:firebox_on"},
run_at_every_load = true,
action = function(pos, node)
local nvm = techage.get_nvm(pos)
nvm.running = true
minetest.get_node_timer(pos):start(CYCLE_TIME)
local mem = tubelib2.get_mem(pos)
mem.power_level = nil
end
})

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -13,7 +13,6 @@
]]--
-- for lazy programmers
local P = minetest.string_to_pos
local M = minetest.get_meta
local S = techage.S
@ -24,42 +23,50 @@ local PWR_CAPA = 25
local Axle = techage.Axle
local power = techage.power
local networks = techage.networks
local function formspec(self, pos, mem)
return "size[8,7]"..
-- Axles texture animation
local function switch_axles(pos, on)
local outdir = M(pos):get_int("outdir")
Axle:switch_tube_line(pos, outdir, on and "on" or "off")
end
local function formspec(self, pos, nvm)
return "size[4,4]"..
"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..
"image[6,0.5;1,2;"..power.formspec_power_bar(PWR_CAPA, mem.provided).."]"..
"image_button[5,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]"..
"button[2,1.5;2,1;update;"..S("Update").."]"..
"list[current_player;main;0,3;8,4;]"..
default.get_hotbar_bg(0, 3)
power.formspec_label_bar(0, 0.8, S("power"), PWR_CAPA, nvm.provided)..
"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
local function can_start(pos, mem, state)
return (mem.firebox_trigger or 0) > 0 -- by means of firebox
local function transfer_cylinder(pos, topic, payload)
return techage.transfer(pos, "L", topic, payload, nil,
{"techage:cylinder", "techage:cylinder_on"})
end
local function start_node(pos, mem, state)
mem.generating = true -- needed for power distribution
techage.switch_axles(pos, true)
mem.handle = minetest.sound_play("techage_steamengine", {
pos = pos,
gain = 0.5,
max_hear_distance = 10})
power.generator_start(pos, mem, PWR_CAPA)
local function can_start(pos, nvm, state)
return (nvm.firebox_trigger or 0) > 0 -- by means of firebox
end
local function stop_node(pos, mem, state)
mem.generating = false
techage.switch_axles(pos, false)
if mem.handle then
minetest.sound_stop(mem.handle)
mem.handle = nil
end
power.generator_stop(pos, mem)
mem.provided = 0
local function start_node(pos, nvm, state)
switch_axles(pos, true)
local outdir = M(pos):get_int("outdir")
power.generator_start(pos, Axle, CYCLE_TIME, outdir)
transfer_cylinder(pos, "start")
nvm.running = true
end
local function stop_node(pos, nvm, state)
switch_axles(pos, false)
local outdir = M(pos):get_int("outdir")
power.generator_stop(pos, Axle, outdir)
nvm.provided = 0
transfer_cylinder(pos, "stop")
nvm.running = false
end
local State = techage.NodeStates:new({
@ -74,48 +81,62 @@ local State = techage.NodeStates:new({
})
local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos)
if mem.generating then
mem.firebox_trigger = (mem.firebox_trigger or 0) - 1
if mem.firebox_trigger <= 0 then
State:nopower(pos, mem)
mem.generating = false
techage.switch_axles(pos, false)
power.generator_stop(pos, mem)
mem.provided = 0
techage.transfer(pos, "L", "stop", nil, nil, {"techage:cylinder_on"})
else
mem.provided = power.generator_alive(pos, mem)
State:keep_running(pos, mem, COUNTDOWN_TICKS)
mem.handle = minetest.sound_play("techage_steamengine", {
pos = pos,
gain = 0.5,
max_hear_distance = 10})
end
local nvm = techage.get_nvm(pos)
nvm.firebox_trigger = (nvm.firebox_trigger or 0) - 1
if nvm.firebox_trigger <= 0 then
State:nopower(pos, nvm)
stop_node(pos, nvm, State)
transfer_cylinder(pos, "stop")
else
local outdir = M(pos):get_int("outdir")
nvm.provided = power.generator_alive(pos, Axle, CYCLE_TIME, outdir)
State:keep_running(pos, nvm, COUNTDOWN_TICKS)
end
return State:is_active(mem)
if techage.is_activeformspec(pos) then
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
return State:is_active(nvm)
end
local function on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then
return
end
local mem = tubelib2.get_mem(pos)
State:state_button_event(pos, mem, fields)
if fields.update then
M(pos):set_string("formspec", formspec(State, pos, mem))
end
local nvm,_ = techage.get_nvm(pos, true)
State:state_button_event(pos, nvm, fields)
end
local function on_rightclick(pos)
local mem = tubelib2.get_mem(pos)
M(pos):set_string("formspec", formspec(State, pos, mem))
if mem.generating then
minetest.get_node_timer(pos):start(CYCLE_TIME)
end
local function on_rightclick(pos, node, clicker)
local nvm = techage.get_nvm(pos)
techage.set_activeformspec(pos, clicker)
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
local function after_place_node(pos)
local nvm = techage.get_nvm(pos)
State:node_init(pos, nvm, "")
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
M(pos):set_string("formspec", formspec(State, pos, nvm))
Axle:after_place_node(pos)
end
local function after_dig_node(pos, oldnode)
Axle:after_dig_node(pos)
techage.del_mem(pos)
end
local function tubelib2_on_update2(pos, outdir, tlib2, node)
power.update_network(pos, outdir, tlib2)
end
local net_def = {
axle = {
sides = {R = 1},
ntype = "gen1",
nominal = PWR_CAPA,
},
}
minetest.register_node("techage:flywheel", {
description = S("TA2 Flywheel"),
tiles = {
@ -131,6 +152,10 @@ minetest.register_node("techage:flywheel", {
on_receive_fields = on_receive_fields,
on_rightclick = on_rightclick,
on_timer = node_timer,
after_place_node = after_place_node,
after_dig_node = after_dig_node,
tubelib2_on_update2 = tubelib2_on_update2,
networks = net_def,
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2},
@ -161,8 +186,8 @@ minetest.register_node("techage:flywheel_on", {
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
aspect_w = 64,
aspect_h = 64,
length = 1.2,
},
},
@ -171,8 +196,8 @@ minetest.register_node("techage:flywheel_on", {
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
aspect_w = 64,
aspect_h = 64,
length = 1.2,
},
},
@ -181,6 +206,10 @@ minetest.register_node("techage:flywheel_on", {
on_receive_fields = on_receive_fields,
on_rightclick = on_rightclick,
on_timer = node_timer,
after_place_node = after_place_node,
after_dig_node = after_dig_node,
tubelib2_on_update2 = tubelib2_on_update2,
networks = net_def,
drop = "",
paramtype2 = "facedir",
@ -191,29 +220,24 @@ minetest.register_node("techage:flywheel_on", {
sounds = default.node_sound_wood_defaults(),
})
techage.power.register_node({"techage:flywheel", "techage:flywheel_on"}, {
conn_sides = {"R"},
power_network = Axle,
after_place_node = function(pos, placer)
local mem = tubelib2.init_mem(pos)
State:node_init(pos, mem, "")
on_rightclick(pos)
end,
})
Axle:add_secondary_node_names({"techage:flywheel", "techage:flywheel_on"})
techage.register_node({"techage:flywheel", "techage:flywheel_on"}, {
on_transfer = function(pos, in_dir, topic, payload)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
if topic == "trigger" then
mem.firebox_trigger = 3
if mem.generating then
return math.max((mem.provided or PWR_CAPA) / PWR_CAPA, 0.1)
nvm.firebox_trigger = 3
if nvm.running then
return math.max((nvm.provided or PWR_CAPA) / PWR_CAPA, 0.1)
else
return 0
end
end
end
end,
on_node_load = function(pos, node)
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
State:on_node_load(pos)
end,
})
minetest.register_craft({
@ -225,3 +249,4 @@ minetest.register_craft({
},
})

View File

@ -1,117 +0,0 @@
--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
TA2 Gearbox
]]--
-- for lazy programmers
local P = minetest.string_to_pos
local M = minetest.get_meta
local S = techage.S
local PWR_NEEDED = 1
local CYCLE_TIME = 4
local Axle = techage.Axle
local power = techage.power
local function swap_node(pos, name)
local node = techage.get_node_lvm(pos)
if node.name == name then
return
end
node.name = name
minetest.swap_node(pos, node)
end
local function on_power(pos, mem)
swap_node(pos, "techage:gearbox_on")
techage.switch_axles(pos, true)
end
local function on_nopower(pos, mem)
swap_node(pos, "techage:gearbox")
techage.switch_axles(pos, false)
end
local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos)
power.consumer_alive(pos, mem)
return true
end
-- to be able to restart the node after server crashes
local function on_rightclick(pos)
local mem = tubelib2.get_mem(pos)
minetest.get_node_timer(pos):start(CYCLE_TIME)
power.consumer_start(pos, mem, CYCLE_TIME, PWR_NEEDED)
end
minetest.register_node("techage:gearbox", {
description = S("TA2 Gearbox"),
tiles = {"techage_filling_ta2.png^techage_axle_gearbox.png^techage_frame_ta2.png"},
on_rightclick = on_rightclick,
on_timer = node_timer,
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2},
on_rotate = screwdriver.disallow,
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
minetest.register_node("techage:gearbox_on", {
tiles = {
-- up, down, right, left, back, front
{
image = "techage_filling4_ta2.png^techage_axle_gearbox4.png^techage_frame4_ta2.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 0.6,
},
},
},
on_rightclick = on_rightclick,
on_timer = node_timer,
paramtype2 = "facedir",
groups = {not_in_creative_inventory=1},
diggable = false,
drop = "",
on_rotate = screwdriver.disallow,
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
techage.power.register_node({"techage:gearbox", "techage:gearbox_on"}, {
power_network = Axle,
on_power = on_power,
on_nopower = on_nopower,
after_place_node = function(pos, placer, itemstack, pointed_thing)
on_rightclick(pos)
end,
after_tube_update = function(node, pos, out_dir, peer_pos, peer_in_dir)
techage.switch_axles(pos, node.name == "techage:gearbox_on")
end,
})
minetest.register_craft({
output = "techage:gearbox 2",
recipe = {
{"default:junglewood", "techage:axle", "default:wood"},
{"techage:axle", "techage:iron_ingot", "techage:axle"},
{"default:wood", "techage:axle", "default:junglewood"},
},
})

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 219 B

After

Width:  |  Height:  |  Size: 213 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 219 B

After

Width:  |  Height:  |  Size: 213 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 866 B

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -88,10 +88,10 @@ local function read_state(itemstack, user, pointed_thing)
load = dump(load)
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": load = "..load.." % ")
end
local capa = techage.send_single("0", number, "capa", nil)
if capa and capa ~= "" and capa ~= "unsupported" then
capa = dump(capa)
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": capa = "..capa.." % ")
local size = techage.send_single("0", number, "size", nil)
if size and size ~= "" and size ~= "unsupported" then
size = dump(size)
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": size = "..size.." units ")
end
local owner = M(pos):get_string("owner") or ""
if owner ~= "" then

View File

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