2019-06-10 22:31:58 +03:00
|
|
|
--[[
|
|
|
|
|
|
|
|
TechAge
|
|
|
|
=======
|
|
|
|
|
2022-06-05 22:20:43 +03:00
|
|
|
Copyright (C) 2019-2022 Joachim Stolberg
|
2019-06-10 22:31:58 +03:00
|
|
|
|
2020-10-19 20:09:17 +03:00
|
|
|
AGPL v3
|
2019-06-10 22:31:58 +03:00
|
|
|
See LICENSE.txt for more information
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2019-06-10 22:31:58 +03:00
|
|
|
TA3 Industrial Furnace Firebox
|
|
|
|
|
|
|
|
]]--
|
|
|
|
|
|
|
|
-- for lazy programmers
|
|
|
|
local M = minetest.get_meta
|
2019-07-02 22:33:12 +03:00
|
|
|
local S = techage.S
|
2019-06-10 22:31:58 +03:00
|
|
|
|
|
|
|
local firebox = techage.firebox
|
2019-11-10 01:36:28 +03:00
|
|
|
local fuel = techage.fuel
|
2019-11-03 23:21:03 +03:00
|
|
|
local Pipe = techage.LiquidPipe
|
2021-06-09 23:09:59 +03:00
|
|
|
local liquid = networks.liquid
|
2019-06-10 22:31:58 +03:00
|
|
|
|
|
|
|
local CYCLE_TIME = 2
|
2019-11-10 01:36:28 +03:00
|
|
|
local EFFICIENCY = 2 -- burn cycles
|
|
|
|
local CATEGORY = 3
|
2019-06-10 22:31:58 +03:00
|
|
|
|
2020-01-31 21:55:10 +03:00
|
|
|
local function has_fuel(pos, nvm)
|
2020-02-24 22:59:26 +03:00
|
|
|
return (nvm.burn_cycles or 0) > 0 or (nvm.liquid and nvm.liquid.amount and nvm.liquid.amount > 0)
|
2019-06-10 22:31:58 +03:00
|
|
|
end
|
|
|
|
|
2020-01-31 21:55:10 +03:00
|
|
|
local function stop_firebox(pos, nvm)
|
|
|
|
nvm.running = false
|
2019-06-10 22:31:58 +03:00
|
|
|
firebox.swap_node(pos, "techage:furnace_firebox")
|
|
|
|
minetest.get_node_timer(pos):stop()
|
2020-01-31 21:55:10 +03:00
|
|
|
M(pos):set_string("formspec", fuel.formspec(nvm))
|
2019-06-10 22:31:58 +03:00
|
|
|
end
|
|
|
|
|
2024-06-30 13:54:42 +03:00
|
|
|
local function furnace_active(pos)
|
|
|
|
-- Check if furnace is not in standby mode
|
|
|
|
return techage.get_node_lvm({x=pos.x, y=pos.y+1, z=pos.z}).name == "techage:ta3_furnace_act"
|
|
|
|
end
|
|
|
|
|
2019-06-10 22:31:58 +03:00
|
|
|
local function node_timer(pos, elapsed)
|
2020-01-31 21:55:10 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
nvm.liquid = nvm.liquid or {}
|
|
|
|
nvm.liquid.amount = nvm.liquid.amount or 0
|
2024-06-30 13:54:42 +03:00
|
|
|
if nvm.running and furnace_active(pos) then
|
2020-01-31 21:55:10 +03:00
|
|
|
nvm.burn_cycles = (nvm.burn_cycles or 0) - 1
|
|
|
|
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
|
2019-06-10 22:31:58 +03:00
|
|
|
else
|
2020-01-31 21:55:10 +03:00
|
|
|
nvm.liquid.name = nil
|
|
|
|
stop_firebox(pos, nvm)
|
2019-06-10 22:31:58 +03:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
2024-06-30 13:54:42 +03:00
|
|
|
else
|
|
|
|
stop_firebox(pos, nvm)
|
|
|
|
return false
|
2019-06-10 22:31:58 +03:00
|
|
|
end
|
2020-02-02 00:00:58 +03:00
|
|
|
if techage.is_activeformspec(pos) then
|
|
|
|
M(pos):set_string("formspec", fuel.formspec(nvm))
|
|
|
|
end
|
|
|
|
return true
|
2019-06-10 22:31:58 +03:00
|
|
|
end
|
|
|
|
|
2020-01-31 21:55:10 +03:00
|
|
|
local function start_firebox(pos, nvm)
|
2024-06-30 13:54:42 +03:00
|
|
|
|
|
|
|
if not nvm.running and furnace_active(pos) then
|
2020-01-31 21:55:10 +03:00
|
|
|
nvm.running = true
|
2019-06-10 22:31:58 +03:00
|
|
|
node_timer(pos, 0)
|
|
|
|
firebox.swap_node(pos, "techage:furnace_firebox_on")
|
|
|
|
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
2020-01-31 21:55:10 +03:00
|
|
|
M(pos):set_string("formspec", fuel.formspec(nvm))
|
2019-06-10 22:31:58 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function booster_cmnd(pos, cmnd)
|
|
|
|
return techage.transfer(
|
2022-01-03 23:40:31 +03:00
|
|
|
pos,
|
2019-06-10 22:31:58 +03:00
|
|
|
"L", -- outdir
|
|
|
|
cmnd, -- topic
|
|
|
|
nil, -- payload
|
|
|
|
nil, -- network
|
|
|
|
{"techage:ta3_booster", "techage:ta3_booster_on"})
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_node("techage:furnace_firebox", {
|
2019-11-03 23:21:03 +03:00
|
|
|
description = S("TA3 Furnace Oil Burner"),
|
2019-06-10 22:31:58 +03:00
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
"techage_concrete.png^techage_appl_open.png^techage_frame_ta3.png",
|
|
|
|
"techage_concrete.png^techage_frame_ta3.png",
|
|
|
|
"techage_concrete.png^techage_frame_ta3.png",
|
2019-11-03 01:39:10 +03:00
|
|
|
"techage_concrete.png^techage_appl_hole_pipe.png^techage_frame_ta3.png",
|
2019-06-10 22:31:58 +03:00
|
|
|
"techage_concrete.png^techage_frame_ta3.png",
|
|
|
|
"techage_concrete.png^techage_appl_firehole.png^techage_frame_ta3.png",
|
|
|
|
},
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
on_rotate = screwdriver.disallow,
|
|
|
|
groups = {cracky=2},
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_stone_defaults(),
|
|
|
|
|
|
|
|
on_timer = node_timer,
|
2019-11-10 01:36:28 +03:00
|
|
|
can_dig = fuel.can_dig,
|
2020-02-02 00:00:58 +03:00
|
|
|
on_punch = fuel.on_punch,
|
2019-11-10 01:36:28 +03:00
|
|
|
on_receive_fields = fuel.on_receive_fields,
|
|
|
|
on_rightclick = fuel.on_rightclick,
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2019-06-10 22:31:58 +03:00
|
|
|
on_construct = function(pos)
|
2020-01-31 21:55:10 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
2022-08-18 15:29:33 +03:00
|
|
|
techage.add_node(pos, "techage:furnace_firebox", true)
|
2020-01-31 21:55:10 +03:00
|
|
|
nvm.running = false
|
|
|
|
nvm.burn_cycles = 0
|
|
|
|
nvm.liquid = {}
|
|
|
|
nvm.liquid.amount = 0
|
2019-06-10 22:31:58 +03:00
|
|
|
local meta = M(pos)
|
2020-01-31 21:55:10 +03:00
|
|
|
meta:set_string("formspec", fuel.formspec(nvm))
|
2019-06-10 22:31:58 +03:00
|
|
|
local inv = meta:get_inventory()
|
|
|
|
inv:set_size('fuel', 1)
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_node("techage:furnace_firebox_on", {
|
2019-11-03 23:21:03 +03:00
|
|
|
description = S("TA3 Furnace Oil Burner"),
|
2019-06-10 22:31:58 +03:00
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
"techage_concrete.png^techage_frame_ta3.png",
|
|
|
|
"techage_concrete.png^techage_frame_ta3.png",
|
|
|
|
"techage_concrete.png^techage_frame_ta3.png",
|
|
|
|
"techage_concrete.png^techage_frame_ta3.png",
|
|
|
|
"techage_concrete.png^techage_frame_ta3.png",
|
|
|
|
{
|
2023-04-07 11:51:33 +03:00
|
|
|
name = "techage_concrete4.png^techage_appl_firehole4.png^techage_frame4_ta3.png",
|
2019-06-10 22:31:58 +03:00
|
|
|
backface_culling = false,
|
|
|
|
animation = {
|
|
|
|
type = "vertical_frames",
|
|
|
|
aspect_w = 32,
|
|
|
|
aspect_h = 32,
|
|
|
|
length = 0.4,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
light_source = 8,
|
|
|
|
on_rotate = screwdriver.disallow,
|
|
|
|
diggable = false,
|
|
|
|
groups = {not_in_creative_inventory = 1},
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_stone_defaults(),
|
|
|
|
drop = "techage:furnace_firebox",
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2019-06-10 22:31:58 +03:00
|
|
|
on_timer = node_timer,
|
2019-11-10 01:36:28 +03:00
|
|
|
can_dig = fuel.can_dig,
|
|
|
|
on_receive_fields = fuel.on_receive_fields,
|
2020-02-02 00:00:58 +03:00
|
|
|
on_punch = fuel.on_punch,
|
2019-11-10 01:36:28 +03:00
|
|
|
on_rightclick = fuel.on_rightclick,
|
2019-06-10 22:31:58 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "techage:furnace_firebox",
|
|
|
|
recipe = {
|
|
|
|
{'techage:basalt_stone', 'techage:basalt_stone', 'techage:basalt_stone'},
|
|
|
|
{'default:steel_ingot', '', 'default:steel_ingot'},
|
|
|
|
{'techage:basalt_stone', 'techage:basalt_stone', 'techage:basalt_stone'},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
techage.register_node({"techage:furnace_firebox", "techage:furnace_firebox_on"}, {
|
2019-08-25 19:08:30 +03:00
|
|
|
on_recv_message = function(pos, src, topic, payload)
|
2020-01-31 21:55:10 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
2019-06-10 22:31:58 +03:00
|
|
|
if topic == "state" then
|
2020-02-28 00:33:42 +03:00
|
|
|
return nvm.running and "running" or "stopped"
|
2019-06-29 00:46:44 +03:00
|
|
|
elseif topic == "fuel" then
|
2021-06-09 23:09:59 +03:00
|
|
|
return fuel.get_fuel_amount(nvm)
|
2019-06-10 22:31:58 +03:00
|
|
|
else
|
|
|
|
return "unsupported"
|
|
|
|
end
|
|
|
|
end,
|
2022-06-05 22:20:43 +03:00
|
|
|
on_beduino_request_data = function(pos, src, topic, payload)
|
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
if topic == 128 then
|
|
|
|
return 0, techage.get_node_lvm(pos).name
|
|
|
|
elseif topic == 129 then -- State
|
2022-06-09 13:59:17 +03:00
|
|
|
return 0, {nvm.running and techage.RUNNING or techage.STOPPED}
|
2022-06-05 22:20:43 +03:00
|
|
|
elseif topic == 132 then -- Fuel Level
|
|
|
|
return 0, {fuel.get_fuel_amount(nvm)}
|
|
|
|
else
|
|
|
|
return 2, ""
|
|
|
|
end
|
|
|
|
end,
|
2019-06-10 22:31:58 +03:00
|
|
|
-- called from furnace_top
|
|
|
|
on_transfer = function(pos, in_dir, topic, payload)
|
2020-01-31 21:55:10 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
2019-06-10 22:31:58 +03:00
|
|
|
if topic == "fuel" then
|
2020-01-31 21:55:10 +03:00
|
|
|
return has_fuel(pos, nvm) and booster_cmnd(pos, "power")
|
2019-11-10 01:36:28 +03:00
|
|
|
elseif topic == "running" then
|
2020-07-16 19:34:19 +03:00
|
|
|
return nvm.running and booster_cmnd(pos, "running")
|
2019-06-10 22:31:58 +03:00
|
|
|
elseif topic == "start" then
|
2020-01-31 21:55:10 +03:00
|
|
|
start_firebox(pos, nvm)
|
2019-06-10 22:31:58 +03:00
|
|
|
booster_cmnd(pos, "start")
|
|
|
|
elseif topic == "stop" then
|
2020-01-31 21:55:10 +03:00
|
|
|
stop_firebox(pos, nvm)
|
2019-06-10 22:31:58 +03:00
|
|
|
booster_cmnd(pos, "stop")
|
|
|
|
end
|
2020-03-27 21:44:19 +03:00
|
|
|
end,
|
|
|
|
on_node_load = function(pos, node)
|
|
|
|
local inv = M(pos):get_inventory()
|
|
|
|
if not inv:is_empty("fuel") then
|
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
nvm.liquid = nvm.liquid or {}
|
|
|
|
local count = inv:get_stack("fuel", 1):get_count()
|
|
|
|
nvm.liquid.amount = (nvm.liquid.amount or 0) + count
|
|
|
|
nvm.liquid.name = "techage:gasoline"
|
|
|
|
inv:set_stack("fuel", 1, nil)
|
2022-01-03 23:40:31 +03:00
|
|
|
end
|
2020-03-27 21:44:19 +03:00
|
|
|
end,
|
2022-01-03 23:40:31 +03:00
|
|
|
})
|
2019-06-10 22:31:58 +03:00
|
|
|
|
2021-06-09 23:09:59 +03:00
|
|
|
liquid.register_nodes({"techage:furnace_firebox", "techage:furnace_firebox_on"},
|
2022-01-04 21:40:27 +03:00
|
|
|
Pipe, "tank", nil, fuel.get_liquid_table(fuel.BT_OIL, fuel.CAPACITY, start_firebox))
|