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 -- for lazy programmers
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end local P2S = minetest.pos_to_string
local P = minetest.string_to_pos
local M = minetest.get_meta local M = minetest.get_meta
local S = techage.S
local PWR_NEEDED = 5 local PWR_NEEDED = 5
local CYCLE_TIME = 4 local CYCLE_TIME = 2
local Cable = techage.ElectricCable local Cable = techage.ElectricCable
local power = techage.power local power = techage.power
@ -18,59 +32,74 @@ local function swap_node(pos, name)
minetest.swap_node(pos, node) minetest.swap_node(pos, node)
end end
local function on_power(pos, mem) local function on_power(pos)
if mem.running then print("on_power sink "..P2S(pos))
swap_node(pos, "techage:sink_on") swap_node(pos, "techage:sink_on")
minetest.get_node_timer(pos):start(CYCLE_TIME)
M(pos):set_string("infotext", "on") M(pos):set_string("infotext", "on")
end
end end
local function on_nopower(pos, mem) local function on_nopower(pos)
print("on_nopower sink "..P2S(pos))
swap_node(pos, "techage:sink") swap_node(pos, "techage:sink")
M(pos):set_string("infotext", "nopower") M(pos):set_string("infotext", "off")
end end
local function node_timer(pos, elapsed) local function node_timer(pos, elapsed)
--print("node_timer sink "..S(pos)) --print("node_timer sink "..P2S(pos))
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
power.consumer_alive(pos, mem) power.consumer_alive(pos, Cable, CYCLE_TIME)
return mem.running -- 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 end
local function on_rightclick(pos, node, clicker) local function on_rightclick(pos, node, clicker)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if not mem.running and power.power_available(pos, mem, PWR_NEEDED) then if not nvm.running and power.power_available(pos, Cable) then
mem.running = true nvm.running = true
power.consumer_start(pos, mem, CYCLE_TIME, PWR_NEEDED) -- 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", "...") M(pos):set_string("infotext", "...")
else else
mem.running = false nvm.running = false
swap_node(pos, "techage:sink") swap_node(pos, "techage:sink")
power.consumer_stop(pos, mem) power.consumer_stop(pos, Cable)
minetest.get_node_timer(pos):stop() minetest.get_node_timer(pos):stop()
M(pos):set_string("infotext", "off") M(pos):set_string("infotext", "off")
end end
end end
--
-- Modul shows the usage of the power2 alternative function set
--
local function after_place_node(pos) local function after_place_node(pos)
local mem = tubelib2.init_mem(pos) local nvm = techage.get_nvm(pos)
M(pos):set_string("infotext", "off") M(pos):set_string("infotext", "off")
techage.power.after_place_node(pos) Cable:after_place_node(pos)
end end
local function after_dig_node(pos, oldnode) local function after_dig_node(pos, oldnode)
techage.power.after_dig_node(pos, oldnode) Cable:after_dig_node(pos)
tubelib2.del_mem(pos) techage.del_mem(pos)
end end
local function after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir) local function tubelib2_on_update2(pos, outdir, tlib2, node)
techage.power.after_tube_update2(node, pos, out_dir, peer_pos, peer_in_dir) power.update_network(pos, outdir, tlib2)
end 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", { minetest.register_node("techage:sink", {
description = "Sink", description = "Sink",
tiles = {'techage_electric_button.png'}, tiles = {'techage_electric_button.png'},
@ -79,13 +108,13 @@ minetest.register_node("techage:sink", {
on_rightclick = on_rightclick, on_rightclick = on_rightclick,
after_place_node = after_place_node, after_place_node = after_place_node,
after_dig_node = after_dig_node, after_dig_node = after_dig_node,
after_tube_update = after_tube_update, tubelib2_on_update2 = tubelib2_on_update2,
networks = net_def,
paramtype = "light", paramtype = "light",
light_source = 0, light_source = 0,
sunlight_propagates = true,
paramtype2 = "facedir", paramtype2 = "facedir",
groups = {choppy=2, cracky=2, crumbly=2}, groups = {choppy = 2, cracky = 2, crumbly = 2},
is_ground_content = false, is_ground_content = false,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
}) })
@ -98,22 +127,18 @@ minetest.register_node("techage:sink_on", {
on_rightclick = on_rightclick, on_rightclick = on_rightclick,
after_place_node = after_place_node, after_place_node = after_place_node,
after_dig_node = after_dig_node, after_dig_node = after_dig_node,
after_tube_update = after_tube_update, tubelib2_on_update2 = tubelib2_on_update2,
networks = net_def,
paramtype = "light", paramtype = "light",
light_source = minetest.LIGHT_MAX, light_source = minetest.LIGHT_MAX,
sunlight_propagates = true,
paramtype2 = "facedir", paramtype2 = "facedir",
diggable = false, diggable = false,
drop = "", drop = "",
groups = {not_in_creative_inventory=1}, groups = {not_in_creative_inventory = 1},
is_ground_content = false, is_ground_content = false,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
}) })
-- Alternative registration function Cable:add_secondary_node_names({"techage:sink", "techage:sink_on"})
techage.power.enrich_node({"techage:sink", "techage:sink_on"}, {
power_network = Cable,
on_power = on_power,
on_nopower = on_nopower,
})

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -25,7 +25,7 @@ local CYCLE_TIME = 4
local Probability = {} local Probability = {}
local function formspec(self, pos, mem) local function formspec(self, pos, nvm)
return "size[8,8]".. return "size[8,8]"..
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
@ -33,9 +33,10 @@ local function formspec(self, pos, mem)
"list[context;src;0,0;3,3;]".. "list[context;src;0,0;3,3;]"..
"item_image[0,0;1,1;default:gravel]".. "item_image[0,0;1,1;default:gravel]"..
"image[0,0;1,1;techage_form_mask.png]".. "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[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[context;dst;5,0;3,3;]"..
"list[current_player;main;0,4;8,4;]".. "list[current_player;main;0,4;8,4;]"..
"listring[context;dst]".. "listring[context;dst]"..
@ -101,12 +102,14 @@ local function determine_water_dir(pos)
end end
local function set_velocity(obj, pos, vel) local function set_velocity(obj, pos, vel)
if obj then
obj:set_acceleration({x = 0, y = 0, z = 0}) obj:set_acceleration({x = 0, y = 0, z = 0})
local p = obj:get_pos() local p = obj:get_pos()
if p then if p then
obj:set_pos({x=p.x, y=p.y-0.3, z=p.z}) obj:set_pos({x=p.x, y=p.y-0.3, z=p.z})
obj:set_velocity(vel) obj:set_velocity(vel)
end end
end
end end
local function add_object(pos, name) local function add_object(pos, name)
@ -126,12 +129,12 @@ local function get_random_gravel_ore()
end end
end end
local function washing(pos, crd, mem, inv) local function washing(pos, crd, nvm, inv)
-- for testing purposes -- for testing purposes
if inv:contains_item("src", ItemStack("default:stick")) then if inv:contains_item("src", ItemStack("default:stick")) then
add_object({x=pos.x, y=pos.y+1, z=pos.z}, "default:stick") add_object({x=pos.x, y=pos.y+1, z=pos.z}, "default:stick")
inv:remove_item("src", ItemStack("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 return
end 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) add_object({x=pos.x, y=pos.y+1, z=pos.z}, ore)
end end
else else
crd.State:idle(pos, mem) crd.State:idle(pos, nvm)
return return
end end
if not inv:room_for_item("dst", dst) then if not inv:room_for_item("dst", dst) then
crd.State:idle(pos, mem) crd.State:idle(pos, nvm)
return return
end end
inv:add_item("dst", dst) inv:add_item("dst", dst)
inv:remove_item("src", src) inv:remove_item("src", src)
crd.State:keep_running(pos, mem, COUNTDOWN_TICKS) crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
end end
local function keep_running(pos, elapsed) local function keep_running(pos, elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
local crd = CRD(pos) local crd = CRD(pos)
local inv = M(pos):get_inventory() local inv = M(pos):get_inventory()
washing(pos, crd, mem, inv) washing(pos, crd, nvm, inv)
return crd.State:is_active(mem) return crd.State:is_active(nvm)
end end
local function on_receive_fields(pos, formname, fields, player) local function on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then if minetest.is_protected(pos, player:get_player_name()) then
return return
end end
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
CRD(pos).State:state_button_event(pos, mem, fields) CRD(pos).State:state_button_event(pos, nvm, fields)
end end
local function can_dig(pos, player) local function can_dig(pos, player)
@ -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="techage:usmium_nuggets", probability=30})
techage.add_rinser_recipe({input="techage:sieved_gravel", output="default:copper_lump", probability=20}) 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 -- Consumer Related Data
local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).consumer end local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).consumer end
local STANDBY_TICKS = 10 local STANDBY_TICKS = 6
local COUNTDOWN_TICKS = 10 local COUNTDOWN_TICKS = 4
local CYCLE_TIME = 4 local CYCLE_TIME = 4
local get_random_gravel_ore = techage.gravelsieve_get_random_gravel_ore local get_random_gravel_ore = techage.gravelsieve_get_random_gravel_ore
local get_random_basalt_ore = techage.gravelsieve_get_random_basalt_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]".. return "size[8,8]"..
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
@ -35,9 +35,10 @@ local function formspec(self, pos, mem)
"list[context;src;0,0;3,3;]".. "list[context;src;0,0;3,3;]"..
"item_image[0,0;1,1;default:gravel]".. "item_image[0,0;1,1;default:gravel]"..
"image[0,0;1,1;techage_form_mask.png]".. "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[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[context;dst;5,0;3,3;]"..
"list[current_player;main;0,4;8,4;]".. "list[current_player;main;0,4;8,4;]"..
"listring[context;dst]".. "listring[context;dst]"..
@ -60,8 +61,7 @@ local function allow_metadata_inventory_put(pos, listname, index, stack, player)
end end
local function allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player) 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 = M(pos):get_inventory()
local inv = meta:get_inventory()
local stack = inv:get_stack(from_list, from_index) local stack = inv:get_stack(from_list, from_index)
return allow_metadata_inventory_put(pos, to_list, to_index, stack, player) return allow_metadata_inventory_put(pos, to_list, to_index, stack, player)
end end
@ -73,39 +73,38 @@ local function allow_metadata_inventory_take(pos, listname, index, stack, player
return stack:get_count() return stack:get_count()
end end
local function sieving(pos, crd, mem, inv) local function sieving(pos, crd, nvm, inv)
local src, dst local src, dst
if inv:contains_item("src", ItemStack("techage:basalt_gravel")) then if inv:contains_item("src", ItemStack("techage:basalt_gravel")) then
dst, src = get_random_basalt_ore(), ItemStack("techage:basalt_gravel") dst, src = get_random_basalt_ore(), ItemStack("techage:basalt_gravel")
elseif inv:contains_item("src", ItemStack("default:gravel")) then elseif inv:contains_item("src", ItemStack("default:gravel")) then
dst, src = get_random_gravel_ore(), ItemStack("default:gravel") dst, src = get_random_gravel_ore(), ItemStack("default:gravel")
else else
crd.State:idle(pos, mem) crd.State:idle(pos, nvm)
return return
end end
if not inv:room_for_item("dst", dst) then if not inv:room_for_item("dst", dst) then
crd.State:idle(pos, mem) crd.State:idle(pos, nvm)
return return
end end
inv:add_item("dst", dst) inv:add_item("dst", dst)
inv:remove_item("src", src) inv:remove_item("src", src)
crd.State:keep_running(pos, mem, COUNTDOWN_TICKS) crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
end end
local function keep_running(pos, elapsed) local function keep_running(pos, elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
local crd = CRD(pos) local crd = CRD(pos)
local inv = M(pos):get_inventory() local inv = M(pos):get_inventory()
sieving(pos, crd, mem, inv) sieving(pos, crd, nvm, inv)
return crd.State:is_active(mem)
end end
local function on_receive_fields(pos, formname, fields, player) local function on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then if minetest.is_protected(pos, player:get_player_name()) then
return return
end end
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
CRD(pos).State:state_button_event(pos, mem, fields) CRD(pos).State:state_button_event(pos, nvm, fields)
end end
local function can_dig(pos, player) local function can_dig(pos, player)

View File

@ -14,11 +14,11 @@
-- for lazy programmers -- for lazy programmers
local M = minetest.get_meta local M = minetest.get_meta
local S = techage.S
-- Consumer Related Data -- Consumer Related Data
local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).consumer end local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).consumer end
local S = techage.S
local STANDBY_TICKS = 6 local STANDBY_TICKS = 6
local COUNTDOWN_TICKS = 4 local COUNTDOWN_TICKS = 4
local CYCLE_TIME = 4 local CYCLE_TIME = 4
@ -27,7 +27,7 @@ local CYCLE_TIME = 4
-- Grinder recipes -- Grinder recipes
local Recipes = {} local Recipes = {}
local function formspec(self, pos, mem) local function formspec(self, pos, nvm)
return "size[8,8]".. return "size[8,8]"..
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
@ -35,9 +35,10 @@ local function formspec(self, pos, mem)
"list[context;src;0,0;3,3;]".. "list[context;src;0,0;3,3;]"..
"item_image[0,0;1,1;default:cobble]".. "item_image[0,0;1,1;default:cobble]"..
"image[0,0;1,1;techage_form_mask.png]".. "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[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[context;dst;5,0;3,3;]"..
"item_image[5,0;1,1;default:gravel]".. "item_image[5,0;1,1;default:gravel]"..
"image[5,0;1,1;techage_form_mask.png]".. "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 return false
end end
local function grinding(pos, crd, mem, inv) local function grinding(pos, crd, nvm, inv)
local num_items = 0 local num_items = 0
for idx,stack in ipairs(inv:get_list("src")) do for idx,stack in ipairs(inv:get_list("src")) do
if not stack:is_empty() then if not stack:is_empty() then
local name = stack:get_name() local name = stack:get_name()
if Recipes[name] then if Recipes[name] then
if src_to_dst(stack, idx, crd.num_items, inv, 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 else
crd.State:blocked(pos, mem) crd.State:blocked(pos, nvm)
end end
else else
crd.State:fault(pos, mem) crd.State:fault(pos, nvm)
end end
return return
end end
end end
crd.State:idle(pos, mem) crd.State:idle(pos, nvm)
end end
local function keep_running(pos, elapsed) local function keep_running(pos, elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
local crd = CRD(pos) local crd = CRD(pos)
local inv = M(pos):get_inventory() local inv = M(pos):get_inventory()
grinding(pos, crd, mem, inv) grinding(pos, crd, nvm, inv)
end end
local function on_receive_fields(pos, formname, fields, player) local function on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then if minetest.is_protected(pos, player:get_player_name()) then
return return
end end
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
CRD(pos).State:state_button_event(pos, mem, fields) CRD(pos).State:state_button_event(pos, nvm, fields)
end end
local function can_dig(pos, player) local function can_dig(pos, player)
@ -183,7 +184,12 @@ local tubing = {
end end
end, end,
on_recv_message = function(pos, src, topic, payload) 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, end,
on_node_load = function(pos) on_node_load = function(pos)
CRD(pos).State:on_node_load(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"}) 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 TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -23,16 +23,17 @@ local STANDBY_TICKS = 4
local COUNTDOWN_TICKS = 2 local COUNTDOWN_TICKS = 2
local CYCLE_TIME = 8 local CYCLE_TIME = 8
local function formspec(self, pos, mem) local function formspec(self, pos, nvm)
return "size[9,8.5]".. return "size[9,8.5]"..
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
"list[context;src;0,0;1,4;]".. "list[context;src;0,0;1,4;]"..
"image[0,0;1,1;bucket.png]".. "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[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[context;dst;2,0;7,4;]"..
"list[current_player;main;0.5,4.5;8,4;]".. "list[current_player;main;0.5,4.5;8,4;]"..
"listring[current_player;main]".. "listring[current_player;main]"..
@ -73,7 +74,7 @@ local function test_liquid(node)
end end
end end
local function sample_liquid(pos, crd, mem, inv) local function sample_liquid(pos, crd, nvm, inv)
local meta = M(pos) local meta = M(pos)
local water_pos = minetest.string_to_pos(meta:get_string("water_pos")) local water_pos = minetest.string_to_pos(meta:get_string("water_pos"))
local giving_back = test_liquid(techage.get_node_lvm(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) minetest.remove_node(water_pos)
inv:remove_item("src", ItemStack("bucket:bucket_empty")) inv:remove_item("src", ItemStack("bucket:bucket_empty"))
inv:add_item("dst", ItemStack(giving_back)) inv:add_item("dst", ItemStack(giving_back))
crd.State:keep_running(pos, mem, COUNTDOWN_TICKS) crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
else else
crd.State:idle(pos, mem) crd.State:idle(pos, nvm)
end end
else else
crd.State:fault(pos, mem) crd.State:fault(pos, nvm)
end end
end end
local function keep_running(pos, elapsed) local function keep_running(pos, elapsed)
--if tubelib.data_not_corrupted(pos) then --if tubelib.data_not_corrupted(pos) then
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
local crd = CRD(pos) local crd = CRD(pos)
local inv = M(pos):get_inventory() local inv = M(pos):get_inventory()
sample_liquid(pos, crd, mem, inv) sample_liquid(pos, crd, nvm, inv)
end end
local function on_receive_fields(pos, formname, fields, player) local function on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then if minetest.is_protected(pos, player:get_player_name()) then
return return
end end
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
CRD(pos).State:state_button_event(pos, mem, fields) CRD(pos).State:state_button_event(pos, nvm, fields)
end end
local function can_dig(pos, player) local function can_dig(pos, player)
@ -121,7 +122,7 @@ local tiles = {}
-- '{power}' will be replaced by the power PNG -- '{power}' will be replaced by the power PNG
tiles.pas = { tiles.pas = {
-- up, down, right, left, back, front -- 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_filling_ta#.png^techage_frame_ta#.png^techage_appl_outp.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", "techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_inp.png",
@ -130,7 +131,7 @@ tiles.pas = {
} }
tiles.act = { tiles.act = {
-- up, down, right, left, back, front -- 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_filling_ta#.png^techage_frame_ta#.png^techage_appl_outp.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", "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) inv:set_size("dst", 28)
local water_pos = techage.get_pos(pos, "B") local water_pos = techage.get_pos(pos, "B")
M(pos):set_string("water_pos", minetest.pos_to_string(water_pos)) M(pos):set_string("water_pos", minetest.pos_to_string(water_pos))
techage.power.set_conn_dirs(pos, {"U"})
end, end,
can_dig = can_dig, can_dig = can_dig,
node_timer = keep_running, node_timer = keep_running,
@ -201,6 +201,7 @@ local node_name_ta2, node_name_ta3, node_name_ta4 =
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
num_items = {0,1,2,4}, num_items = {0,1,2,4},
power_consumption = {0,3,5,8}, power_consumption = {0,3,5,8},
power_sides = {U=1},
}) })
minetest.register_craft({ minetest.register_craft({

View File

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

View File

@ -3,12 +3,12 @@
TechAge TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
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 M = minetest.get_meta
local S = techage.S local S = techage.S
local TA2_Power = techage.Axle local Axle = techage.Axle
local TA3_Power = techage.SteamPipe local Pipe = techage.SteamPipe
local TA4_Power = techage.ElectricCable local Cable = techage.ElectricCable
local power = techage.power local power = techage.power
local networks = techage.networks
local STANDBY_TICKS = 4 local STANDBY_TICKS = 4
local COUNTDOWN_TICKS = 4 local COUNTDOWN_TICKS = 4
local CYCLE_TIME = 2 local CYCLE_TIME = 2
local PWR_CAPA = 20 local PWR_CAPA = 20
local function formspec(self, pos, mem) local function formspec(self, pos, nvm)
return "size[8,7]".. 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..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
"image[6,0.5;1,2;"..techage.power.formspec_power_bar(PWR_CAPA, mem.provided).."]".. power.formspec_label_bar(0, 0.8, S("power"), PWR_CAPA, nvm.provided)..
"image_button[5,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]".. "image_button[2.8,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"button[2.5,1;1.8,1;update;"..S("Update").."]".. "tooltip[2.8,2;1,1;"..self:get_state_tooltip(nvm).."]"
"list[current_player;main;0,3;8,4;]"..
default.get_hotbar_bg(0, 3)
end end
local function start_node(pos, mem, state) -- Axles texture animation
mem.generating = true local function switch_axles(pos, on)
power.generator_start(pos, mem, PWR_CAPA) local outdir = M(pos):get_int("outdir")
techage.switch_axles(pos, true) Axle:switch_tube_line(pos, outdir, on and "on" or "off")
end end
local function stop_node(pos, mem, state) local function start_node2(pos, nvm, state)
mem.generating = false nvm.generating = true
mem.provided = 0 local outdir = M(pos):get_int("outdir")
power.generator_stop(pos, mem) power.generator_start(pos, Axle, CYCLE_TIME, outdir)
techage.switch_axles(pos, false) 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 end
local State2 = techage.NodeStates:new({ local State2 = techage.NodeStates:new({
@ -57,8 +92,8 @@ local State2 = techage.NodeStates:new({
cycle_time = CYCLE_TIME, cycle_time = CYCLE_TIME,
standby_ticks = STANDBY_TICKS, standby_ticks = STANDBY_TICKS,
formspec_func = formspec, formspec_func = formspec,
start_node = start_node, start_node = start_node2,
stop_node = stop_node, stop_node = stop_node2,
}) })
local State3 = techage.NodeStates:new({ local State3 = techage.NodeStates:new({
@ -66,8 +101,8 @@ local State3 = techage.NodeStates:new({
cycle_time = CYCLE_TIME, cycle_time = CYCLE_TIME,
standby_ticks = STANDBY_TICKS, standby_ticks = STANDBY_TICKS,
formspec_func = formspec, formspec_func = formspec,
start_node = start_node, start_node = start_node3,
stop_node = stop_node, stop_node = stop_node3,
}) })
local State4 = techage.NodeStates:new({ local State4 = techage.NodeStates:new({
@ -75,39 +110,153 @@ local State4 = techage.NodeStates:new({
cycle_time = CYCLE_TIME, cycle_time = CYCLE_TIME,
standby_ticks = STANDBY_TICKS, standby_ticks = STANDBY_TICKS,
formspec_func = formspec, formspec_func = formspec,
start_node = start_node, start_node = start_node4,
stop_node = stop_node, stop_node = stop_node4,
}) })
local function node_timer(pos, elapsed) local function node_timer2(pos, elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if mem.generating then local outdir = M(pos):get_int("outdir")
local provided = power.generator_alive(pos, mem) 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 end
return mem.generating return true
end 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 if minetest.is_protected(pos, player:get_player_name()) then
return return
end end
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
local state = tStates[mem.state_num or 2] State2:state_button_event(pos, nvm, fields)
state:state_button_event(pos, mem, fields) M(pos):set_string("formspec", formspec(State2, pos, nvm))
end
if fields.update then local function on_receive_fields3(pos, formname, fields, player)
M(pos):set_string("formspec", formspec(state, pos, mem)) if minetest.is_protected(pos, player:get_player_name()) then
return
end end
local nvm = techage.get_nvm(pos)
State3:state_button_event(pos, nvm, fields)
M(pos):set_string("formspec", formspec(State3, pos, nvm))
end end
local function on_rightclick(pos) local function on_receive_fields4(pos, formname, fields, player)
local mem = tubelib2.get_mem(pos) if minetest.is_protected(pos, player:get_player_name()) then
local state = tStates[mem.state_num or 2] return
M(pos):set_string("formspec", formspec(state, pos, mem)) end
local nvm = techage.get_nvm(pos)
State4:state_button_event(pos, nvm, fields)
M(pos):set_string("formspec", formspec(State4, pos, nvm))
end 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", { minetest.register_node("techage:t2_source", {
description = S("Axle Power Source"), description = S("Axle Power Source"),
tiles = { tiles = {
@ -123,9 +272,13 @@ minetest.register_node("techage:t2_source", {
groups = {cracky=2, crumbly=2, choppy=2}, groups = {cracky=2, crumbly=2, choppy=2},
on_rotate = screwdriver.disallow, on_rotate = screwdriver.disallow,
is_ground_content = false, is_ground_content = false,
on_receive_fields = on_receive_fields, on_receive_fields = on_receive_fields2,
on_rightclick = on_rightclick, on_rightclick = on_rightclick2,
on_timer = node_timer, 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", { minetest.register_node("techage:t3_source", {
@ -143,9 +296,13 @@ minetest.register_node("techage:t3_source", {
groups = {cracky=2, crumbly=2, choppy=2}, groups = {cracky=2, crumbly=2, choppy=2},
on_rotate = screwdriver.disallow, on_rotate = screwdriver.disallow,
is_ground_content = false, is_ground_content = false,
on_receive_fields = on_receive_fields, on_receive_fields = on_receive_fields3,
on_rightclick = on_rightclick, on_rightclick = on_rightclick3,
on_timer = node_timer, 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", { minetest.register_node("techage:t4_source", {
@ -163,40 +320,15 @@ minetest.register_node("techage:t4_source", {
groups = {cracky=2, crumbly=2, choppy=2}, groups = {cracky=2, crumbly=2, choppy=2},
on_rotate = screwdriver.disallow, on_rotate = screwdriver.disallow,
is_ground_content = false, is_ground_content = false,
on_receive_fields = on_receive_fields, on_receive_fields = on_receive_fields4,
on_rightclick = on_rightclick, on_rightclick = on_rightclick4,
on_timer = node_timer, 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"}, { Axle:add_secondary_node_names({"techage:t2_source"})
conn_sides = {"R"}, --Pipe:add_secondary_node_names({"techage:t3_source"})
power_network = TA2_Power, Cable:add_secondary_node_names({"techage:t4_source"})
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,
})

View File

@ -103,7 +103,7 @@ local function register_lbm(name, nodenames)
run_at_every_load = true, run_at_every_load = true,
action = function(pos, node) action = function(pos, node)
if NodeDef[node.name] and NodeDef[node.name].on_node_load then 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
end end
}) })
@ -180,6 +180,15 @@ function techage.get_node_number(pos)
return nil return nil
end 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 is used for available nodes with lost numbers, only.
function techage.get_new_number(pos, name) function techage.get_new_number(pos, name)
-- store position -- 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 end
minetest.after(1, determine_burntimes) minetest.after(1, determine_burntimes)
function techage.firebox.formspec(mem) function techage.firebox.formspec(nvm)
local fuel_percent = 0 local fuel_percent = 0
if mem.running then if nvm.running then
fuel_percent = ((mem.burn_cycles or 1) * 100) / (mem.burn_cycles_total or 1) fuel_percent = ((nvm.burn_cycles or 1) * 100) / (nvm.burn_cycles_total or 1)
end end
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]".. return "size[8,6]"..
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
"list[current_name;fuel;1,0.5;1,1;]".. "box[0,-0.1;7.8,0.5;#c6e8ff]"..
"image[3,0.5;1,1;default_furnace_fire_bg.png^[lowpart:".. "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]".. fuel_percent..":default_furnace_fire_fg.png]"..
"button[5,0.5;1.8,1;update;"..S("Update").."]".. "list[current_player;main;0,2.3;8,4;]"..
"list[current_player;main;0,2;8,4;]"..
"listring[current_name;fuel]".. "listring[current_name;fuel]"..
"listring[current_player;main]".. "listring[current_player;main]"..
default.get_hotbar_bg(0, 2) default.get_hotbar_bg(0, 2.3)
end
end end
function techage.firebox.can_dig(pos, player) 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() return stack:get_count()
end 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) function techage.firebox.on_rightclick(pos, node, clicker)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", techage.firebox.formspec(mem)) techage.set_activeformspec(pos, clicker)
M(pos):set_string("formspec", techage.firebox.formspec(nvm))
end end
function techage.firebox.swap_node(pos, name) 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 return offs + rot
end end
function techage.range(val, min, max) function techage.in_range(val, min, max)
val = tonumber(val) val = tonumber(val)
if val < min then return min end if val < min then return min end
if val > max then return max end if val > max then return max end
@ -100,8 +100,6 @@ function techage.get_node_lvm(pos)
return node return node
end end
-- --
-- Functions used to hide electric cable and biogas pipes -- 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 for name, _ in pairs(minetest.registered_biomes) do
if string.find(name, "ocean") then if string.find(name, "ocean") then
local id = minetest.get_biome_id(name) local id = minetest.get_biome_id(name)
print(id, name) --print(id, name)
techage.OceanIdTbl[id] = true techage.OceanIdTbl[id] = true
end end
end end
@ -191,3 +189,47 @@ function techage.item_image(x, y, itemname)
"tooltip["..x..","..y..";1,1;"..tooltip(itemname)..";#0C3D32;#FFFFFF]" "tooltip["..x..","..y..";1,1;"..tooltip(itemname)..";#0C3D32;#FFFFFF]"
end 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, 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, ", ")) --print("Network ("..valid.."): "..table.concat(tbl, ", "))
end 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 -- return the node definition local networks table
local function net_def(pos, net_name) local function net_def(pos, net_name)
local ndef = minetest.registered_nodes[techage.get_node_lvm(pos).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 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] 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 end
local function connected(tlib2, pos, dir) local function connected(tlib2, pos, dir)
@ -71,6 +88,10 @@ local function connected(tlib2, pos, dir)
if not num then return end if not num then return end
return Flip[dir] == d1 or Flip[dir] == d2 return Flip[dir] == d1 or Flip[dir] == d2
end end
-- secondary nodes allowed?
if not tlib2.force_to_use_tubes then
return tlib2:is_secondary_node(pos, dir)
end
return false return false
end end
@ -114,25 +135,28 @@ local function get_node_connections(pos, net_name)
return tbl return tbl
end end
-- determine all node sides with tube connections -- store all node sides with tube connections as nodemeta
local function node_connections(pos, tlib2) local function node_connections(pos, tlib2)
local node = techage.get_node_lvm(pos) local node = techage.get_node_lvm(pos)
local val = 0 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 if sides then
for dir = 1,6 do for dir = 1,6 do
val = val * 2 val = val * 2
local side = DirToSide[outdir_to_dir(dir, node.param2)] local side = DirToSide[outdir_to_dir(dir, node.param2)]
if sides[side] then if sides[side] then
print(side, sides[side], P2S(pos), dir, connected(tlib2, pos, dir))
if connected(tlib2, pos, dir) then if connected(tlib2, pos, dir) then
techage.mark_side("singleplayer", pos, dir, "node_connections", "", 1)--------------------
val = val + 1 val = val + 1
end end
end end
end end
M(pos):set_int(tlib2.tube_type.."_conn", val) M(pos):set_int(tlib2.tube_type.."_conn", val)
else else
error(pos, "sides missing") --error(pos, "sides missing")
end end
end end
@ -147,14 +171,30 @@ local function pos_already_reached(pos)
end end
-- check if the given pipe dir into the node is valid -- check if the given pipe dir into the node is valid
local function valid_indir(indir, node, net_name) local function valid_indir(pos, indir, node, net_name)
local ndef = net_def2(node.name, net_name) local ndef = net_def2(pos, node.name, net_name)
if not ndef or not ndef.sides then return false end local sides = ndef.sides or ndef.get_sides and ndef.get_sides(pos, node)
local side = DirToSide[indir_to_dir(indir, node.param2)] 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 return true
end 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 -- do the walk through the tubelib2 network
-- indir is the direction which should not be covered by the walk -- indir is the direction which should not be covered by the walk
-- (coming from there) -- (coming from there)
@ -162,18 +202,20 @@ end
local function connection_walk(pos, outdirs, indir, node, tlib2, clbk) local function connection_walk(pos, outdirs, indir, node, tlib2, clbk)
if clbk then clbk(pos, indir, node) end if clbk then clbk(pos, indir, node) end
--techage.mark_position("singleplayer", pos, "walk", "", 1) --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 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 pos2, indir2 = tlib2:get_connected_node_pos(pos, outdir)
local node = techage.get_node_lvm(pos2) 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) connection_walk(pos2, nil, indir2, node, tlib2, clbk)
end end
end end
end end
end end
local function collect_network_nodes(pos, outdir, tlib2) local function collect_network_nodes(pos, outdir, tlib2)
Route = {} Route = {}
NumNodes = 0 NumNodes = 0
@ -183,17 +225,24 @@ local function collect_network_nodes(pos, outdir, tlib2)
local net_name = tlib2.tube_type local net_name = tlib2.tube_type
-- outdir corresponds to the indir coming from -- outdir corresponds to the indir coming from
connection_walk(pos, outdir and {outdir}, nil, node, tlib2, function(pos, indir, node) connection_walk(pos, outdir and {outdir}, nil, node, tlib2, function(pos, indir, node)
local ntype = net_def2(node.name, net_name).ntype local ndef = net_def2(pos, node.name, net_name)
if ntype then -- 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 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
end) end)
netw.best_before = minetest.get_gametime() + BEST_BEFORE netw.best_before = minetest.get_gametime() + BEST_BEFORE
netw.num_nodes = NumNodes
return netw return netw
end end
-- keep data base small and valid -- keep data base small and valid
-- needed for networks without scheduler
local function remove_outdated_networks() local function remove_outdated_networks()
local to_be_deleted = {} local to_be_deleted = {}
local t = minetest.get_gametime() 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(pos, side)
techage.networks.side_to_outdir = side_to_outdir 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(pos, tlib2)
techage.networks.node_connections = node_connections techage.networks.node_connections = node_connections
@ -245,44 +290,66 @@ function techage.networks.connection_walk(pos, outdir, tlib2, clbk)
NumNodes = 0 NumNodes = 0
pos_already_reached(pos) -- don't consider the start pos pos_already_reached(pos) -- don't consider the start pos
local node = techage.get_node_lvm(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 return NumNodes
end end
function techage.networks.get_network(netID, tlib2) function techage.networks.get_network(tube_type, netID)
if Networks[tlib2.tube_type] and Networks[tlib2.tube_type][netID] then if Networks[tube_type] and Networks[tube_type][netID] then
Networks[tlib2.tube_type][netID].best_before = minetest.get_gametime() + BEST_BEFORE Networks[tube_type][netID].best_before = minetest.get_gametime() + BEST_BEFORE
return Networks[tlib2.tube_type][netID] return Networks[tube_type][netID]
end end
end end
function techage.networks.set_network(netID, tlib2, network) function techage.networks.set_network(tube_type, netID, network)
if netID then if netID then
if not Networks[tlib2.tube_type] then if not Networks[tube_type] then
Networks[tlib2.tube_type] = {} Networks[tube_type] = {}
end end
Networks[tlib2.tube_type][netID] = network Networks[tube_type][netID] = network
Networks[tlib2.tube_type][netID].best_before = minetest.get_gametime() + BEST_BEFORE 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
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
end end
--
-- 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.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 | FAULT none no no
| STOPPED none no no | STOPPED none no no
Node mem data: Node nvm data:
"techage_state" - node state, like "RUNNING" "techage_state" - node state, like "RUNNING"
"techage_item_meter" - node item/runtime counter "techage_item_meter" - node item/runtime counter
"techage_countdown" - countdown to stadby mode "techage_countdown" - countdown to standby mode
]]-- ]]--
-- for lazy programmers -- for lazy programmers
@ -95,7 +95,7 @@ function techage.state_button(state)
return "techage_inv_button_off.png" return "techage_inv_button_off.png"
end end
function techage.get_power_image(pos, mem) function techage.get_power_image(pos, nvm)
local node = techage.get_node_lvm(pos) local node = techage.get_node_lvm(pos)
local s = "3" -- electrical power local s = "3" -- electrical power
if string.find(node.name, "techage:ta2") then if string.find(node.name, "techage:ta2") then
@ -124,12 +124,12 @@ local STOPPED = techage.STOPPED
techage.NodeStates = {} techage.NodeStates = {}
local NodeStates = techage.NodeStates local NodeStates = techage.NodeStates
local function can_start(pos, mem) local function can_start(pos, nvm)
--if false, node goes in FAULT --if false, node goes in FAULT
return true return true
end end
local function has_power(pos, mem) local function has_power(pos, nvm)
--if false, node goes in NOPOWER --if false, node goes in NOPOWER
return true return true
end end
@ -144,14 +144,14 @@ local function swap_node(pos, name)
end end
-- true if node_timer should be executed -- true if node_timer should be executed
function techage.is_operational(mem) function techage.is_operational(nvm)
local state = mem.techage_state or STOPPED local state = nvm.techage_state or STOPPED
return state < NOPOWER return state < NOPOWER
end end
-- consumes power -- consumes power
function techage.needs_power(mem) function techage.needs_power(nvm)
local state = mem.techage_state or STOPPED local state = nvm.techage_state or STOPPED
return state < BLOCKED return state < BLOCKED
end end
@ -159,8 +159,8 @@ function techage.needs_power2(state)
return state < BLOCKED return state < BLOCKED
end end
function techage.get_state_string(mem) function techage.get_state_string(nvm)
return techage.StateStrings[mem.techage_state or STOPPED] return techage.StateStrings[nvm.techage_state or STOPPED]
end end
function NodeStates:new(attr) function NodeStates:new(attr)
@ -184,15 +184,15 @@ function NodeStates:new(attr)
return o return o
end end
function NodeStates:node_init(pos, mem, number) function NodeStates:node_init(pos, nvm, number)
mem.techage_state = STOPPED nvm.techage_state = STOPPED
M(pos):set_string("node_number", number) M(pos):set_string("node_number", number)
if self.infotext_name then if self.infotext_name then
M(pos):set_string("infotext", self.infotext_name.." "..number..": stopped") M(pos):set_string("infotext", self.infotext_name.." "..number..": stopped")
end end
mem.techage_item_meter = 0 nvm.techage_item_meter = 0
if self.formspec_func then 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
end end
@ -207,11 +207,11 @@ local function start_timer_delayed(pos, cycle_time)
end end
end end
function NodeStates:stop(pos, mem) function NodeStates:stop(pos, nvm)
local state = mem.techage_state or STOPPED local state = nvm.techage_state or STOPPED
mem.techage_state = STOPPED nvm.techage_state = STOPPED
if self.stop_node then if self.stop_node then
self.stop_node(pos, mem, state) self.stop_node(pos, nvm, state)
end end
if self.node_name_passive then if self.node_name_passive then
swap_node(pos, self.node_name_passive) 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") M(pos):set_string("infotext", self.infotext_name.." "..number..": stopped")
end end
if self.formspec_func then if self.formspec_func then
mem.ta_state_tooltip = "stopped" nvm.ta_state_tooltip = "stopped"
M(pos):set_string("formspec", self.formspec_func(self, pos, mem)) M(pos):set_string("formspec", self.formspec_func(self, pos, nvm))
end end
if self.on_state_change then if self.on_state_change then
self.on_state_change(pos, state, STOPPED) self.on_state_change(pos, state, STOPPED)
@ -233,23 +233,23 @@ function NodeStates:stop(pos, mem)
return true return true
end end
function NodeStates:start(pos, mem) function NodeStates:start(pos, nvm)
local state = mem.techage_state or STOPPED local state = nvm.techage_state or STOPPED
if state ~= RUNNING and state ~= FAULT then 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 if res ~= true then
self:fault(pos, mem, res) self:fault(pos, nvm, res)
return false return false
end end
if not self.has_power(pos, mem, state) then if not self.has_power(pos, nvm, state) then
self:nopower(pos, mem) self:nopower(pos, nvm)
return false return false
end end
mem.techage_state = RUNNING nvm.techage_state = RUNNING
if self.start_node then if self.start_node then
self.start_node(pos, mem, state) self.start_node(pos, nvm, state)
end end
mem.techage_countdown = 1 nvm.techage_countdown = 1
if self.node_name_active then if self.node_name_active then
swap_node(pos, self.node_name_active) swap_node(pos, self.node_name_active)
end end
@ -258,8 +258,8 @@ function NodeStates:start(pos, mem)
M(pos):set_string("infotext", self.infotext_name.." "..number..": running") M(pos):set_string("infotext", self.infotext_name.." "..number..": running")
end end
if self.formspec_func then if self.formspec_func then
mem.ta_state_tooltip = "running" nvm.ta_state_tooltip = "running"
M(pos):set_string("formspec", self.formspec_func(self, pos, mem)) M(pos):set_string("formspec", self.formspec_func(self, pos, nvm))
end end
if minetest.get_node_timer(pos):is_started() then if minetest.get_node_timer(pos):is_started() then
minetest.get_node_timer(pos):stop() minetest.get_node_timer(pos):stop()
@ -273,10 +273,10 @@ function NodeStates:start(pos, mem)
return false return false
end end
function NodeStates:standby(pos, mem) function NodeStates:standby(pos, nvm)
local state = mem.techage_state or STOPPED local state = nvm.techage_state or STOPPED
if state == RUNNING then if state == RUNNING then
mem.techage_state = STANDBY nvm.techage_state = STANDBY
if self.node_name_passive then if self.node_name_passive then
swap_node(pos, self.node_name_passive) swap_node(pos, self.node_name_passive)
end end
@ -285,8 +285,8 @@ function NodeStates:standby(pos, mem)
M(pos):set_string("infotext", self.infotext_name.." "..number..": standby") M(pos):set_string("infotext", self.infotext_name.." "..number..": standby")
end end
if self.formspec_func then if self.formspec_func then
mem.ta_state_tooltip = "standby" nvm.ta_state_tooltip = "standby"
M(pos):set_string("formspec", self.formspec_func(self, pos, mem)) M(pos):set_string("formspec", self.formspec_func(self, pos, nvm))
end end
if self.on_state_change then if self.on_state_change then
self.on_state_change(pos, state, STANDBY) self.on_state_change(pos, state, STANDBY)
@ -298,10 +298,10 @@ function NodeStates:standby(pos, mem)
end end
-- special case of standby for pushing nodes -- special case of standby for pushing nodes
function NodeStates:blocked(pos, mem) function NodeStates:blocked(pos, nvm)
local state = mem.techage_state or STOPPED local state = nvm.techage_state or STOPPED
if state == RUNNING then if state == RUNNING then
mem.techage_state = BLOCKED nvm.techage_state = BLOCKED
if self.node_name_passive then if self.node_name_passive then
swap_node(pos, self.node_name_passive) swap_node(pos, self.node_name_passive)
end end
@ -310,8 +310,8 @@ function NodeStates:blocked(pos, mem)
M(pos):set_string("infotext", self.infotext_name.." "..number..": blocked") M(pos):set_string("infotext", self.infotext_name.." "..number..": blocked")
end end
if self.formspec_func then if self.formspec_func then
mem.ta_state_tooltip = "blocked" nvm.ta_state_tooltip = "blocked"
M(pos):set_string("formspec", self.formspec_func(self, pos, mem)) M(pos):set_string("formspec", self.formspec_func(self, pos, nvm))
end end
if self.on_state_change then if self.on_state_change then
self.on_state_change(pos, state, BLOCKED) self.on_state_change(pos, state, BLOCKED)
@ -322,10 +322,10 @@ function NodeStates:blocked(pos, mem)
return false return false
end end
function NodeStates:nopower(pos, mem, err_string) function NodeStates:nopower(pos, nvm, err_string)
local state = mem.techage_state or RUNNING local state = nvm.techage_state or RUNNING
if state ~= NOPOWER then if state ~= NOPOWER then
mem.techage_state = NOPOWER nvm.techage_state = NOPOWER
if self.node_name_passive then if self.node_name_passive then
swap_node(pos, self.node_name_passive) swap_node(pos, self.node_name_passive)
end end
@ -334,8 +334,8 @@ function NodeStates:nopower(pos, mem, err_string)
M(pos):set_string("infotext", self.infotext_name.." "..number..": no power") M(pos):set_string("infotext", self.infotext_name.." "..number..": no power")
end end
if self.formspec_func then if self.formspec_func then
mem.ta_state_tooltip = err_string or "no power" nvm.ta_state_tooltip = err_string or "no power"
M(pos):set_string("formspec", self.formspec_func(self, pos, mem)) M(pos):set_string("formspec", self.formspec_func(self, pos, nvm))
end end
if self.on_state_change then if self.on_state_change then
self.on_state_change(pos, state, NOPOWER) self.on_state_change(pos, state, NOPOWER)
@ -346,11 +346,11 @@ function NodeStates:nopower(pos, mem, err_string)
return false return false
end end
function NodeStates:fault(pos, mem, err_string) function NodeStates:fault(pos, nvm, err_string)
local state = mem.techage_state or STOPPED local state = nvm.techage_state or STOPPED
err_string = err_string or "fault" err_string = err_string or "fault"
if state == RUNNING or state == STOPPED then if state == RUNNING or state == STOPPED then
mem.techage_state = FAULT nvm.techage_state = FAULT
if self.node_name_passive then if self.node_name_passive then
swap_node(pos, self.node_name_passive) swap_node(pos, self.node_name_passive)
end end
@ -359,8 +359,8 @@ function NodeStates:fault(pos, mem, err_string)
M(pos):set_string("infotext", self.infotext_name.." "..number..": "..err_string) M(pos):set_string("infotext", self.infotext_name.." "..number..": "..err_string)
end end
if self.formspec_func then if self.formspec_func then
mem.ta_state_tooltip = err_string or "fault" nvm.ta_state_tooltip = err_string or "fault"
M(pos):set_string("formspec", self.formspec_func(self, pos, mem)) M(pos):set_string("formspec", self.formspec_func(self, pos, nvm))
end end
if self.on_state_change then if self.on_state_change then
self.on_state_change(pos, state, FAULT) self.on_state_change(pos, state, FAULT)
@ -371,90 +371,90 @@ function NodeStates:fault(pos, mem, err_string)
return false return false
end end
function NodeStates:get_state(mem) function NodeStates:get_state(nvm)
return mem.techage_state or techage.STOPPED return nvm.techage_state or techage.STOPPED
end end
-- keep the timer running? -- keep the timer running?
function NodeStates:is_active(mem) function NodeStates:is_active(nvm)
local state = mem.techage_state or STOPPED local state = nvm.techage_state or STOPPED
return state < FAULT return state < FAULT
end end
function NodeStates:start_if_standby(pos) function NodeStates:start_if_standby(pos)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if mem.techage_state == STANDBY then if nvm.techage_state == STANDBY then
self:start(pos, mem) self:start(pos, nvm)
end end
end end
-- To be called if node is idle. -- To be called if node is idle.
-- If countdown reaches zero, the node is set to STANDBY. -- If countdown reaches zero, the node is set to STANDBY.
function NodeStates:idle(pos, mem) function NodeStates:idle(pos, nvm)
local countdown = (mem.techage_countdown or 0) - 1 local countdown = (nvm.techage_countdown or 0) - 1
mem.techage_countdown = countdown nvm.techage_countdown = countdown
if countdown <= 0 then if countdown <= 0 then
self:standby(pos, mem) self:standby(pos, nvm)
end end
end end
-- To be called after successful node action to raise the timer -- To be called after successful node action to raise the timer
-- and keep the node in state RUNNING -- 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 -- set to RUNNING if not already done
if mem.techage_state ~= RUNNING then if nvm.techage_state ~= RUNNING then
self:start(pos, mem) self:start(pos, nvm)
end end
mem.techage_countdown = val or 4 nvm.techage_countdown = val or 4
mem.techage_item_meter = (mem.techage_item_meter or 0) + (num_items or 1) nvm.techage_item_meter = (nvm.techage_item_meter or 0) + (num_items or 1)
end end
-- Start/stop node based on button events. -- Start/stop node based on button events.
-- if function returns false, no button was pressed -- 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 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 state == STOPPED or state == STANDBY or state == BLOCKED then
if not self:start(pos, mem) and (state == STANDBY or state == BLOCKED) then if not self:start(pos, nvm) and (state == STANDBY or state == BLOCKED) then
self:stop(pos, mem) self:stop(pos, nvm)
end end
elseif state == RUNNING or state == FAULT or state == NOPOWER then elseif state == RUNNING or state == FAULT or state == NOPOWER then
self:stop(pos, mem) self:stop(pos, nvm)
end end
return true return true
end end
return false return false
end end
function NodeStates:get_state_button_image(mem) function NodeStates:get_state_button_image(nvm)
local state = mem.techage_state or STOPPED local state = nvm.techage_state or STOPPED
return techage.state_button(state) return techage.state_button(state)
end end
function NodeStates:get_state_tooltip(mem) function NodeStates:get_state_tooltip(nvm)
local tp = mem.ta_state_tooltip or "" local tp = nvm.ta_state_tooltip or ""
return tp..";#0C3D32;#FFFFFF" return tp..";#0C3D32;#FFFFFF"
end end
-- command interface -- command interface
function NodeStates:on_receive_message(pos, topic, payload) function NodeStates:on_receive_message(pos, topic, payload)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if topic == "on" then if topic == "on" then
self:start(pos, tubelib2.get_mem(pos)) self:start(pos, techage.get_nvm(pos))
return true return true
elseif topic == "off" then elseif topic == "off" then
self:stop(pos, tubelib2.get_mem(pos)) self:stop(pos, techage.get_nvm(pos))
return true return true
elseif topic == "state" then elseif topic == "state" then
local node = techage.get_node_lvm(pos) local node = techage.get_node_lvm(pos)
if node.name == "ignore" then -- unloaded node? if node.name == "ignore" then -- unloaded node?
return "unloaded" return "unloaded"
end end
return techage.get_state_string(tubelib2.get_mem(pos)) return techage.get_state_string(techage.get_nvm(pos))
elseif topic == "counter" then elseif topic == "counter" then
return mem.techage_item_meter or 1 return nvm.techage_item_meter or 1
elseif topic == "clear_counter" then elseif topic == "clear_counter" then
mem.techage_item_meter = 0 nvm.techage_item_meter = 0
return true return true
elseif topic == "fuel" then elseif topic == "fuel" then
local inv = M(pos):get_inventory() local inv = M(pos):get_inventory()
@ -470,7 +470,7 @@ end
-- repair corrupt node data -- repair corrupt node data
function NodeStates:on_node_load(pos, not_start_timer) function NodeStates:on_node_load(pos, not_start_timer)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
-- Meta data corrupt? -- Meta data corrupt?
local number = M(pos):get_string("node_number") 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") minetest.log("warning", "[TA] Node at "..S(pos).." has no node_number")
local name = techage.get_node_lvm(pos).name local name = techage.get_node_lvm(pos).name
local number = techage.add_node(pos, name) local number = techage.add_node(pos, name)
self:node_init(pos, mem, number) self:node_init(pos, nvm, number)
return return
end end
@ -499,12 +499,12 @@ function NodeStates:on_node_load(pos, not_start_timer)
end end
-- state corrupt? -- state corrupt?
local state = mem.techage_state or 0 local state = nvm.techage_state or 0
if state == 0 then if state == 0 then
if minetest.get_node_timer(pos):is_started() then if minetest.get_node_timer(pos):is_started() then
mem.techage_state = RUNNING nvm.techage_state = RUNNING
else else
mem.techage_state = STOPPED nvm.techage_state = STOPPED
end end
elseif state == RUNNING and not not_start_timer then elseif state == RUNNING and not not_start_timer then
minetest.get_node_timer(pos):start(self.cycle_time) minetest.get_node_timer(pos):start(self.cycle_time)
@ -515,7 +515,12 @@ function NodeStates:on_node_load(pos, not_start_timer)
end end
if self.formspec_func then 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
end end

View File

@ -18,7 +18,7 @@ local M = minetest.get_meta
local Recipes = {} -- {rtype = {ouput = {....},...}} local Recipes = {} -- {rtype = {ouput = {....},...}}
local RecipeList = {} -- {rtype = {<output name>,...}} local RecipeList = {} -- {rtype = {<output name>,...}}
local range = techage.range local range = techage.in_range
techage.recipes = {} 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 TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -17,6 +17,15 @@ local M = minetest.get_meta
local S = techage.S local S = techage.S
local Pipe = techage.SteamPipe 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", { minetest.register_node("techage:coalboiler_base", {
description = S("TA3 Boiler 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}, 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", paramtype = "light",
paramtype2 = "facedir", paramtype2 = "facedir",
@ -38,21 +48,12 @@ minetest.register_node("techage:coalboiler_base", {
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
}) })
techage.power.register_node({"techage:coalboiler_base"}, { Pipe:add_secondary_node_names({"techage:coalboiler_base"})
conn_sides = {"F"},
power_network = Pipe,
})
-- for logical communication -- for logical communication
techage.register_node({"techage:coalboiler_base"}, { techage.register_node({"techage:coalboiler_base"}, {
on_transfer = function(pos, in_dir, topic, payload) on_transfer = function(pos, in_dir, topic, payload)
if topic == "start" then
return true return true
elseif topic == "stop" then
return true
elseif topic == "running" then
return true
end
end end
}) })

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -17,206 +17,40 @@ local M = minetest.get_meta
local S = techage.S local S = techage.S
local CYCLE_TIME = 4 local CYCLE_TIME = 4
local STANDBY_TICKS = 2
local COUNTDOWN_TICKS = 20
local HEAT_STEP = 10
local WATER_CONSUMPTION = 0.1 local WATER_CONSUMPTION = 0.1
local MAX_WATER = 10
local Pipe = techage.SteamPipe local Pipe = techage.SteamPipe
local boiler = techage.boiler
local function transfer(pos, topic, payload) local function steaming(pos, nvm, temp)
return techage.transfer(pos, "F", topic, payload, Pipe, if temp >= 80 then
{"techage:turbine", "techage:turbine_on"}) local wc = WATER_CONSUMPTION * (nvm.power_ratio or 1)
end nvm.water_level = math.max((nvm.water_level or 0) - wc, 0)
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
end end
end end
local function node_timer(pos, elapsed) local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
local temp = water_temperature(pos, mem) local temp = boiler.water_temperature(pos, nvm)
if State:is_active(mem) then steaming(pos, nvm, temp)
steaming(pos, mem, temp) if techage.is_activeformspec(pos) then
M(pos):set_string("formspec", boiler.formspec(pos, nvm))
end end
return mem.temperature > 20 return temp > 20
end end
local function on_receive_fields(pos, formname, fields, player) local function after_place_node(pos)
if minetest.is_protected(pos, player:get_player_name()) then local node = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z})
return if node.name == "techage:coalboiler_base" then
end local nvm = techage.get_nvm(pos)
local mem = tubelib2.get_mem(pos) M(pos):set_string("formspec", boiler.formspec(pos, nvm))
mem.temperature = mem.temperature or 20 Pipe:after_place_node(pos)
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))
end end
end end
local function after_dig_node(pos, oldnode)
local function on_rightclick(pos) Pipe:after_dig_node(pos)
local mem = tubelib2.get_mem(pos) techage.del_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
end end
minetest.register_node("techage:coalboiler_top", { 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}, 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, on_timer = node_timer,
allow_metadata_inventory_put = allow_metadata_inventory_put, on_rightclick = boiler.on_rightclick,
allow_metadata_inventory_take = allow_metadata_inventory_take, after_place_node = after_place_node,
allow_metadata_inventory_move = function(pos) return 0 end, after_dig_node = after_dig_node,
on_receive_fields = on_receive_fields, on_punch = boiler.on_punch,
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", paramtype = "light",
paramtype2 = "facedir", paramtype2 = "facedir",
@ -255,36 +78,28 @@ minetest.register_node("techage:coalboiler_top", {
sounds = default.node_sound_metal_defaults(), sounds = default.node_sound_metal_defaults(),
}) })
techage.power.register_node({"techage:coalboiler_top"}, { Pipe:add_secondary_node_names({"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,
})
techage.register_node({"techage:coalboiler_top"}, { techage.register_node({"techage:coalboiler_top"}, {
on_transfer = function(pos, in_dir, topic, payload) on_transfer = function(pos, in_dir, topic, payload)
if topic == "trigger" then if topic == "trigger" then
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.fire_trigger = true nvm.fire_trigger = true
if not minetest.get_node_timer(pos):is_started() then if not minetest.get_node_timer(pos):is_started() then
minetest.get_node_timer(pos):start(CYCLE_TIME) minetest.get_node_timer(pos):start(CYCLE_TIME)
end end
if mem.running then if (nvm.temperature or 20) > 80 then
mem.power_ratio = transfer(pos, topic, payload) nvm.power_ratio = techage.transfer(pos, "F", "trigger", nil, Pipe, {
return mem.power_ratio "techage:turbine", "techage:turbine_on"}) or 0
end return nvm.power_ratio
else
return 0
end end
end end
end,
}) })
minetest.register_craft({ minetest.register_craft({
output = "techage:coalboiler_top", output = "techage:coalboiler_top",
recipe = { recipe = {

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -23,28 +23,47 @@ local function transfer(pos, in_dir, topic, payload)
{"techage:coalboiler_base"}) {"techage:coalboiler_base"})
end end
local function swap_node(pos, name) local function after_place_node(pos)
local node = techage.get_node_lvm(pos) Pipe:after_place_node(pos)
if node.name == name then end
return
end local function after_dig_node(pos, oldnode)
node.name = name Pipe:after_dig_node(pos)
minetest.swap_node(pos, node) techage.del_mem(pos)
end end
minetest.register_node("techage:cooler", { minetest.register_node("techage:cooler", {
description = S("TA3 Cooler"), description = S("TA3 Cooler"),
tiles = { tiles = {
-- up, down, right, left, back, front -- 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_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",
"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", paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2}, groups = {cracky=2, crumbly=2, choppy=2},
@ -53,8 +72,9 @@ minetest.register_node("techage:cooler", {
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
}) })
-- legacy node
minetest.register_node("techage:cooler_on", { minetest.register_node("techage:cooler_on", {
description = S("TA3 Cooler"),
tiles = { tiles = {
-- up, down, right, left, back, front -- 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", "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", paramtype2 = "facedir",
groups = {not_in_creative_inventory=1}, drop = "techage:cooler",
diggable = false, groups = {cracky=2, crumbly=2, choppy=2, not_in_creative_inventory=1},
on_rotate = screwdriver.disallow, on_rotate = screwdriver.disallow,
is_ground_content = false, is_ground_content = false,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
}) })
-- for mechanical pipe connections Pipe:add_secondary_node_names({"techage:cooler", "techage:cooler_on"})
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,
})
-- for logical communication -- for logical communication
techage.register_node({"techage:cooler", "techage:cooler_on"}, { techage.register_node({"techage:cooler", "techage:cooler_on"}, {
on_transfer = function(pos, in_dir, topic, payload) on_transfer = function(pos, in_dir, topic, payload)
if topic == "start" then return transfer(pos, in_dir, topic, payload)
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
end end
}) })

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -18,12 +18,9 @@ local M = minetest.get_meta
local S = techage.S local S = techage.S
local firebox = techage.firebox local firebox = techage.firebox
local fuel = techage.fuel
local Pipe = techage.LiquidPipe
local liquid = techage.liquid
local CYCLE_TIME = 2 local CYCLE_TIME = 2
local EFFICIENCY = 0.5 local BURN_CYCLE_FACTOR = 0.5
local function firehole(pos, on) local function firehole(pos, on)
local param2 = techage.get_node_lvm(pos).param2 local param2 = techage.get_node_lvm(pos).param2
@ -38,38 +35,39 @@ local function firehole(pos, on)
end end
local function node_timer(pos, elapsed) local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if mem.running then if nvm.running then
-- trigger generator and provide power ratio 0..1 local power = techage.transfer(
local ratio = techage.transfer(
{x=pos.x, y=pos.y+2, z=pos.z}, {x=pos.x, y=pos.y+2, z=pos.z},
nil, -- outdir nil, -- outdir
"trigger", -- topic "trigger", -- topic
(mem.power_level or 4)/4.0, -- payload nil, -- payload
nil, -- network nil, -- network
{"techage:coalboiler_top"} -- nodenames {"techage:coalboiler_top"} -- nodenames
) )
ratio = math.max((ratio or 0.02), 0.02) nvm.burn_cycles = (nvm.burn_cycles or 0) - math.max((power or 0.02), 0.02)
mem.burn_cycles = (mem.burn_cycles or 0) - ratio if nvm.burn_cycles <= 0 then
if mem.burn_cycles <= 0 then
local taken = firebox.get_fuel(pos) local taken = firebox.get_fuel(pos)
if taken then if taken then
mem.burn_cycles = (firebox.Burntime[taken:get_name()] or 1) * EFFICIENCY / CYCLE_TIME nvm.burn_cycles = (firebox.Burntime[taken:get_name()] or 1) / CYCLE_TIME * BURN_CYCLE_FACTOR
mem.burn_cycles_total = mem.burn_cycles nvm.burn_cycles_total = nvm.burn_cycles
else else
mem.running = false nvm.running = false
firehole(pos, false) firehole(pos, false)
M(pos):set_string("formspec", firebox.formspec(mem)) M(pos):set_string("formspec", firebox.formspec(nvm))
return false return false
end end
end end
if techage.is_activeformspec(pos) then
M(pos):set_string("formspec", firebox.formspec(nvm))
end
return true return true
end end
end end
local function start_firebox(pos, mem) local function start_firebox(pos, nvm)
if not mem.running then if not nvm.running then
mem.running = true nvm.running = true
node_timer(pos, 0) node_timer(pos, 0)
firehole(pos, true) firehole(pos, true)
minetest.get_node_timer(pos):start(CYCLE_TIME) minetest.get_node_timer(pos):start(CYCLE_TIME)
@ -98,17 +96,15 @@ minetest.register_node("techage:coalfirebox", {
can_dig = firebox.can_dig, can_dig = firebox.can_dig,
allow_metadata_inventory_put = firebox.allow_metadata_inventory_put, allow_metadata_inventory_put = firebox.allow_metadata_inventory_put,
allow_metadata_inventory_take = firebox.allow_metadata_inventory_take, allow_metadata_inventory_take = firebox.allow_metadata_inventory_take,
on_receive_fields = firebox.on_receive_fields,
on_rightclick = firebox.on_rightclick, on_rightclick = firebox.on_rightclick,
on_construct = function(pos) on_construct = function(pos)
local mem = tubelib2.init_mem(pos)
techage.add_node(pos, "techage:coalfirebox") techage.add_node(pos, "techage:coalfirebox")
mem.running = false local nvm = techage.get_nvm(pos)
mem.burn_cycles = 0 nvm.running = false
mem.power_level = 4 nvm.burn_cycles = 0
local meta = M(pos) local meta = M(pos)
meta:set_string("formspec", firebox.formspec(mem)) meta:set_string("formspec", firebox.formspec(nvm))
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size('fuel', 1) inv:set_size('fuel', 1)
firehole(pos, false) firehole(pos, false)
@ -119,9 +115,9 @@ minetest.register_node("techage:coalfirebox", {
end, end,
on_metadata_inventory_put = function(pos, listname, index, stack, player) on_metadata_inventory_put = function(pos, listname, index, stack, player)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
start_firebox(pos, mem) start_firebox(pos, nvm)
M(pos):set_string("formspec", firebox.formspec(mem)) M(pos):set_string("formspec", firebox.formspec(nvm))
end, end,
}) })
@ -188,128 +184,6 @@ minetest.register_node("techage:coalfirehole_on", {
groups = {not_in_creative_inventory=1}, 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"}, { techage.register_node({"techage:coalfirebox"}, {
on_pull_item = function(pos, in_dir, num) on_pull_item = function(pos, in_dir, num)
@ -321,8 +195,8 @@ techage.register_node({"techage:coalfirebox"}, {
if firebox.Burntime[stack:get_name()] then if firebox.Burntime[stack:get_name()] then
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
start_firebox(pos, mem) start_firebox(pos, nvm)
return techage.put_items(inv, "fuel", stack) return techage.put_items(inv, "fuel", stack)
end end
return false return false
@ -333,9 +207,9 @@ techage.register_node({"techage:coalfirebox"}, {
return techage.put_items(inv, "fuel", stack) return techage.put_items(inv, "fuel", stack)
end, end,
on_recv_message = function(pos, src, topic, payload) on_recv_message = function(pos, src, topic, payload)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if topic == "state" then if topic == "state" then
if mem.running then if nvm.running then
return "running" return "running"
else else
return "stopped" return "stopped"
@ -350,23 +224,6 @@ techage.register_node({"techage:coalfirebox"}, {
end, 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({ minetest.register_craft({
output = "techage:coalfirebox", output = "techage:coalfirebox",
recipe = { recipe = {
@ -376,21 +233,14 @@ minetest.register_craft({
}, },
}) })
minetest.register_craft({
output = "techage:oilfirebox",
recipe = {
{'', 'techage:coalfirebox', ''},
{'', 'techage:ta3_barrel_empty', ''},
{'', '', ''},
},
})
minetest.register_lbm({ minetest.register_lbm({
label = "[techage] Power Station firebox", label = "[techage] Power Station firebox",
name = "techage:steam_engine", name = "techage:coalfirebox",
nodenames = {"techage:coalfirebox", "techage:oilfirebox"}, nodenames = {"techage:coalfirebox"},
run_at_every_load = true, run_at_every_load = true,
action = function(pos, node) action = function(pos, node)
local nvm = techage.get_nvm(pos)
nvm.running = true
minetest.get_node_timer(pos):start(CYCLE_TIME) minetest.get_node_timer(pos):start(CYCLE_TIME)
end end
}) })

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -23,32 +23,42 @@ local PWR_CAPA = 80
local Cable = techage.ElectricCable local Cable = techage.ElectricCable
local power = techage.power local power = techage.power
local networks = techage.networks
local function formspec(self, pos, mem) local function formspec(self, pos, nvm)
return "size[8,7]".. 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..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
"image[6,0.5;1,2;"..power.formspec_power_bar(PWR_CAPA, mem.provided).."]".. power.formspec_label_bar(0, 0.8, S("power"), PWR_CAPA, nvm.provided)..
"image_button[5,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]".. "image_button[2.8,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"button[2,1.5;2,1;update;"..S("Update").."]".. "tooltip[2.8,2;1,1;"..self:get_state_tooltip(nvm).."]"
"list[current_player;main;0,3;8,4;]"..
default.get_hotbar_bg(0, 3)
end end
local function can_start(pos, mem, state) local function transfer_turbine(pos, topic, payload)
return (mem.firebox_trigger or 0) > 0 -- by means of firebox return techage.transfer(pos, "L", topic, payload, nil,
{"techage:turbine", "techage:turbine_on"})
end end
local function start_node(pos, mem, state) local function can_start(pos, nvm, state)
mem.generating = true -- needed for power distribution return (nvm.firebox_trigger or 0) > 0 -- by means of firebox
power.generator_start(pos, mem, PWR_CAPA)
end end
local function stop_node(pos, mem, state) local function start_node(pos, nvm, state)
mem.generating = false local outdir = M(pos):get_int("outdir")
power.generator_stop(pos, mem) power.generator_start(pos, Cable, CYCLE_TIME, outdir)
mem.provided = 0 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 end
local State = techage.NodeStates:new({ local State = techage.NodeStates:new({
@ -64,42 +74,63 @@ local State = techage.NodeStates:new({
}) })
local function node_timer(pos, elapsed) local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if mem.generating then nvm.firebox_trigger = (nvm.firebox_trigger or 0) - 1
mem.firebox_trigger = (mem.firebox_trigger or 0) - 1 if nvm.firebox_trigger <= 0 then
if mem.firebox_trigger <= 0 then State:nopower(pos, nvm)
State:nopower(pos, mem) stop_node(pos, nvm, State)
mem.generating = false transfer_turbine(pos, "stop")
power.generator_stop(pos, mem)
mem.provided = 0
else else
mem.provided = power.generator_alive(pos, mem) local outdir = M(pos):get_int("outdir")
State:keep_running(pos, mem, COUNTDOWN_TICKS) nvm.provided = power.generator_alive(pos, Cable, CYCLE_TIME, outdir)
State:keep_running(pos, nvm, COUNTDOWN_TICKS)
end end
if techage.is_activeformspec(pos) then
M(pos):set_string("formspec", formspec(State, pos, nvm))
end end
return State:is_active(mem) return State:is_active(nvm)
end end
local function on_receive_fields(pos, formname, fields, player) local function on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then if minetest.is_protected(pos, player:get_player_name()) then
return return
end end
local mem = tubelib2.get_mem(pos) local nvm,_ = techage.get_nvm(pos, true)
State:state_button_event(pos, mem, fields) State:state_button_event(pos, nvm, fields)
if fields.update then
M(pos):set_string("formspec", formspec(State, pos, mem))
end
end end
local function on_rightclick(pos) local function on_rightclick(pos, node, clicker)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(State, pos, mem)) techage.set_activeformspec(pos, clicker)
if mem.generating then M(pos):set_string("formspec", formspec(State, pos, nvm))
minetest.get_node_timer(pos):start(CYCLE_TIME)
end
end 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", { minetest.register_node("techage:generator", {
description = S("TA3 Generator"), description = S("TA3 Generator"),
tiles = { 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",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_generator.png^[transformFX]", "techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_generator.png^[transformFX]",
}, },
on_receive_fields = on_receive_fields, on_receive_fields = on_receive_fields,
on_rightclick = on_rightclick, on_rightclick = on_rightclick,
on_timer = node_timer, on_timer = node_timer,
after_place_node = after_place_node,
after_dig_node = after_dig_node,
tubelib2_on_update2 = tubelib2_on_update2,
networks = net_def,
paramtype2 = "facedir", paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2}, groups = {cracky=2, crumbly=2, choppy=2},
on_rotate = screwdriver.disallow, on_rotate = screwdriver.disallow,
@ -154,6 +191,11 @@ minetest.register_node("techage:generator_on", {
on_receive_fields = on_receive_fields, on_receive_fields = on_receive_fields,
on_rightclick = on_rightclick, on_rightclick = on_rightclick,
on_timer = node_timer, on_timer = node_timer,
after_place_node = after_place_node,
after_dig_node = after_dig_node,
tubelib2_on_update2 = tubelib2_on_update2,
networks = net_def,
drop = "", drop = "",
paramtype2 = "facedir", paramtype2 = "facedir",
groups = {not_in_creative_inventory=1}, groups = {not_in_creative_inventory=1},
@ -163,38 +205,15 @@ minetest.register_node("techage:generator_on", {
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
}) })
minetest.register_craft({ Cable:add_secondary_node_names({"techage:generator", "techage:generator_on"})
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"},
},
})
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"}, { techage.register_node({"techage:generator", "techage:generator_on"}, {
on_transfer = function(pos, in_dir, topic, payload) on_transfer = function(pos, in_dir, topic, payload)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if topic == "power_level" then if topic == "trigger" then
local mem = tubelib2.get_mem(pos) nvm.firebox_trigger = 3
mem.power_level = payload if nvm.running then
elseif topic == "trigger" then return math.max((nvm.provided or PWR_CAPA) / PWR_CAPA, 0.1)
mem.firebox_trigger = 3
mem.power_level = payload
if mem.generating then
return math.max((mem.provided or PWR_CAPA) / PWR_CAPA, 0.02)
else else
return 0 return 0
end end
@ -209,7 +228,18 @@ techage.register_node({"techage:generator", "techage:generator_on"}, {
end end
end, end,
on_node_load = function(pos) on_node_load = function(pos)
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
State:on_node_load(pos) State:on_node_load(pos)
end, 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 TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -37,35 +37,41 @@ local function swap_node(pos, name)
minetest.swap_node(pos, node) minetest.swap_node(pos, node)
end end
local function play_sound(pos)
local function node_timer(pos) local mem = techage.get_mem(pos)
local mem = tubelib2.get_mem(pos)
if mem.running then
mem.handle = minetest.sound_play("techage_turbine", { mem.handle = minetest.sound_play("techage_turbine", {
pos = pos, pos = pos,
gain = 1, gain = 1,
max_hear_distance = 15}) max_hear_distance = 15,
end loop = true})
return mem.running if mem.handle == -1 then
end minetest.after(1, play_sound, pos)
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)
end end
end end
local function stop_sound(pos) local function stop_sound(pos)
local mem = tubelib2.get_mem(pos) local mem = techage.get_mem(pos)
if mem.running and mem.handle then if mem.handle then
minetest.sound_stop(mem.handle) minetest.sound_stop(mem.handle)
mem.handle = nil mem.handle = nil
minetest.get_node_timer(pos):stop(2)
end end
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", { minetest.register_node("techage:turbine", {
description = S("TA3 Turbine"), description = S("TA3 Turbine"),
tiles = { 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",
"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", paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2}, groups = {cracky=2, crumbly=2, choppy=2},
on_rotate = screwdriver.disallow, 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", paramtype2 = "facedir",
groups = {not_in_creative_inventory=1}, groups = {not_in_creative_inventory=1},
diggable = false, diggable = false,
@ -121,49 +134,41 @@ minetest.register_node("techage:turbine_on", {
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
}) })
-- for mechanical pipe connections Pipe:add_secondary_node_names({"techage:turbine", "techage:turbine_on"})
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
})
-- for logical communication
techage.register_node({"techage:turbine", "techage:turbine_on"}, { techage.register_node({"techage:turbine", "techage:turbine_on"}, {
on_transfer = function(pos, in_dir, topic, payload) on_transfer = function(pos, in_dir, topic, payload)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
if topic == "trigger" then if topic == "trigger" then -- used by boiler
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
if not transfer_cooler(pos, topic, payload) then if not transfer_cooler(pos, topic, payload) then
swap_node(pos, "techage:turbine") return 0
mem.running = false
stop_sound(pos)
return false
end end
return true local power = transfer_generator(pos, topic, payload)
elseif topic == "stop" then if not power or power <= 0 and nvm.running then
transfer_cooler(pos, topic, payload) swap_node(pos, "techage:cylinder")
swap_node(pos, "techage:turbine")
mem.running = false
stop_sound(pos) 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 -- used by generator
swap_node(pos, "techage:turbine")
stop_sound(pos)
nvm.running = false
return true 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
end,
}) })
minetest.register_craft({ 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", "\n",
"Erdöl kann nur mit Hilfe des Explorers gefunden und mit Hilfe entsprechender TA3 Maschinen gefördert werden. Siehe TA3.\n".. "Erdöl kann nur mit Hilfe des Explorers gefunden und mit Hilfe entsprechender TA3 Maschinen gefördert werden. Siehe TA3.\n"..
"\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".. "Es wird zur Herstellung von Aluminium benötigt\\, was vor allem in TA4 Verwendung findet.\n"..
"\n", "\n",
" - 28.09.2019: Um Solaranlage erweitert\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"}, { techage.register_node({"techage:heatexchanger1"}, {
on_recv_message = function(pos, src, topic, payload) on_recv_message = function(pos, src, topic, payload)
local mem = tubelib2.get_mem(pos) local mem = tubelib2.get_mem(pos)
if topic == "capa" then if topic == "load" then
return techage.power.percent(mem.capa_max, mem.capa) return techage.power.percent(mem.capa_max, mem.capa)
elseif topic == "size" then
return (mem.capa_max or 0) / GRVL_CAPA
else else
return State:on_receive_message(pos, topic, payload) return State:on_receive_message(pos, topic, payload)
end end

View File

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

View File

@ -17,7 +17,7 @@ local P = minetest.string_to_pos
local M = minetest.get_meta local M = minetest.get_meta
local S = techage.S local S = techage.S
local range = techage.range local range = techage.in_range
local Recipes = {} -- registered recipes {output = {recipe, ...},} local Recipes = {} -- registered recipes {output = {recipe, ...},}
local Ingredients = {} -- {{input = output}, 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 reset_cooking = techage.furnace.reset_cooking
local get_ingredients = techage.furnace.get_ingredients local get_ingredients = techage.furnace.get_ingredients
local check_if_worth_to_wakeup = techage.furnace.check_if_worth_to_wakeup 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) local function update_recipe_menu(pos, mem)

View File

@ -8,7 +8,7 @@
GPL v3 GPL v3
See LICENSE.txt for more information 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.ElectricCable
local power = techage.power local power = techage.power
local Pipe = techage.LiquidPipe
local liquid = techage.liquid
local CYCLE_TIME = 2 local CYCLE_TIME = 2
local STANDBY_TICKS = 5 local STANDBY_TICKS = 5
local PWR_NEEDED = 40 local PWR_NEEDED = 40
local PWR_UNITS_PER_HYDROGEN_ITEM = 320 local PWR_UNITS_PER_HYDROGEN_ITEM = 320
local CAPACITY = 400
local function formspec(self, pos, mem) local function formspec(self, pos, mem)
local update = ((mem.countdown or 0) > 0 and mem.countdown) or S("Update")
return "size[8,6.6]".. return "size[8,6.6]"..
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
"image[0.5,0;1,2;"..power.formspec_power_bar(PWR_NEEDED, mem.consumed).."]".. "image[0.0,0;1,2;"..power.formspec_power_bar(PWR_NEEDED, mem.consumed).."]"..
"label[0.7,1.9;"..S("\\[ku\\]").."]".. "label[0.2,1.9;"..S("\\[ku\\]").."]"..
"image[3,0;1,1;techage_form_arrow_fg.png^[transformR270]".. "image[2.5,0;1,1;techage_form_arrow_fg.png^[transformR270]"..
"image_button[4,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]".. "image_button[3.5,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]"..
"button[2.1,1;1.8,1;update;"..S("Update").."]".. "tooltip[3.5,1;1,1;"..self:get_state_tooltip(mem).."]"..
"list[context;dst;5.5,0;2,2;]".. "button[1.6,1;1.8,1;update;"..update.."]"..
"list[current_player;main;0,2.8;8,4;]" .. "list[current_player;main;0,2.8;8,4;]" ..
"listring[current_player;main]".. liquid.formspec_liquid(5, 0, mem)..
"listring[context;dst]" ..
"listring[current_player;main]"..
default.get_hotbar_bg(0, 2.8) default.get_hotbar_bg(0, 2.8)
end end
@ -55,8 +57,8 @@ local function stop_node(pos, mem, state)
end end
local State = techage.NodeStates:new({ local State = techage.NodeStates:new({
node_name_passive = "techage:ta4_electrolyzer", node_name_passive = "techage:ta4_electrolyzer2",
node_name_active = "techage:ta4_electrolyzer_on", node_name_active = "techage:ta4_electrolyzer2_on",
cycle_time = CYCLE_TIME, cycle_time = CYCLE_TIME,
standby_ticks = STANDBY_TICKS, standby_ticks = STANDBY_TICKS,
formspec_func = formspec, formspec_func = formspec,
@ -65,47 +67,45 @@ local State = techage.NodeStates:new({
stop_node = stop_node, 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 -- converts power into hydrogen
local function node_timer(pos, elapsed) local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos) local mem = tubelib2.get_mem(pos)
mem.num_pwr_units = mem.num_pwr_units or 0 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 mem.running then
if techage.needs_power(mem) then if techage.needs_power(mem) then
mem.consumed = -power.secondary_alive(pos, mem, 0, 1) mem.consumed = -power.secondary_alive(pos, mem, 0, 1)
--print("mem.consumed", mem.consumed) --print("mem.consumed", mem.consumed)
if mem.consumed > 0 then if mem.consumed > 0 then
if mem.liquid.amount < CAPACITY then
mem.num_pwr_units = mem.num_pwr_units + mem.consumed mem.num_pwr_units = mem.num_pwr_units + mem.consumed
if mem.num_pwr_units >= PWR_UNITS_PER_HYDROGEN_ITEM then if mem.num_pwr_units >= PWR_UNITS_PER_HYDROGEN_ITEM then
if add_hydrogen(pos) 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 mem.num_pwr_units = mem.num_pwr_units - PWR_UNITS_PER_HYDROGEN_ITEM
State:keep_running(pos, mem, 1, 0) -- count items State:keep_running(pos, mem, 1, 0) -- count items
end
else else
State:blocked(pos, mem) State:blocked(pos, mem)
power.secondary_stop(pos, mem) power.secondary_stop(pos, mem)
end end
end end
end
else else
mem.consumed = -power.secondary_alive(pos, mem, 1, 1) 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) State:start(pos, mem)
power.secondary_start(pos, mem, PWR_NEEDED, PWR_NEEDED) power.secondary_start(pos, mem, PWR_NEEDED, PWR_NEEDED)
end end
end 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 end
local function on_receive_fields(pos, formname, fields, player) 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) local mem = tubelib2.get_mem(pos)
State:state_button_event(pos, mem, fields) State:state_button_event(pos, mem, fields)
if fields.update then mem.countdown = 10
M(pos):set_string("formspec", formspec(State, pos, mem)) M(pos):set_string("formspec", formspec(State, pos, mem))
end minetest.get_node_timer(pos):start(CYCLE_TIME)
end end
local function allow_metadata_inventory(pos, listname, index, stack, player) local function allow_metadata_inventory(pos, listname, index, stack, player)
@ -132,10 +132,12 @@ end
local function on_rightclick(pos) local function on_rightclick(pos)
local mem = tubelib2.get_mem(pos) local mem = tubelib2.get_mem(pos)
mem.countdown = 10
M(pos):set_string("formspec", formspec(State, pos, mem)) M(pos):set_string("formspec", formspec(State, pos, mem))
minetest.get_node_timer(pos):start(CYCLE_TIME)
end end
minetest.register_node("techage:ta4_electrolyzer", { minetest.register_node("techage:ta4_electrolyzer2", {
description = S("TA4 Electrolyzer"), description = S("TA4 Electrolyzer"),
tiles = { tiles = {
-- up, down, right, left, back, front -- up, down, right, left, back, front
@ -149,14 +151,19 @@ minetest.register_node("techage:ta4_electrolyzer", {
on_construct = function(pos) on_construct = function(pos)
local mem = tubelib2.init_mem(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.running = false
mem.num_pwr_units = 0 mem.num_pwr_units = 0
State:node_init(pos, mem, number) State:node_init(pos, mem, number)
local meta = M(pos) local meta = M(pos)
meta:set_string("formspec", formspec(State, pos, mem)) meta:set_string("formspec", formspec(State, pos, mem))
local inv = meta:get_inventory() 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, end,
can_dig = function(pos, player) can_dig = function(pos, player)
@ -164,6 +171,26 @@ minetest.register_node("techage:ta4_electrolyzer", {
return inv:is_empty("dst") return inv:is_empty("dst")
end, 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_put = allow_metadata_inventory,
allow_metadata_inventory_take = allow_metadata_inventory, allow_metadata_inventory_take = allow_metadata_inventory,
on_receive_fields = on_receive_fields, on_receive_fields = on_receive_fields,
@ -176,7 +203,7 @@ minetest.register_node("techage:ta4_electrolyzer", {
is_ground_content = false, is_ground_content = false,
}) })
minetest.register_node("techage:ta4_electrolyzer_on", { minetest.register_node("techage:ta4_electrolyzer2_on", {
description = S("TA4 Electrolyzer"), description = S("TA4 Electrolyzer"),
tiles = { tiles = {
-- up, down, right, left, back, front -- 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_put = allow_metadata_inventory,
allow_metadata_inventory_take = allow_metadata_inventory, allow_metadata_inventory_take = allow_metadata_inventory,
on_receive_fields = on_receive_fields, on_receive_fields = on_receive_fields,
@ -221,46 +272,29 @@ minetest.register_node("techage:ta4_electrolyzer_on", {
light_source = 6, 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"}, conn_sides = {"L"},
power_network = Power, power_network = Power,
after_place_node = function(pos) after_place_node = function(pos)
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
local indir = techage.side_to_indir("R", node.param2) local indir = techage.side_to_indir("R", node.param2)
M(pos):set_int("in_dir", indir) 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, end,
}) })
techage.register_node({"techage:ta4_electrolyzer", "techage:ta4_electrolyzer_on"}, { -- Register for tubes
on_pull_item = function(pos, in_dir, num) techage.register_node({"techage:ta4_electrolyzer2", "techage:ta4_electrolyzer2_on"}, liquid.tubing)
local meta = minetest.get_meta(pos)
if meta:get_int("in_dir") == in_dir then -- Register for pipes
local inv = M(pos):get_inventory() Pipe:add_secondary_node_names({"techage:ta3_tank", "techage:ta4_tank", "techage:oiltank"})
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,
})
minetest.register_craft({ minetest.register_craft({
output = "techage:ta4_electrolyzer", output = "techage:ta4_electrolyzer2",
recipe = { recipe = {
{'default:steel_ingot', 'dye:blue', 'default:steel_ingot'}, {'default:steel_ingot', 'dye:blue', 'default:steel_ingot'},
{'techage:electric_cableS', 'default:glass', 'techage:tubeS'}, {'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'},
},
})

226
init.lua
View File

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

View File

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

View File

@ -32,7 +32,7 @@ minetest.register_node("techage:lighter_burn", {
drop = "", drop = "",
light_source = 10, light_source = 10,
is_ground_content = false, 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(), sounds = default.node_sound_dirt_defaults(),
}) })
@ -56,7 +56,7 @@ minetest.register_node("techage:coal_lighter_burn", {
drop = "", drop = "",
light_source = 10, light_source = 10,
is_ground_content = false, 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(), sounds = default.node_sound_dirt_defaults(),
}) })
@ -75,7 +75,7 @@ minetest.register_node("techage:lighter", {
meta:set_string("playername", placer:get_player_name()) meta:set_string("playername", placer:get_player_name())
end, end,
is_ground_content = false, 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(), sounds = default.node_sound_dirt_defaults(),
}) })

View File

@ -40,7 +40,7 @@ minetest.register_ore({
clust_num_ores = 5, clust_num_ores = 5,
clust_size = 3, clust_size = 3,
y_min = -340, y_min = -340,
y_max = -260, y_max = -250,
}) })
minetest.register_craft({ 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", 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({ minetest.register_craft({
output = 'techage:ta3_barrel_empty 6', 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_water", "bucket:bucket_empty", 1, "techage:water")
techage.register_liquid("bucket:bucket_river_water", "bucket:bucket_empty", 1, "techage:river_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(), 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", { minetest.register_node("techage:basalt_cobble", {
description = S("Basalt Cobble"), description = S("Basalt Cobble"),
tiles = {"default_cobble.png^[brighten"}, tiles = {"default_cobble.png^[brighten"},
@ -40,6 +51,17 @@ minetest.register_node("techage:basalt_cobble", {
sounds = default.node_sound_stone_defaults(), 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", { minetest.register_node("techage:basalt_stone_brick", {
description = S("Basalt Stone Brick"), description = S("Basalt Stone Brick"),
paramtype2 = "facedir", paramtype2 = "facedir",
@ -50,6 +72,17 @@ minetest.register_node("techage:basalt_stone_brick", {
sounds = default.node_sound_stone_defaults(), 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", { minetest.register_node("techage:basalt_stone_block", {
description = S("Basalt Stone Block"), description = S("Basalt Stone Block"),
tiles = {"default_stone_block.png^[brighten"}, tiles = {"default_stone_block.png^[brighten"},
@ -58,6 +91,17 @@ minetest.register_node("techage:basalt_stone_block", {
sounds = default.node_sound_stone_defaults(), 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", { minetest.register_node("techage:basalt_gravel", {
description = S("Basalt Gravel"), description = S("Basalt Gravel"),
tiles = {"default_gravel.png^[brighten"}, tiles = {"default_gravel.png^[brighten"},
@ -65,6 +109,17 @@ minetest.register_node("techage:basalt_gravel", {
sounds = default.node_sound_gravel_defaults(), 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", { minetest.register_node("techage:sieved_basalt_gravel", {
description = S("Sieved Basalt Gravel"), description = S("Sieved Basalt Gravel"),
tiles = {"default_gravel.png^[brighten"}, tiles = {"default_gravel.png^[brighten"},
@ -85,6 +140,17 @@ minetest.register_node("techage:basalt_glass", {
sounds = default.node_sound_glass_defaults(), 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", { minetest.register_node("techage:basalt_glass2", {
description = S("Basalt Glass 2"), description = S("Basalt Glass 2"),
drawtype = "glasslike_framed_optional", drawtype = "glasslike_framed_optional",
@ -98,6 +164,17 @@ minetest.register_node("techage:basalt_glass2", {
sounds = default.node_sound_glass_defaults(), 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", { minetest.register_node("techage:basalt_glass_thin", {
description = S("Basalt Glass Thin"), description = S("Basalt Glass Thin"),
drawtype = "nodebox", drawtype = "nodebox",
@ -174,50 +251,6 @@ minetest.register_node("techage:basalt_glass_thin_xl2", {
sounds = default.node_sound_glass_defaults(), 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({ minetest.register_craft({
output = "techage:basalt_stone_brick 4", output = "techage:basalt_stone_brick 4",
recipe = { recipe = {

View File

@ -38,9 +38,19 @@ minetest.register_craftitem("techage:gasoline", {
minetest.register_craftitem("techage:gas", { minetest.register_craftitem("techage:gas", {
description = S("TA3 Gas"), description = S("TA3 Gas"),
inventory_image = "techage_gas_inv.png", 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", { minetest.register_craftitem("techage:ta3_barrel_bitumen", {
description = S("TA3 Bitumen Barrel"), 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_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_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_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_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_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_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_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_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 function get_network_table(pos, outdir, ntype)
local netID = get_netID(pos, outdir) local netID = get_netID(pos, outdir)
if netID then if netID then
local netw = networks.get_network(netID, Pipe) local netw = networks.get_network("pipe", netID)
if not netw then if not netw then
netw = networks.collect_network_nodes(pos, outdir, Pipe) netw = networks.collect_network_nodes(pos, outdir, Pipe)
networks.set_network(netID, Pipe, netw) networks.set_network("pipe", netID, netw)
end end
local s = minetest.pos_to_string(minetest.get_position_from_hash(netID)) local s = minetest.pos_to_string(minetest.get_position_from_hash(netID))
--print("netw", string.format("%012X", netID), s, dump(netw)) --print("netw", string.format("%012X", netID), s, dump(netw))

View File

@ -16,93 +16,22 @@ local S2P = minetest.string_to_pos
local P2S = minetest.pos_to_string local P2S = minetest.pos_to_string
local M = minetest.get_meta local M = minetest.get_meta
local S = techage.S local S = techage.S
local LQD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).liquid end
local Pipe = techage.LiquidPipe local Pipe = techage.LiquidPipe
local liquid = techage.liquid local liquid = techage.liquid
local CAPACITY = 500 local CAPACITY = 500
local function formspec(pos, mem)
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 update = ((mem.countdown or 0) > 0 and mem.countdown) or S("Update") local update = ((mem.countdown or 0) > 0 and mem.countdown) or S("Update")
return "size[8,6]".. return "size[8,6]"..
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
formspec_tank(2, 0, mem).. liquid.formspec_liquid(2, 0, mem)..
"button[5.5,0.5;2,1;update;"..update.."]".. "button[5.5,0.5;2,1;update;"..update.."]"..
"list[current_player;main;0,2.3;8,4;]" "list[current_player;main;0,2.3;8,4;]"
end end
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) local function allow_metadata_inventory_put(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then if minetest.is_protected(pos, player:get_player_name()) then
return 0 return 0
@ -122,13 +51,13 @@ local function allow_metadata_inventory_move()
end end
local function on_metadata_inventory_put(pos, listname, index, stack, player) 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 end
local function on_rightclick(pos) local function on_rightclick(pos)
local mem = tubelib2.get_mem(pos) local mem = tubelib2.get_mem(pos)
mem.countdown = 10 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) minetest.get_node_timer(pos):start(2)
end end
@ -138,7 +67,7 @@ local function on_receive_fields(pos, formname, fields, player)
end end
local mem = tubelib2.get_mem(pos) local mem = tubelib2.get_mem(pos)
mem.countdown = 10 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) minetest.get_node_timer(pos):start(2)
end end
@ -146,9 +75,7 @@ local function can_dig(pos, player)
if minetest.is_protected(pos, player:get_player_name()) then if minetest.is_protected(pos, player:get_player_name()) then
return false return false
end end
local mem = tubelib2.get_mem(pos) return liquid.is_empty(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)
end end
@ -176,7 +103,7 @@ minetest.register_node("techage:ta3_tank", {
local number = techage.add_node(pos, "techage:ta3_tank") local number = techage.add_node(pos, "techage:ta3_tank")
meta:set_string("node_number", number) meta:set_string("node_number", number)
meta:set_string("owner", placer:get_player_name()) meta:set_string("owner", placer:get_player_name())
meta:set_string("formspec", formspec(mem)) meta:set_string("formspec", formspec(pos, mem))
meta:set_string("infotext", S("TA3 Tank").." "..number) meta:set_string("infotext", S("TA3 Tank").." "..number)
Pipe:after_place_node(pos) Pipe:after_place_node(pos)
end, end,
@ -187,7 +114,7 @@ minetest.register_node("techage:ta3_tank", {
local mem = tubelib2.get_mem(pos) local mem = tubelib2.get_mem(pos)
if mem.countdown then if mem.countdown then
mem.countdown = mem.countdown - 1 mem.countdown = mem.countdown - 1
M(pos):set_string("formspec", formspec(mem)) M(pos):set_string("formspec", formspec(pos, mem))
return mem.countdown > 0 return mem.countdown > 0
end end
end, end,
@ -202,7 +129,7 @@ minetest.register_node("techage:ta3_tank", {
local leftover = liquid.srv_put(pos, indir, name, amount) local leftover = liquid.srv_put(pos, indir, name, amount)
local inv = M(pos):get_inventory() local inv = M(pos):get_inventory()
if not inv:is_empty("src") and inv:is_empty("dst") then if not inv:is_empty("src") and inv:is_empty("dst") then
fill_container(pos, inv) liquid.fill_container(pos, inv)
end end
return leftover return leftover
end, end,
@ -263,7 +190,7 @@ minetest.register_node("techage:oiltank", {
local number = techage.add_node(pos, "techage:oiltank") local number = techage.add_node(pos, "techage:oiltank")
meta:set_string("node_number", number) meta:set_string("node_number", number)
meta:set_string("owner", placer:get_player_name()) meta:set_string("owner", placer:get_player_name())
meta:set_string("formspec", formspec(mem)) meta:set_string("formspec", formspec(pos, mem))
meta:set_string("infotext", S("Oil Tank").." "..number) meta:set_string("infotext", S("Oil Tank").." "..number)
Pipe:after_place_node(pos) Pipe:after_place_node(pos)
end, end,
@ -274,7 +201,7 @@ minetest.register_node("techage:oiltank", {
local mem = tubelib2.get_mem(pos) local mem = tubelib2.get_mem(pos)
if mem.countdown then if mem.countdown then
mem.countdown = mem.countdown - 1 mem.countdown = mem.countdown - 1
M(pos):set_string("formspec", formspec(mem)) M(pos):set_string("formspec", formspec(pos, mem))
return mem.countdown > 0 return mem.countdown > 0
end end
end, end,
@ -289,7 +216,7 @@ minetest.register_node("techage:oiltank", {
local leftover = liquid.srv_put(pos, indir, name, amount) local leftover = liquid.srv_put(pos, indir, name, amount)
local inv = M(pos):get_inventory() local inv = M(pos):get_inventory()
if not inv:is_empty("src") and inv:is_empty("dst") then if not inv:is_empty("src") and inv:is_empty("dst") then
fill_container(pos, inv) liquid.fill_container(pos, inv)
end end
return leftover return leftover
end, end,
@ -340,7 +267,7 @@ minetest.register_node("techage:ta4_tank", {
local number = techage.add_node(pos, "techage:ta4_tank") local number = techage.add_node(pos, "techage:ta4_tank")
meta:set_string("node_number", number) meta:set_string("node_number", number)
meta:set_string("owner", placer:get_player_name()) meta:set_string("owner", placer:get_player_name())
meta:set_string("formspec", formspec(mem)) meta:set_string("formspec", formspec(pos, mem))
meta:set_string("infotext", S("TA4 Tank").." "..number) meta:set_string("infotext", S("TA4 Tank").." "..number)
Pipe:after_place_node(pos) Pipe:after_place_node(pos)
end, end,
@ -351,7 +278,7 @@ minetest.register_node("techage:ta4_tank", {
local mem = tubelib2.get_mem(pos) local mem = tubelib2.get_mem(pos)
if mem.countdown then if mem.countdown then
mem.countdown = mem.countdown - 1 mem.countdown = mem.countdown - 1
M(pos):set_string("formspec", formspec(mem)) M(pos):set_string("formspec", formspec(pos, mem))
return mem.countdown > 0 return mem.countdown > 0
end end
end, end,
@ -366,7 +293,7 @@ minetest.register_node("techage:ta4_tank", {
local leftover = liquid.srv_put(pos, indir, name, amount) local leftover = liquid.srv_put(pos, indir, name, amount)
local inv = M(pos):get_inventory() local inv = M(pos):get_inventory()
if not inv:is_empty("src") and inv:is_empty("dst") then if not inv:is_empty("src") and inv:is_empty("dst") then
fill_container(pos, inv) liquid.fill_container(pos, inv)
end end
return leftover return leftover
end, end,
@ -392,45 +319,7 @@ minetest.register_node("techage:ta4_tank", {
sounds = default.node_sound_metal_defaults(), sounds = default.node_sound_metal_defaults(),
}) })
techage.register_node({"techage:ta3_tank", "techage:ta4_tank", "techage:oiltank"}, { techage.register_node({"techage:ta3_tank", "techage:ta4_tank", "techage:oiltank"}, liquid.tubing)
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,
})
Pipe:add_secondary_node_names({"techage:ta3_tank", "techage:ta4_tank", "techage:oiltank"}) 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. 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. 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. 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 ### 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] [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, max_hear_distance = 20,
gain = 1, gain = 1,
loop = true}) loop = true})
print("handle", handle) --print("handle", handle)
meta:set_int("handle", handle) meta:set_int("handle", handle)
end end
@ -140,7 +140,7 @@ minetest.register_node("techage:gasflare", {
end, end,
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
print(dump(oldmetadata)) --print(dump(oldmetadata))
stop_flarestack(pos, oldmetadata.fields.handle) stop_flarestack(pos, oldmetadata.fields.handle)
local node = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}) local node = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z})
if node.name == "techage:gasflare2" then 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 TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -33,11 +33,6 @@ local Axle = tubelib2.Tube:new({
end, 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", { minetest.register_node("techage:axle", {
description = S("TA2 Drive Axle"), description = S("TA2 Drive Axle"),
@ -182,17 +177,4 @@ minetest.register_craft({
}) })
-- Axles PNG animation techage.Axle = Axle
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

View File

@ -3,12 +3,12 @@
TechAge TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
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 M = minetest.get_meta
local S = techage.S local S = techage.S
local ELE1_MAX_CABLE_LENGHT = 1000
local Cable = tubelib2.Tube:new({ local Cable = tubelib2.Tube:new({
dirs_to_check = {1,2,3,4,5,6}, dirs_to_check = {1,2,3,4,5,6},
max_tube_length = 1000, max_tube_length = ELE1_MAX_CABLE_LENGHT,
show_infotext = false, show_infotext = false,
tube_type = "electric_cable", tube_type = "ele1",
primary_node_names = {"techage:electric_cableS", "techage:electric_cableA", primary_node_names = {"techage:electric_cableS", "techage:electric_cableA",
"techage:power_line", "techage:power_lineS", "techage:power_lineA", "techage:power_pole2"}, "techage:power_line", "techage:power_lineS", "techage:power_lineA",
"techage:power_pole2"},
secondary_node_names = {}, secondary_node_names = {},
after_place_tube = function(pos, param2, tube_type, num_tubes) after_place_tube = function(pos, param2, tube_type, num_tubes)
-- Handle "power line" nodes -- Handle "power line" nodes
@ -154,14 +157,6 @@ minetest.register_node("techage:electric_cableA", {
drop = "techage:electric_cableS", 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({ minetest.register_craft({
output = "techage:electric_cableS 6", output = "techage:electric_cableS 6",
recipe = { 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 TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -48,10 +48,10 @@ end
-- 'size' is the size of the junction cube without any connection, e.g. 1/8 -- '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 -- '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 -- 'node' is the node definition with tiles, callback functions, and so on
-- 'index' number for the inventory node (default 0) -- '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 for idx = 0,63 do
local ndef = table.copy(node) local ndef = table.copy(node)
if idx == (index or 0) then if idx == (index or 0) then
@ -69,23 +69,23 @@ function techage.register_junction(name, size, boxes, network, node, index)
ndef.is_ground_content = false ndef.is_ground_content = false
ndef.drop = name..(index or "0") ndef.drop = name..(index or "0")
minetest.register_node(name..idx, ndef) minetest.register_node(name..idx, ndef)
-- Register in addition for power distribution tlib2:add_secondary_node_names({name..idx})
if network then
techage.power.register_node({name..idx}, {
power_network = network,
after_tube_update = ndef.after_tube_update,
})
end
end end
end end
function techage.junction_type(pos, network) function techage.junction_type(pos, network)
local val = 0 local val = 0
for dir = 1,6 do for dir = 1,6 do
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 if network:connected(pos, dir) then
val = setbit(val, bit(dir)) val = setbit(val, bit(dir))
end end
end end
end
return val return val
end end

View File

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

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 TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -16,7 +16,9 @@ local P = minetest.string_to_pos
local M = minetest.get_meta local M = minetest.get_meta
local S = techage.S local S = techage.S
local networks = techage.networks
local Cable = techage.ElectricCable local Cable = techage.ElectricCable
local power = techage.power
-- Primary techage.ElectricCable node -- Primary techage.ElectricCable node
minetest.register_node("techage:power_line", { minetest.register_node("techage:power_line", {
@ -162,81 +164,6 @@ minetest.register_node("techage:power_lineA", {
sounds = default.node_sound_defaults(), 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", { minetest.register_node("techage:power_pole2", {
description = S("TA Power Pole Top 2 (for landlines)"), description = S("TA Power Pole Top 2 (for landlines)"),
tiles = { tiles = {
@ -256,8 +183,6 @@ minetest.register_node("techage:power_pole2", {
{ -2/32, -4/32, 12/32, 2/32, 4/32, 16/32}, { -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) after_place_node = function(pos, placer, itemstack, pointed_thing)
M(pos):set_string("owner", placer:get_player_name()) M(pos):set_string("owner", placer:get_player_name())
@ -296,9 +221,113 @@ minetest.register_node("techage:power_pole2", {
sounds = default.node_sound_defaults(), 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", { minetest.register_node("techage:power_pole3", {
description = S("TA Power Pole"), description = S("TA Power Pole"),
--tiles = {"techage_power_pole.png"},
tiles = { tiles = {
"default_wood.png", "default_wood.png",
"default_wood.png", "default_wood.png",
@ -321,24 +350,6 @@ minetest.register_node("techage:power_pole3", {
sounds = default.node_sound_defaults(), 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({ minetest.register_craft({
output = "techage:power_lineS 24", output = "techage:power_lineS 24",
recipe = { 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 TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -18,70 +18,64 @@ local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local M = minetest.get_meta local M = minetest.get_meta
local N = function(pos) return minetest.get_node(pos).name end 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 = {} techage.schedule = {}
local NetList = {} local JobTable = {}
local JobQueue = {} local JobQueue = {}
local first = 0 local first = 0
local last = -1 local last = -1
local LocalTime = 0
techage.SystemTime = 0
local function push(item) local function push(item)
last = last + 1 last = last + 1
item.time = LocalTime + CYCLE_TIME item.time = techage.SystemTime + CYCLE_TIME
JobQueue[last] = item JobQueue[last] = item
end end
local function pop() local function pop()
if first > last then return end if first > last then return end
local item = JobQueue[first] local item = JobQueue[first]
if item.time <= LocalTime then if item.time <= techage.SystemTime then
JobQueue[first] = nil -- to allow garbage collection JobQueue[first] = nil -- to allow garbage collection
first = first + 1 first = first + 1
return item return item
end end
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 -- Scheduler
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
LocalTime = LocalTime + dtime techage.SystemTime = techage.SystemTime + dtime
local item = pop() local item = pop()
while item do 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 if network and network.alive and network.alive >= 0 then
--techage.distribute.power_distribution(LocalTime, network) power_distribution(network, item.tube_type)
techage.power.power_distribution(LocalTime, network.mst_pos, network)
network.alive = network.alive - 1 network.alive = network.alive - 1
push(item) push(item)
else else
NetList[item.netkey] = nil JobTable[item.netID] = nil
networks.delete_network(item.tube_type, item.netID)
end end
item = pop() item = pop()
end end
end) end)
function techage.schedule.add_network(netkey, network) function techage.schedule.start(tube_type, netID)
if netkey then if not JobTable[netID] then
if NetList[netkey] then -- already scheduled push({tube_type = tube_type, netID = netID})
NetList[netkey] = network JobTable[netID] = true
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]
end end
end end

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -22,7 +22,7 @@ local Pipe = tubelib2.Tube:new({
max_tube_length = 12, max_tube_length = 12,
show_infotext = false, show_infotext = false,
force_to_use_tubes = true, force_to_use_tubes = true,
tube_type = "steam_pipe", tube_type = "pipe1",
primary_node_names = {"techage:steam_pipeS", "techage:steam_pipeA"}, primary_node_names = {"techage:steam_pipeS", "techage:steam_pipeA"},
secondary_node_names = {"techage:cylinder", "techage:cylinder_on", "techage:boiler2"}, secondary_node_names = {"techage:cylinder", "techage:cylinder_on", "techage:boiler2"},
after_place_tube = function(pos, param2, tube_type, num_tubes) after_place_tube = function(pos, param2, tube_type, num_tubes)
@ -30,13 +30,6 @@ local Pipe = tubelib2.Tube:new({
end, 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", { minetest.register_node("techage:steam_pipeS", {
description = S("TA2 Steam Pipe"), description = S("TA2 Steam Pipe"),
tiles = { tiles = {
@ -57,7 +50,7 @@ minetest.register_node("techage:steam_pipeS", {
end, end,
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
Pipe:after_dig_tube(pos, oldnode) Pipe:after_dig_tube(pos, oldnode, oldmetadata)
end, end,
paramtype2 = "facedir", -- important! paramtype2 = "facedir", -- important!
@ -88,7 +81,7 @@ minetest.register_node("techage:steam_pipeA", {
}, },
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
Pipe:after_dig_tube(pos, oldnode) Pipe:after_dig_tube(pos, oldnode, oldmetadata)
end, end,
paramtype2 = "facedir", -- important! paramtype2 = "facedir", -- important!
@ -117,3 +110,5 @@ minetest.register_craft({
{"default:bronze_ingot", '', ''}, {"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 TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -13,202 +13,91 @@
]]-- ]]--
-- for lazy programmers -- for lazy programmers
local P = minetest.string_to_pos
local M = minetest.get_meta local M = minetest.get_meta
local S = techage.S local S = techage.S
local CYCLE_TIME = 4 local CYCLE_TIME = 4
local STANDBY_TICKS = 2
local COUNTDOWN_TICKS = 2
local HEAT_STEP = 10
local WATER_CONSUMPTION = 0.5 local WATER_CONSUMPTION = 0.5
local MAX_WATER = 10
local Pipe = techage.SteamPipe local Pipe = techage.SteamPipe
local boiler = techage.boiler
local Water = { local function steaming(pos, nvm, temp)
["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)
if temp >= 80 then if temp >= 80 then
if mem.running then local wc = WATER_CONSUMPTION * (nvm.power_ratio or 1)
State:keep_running(pos, mem, COUNTDOWN_TICKS) nvm.water_level = math.max((nvm.water_level or 0) - wc, 0)
else
State:fault(pos, mem)
end
else
State:stop(pos, mem)
minetest.get_node_timer(pos):start(CYCLE_TIME)
end end
end end
local function node_timer(pos, elapsed) local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos) local nvm = techage.get_nvm(pos)
local temp = water_temperature(pos, mem) local temp = boiler.water_temperature(pos, nvm)
if State:is_active(mem) then steaming(pos, nvm, temp)
steaming(pos, mem, temp) if techage.is_activeformspec(pos) then
M(pos):set_string("formspec", boiler.formspec(pos, nvm))
end end
return mem.temperature > 20 return temp > 20
end end
local function on_receive_fields(pos, formname, fields, player) local function after_place_node(pos)
if minetest.is_protected(pos, player:get_player_name()) then local node = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z})
return 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 end
local mem = tubelib2.get_mem(pos) end
mem.temperature = mem.temperature or 20
State:state_button_event(pos, mem, fields)
if fields.update then local function after_dig_node(pos, oldnode)
if mem.temperature > 20 then 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},
},
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,
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) minetest.get_node_timer(pos):start(CYCLE_TIME)
end end
M(pos):set_string("formspec", formspec(State, pos, mem)) if (nvm.temperature or 20) > 80 then
end nvm.power_ratio = techage.transfer(pos, 6, "trigger", nil, Pipe, {
end "techage:cylinder", "techage:cylinder_on"}) or 0
return nvm.power_ratio
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)
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 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 return 0
end end
if listname == "input" and Water[stack:get_name()] then
return stack:get_count()
end end
return 0 end,
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
minetest.register_node("techage:boiler1", { minetest.register_node("techage:boiler1", {
description = S("TA2 Boiler Base"), description = S("TA2 Boiler Base"),
@ -227,73 +116,7 @@ minetest.register_node("techage:boiler1", {
sounds = default.node_sound_metal_defaults(), 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({ minetest.register_craft({
output = "techage:boiler1", output = "techage:boiler1",

View File

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

View File

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

View File

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