techage/coal_power_station/oilfirebox.lua

157 lines
3.9 KiB
Lua
Raw Permalink Normal View History

2020-01-26 01:22:06 +03:00
--[[
TechAge
=======
2022-06-05 22:20:43 +03:00
Copyright (C) 2019-2022 Joachim Stolberg
2020-01-26 01:22:06 +03:00
2020-10-19 20:09:17 +03:00
AGPL v3
2020-01-26 01:22:06 +03:00
See LICENSE.txt for more information
2022-01-03 23:40:31 +03:00
2020-01-26 01:22:06 +03:00
TA3 Coal Power Station Firebox
]]--
-- for lazy programmers
local P = minetest.string_to_pos
local M = minetest.get_meta
local S = techage.S
local firebox = techage.firebox
local fuel = techage.fuel
local Pipe = techage.LiquidPipe
2021-06-09 23:09:59 +03:00
local liquid = networks.liquid
2020-01-26 01:22:06 +03:00
local CYCLE_TIME = 2
local BURN_CYCLE_FACTOR = 0.5
2020-01-26 01:22:06 +03:00
local function node_timer(pos, elapsed)
2020-01-31 21:55:10 +03:00
local nvm = techage.get_nvm(pos)
local power = techage.transfer(
2022-01-03 23:40:31 +03:00
{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
firebox.set_firehole(pos, false)
M(pos):set_string("formspec", fuel.formspec(nvm))
return false
2020-01-26 01:22:06 +03:00
end
end
if techage.is_activeformspec(pos) then
M(pos):set_string("formspec", fuel.formspec(nvm))
end
return true
2020-01-26 01:22:06 +03:00
end
2020-01-31 21:55:10 +03:00
local function start_firebox(pos, nvm)
if not nvm.running and fuel.has_fuel(nvm) then
2020-01-31 21:55:10 +03:00
nvm.running = true
2020-01-26 01:22:06 +03:00
node_timer(pos, 0)
firebox.set_firehole(pos, true)
2020-01-26 01:22:06 +03:00
minetest.get_node_timer(pos):start(CYCLE_TIME)
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 = node_timer,
2020-01-26 01:22:06 +03:00
can_dig = fuel.can_dig,
on_rightclick = fuel.on_rightclick,
on_receive_fields = fuel.on_receive_fields,
2022-01-03 23:40:31 +03:00
after_place_node = function(pos, placer)
if firebox.is_free_position(pos, placer:get_player_name()) then
techage.add_node(pos, "techage:oilfirebox", true)
local nvm = techage.get_nvm(pos)
nvm.running = false
nvm.burn_cycles = 0
nvm.liquid = {}
nvm.liquid.amount = 0
local meta = M(pos)
meta:set_string("formspec", fuel.formspec(nvm))
local inv = meta:get_inventory()
firebox.set_firehole(pos, false)
else
minetest.remove_node(pos)
return true
end
2020-01-26 01:22:06 +03:00
end,
2022-01-03 23:40:31 +03:00
2020-01-26 01:22:06 +03:00
on_destruct = function(pos)
firebox.set_firehole(pos, nil)
2020-01-26 01:22:06 +03:00
end,
2020-03-11 21:25:54 +03:00
on_punch = function(pos, node, puncher, pointed_thing)
2020-01-31 21:55:10 +03:00
local nvm = techage.get_nvm(pos)
2020-03-11 21:25:54 +03:00
fuel.on_punch(pos, node, puncher, pointed_thing)
if nvm.liquid and nvm.liquid.amount and nvm.liquid.amount > 0 then
minetest.after(1, start_firebox, pos, nvm)
end
2020-01-26 01:22:06 +03:00
end,
})
2021-06-09 23:09:59 +03:00
liquid.register_nodes({"techage:oilfirebox"},
Pipe, "tank", nil, fuel.get_liquid_table(fuel.BT_OIL, fuel.CAPACITY, start_firebox))
2020-01-26 01:22:06 +03:00
techage.register_node({"techage:oilfirebox"}, {
on_recv_message = function(pos, src, topic, payload)
2020-01-31 21:55:10 +03:00
local nvm = techage.get_nvm(pos)
2020-01-26 01:22:06 +03:00
if topic == "state" then
2020-02-28 00:33:42 +03:00
return nvm.running and "running" or "stopped"
2020-01-26 01:22:06 +03:00
elseif topic == "fuel" then
2021-06-09 23:09:59 +03:00
return fuel.get_fuel_amount(nvm)
2020-01-26 01:22:06 +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
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
return 0, {fuel.get_fuel_amount(nvm)}
else
return 2, ""
end
end,
2020-01-26 01:22:06 +03:00
})
minetest.register_craft({
output = "techage:oilfirebox",
recipe = {
{'', 'techage:coalfirebox', ''},
{'', 'techage:ta3_barrel_empty', ''},
{'', '', ''},
},
})