2019-03-02 14:24:48 +03:00
|
|
|
--[[
|
|
|
|
|
|
|
|
TechAge
|
|
|
|
=======
|
|
|
|
|
|
|
|
Copyright (C) 2019 Joachim Stolberg
|
|
|
|
|
|
|
|
LGPLv2.1+
|
|
|
|
See LICENSE.txt for more information
|
|
|
|
|
|
|
|
TA2 Steam Engine Firebox
|
|
|
|
|
|
|
|
]]--
|
|
|
|
|
|
|
|
-- 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
|
2019-03-09 22:30:41 +03:00
|
|
|
-- Techage Related Data
|
|
|
|
local TRD = function(pos) return (minetest.registered_nodes[minetest.get_node(pos).name] or {}).techage end
|
2019-03-02 14:24:48 +03:00
|
|
|
|
|
|
|
-- Load support for intllib.
|
2019-03-17 17:33:13 +03:00
|
|
|
local MP = minetest.get_modpath("techage")
|
2019-03-02 14:24:48 +03:00
|
|
|
local I,_ = dofile(MP.."/intllib.lua")
|
|
|
|
|
2019-03-19 00:40:17 +03:00
|
|
|
local firebox = techage.firebox
|
2019-03-02 14:24:48 +03:00
|
|
|
|
2019-03-19 00:40:17 +03:00
|
|
|
local CYCLE_TIME = 2
|
2019-03-02 14:24:48 +03:00
|
|
|
|
|
|
|
|
|
|
|
local function node_timer(pos, elapsed)
|
|
|
|
local mem = tubelib2.get_mem(pos)
|
|
|
|
if mem.running then
|
2019-03-09 22:30:41 +03:00
|
|
|
local trd = TRD({x=pos.x, y=pos.y+2, z=pos.z})
|
2019-05-02 00:01:14 +03:00
|
|
|
if trd and trd.signal_heat then
|
|
|
|
trd.signal_heat({x=pos.x, y=pos.y+2, z=pos.z})
|
2019-03-02 14:24:48 +03:00
|
|
|
end
|
|
|
|
mem.burn_cycles = (mem.burn_cycles or 0) - 1
|
|
|
|
if mem.burn_cycles <= 0 then
|
2019-03-19 00:40:17 +03:00
|
|
|
local taken = firebox.get_fuel(pos)
|
|
|
|
if taken then
|
|
|
|
mem.burn_cycles = firebox.Burntime[taken:get_name()] / CYCLE_TIME
|
|
|
|
mem.burn_cycles_total = mem.burn_cycles
|
2019-03-02 14:24:48 +03:00
|
|
|
else
|
|
|
|
mem.running = false
|
2019-03-19 00:40:17 +03:00
|
|
|
firebox.swap_node(pos, "techage:firebox")
|
|
|
|
M(pos):set_string("formspec", firebox.formspec(mem))
|
2019-03-02 14:24:48 +03:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_node("techage:firebox", {
|
|
|
|
description = I("TA2 Firebox"),
|
|
|
|
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",
|
|
|
|
"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,
|
2019-03-19 00:40:17 +03:00
|
|
|
can_dig = firebox.can_dig,
|
|
|
|
allow_metadata_inventory_put = firebox.allow_metadata_inventory,
|
|
|
|
allow_metadata_inventory_take = firebox.allow_metadata_inventory,
|
|
|
|
on_receive_fields = firebox.on_receive_fields,
|
|
|
|
on_rightclick = firebox.on_rightclick,
|
2019-03-02 14:24:48 +03:00
|
|
|
|
|
|
|
on_construct = function(pos)
|
|
|
|
local mem = tubelib2.init_mem(pos)
|
|
|
|
mem.running = false
|
|
|
|
mem.burn_cycles = 0
|
|
|
|
local meta = M(pos)
|
2019-03-19 00:40:17 +03:00
|
|
|
meta:set_string("formspec", firebox.formspec(mem))
|
2019-03-02 14:24:48 +03:00
|
|
|
local inv = meta:get_inventory()
|
|
|
|
inv:set_size('fuel', 1)
|
|
|
|
end,
|
|
|
|
|
2019-03-19 00:40:17 +03:00
|
|
|
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
2019-03-02 14:24:48 +03:00
|
|
|
local mem = tubelib2.init_mem(pos)
|
|
|
|
mem.running = true
|
|
|
|
-- activate the formspec fire temporarily
|
2019-03-19 00:40:17 +03:00
|
|
|
mem.burn_cycles = firebox.Burntime[stack:get_name()] / CYCLE_TIME
|
|
|
|
mem.burn_cycles_total = mem.burn_cycles
|
|
|
|
M(pos):set_string("formspec", firebox.formspec(mem))
|
2019-03-02 14:24:48 +03:00
|
|
|
mem.burn_cycles = 0
|
2019-03-19 00:40:17 +03:00
|
|
|
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 = I("TA2 Firebox"),
|
|
|
|
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",
|
|
|
|
{
|
|
|
|
image = "techage_firebox4.png^techage_appl_firehole4.png^techage_frame4_ta2.png",
|
|
|
|
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",
|
|
|
|
|
|
|
|
on_timer = node_timer,
|
2019-03-19 00:40:17 +03:00
|
|
|
can_dig = firebox.can_dig,
|
|
|
|
allow_metadata_inventory_put = firebox.allow_metadata_inventory,
|
|
|
|
allow_metadata_inventory_take = firebox.allow_metadata_inventory,
|
|
|
|
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 = {
|
|
|
|
{'group:stone', 'group:stone', 'group:stone'},
|
|
|
|
{'techage:iron_ingot', '', 'techage:iron_ingot'},
|
|
|
|
{'group:stone', 'group:stone', 'group:stone'},
|
|
|
|
},
|
|
|
|
})
|
2019-05-02 00:01:14 +03:00
|
|
|
|
|
|
|
techage.register_node("techage:firebox", {"techage:firebox_on"}, {
|
|
|
|
on_push_item = function(pos, in_dir, stack)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
if inv:room_for_item("fuel", stack) then
|
|
|
|
inv:add_item("fuel", stack)
|
|
|
|
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end,
|
|
|
|
})
|