techage/steam_engine/firebox.lua

173 lines
4.8 KiB
Lua
Raw Normal View History

2019-03-02 14:24:48 +03:00
--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
2020-10-19 20:09:17 +03:00
AGPL v3
2019-03-02 14:24:48 +03:00
See LICENSE.txt for more information
2022-01-03 23:40:31 +03:00
2019-03-02 14:24:48 +03:00
TA2 Steam Engine Firebox
]]--
-- for lazy programmers
local P = minetest.string_to_pos
local M = minetest.get_meta
local S = techage.S
2019-03-02 14:24:48 +03:00
local firebox = techage.firebox
2019-03-02 14:24:48 +03:00
local CYCLE_TIME = 2
local BURN_CYCLE_FACTOR = 0.8
2019-03-02 14:24:48 +03:00
local function node_timer(pos, elapsed)
2020-01-26 01:15:44 +03:00
local nvm = techage.get_nvm(pos)
if nvm.running then
2019-06-16 22:06:16 +03:00
local power = techage.transfer(
2022-01-03 23:40:31 +03:00
{x=pos.x, y=pos.y+2, z=pos.z},
2019-06-08 23:57:01 +03:00
nil, -- outdir
"trigger", -- topic
nil, -- payload
nil, -- network
{"techage:boiler2"} -- nodenames
)
2020-01-26 01:15:44 +03:00
nvm.burn_cycles = (nvm.burn_cycles or 0) - math.max((power or 0.1), 0.1)
if nvm.burn_cycles <= 0 then
2022-01-03 23:40:31 +03:00
local taken = firebox.get_fuel(pos)
if taken then
2020-01-26 01:15:44 +03:00
nvm.burn_cycles = (firebox.Burntime[taken:get_name()] or 1) / CYCLE_TIME * BURN_CYCLE_FACTOR
nvm.burn_cycles_total = nvm.burn_cycles
2019-03-02 14:24:48 +03:00
else
2020-01-26 01:15:44 +03:00
nvm.running = false
firebox.swap_node(pos, "techage:firebox")
2020-01-26 01:15:44 +03:00
M(pos):set_string("formspec", firebox.formspec(nvm))
2019-03-02 14:24:48 +03:00
return false
end
end
2020-01-26 01:15:44 +03:00
if techage.is_activeformspec(pos) then
M(pos):set_string("formspec", firebox.formspec(nvm))
end
2019-03-02 14:24:48 +03:00
return true
end
end
minetest.register_node("techage:firebox", {
description = S("TA2 Firebox"),
2019-03-02 14:24:48 +03:00
tiles = {
-- up, down, right, left, back, front
2019-06-10 22:31:58 +03:00
"techage_firebox.png^techage_appl_open.png^techage_frame_ta2.png",
2019-03-02 14:24:48 +03:00
"techage_firebox.png^techage_frame_ta2.png",
"techage_firebox.png^techage_frame_ta2.png",
"techage_firebox.png^techage_frame_ta2.png",
"techage_firebox.png^techage_frame_ta2.png",
"techage_firebox.png^techage_appl_firehole.png^techage_frame_ta2.png",
},
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,
2019-06-10 22:31:58 +03:00
on_rightclick = firebox.on_rightclick,
2022-01-03 23:40:31 +03:00
2019-03-02 14:24:48 +03:00
on_construct = function(pos)
2020-01-26 01:15:44 +03:00
local nvm = techage.get_nvm(pos)
nvm.running = false
nvm.burn_cycles = 0
2019-03-02 14:24:48 +03:00
local meta = M(pos)
2020-01-26 01:15:44 +03:00
meta:set_string("formspec", firebox.formspec(nvm))
2019-03-02 14:24:48 +03:00
local inv = meta:get_inventory()
inv:set_size('fuel', 1)
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
2020-01-26 01:15:44 +03:00
local nvm = techage.get_nvm(pos)
nvm.running = true
2019-03-02 14:24:48 +03:00
-- activate the formspec fire temporarily
2020-01-26 01:15:44 +03:00
nvm.burn_cycles = firebox.Burntime[stack:get_name()] / CYCLE_TIME
nvm.burn_cycles_total = nvm.burn_cycles
M(pos):set_string("formspec", firebox.formspec(nvm))
nvm.burn_cycles = 0
firebox.swap_node(pos, "techage:firebox_on")
2019-03-02 14:24:48 +03:00
minetest.get_node_timer(pos):start(CYCLE_TIME)
end,
})
minetest.register_node("techage:firebox_on", {
description = S("TA2 Firebox"),
2019-03-02 14:24:48 +03:00
tiles = {
-- up, down, right, left, back, front
"techage_firebox.png^techage_frame_ta2.png",
"techage_firebox.png^techage_frame_ta2.png",
"techage_firebox.png^techage_frame_ta2.png",
"techage_firebox.png^techage_frame_ta2.png",
"techage_firebox.png^techage_frame_ta2.png",
{
name = "techage_firebox4.png^techage_appl_firehole4.png^techage_frame4_ta2.png",
2019-03-02 14:24:48 +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,
groups = {cracky=2, not_in_creative_inventory=1},
is_ground_content = false,
sounds = default.node_sound_stone_defaults(),
drop = "techage:firebox",
2022-01-03 23:40:31 +03:00
2019-03-02 14:24:48 +03:00
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,
2019-06-10 22:31:58 +03:00
on_receive_fields = firebox.on_receive_fields,
on_rightclick = firebox.on_rightclick,
2019-03-02 14:24:48 +03:00
})
2019-04-28 17:04:45 +03:00
minetest.register_craft({
output = "techage:firebox",
recipe = {
{'default:stone', 'default:stone', 'default:stone'},
2019-04-28 17:04:45 +03:00
{'techage:iron_ingot', '', 'techage:iron_ingot'},
{'default:stone', 'default:stone', 'default:stone'},
2019-04-28 17:04:45 +03:00
},
})
2019-05-02 00:01:14 +03:00
2019-06-08 23:57:01 +03:00
techage.register_node({"techage:firebox", "techage:firebox_on"}, {
2019-05-02 00:01:14 +03:00
on_push_item = function(pos, in_dir, stack)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
2019-06-10 22:31:58 +03:00
if firebox.Burntime[stack:get_name()] then
if inv:room_for_item("fuel", stack) then
inv:add_item("fuel", stack)
minetest.get_node_timer(pos):start(CYCLE_TIME)
return true
end
2019-05-02 00:01:14 +03:00
end
return false
end,
2022-01-03 23:40:31 +03:00
})
2019-05-11 17:52:59 +03:00
minetest.register_lbm({
label = "[techage] Steam engine firebox",
name = "techage:steam_engine",
nodenames = {"techage:firebox_on"},
run_at_every_load = true,
action = function(pos, node)
2020-01-26 01:15:44 +03:00
local nvm = techage.get_nvm(pos)
nvm.running = true
2019-05-11 17:52:59 +03:00
minetest.get_node_timer(pos):start(CYCLE_TIME)
end
})