diff --git a/basis/boiler_lib.lua b/basis/boiler_lib.lua index f93b747..929bb80 100644 --- a/basis/boiler_lib.lua +++ b/basis/boiler_lib.lua @@ -67,6 +67,7 @@ end function techage.boiler.water_temperature(pos, nvm) nvm.temperature = nvm.temperature or 20 nvm.num_water = nvm.num_water or 0 + nvm.water_level = nvm.water_level or 0 if nvm.fire_trigger then nvm.temperature = math.min(nvm.temperature + HEAT_STEP, 100) else diff --git a/basis/fuel_lib.lua b/basis/fuel_lib.lua index 7b48fa4..df46357 100644 --- a/basis/fuel_lib.lua +++ b/basis/fuel_lib.lua @@ -71,91 +71,6 @@ function techage.fuel.formspec(nvm) techage.fuel.fuel_container(1.5, 1, nvm) end ---local function fill_container(pos, inv, nvm) --- nvm.liquid = nvm.liquid or {} --- nvm.liquid.amount = nvm.liquid.amount or 0 --- local empty_container = inv:get_stack("fuel", 1):get_name() --- local full_container = liquid.get_full_container(empty_container, nvm.liquid.name) --- if empty_container and full_container then --- local ldef = liquid.get_liquid_def(full_container) --- if ldef and nvm.liquid.amount - ldef.size >= 0 then --- inv:remove_item("fuel", ItemStack(empty_container)) --- inv:add_item("fuel", ItemStack(full_container)) --- nvm.liquid.amount = nvm.liquid.amount - ldef.size --- if nvm.liquid.amount == 0 then --- nvm.liquid.name = nil --- end --- end --- end ---end - ---local function empty_container(pos, inv, nvm) --- nvm.liquid = nvm.liquid or {} --- nvm.liquid.amount = nvm.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 nvm.liquid.name or ldef.inv_item == nvm.liquid.name then --- if nvm.liquid.amount + ldef.size <= CAPACITY then --- inv:remove_item("fuel", stack) --- inv:add_item("fuel", ItemStack(ldef.container)) --- nvm.liquid.amount = nvm.liquid.amount + ldef.size --- nvm.liquid.name = ldef.inv_item --- end --- end --- end --- end ---end - ---local function move_item(pos, stack) --- local nvm = techage.get_nvm(pos) --- local inv = M(pos):get_inventory() --- if liquid.is_container_empty(stack:get_name()) then --- fill_container(pos, inv, nvm) --- else --- empty_container(pos, inv, nvm) --- end --- M(pos):set_string("formspec", techage.fuel.formspec(nvm)) ---end - ---function techage.fuel.move_item(pos, stack, formspec) --- local nvm = techage.get_nvm(pos) --- local inv = M(pos):get_inventory() --- if liquid.is_container_empty(stack:get_name()) then --- fill_container(pos, inv, nvm) --- else --- empty_container(pos, inv, nvm) --- end --- M(pos):set_string("formspec", formspec(pos, nvm)) ---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 --- if liquid.is_container_empty(stack:get_name()) then --- return 1 --- end --- local category = LQD(pos).fuel_cat --- local ldef = liquid.get_liquid_def(stack:get_name()) --- if ldef and ValidOilFuels[ldef.inv_item] and ValidOilFuels[ldef.inv_item] <= category then --- return 1 --- end --- return 0 ---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 @@ -173,22 +88,6 @@ function techage.fuel.on_rightclick(pos, node, clicker) M(pos):set_string("formspec", techage.fuel.formspec(nvm)) end ---function techage.fuel.on_receive_fields(pos, formname, fields, player) --- if minetest.is_protected(pos, player:get_player_name()) then --- return --- end --- local nvm = techage.get_nvm(pos) --- nvm.countdown = 10 --- M(pos):set_string("formspec", techage.fuel.formspec(nvm)) ---end - ---function techage.fuel.formspec_update(pos, nvm) --- if nvm.countdown and nvm.countdown > 0 then --- nvm.countdown = nvm.countdown - 1 --- M(pos):set_string("formspec", techage.fuel.formspec(nvm)) --- end ---end - -- name is the fuel item name function techage.fuel.burntime(name) if ValidOilFuels[name] then @@ -229,3 +128,20 @@ function techage.fuel.on_punch(pos, node, puncher, pointed_thing) end end end + +function techage.fuel.get_fuel(nvm) + if nvm.liquid and nvm.liquid.name and nvm.liquid.amount then + if nvm.liquid.amount > 0 then + nvm.liquid.amount = nvm.liquid.amount - 1 + return nvm.liquid.name + end + nvm.liquid.name = nil + end + return nil +end + +function techage.fuel.has_fuel(nvm) + nvm.liquid = nvm.liquid or {} + nvm.liquid.amount = nvm.liquid.amount or 0 + return nvm.liquid.amount > 0 +end \ No newline at end of file diff --git a/chemistry/ta4_doser.lua b/chemistry/ta4_doser.lua index cd3dd43..dca4a4e 100644 --- a/chemistry/ta4_doser.lua +++ b/chemistry/ta4_doser.lua @@ -48,15 +48,15 @@ local function get_starter_name(pos) end local function formspec(self, pos, nvm) - return "size[8,7]".. + return "size[6,3.6]".. default.gui_bg.. default.gui_bg_img.. default.gui_slots.. - recipes.formspec(0, 0, "ta4_doser", nvm).. - "image_button[6,1;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. - "tooltip[6,1;1,1;"..self:get_state_tooltip(nvm).."]".. - "list[current_player;main;0,3.3;8,4;]" .. - default.get_hotbar_bg(0, 3.5) + "box[0,-0.1;5.8,0.5;#c6e8ff]".. + "label[2.5,-0.1;"..minetest.colorize( "#000000", S("Doser")).."]".. + recipes.formspec(0.1, 0.8, "ta4_doser", nvm).. + "image_button[5,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. + "tooltip[5,2;1,1;"..self:get_state_tooltip(nvm).."]" end local function get_liquids(pos) diff --git a/chemistry/ta4_stand.lua b/chemistry/ta4_stand.lua index 8ef275c..dd70661 100644 --- a/chemistry/ta4_stand.lua +++ b/chemistry/ta4_stand.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019 Joachim Stolberg + Copyright (C) 2019-2020 Joachim Stolberg GPL v3 See LICENSE.txt for more information @@ -23,16 +23,39 @@ local liquid = techage.liquid local PWR_NEEDED = 8 local CYCLE_TIME = 4 -local function on_power(pos, nvm) - if nvm.running then - minetest.get_node_timer(pos):start(CYCLE_TIME) - M(pos):set_string("infotext", S("on")) - nvm.has_power = true +local function play_sound(pos) + local mem = techage.get_mem(pos) + if not mem.handle or mem.handle == -1 then + mem.handle = minetest.sound_play("techage_reactor", { + pos = pos, + gain = 0.5, + max_hear_distance = 10, + loop = true}) + if mem.handle == -1 then + minetest.after(1, play_sound, pos) + end end end -local function on_nopower(pos, nvm) +local function stop_sound(pos) + local mem = techage.get_mem(pos) + if mem.handle then + minetest.sound_stop(mem.handle) + mem.handle = nil + end +end + +local function on_power(pos) + M(pos):set_string("infotext", S("on")) + play_sound(pos) + local nvm = techage.get_nvm(pos) + nvm.has_power = true +end + +local function on_nopower(pos) M(pos):set_string("infotext", S("no power")) + stop_sound(pos) + local nvm = techage.get_nvm(pos) nvm.has_power = false end @@ -71,29 +94,25 @@ minetest.register_node("techage:ta4_reactor_stand", { after_place_node = function(pos, placer) local nvm = techage.get_nvm(pos) - techage.power.after_place_node(pos) M(pos):set_string("infotext", S("off")) M(pos):set_int("outdir", networks.side_to_outdir(pos, "R")) Pipe:after_place_node(pos) + Cable:after_place_node(pos) end, tubelib2_on_update2 = function(pos, dir, tlib2, node) - liquid.update_network(pos) - end, - after_tube_update = function(node, pos, out_dir, peer_pos, peer_in_dir) - techage.power.after_tube_update2(node, pos, out_dir, peer_pos, peer_in_dir) + if tlib2.tube_type == "ele1" then + power.update_network(pos, dir, tlib2) + else + liquid.update_network(pos, dir, tlib2) + end end, on_timer = function(pos, elapsed) - local nvm = techage.get_nvm(pos) - power.consumer_alive(pos, nvm) - minetest.sound_play("techage_reactor", { - pos = pos, - gain = 0.5, - max_hear_distance = 10}) - return nvm.running + power.consumer_alive(pos, Cable, CYCLE_TIME) + return true end, after_dig_node = function(pos, oldnode) - techage.power.after_dig_node(pos, oldnode) Pipe:after_dig_node(pos) + Cable:after_dig_node(pos) techage.del_mem(pos) end, @@ -103,23 +122,22 @@ minetest.register_node("techage:ta4_reactor_stand", { groups = {cracky=2}, is_ground_content = false, sounds = default.node_sound_metal_defaults(), - -- Pipe connection + networks = { pipe2 = { sides = {R=1}, ntype = "pump", }, + ele1 = { + sides = {L=1}, + ntype = "con1", + on_power = on_power, + on_nopower = on_nopower, + nominal = PWR_NEEDED, + }, }, }) --- for electrical connections -techage.power.enrich_node({"techage:ta4_reactor_stand"}, { - conn_sides = {"L"}, - power_network = Cable, - on_power = on_power, - on_nopower = on_nopower, -}) - -- controlled by the fillerpipe techage.register_node({"techage:ta4_reactor_stand"}, { on_transfer = function(pos, in_dir, topic, payload) @@ -131,14 +149,13 @@ techage.register_node({"techage:ta4_reactor_stand"}, { return liquid.put(pos, outdir, payload.name, payload.amount, payload.player_name) elseif topic == "can_start" then return power.power_available(pos, Cable) - elseif topic == "start" and payload then - nvm.running = true + elseif topic == "start" then nvm.has_power = false power.consumer_start(pos, Cable, CYCLE_TIME) + minetest.get_node_timer(pos):start(CYCLE_TIME) M(pos):set_string("infotext", "...") return true elseif topic == "stop" then - nvm.running = false nvm.has_power = false power.consumer_stop(pos, Cable) minetest.get_node_timer(pos):stop() @@ -146,6 +163,12 @@ techage.register_node({"techage:ta4_reactor_stand"}, { return true end end, + on_node_load = function(pos, node) + local nvm = techage.get_nvm(pos) + if nvm.has_power then + play_sound(pos) + end + end, }) minetest.register_node("techage:ta4_reactor_base", { @@ -165,7 +188,7 @@ minetest.register_node("techage:ta4_reactor_base", { Pipe:after_place_node(pos) end, tubelib2_on_update2 = function(pos, dir, tlib2, node) - liquid.update_network(pos) + liquid.update_network(pos, dir, tlib2) end, after_dig_node = function(pos, oldnode, oldmetadata, digger) Pipe:after_dig_node(pos) @@ -190,6 +213,8 @@ Pipe:add_secondary_node_names({ "techage:ta4_reactor_stand", }) +Cable:add_secondary_node_names({"techage:ta4_reactor_stand"}) + minetest.register_craft({ output = 'techage:ta4_reactor_stand', recipe = { diff --git a/coal_power_station/firebox.lua b/coal_power_station/firebox.lua index 9634035..4a10fbe 100644 --- a/coal_power_station/firebox.lua +++ b/coal_power_station/firebox.lua @@ -36,33 +36,31 @@ end local function node_timer(pos, elapsed) local nvm = techage.get_nvm(pos) - if nvm.running then - local power = techage.transfer( - {x=pos.x, y=pos.y+2, z=pos.z}, - nil, -- outdir - "trigger", -- topic - nil, -- payload - nil, -- network - {"techage:coalboiler_top"} -- nodenames - ) - nvm.burn_cycles = (nvm.burn_cycles or 0) - math.max((power or 0.02), 0.02) - if nvm.burn_cycles <= 0 then - local taken = firebox.get_fuel(pos) - if taken then - nvm.burn_cycles = (firebox.Burntime[taken:get_name()] or 1) / CYCLE_TIME * BURN_CYCLE_FACTOR - nvm.burn_cycles_total = nvm.burn_cycles - else - nvm.running = false - firehole(pos, false) - M(pos):set_string("formspec", firebox.formspec(nvm)) - return false - end - end - if techage.is_activeformspec(pos) then + local power = techage.transfer( + {x=pos.x, y=pos.y+2, z=pos.z}, + nil, -- outdir + "trigger", -- topic + nil, -- payload + nil, -- network + {"techage:coalboiler_top"} -- nodenames + ) + nvm.burn_cycles = (nvm.burn_cycles or 0) - math.max((power or 0.02), 0.02) + if nvm.burn_cycles <= 0 then + local taken = firebox.get_fuel(pos) + if taken then + nvm.burn_cycles = (firebox.Burntime[taken:get_name()] or 1) / CYCLE_TIME * BURN_CYCLE_FACTOR + nvm.burn_cycles_total = nvm.burn_cycles + else + nvm.running = false + firehole(pos, false) M(pos):set_string("formspec", firebox.formspec(nvm)) + return false end - return true end + if techage.is_activeformspec(pos) then + M(pos):set_string("formspec", firebox.formspec(nvm)) + end + return true end local function start_firebox(pos, nvm) diff --git a/coal_power_station/oilfirebox.lua b/coal_power_station/oilfirebox.lua index 16dba80..9c9cfbb 100644 --- a/coal_power_station/oilfirebox.lua +++ b/coal_power_station/oilfirebox.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019 Joachim Stolberg + Copyright (C) 2019-2020 Joachim Stolberg GPL v3 See LICENSE.txt for more information @@ -23,7 +23,7 @@ local Pipe = techage.LiquidPipe local liquid = techage.liquid local CYCLE_TIME = 2 -local EFFICIENCY = 0.5 +local BURN_CYCLE_FACTOR = 0.5 local function firehole(pos, on) local param2 = techage.get_node_lvm(pos).param2 @@ -39,36 +39,35 @@ end local function node_timer(pos, elapsed) local nvm = techage.get_nvm(pos) - if nvm.running then - -- 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 - (nvm.power_level or 4)/4.0, -- payload - nil, -- network - {"techage:coalboiler_top"} -- nodenames - ) - ratio = math.max((ratio or 0.02), 0.02) - nvm.burn_cycles = (nvm.burn_cycles or 0) - ratio - if nvm.burn_cycles <= 0 then - local taken = firebox.get_fuel(pos) - if taken then - nvm.burn_cycles = (firebox.Burntime[taken:get_name()] or 1) * EFFICIENCY / CYCLE_TIME - nvm.burn_cycles_total = nvm.burn_cycles - else - nvm.running = false - firehole(pos, false) - M(pos):set_string("formspec", firebox.formspec(nvm)) - return false - end + local power = techage.transfer( + {x=pos.x, y=pos.y+2, z=pos.z}, + nil, -- outdir + "trigger", -- topic + nil, -- payload + nil, -- network + {"techage:coalboiler_top"} -- nodenames + ) + nvm.burn_cycles = (nvm.burn_cycles or 0) - math.max((power or 0.02), 0.02) + if nvm.burn_cycles <= 0 then + local liq_name = fuel.get_fuel(nvm) + if liq_name then + nvm.burn_cycles = fuel.burntime(liq_name) / CYCLE_TIME * BURN_CYCLE_FACTOR + nvm.burn_cycles_total = nvm.burn_cycles + else + nvm.running = false + firehole(pos, false) + M(pos):set_string("formspec", fuel.formspec(nvm)) + return false end - return true end + if techage.is_activeformspec(pos) then + M(pos):set_string("formspec", fuel.formspec(nvm)) + end + return true end local function start_firebox(pos, nvm) - if not nvm.running then + if not nvm.running and fuel.has_fuel(nvm) then nvm.running = true node_timer(pos, 0) firehole(pos, true) @@ -76,162 +75,6 @@ local function start_firebox(pos, nvm) end end -minetest.register_node("techage:coalfirebox", { - description = S("TA3 Power Station Firebox"), - inventory_image = "techage_coal_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 = node_timer, - can_dig = firebox.can_dig, - allow_metadata_inventory_put = firebox.allow_metadata_inventory_put, - allow_metadata_inventory_take = firebox.allow_metadata_inventory_take, - on_receive_fields = firebox.on_receive_fields, - on_rightclick = firebox.on_rightclick, - - on_construct = function(pos) - local nvm = techage.get_nvm(pos) - techage.add_node(pos, "techage:coalfirebox") - nvm.running = false - nvm.burn_cycles = 0 - nvm.power_level = 4 - local meta = M(pos) - meta:set_string("formspec", firebox.formspec(nvm)) - 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 nvm = techage.get_nvm(pos) - start_firebox(pos, nvm) - M(pos):set_string("formspec", firebox.formspec(nvm)) - end, -}) - -minetest.register_node("techage:coalfirehole", { - description = S("TA3 Coal Power Station Firebox"), - tiles = { - -- up, down, right, left, back, front - "techage_coal_boiler.png", - "techage_coal_boiler.png", - "techage_coal_boiler.png", - "techage_coal_boiler.png", - "techage_coal_boiler.png", - "techage_coal_boiler.png^techage_appl_firehole.png", - }, - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = { - {-6/16, -6/16, 6/16, 6/16, 6/16, 12/16}, - }, - }, - - paramtype = "light", - paramtype2 = "facedir", - pointable = false, - diggable = false, - is_ground_content = false, - groups = {not_in_creative_inventory=1}, -}) - -minetest.register_node("techage:coalfirehole_on", { - description = S("TA3 Coal Power Station Firebox"), - tiles = { - -- up, down, right, left, back, front - "techage_coal_boiler.png^[colorize:black:80", - "techage_coal_boiler.png^[colorize:black:80", - "techage_coal_boiler.png^[colorize:black:80", - "techage_coal_boiler.png^[colorize:black:80", - "techage_coal_boiler.png^[colorize:black:80", - { - image = "techage_coal_boiler4.png^[colorize:black:80^techage_appl_firehole4.png", - backface_culling = false, - animation = { - type = "vertical_frames", - aspect_w = 32, - aspect_h = 32, - length = 0.4, - }, - }, - }, - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = { - {-6/16, -6/16, 6/16, 6/16, 6/16, 12/16}, - }, - }, - paramtype = "light", - paramtype2 = "facedir", - light_source = 8, - pointable = false, - diggable = false, - is_ground_content = false, - groups = {not_in_creative_inventory=1}, -}) - -local function on_timer2(pos, elapsed) - local nvm = techage.get_nvm(pos) - if nvm.running then - fuel.formspec_update(pos, nvm) - -- 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 - (nvm.power_level or 4)/4.0, -- payload - nil, -- network - {"techage:coalboiler_top"} -- nodenames - ) - ratio = math.max((ratio or 0.02), 0.02) - nvm.burn_cycles = (nvm.burn_cycles or 0) - ratio - nvm.liquid = nvm.liquid or {} - nvm.liquid.amount = nvm.liquid.amount or 0 - if nvm.burn_cycles <= 0 then - if nvm.liquid.amount > 0 then - nvm.liquid.amount = nvm.liquid.amount - 1 - nvm.burn_cycles = fuel.burntime(nvm.liquid.name) * EFFICIENCY / CYCLE_TIME - nvm.burn_cycles_total = nvm.burn_cycles - else - nvm.running = false - nvm.liquid.name = nil - firehole(pos, false) - M(pos):set_string("formspec", fuel.formspec(nvm)) - return false - end - end - return true - end -end - -local function start_firebox2(pos, nvm) - if not nvm.running and nvm.liquid.amount > 0 then - nvm.running = true - on_timer2(pos, 0) - firehole(pos, true) - minetest.get_node_timer(pos):start(CYCLE_TIME) - M(pos):set_string("formspec", fuel.formspec(nvm)) - end -end - minetest.register_node("techage:oilfirebox", { description = S("TA3 Power Station Oil Burner"), inventory_image = "techage_oil_boiler_inv.png", @@ -250,16 +93,17 @@ minetest.register_node("techage:oilfirebox", { is_ground_content = false, sounds = default.node_sound_stone_defaults(), - on_timer = on_timer2, + on_timer = node_timer, 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, + allow_metadata_inventory_take = fuel.allow_metadata_inventory_take, on_rightclick = fuel.on_rightclick, + on_receive_fields = fuel.on_receive_fields, + on_punch = fuel.on_punch, on_construct = function(pos) - local nvm = techage.get_nvm(pos) techage.add_node(pos, "techage:oilfirebox") + local nvm = techage.get_nvm(pos) nvm.running = false nvm.burn_cycles = 0 nvm.liquid = {} @@ -279,7 +123,7 @@ minetest.register_node("techage:oilfirebox", { local nvm = techage.get_nvm(pos) nvm.liquid = nvm.liquid or {} nvm.liquid.amount = nvm.liquid.amount or 0 - minetest.after(1, start_firebox2, pos, nvm) + minetest.after(1, start_firebox, pos, nvm) fuel.on_metadata_inventory_put(pos, listname, index, stack, player) end, @@ -293,15 +137,26 @@ minetest.register_node("techage:oilfirebox", { local nvm = techage.get_nvm(pos) nvm.liquid = nvm.liquid or {} nvm.liquid.amount = nvm.liquid.amount or 0 - start_firebox2(pos, nvm) + start_firebox(pos, nvm) + if techage.is_activeformspec(pos) then + local nvm = techage.get_nvm(pos) + M(pos):set_string("formspec", fuel.formspec(nvm)) + end return leftover end return amount end, - take = liquid.srv_take, + take = function(pos, indir, name, amount) + amount, name = liquid.srv_take(pos, indir, name, amount) + if techage.is_activeformspec(pos) then + local nvm = techage.get_nvm(pos) + M(pos):set_string("formspec", fuel.formspec(nvm)) + end + return amount, name + end }, networks = { - pipe = { + pipe2 = { sides = techage.networks.AllSides, -- Pipe connection sides ntype = "tank", }, @@ -311,45 +166,6 @@ minetest.register_node("techage:oilfirebox", { Pipe:add_secondary_node_names({"techage:oilfirebox"}) -techage.register_node({"techage:coalfirebox"}, { - on_pull_item = function(pos, in_dir, num) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - return techage.get_items(inv, "fuel", num) - end, - on_push_item = function(pos, in_dir, stack) - if firebox.Burntime[stack:get_name()] then - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - local nvm = techage.get_nvm(pos) - start_firebox(pos, nvm) - return techage.put_items(inv, "fuel", stack) - end - return false - end, - on_unpull_item = function(pos, in_dir, stack) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - return techage.put_items(inv, "fuel", stack) - end, - on_recv_message = function(pos, src, topic, payload) - local nvm = techage.get_nvm(pos) - if topic == "state" then - if nvm.running then - return "running" - else - return "stopped" - end - elseif topic == "fuel" then - local inv = M(pos):get_inventory() - local stack = inv:get_stack("fuel", 1) - return stack:get_count() - else - return "unsupported" - end - end, -}) - techage.register_node({"techage:oilfirebox"}, { on_recv_message = function(pos, src, topic, payload) local nvm = techage.get_nvm(pos) @@ -367,15 +183,6 @@ techage.register_node({"techage:oilfirebox"}, { end, }) -minetest.register_craft({ - output = "techage:coalfirebox", - recipe = { - {'default:stone', 'default:stone', 'default:stone'}, - {'default:steel_ingot', '', 'default:steel_ingot'}, - {'default:stone', 'default:stone', 'default:stone'}, - }, -}) - minetest.register_craft({ output = "techage:oilfirebox", recipe = { @@ -388,9 +195,11 @@ minetest.register_craft({ minetest.register_lbm({ label = "[techage] Power Station firebox", name = "techage:steam_engine", - nodenames = {"techage:coalfirebox", "techage:oilfirebox"}, + nodenames = {"techage:oilfirebox"}, run_at_every_load = true, action = function(pos, node) + local nvm = techage.get_nvm(pos) + nvm.running = true minetest.get_node_timer(pos):start(CYCLE_TIME) end }) diff --git a/furnace/firebox.lua b/furnace/firebox.lua index 395f67d..760fbd6 100644 --- a/furnace/firebox.lua +++ b/furnace/firebox.lua @@ -41,7 +41,6 @@ local function node_timer(pos, elapsed) nvm.liquid = nvm.liquid or {} nvm.liquid.amount = nvm.liquid.amount or 0 if nvm.running then - fuel.formspec_update(pos, nvm) nvm.burn_cycles = (nvm.burn_cycles or 0) - 1 if nvm.burn_cycles <= 0 then if nvm.liquid.amount > 0 then diff --git a/init.lua b/init.lua index abe4bd8..c153e85 100644 --- a/init.lua +++ b/init.lua @@ -119,6 +119,7 @@ else dofile(MP.."/coal_power_station/generator.lua") dofile(MP.."/coal_power_station/turbine.lua") dofile(MP.."/coal_power_station/cooler.lua") + dofile(MP.."/coal_power_station/oilfirebox.lua") -- -- Industrial Furnace dofile(MP.."/furnace/firebox.lua") @@ -199,8 +200,8 @@ else -- -- Chemistry dofile(MP.."/chemistry/ta4_reactor.lua") --- dofile(MP.."/chemistry/ta4_stand.lua") --- dofile(MP.."/chemistry/ta4_doser.lua") + dofile(MP.."/chemistry/ta4_stand.lua") + dofile(MP.."/chemistry/ta4_doser.lua") -- -- Hydrogen -- dofile(MP.."/hydrogen/fuelcellstack.lua") diff --git a/liquids/fuel_lib.lua b/liquids/fuel_lib.lua deleted file mode 100644 index 9646895..0000000 --- a/liquids/fuel_lib.lua +++ /dev/null @@ -1,268 +0,0 @@ ---[[ - - TechAge - ======= - - Copyright (C) 2019-2020 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 LQD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).liquid end -local Pipe = techage.LiquidPipe -local liquid = techage.liquid -local ValidOilFuels = techage.firebox.ValidOilFuels -local Burntime = techage.firebox.Burntime - -techage.fuel = {} - -local CAPACITY = 50 -local BLOCKING_TIME = 0.3 -- 300ms - -techage.fuel.CAPACITY = CAPACITY - --- fuel burning categories (better than...) -techage.fuel.BT_BITUMEN = 4 -techage.fuel.BT_OIL = 3 -techage.fuel.BT_FUELOIL = 2 -techage.fuel.BT_NAPHTHA = 1 - - -function techage.fuel.fuel_container(x, y, nvm) - local itemname = "" - if nvm.liquid and nvm.liquid.name and nvm.liquid.amount and nvm.liquid.amount > 0 then - itemname = nvm.liquid.name.." "..nvm.liquid.amount - end - local fuel_percent = 0 - if nvm.running then - fuel_percent = ((nvm.burn_cycles or 1) * 100) / (nvm.burn_cycles_total or 1) - end - return "container["..x..","..y.."]".. - "box[0,0;1.05,2.1;#000000]".. - "image[0.1,0.1;1,1;default_furnace_fire_bg.png^[lowpart:".. - fuel_percent..":default_furnace_fire_fg.png]".. - techage.item_image(0.1, 1.1, itemname).. - "container_end[]" -end - -local function help(x, y) - local tooltip = S("To add fuel punch\nthis block\nwith a fuel container") - return "label["..x..","..y..";"..minetest.colorize("#000000", minetest.formspec_escape("[?]")).."]".. - "tooltip["..x..","..y..";0.5,0.5;"..tooltip..";#0C3D32;#FFFFFF]" -end - -function techage.fuel.formspec(nvm) - local title = S("Fuel Menu") - return "size[4,3]".. - default.gui_bg.. - default.gui_bg_img.. - default.gui_slots.. - "box[0,-0.1;3.8,0.5;#c6e8ff]".. - "label[1,-0.1;"..minetest.colorize("#000000", title).."]".. - help(3.4, -0.1).. - techage.fuel.fuel_container(1.5, 1, nvm) -end - ---local function fill_container(pos, inv, nvm) --- nvm.liquid = nvm.liquid or {} --- nvm.liquid.amount = nvm.liquid.amount or 0 --- local empty_container = inv:get_stack("fuel", 1):get_name() --- local full_container = liquid.get_full_container(empty_container, nvm.liquid.name) --- if empty_container and full_container then --- local ldef = liquid.get_liquid_def(full_container) --- if ldef and nvm.liquid.amount - ldef.size >= 0 then --- inv:remove_item("fuel", ItemStack(empty_container)) --- inv:add_item("fuel", ItemStack(full_container)) --- nvm.liquid.amount = nvm.liquid.amount - ldef.size --- if nvm.liquid.amount == 0 then --- nvm.liquid.name = nil --- end --- end --- end ---end - ---local function empty_container(pos, inv, nvm) --- nvm.liquid = nvm.liquid or {} --- nvm.liquid.amount = nvm.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 nvm.liquid.name or ldef.inv_item == nvm.liquid.name then --- if nvm.liquid.amount + ldef.size <= CAPACITY then --- inv:remove_item("fuel", stack) --- inv:add_item("fuel", ItemStack(ldef.container)) --- nvm.liquid.amount = nvm.liquid.amount + ldef.size --- nvm.liquid.name = ldef.inv_item --- end --- end --- end --- end ---end - ---local function move_item(pos, stack) --- local nvm = techage.get_nvm(pos) --- local inv = M(pos):get_inventory() --- if liquid.is_container_empty(stack:get_name()) then --- fill_container(pos, inv, nvm) --- else --- empty_container(pos, inv, nvm) --- end --- M(pos):set_string("formspec", techage.fuel.formspec(nvm)) ---end - ---function techage.fuel.move_item(pos, stack, formspec) --- local nvm = techage.get_nvm(pos) --- local inv = M(pos):get_inventory() --- if liquid.is_container_empty(stack:get_name()) then --- fill_container(pos, inv, nvm) --- else --- empty_container(pos, inv, nvm) --- end --- M(pos):set_string("formspec", formspec(pos, nvm)) ---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 --- if liquid.is_container_empty(stack:get_name()) then --- return 1 --- end --- local category = LQD(pos).fuel_cat --- local ldef = liquid.get_liquid_def(stack:get_name()) --- if ldef and ValidOilFuels[ldef.inv_item] and ValidOilFuels[ldef.inv_item] <= category then --- return 1 --- end --- return 0 ---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 nvm = techage.get_nvm(pos) - nvm.liquid = nvm.liquid or {} - nvm.liquid.amount = nvm.liquid.amount or 0 - local inv = M(pos):get_inventory() - return inv:is_empty("fuel") and nvm.liquid.amount == 0 -end - -function techage.fuel.on_rightclick(pos, node, clicker) - techage.set_activeformspec(pos, clicker) - local nvm = techage.get_nvm(pos) - M(pos):set_string("formspec", techage.fuel.formspec(nvm)) -end - ---function techage.fuel.on_receive_fields(pos, formname, fields, player) --- if minetest.is_protected(pos, player:get_player_name()) then --- return --- end --- local nvm = techage.get_nvm(pos) --- nvm.countdown = 10 --- M(pos):set_string("formspec", techage.fuel.formspec(nvm)) ---end - ---function techage.fuel.formspec_update(pos, nvm) --- if nvm.countdown and nvm.countdown > 0 then --- nvm.countdown = nvm.countdown - 1 --- M(pos):set_string("formspec", techage.fuel.formspec(nvm)) --- end ---end - --- name is the fuel item name -function techage.fuel.burntime(name) - if ValidOilFuels[name] then - return Burntime[name] or 0.01 -- not zero ! - end - return 0.01 -- not zero ! -end - -function techage.fuel.valid_fuel(name, category) - return ValidOilFuels[name] and ValidOilFuels[name] <= category -end - --- check if the given empty container can be replaced by a full --- container and added to the players inventory -local function fill(nvm, empty_container, item_count, puncher) - nvm.liquid = nvm.liquid or {} - nvm.liquid.amount = nvm.liquid.amount or 0 - local full_container = liquid.get_full_container(empty_container, nvm.liquid.name) - if empty_container and full_container then - local item = ItemStack(full_container) -- to be added - local ldef = liquid.get_liquid_def(full_container) - if ldef and nvm.liquid.amount - ldef.size >= 0 then - if item_count > 1 then -- can't be simply replaced? - -- check for extra free space - local inv = puncher:get_inventory() - if inv:room_for_item("main", item) then - -- add full container and return - -- the empty once - 1 - inv:add_item("main", item) - item = {name = empty_container, count = item_count - 1} - else - return -- no free space - end - end - nvm.liquid.amount = nvm.liquid.amount - ldef.size - if nvm.liquid.amount == 0 then - nvm.liquid.name = nil - end - return item -- to be added to the players inv. - end - end -end - -local function empty(nvm, full_container) - nvm.liquid = nvm.liquid or {} - nvm.liquid.amount = nvm.liquid.amount or 0 - local ldef = liquid.get_liquid_def(full_container) - if ldef and ValidOilFuels[ldef.inv_item] then - if not nvm.liquid.name or ldef.inv_item == nvm.liquid.name then - if nvm.liquid.amount + ldef.size <= CAPACITY then - nvm.liquid.amount = nvm.liquid.amount + ldef.size - nvm.liquid.name = ldef.inv_item - return ItemStack(ldef.container) - end - end - end -end - -function techage.fuel.on_punch(pos, node, puncher, pointed_thing) - local nvm = techage.get_nvm(pos) - local mem = techage.get_mem(pos) - mem.blocking_time = mem.blocking_time or 0 - if mem.blocking_time > techage.SystemTime then - return - end - - local wielded_item = puncher:get_wielded_item():get_name() - local item_count = puncher:get_wielded_item():get_count() - local new_item = fill(nvm, wielded_item, item_count, puncher) - or empty(nvm, wielded_item) - if new_item then - puncher:set_wielded_item(ItemStack(new_item)) - M(pos):set_string("formspec", techage.fuel.formspec(pos, nvm)) - mem.blocking_time = techage.SystemTime + BLOCKING_TIME - return - end -end diff --git a/oil/distiller.lua b/oil/distiller.lua index 64d803f..2a33f50 100644 --- a/oil/distiller.lua +++ b/oil/distiller.lua @@ -41,7 +41,7 @@ local function after_place_node(pos, placer) end local function tubelib2_on_update2(pos, dir, tlib2, node) - liquid.update_network(pos) + liquid.update_network(pos, dir, tlib2) end local function after_dig_node(pos, oldnode, oldmetadata, digger) diff --git a/oil/reboiler.lua b/oil/reboiler.lua index 686dc4e..ed7f11d 100644 --- a/oil/reboiler.lua +++ b/oil/reboiler.lua @@ -96,6 +96,7 @@ local function start_node(pos) if power.power_available(pos, Cable) then nvm.running = true power.consumer_start(pos, Cable, CYCLE_TIME) + minetest.get_node_timer(pos):start(CYCLE_TIME) end end end @@ -105,14 +106,14 @@ local function node_timer(pos, elapsed) nvm.liquid = nvm.liquid or {} nvm.liquid.amount = nvm.liquid.amount or 0 - power.consumer_alive(pos, nvm) + power.consumer_alive(pos, Cable, CYCLE_TIME) if nvm.liquid.amount >= 5 and nvm.liquid.name == "techage:oil_source" then nvm.liquid.amount = nvm.liquid.amount - 5 local leftover = pump_cmnd(pos, "put") if (tonumber(leftover) or 1) > 0 then nvm.liquid.amount = nvm.liquid.amount + 5 - nvm.error = 25 -- = 5 pump cycles + nvm.error = 2 -- = 2 pump cycles M(pos):set_string("infotext", S("TA3 Oil Reboiler: blocked")) swap_node(pos, false) return false @@ -135,8 +136,9 @@ local function after_dig_node(pos, oldnode) end local function tubelib2_on_update2(pos, outdir, tlib2, node) - if tlib2 == Pipe then - liquid.update_network(pos, outdir) + print("tubelib2_on_update2", tlib2.tube_type) + if tlib2.tube_type == "pipe2" then + liquid.update_network(pos, outdir, tlib2) else power.update_network(pos, outdir, tlib2) end @@ -196,6 +198,9 @@ minetest.register_node("techage:ta3_reboiler", { local meta = M(pos) meta:set_string("infotext", S("TA3 Oil Reboiler")) meta:set_int("outdir", networks.side_to_outdir(pos, "R")) + local number = techage.add_node(pos, "techage:ta3_reboiler") + meta:set_string("node_number", number) + meta:set_string("owner", placer:get_player_name()) Pipe:after_place_node(pos) power.after_place_node(pos) end, @@ -261,6 +266,33 @@ minetest.register_node("techage:ta3_reboiler_on", { Pipe:add_secondary_node_names({"techage:ta3_reboiler", "techage:ta3_reboiler_on"}) Cable:add_secondary_node_names({"techage:ta3_reboiler", "techage:ta3_reboiler_on"}) +techage.register_node({"techage:ta3_reboiler", "techage:ta3_reboiler_on"}, { + on_recv_message = function(pos, src, topic, payload) + local nvm = techage.get_nvm(pos) + if topic == "on" then + start_node(pos) + return true + elseif topic == "off" then + swap_node(pos, false) + return true + elseif topic == "state" then + if nvm.error and nvm.error > 0 then + return "blocked" + elseif nvm.running then + return "running" + end + return "stopped" + else + return "unsupported" + end + end, + on_node_load = function(pos, node) + if node.name == "techage:ta3_reboiler_on" then + play_sound(pos) + end + end, +}) + minetest.register_craft({ output = "techage:ta3_reboiler", recipe = { diff --git a/power/distribution.lua b/power/distribution.lua index d777980..2dbf146 100644 --- a/power/distribution.lua +++ b/power/distribution.lua @@ -126,7 +126,7 @@ function techage.power.power_distribution(network, tlib_type) network.available2 = get_generator_sum(network.gen2, tlib_type) network.needed1 = get_consumer_sum(network.con1, tlib_type) network.needed2 = get_consumer_sum(network.con2, tlib_type) - print(network.available1, network.available2, network.needed1, network.needed2, network.alive) + --print(network.available1, network.available2, network.needed1, network.needed2, network.alive) -- store results network.on = network.available1 + network.available2 >= network.needed1 diff --git a/sounds/techage_reactor.ogg b/sounds/techage_reactor.ogg index 38d5538..27329b0 100644 Binary files a/sounds/techage_reactor.ogg and b/sounds/techage_reactor.ogg differ