furnace added

master
Joachim Stolberg 2019-06-10 21:31:58 +02:00
parent 8b2e0c6ebb
commit 1349e3c2d5
23 changed files with 1595 additions and 101 deletions

View File

@ -324,7 +324,7 @@ function techage.transfer(pos, outdir, topic, payload, network, nodenames)
if network then
dpos, indir = network:get_connected_node_pos(pos, outdir)
else
dpos, indir = tubelib2.get_pos(pos, outdir)
dpos, indir = tubelib2.get_pos(pos, outdir), outdir
end
-- check node name
local name = techage.get_node_lvm(dpos).name

View File

@ -42,21 +42,35 @@ function techage.firebox.formspec(mem)
if mem.running then
fuel_percent = ((mem.burn_cycles or 1) * 100) / (mem.burn_cycles_total or 1)
end
local power_level = mem.power_level or 4
return "size[8,6.5]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"list[current_name;fuel;1,0.5;1,1;]"..
"image[2,0.5;1,1;default_furnace_fire_bg.png^[lowpart:"..
fuel_percent..":default_furnace_fire_fg.png]"..
"label[4.5,0.1;"..I("Power")..":]"..
"dropdown[6,0;1.8;power_level;25%,50%,75%,100%;"..power_level.."]"..
"button[1,1.5;1.8,1;update;"..I("Update").."]"..
"list[current_player;main;0,2.8;8,4;]"..
"listring[current_name;fuel]"..
"listring[current_player;main]"..
default.get_hotbar_bg(0, 2.8)
if mem.power_level then
return "size[8,6.5]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"list[current_name;fuel;1,0.5;1,1;]"..
"image[2,0.5;1,1;default_furnace_fire_bg.png^[lowpart:"..
fuel_percent..":default_furnace_fire_fg.png]"..
"label[4.5,0.1;"..I("Power")..":]"..
"dropdown[6,0;1.8;power_level;25%,50%,75%,100%;"..power_level.."]"..
"button[1,1.5;1.8,1;update;"..I("Update").."]"..
"list[current_player;main;0,2.8;8,4;]"..
"listring[current_name;fuel]"..
"listring[current_player;main]"..
default.get_hotbar_bg(0, 2.8)
else
return "size[8,6]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"list[current_name;fuel;1,0.5;1,1;]"..
"image[3,0.5;1,1;default_furnace_fire_bg.png^[lowpart:"..
fuel_percent..":default_furnace_fire_fg.png]"..
"button[5,0.5;1.8,1;update;"..I("Update").."]"..
"list[current_player;main;0,2;8,4;]"..
"listring[current_name;fuel]"..
"listring[current_player;main]"..
default.get_hotbar_bg(0, 2)
end
end
function techage.firebox.can_dig(pos, player)
@ -129,3 +143,8 @@ function techage.firebox.get_fuel(pos)
end
end
function techage.firebox.has_fuel(pos)
local inv = M(pos):get_inventory()
local items = inv:get_stack("fuel", 1)
return items:get_count() > 0
end

View File

@ -35,6 +35,13 @@ function techage.one_of(val, selection)
return selection[1]
end
function techage.index(list, x)
for idx, v in pairs(list) do
if v == x then return idx end
end
return nil
end
function techage.get_node_lvm(pos)
local node = minetest.get_node_or_nil(pos)
if node then

View File

@ -103,6 +103,7 @@ minetest.register_node("techage:coalfirebox", {
local mem = tubelib2.init_mem(pos)
mem.running = false
mem.burn_cycles = 0
mem.power_level = 4
local meta = M(pos)
meta:set_string("formspec", firebox.formspec(mem))
local inv = meta:get_inventory()
@ -189,11 +190,14 @@ techage.register_node({"techage:coalfirebox"}, {
return techage.get_items(inv, "fuel", num)
end,
on_push_item = function(pos, in_dir, stack)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local mem = tubelib2.get_mem(pos)
start_firebox(pos, mem)
return techage.put_items(inv, "fuel", stack)
if firebox.Burntime[stack:get_name()] then
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local mem = tubelib2.get_mem(pos)
start_firebox(pos, mem)
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)

208
furnace/booster.lua Normal file
View File

@ -0,0 +1,208 @@
--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
LGPLv2.1+
See LICENSE.txt for more information
TA3 Booster
]]--
-- 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
-- Load support for intllib.
local MP = minetest.get_modpath("techage")
local I,_ = dofile(MP.."/intllib.lua")
local POWER_CONSUMPTION = 3
local Power = techage.ElectricCable
local function infotext(pos, state)
M(pos):set_string("infotext", I("TA3 Booster")..": "..state)
end
local function swap_node(pos, name)
local node = minetest.get_node(pos)
if node.name == name then
return
end
node.name = name
minetest.swap_node(pos, node)
end
local function play_sound(pos)
local mem = tubelib2.get_mem(pos)
if mem.running then
mem.handle = minetest.sound_play("techage_booster", {
pos = pos,
gain = 1,
max_hear_distance = 7})
minetest.after(2, play_sound, pos)
end
end
local function stop_sound(pos)
local mem = tubelib2.get_mem(pos)
if mem.handle then
minetest.sound_stop(mem.handle)
mem.handle = nil
end
end
local function on_power_pass1(pos, mem)
--print("on_power_pass1")
if mem.running then
mem.correction = POWER_CONSUMPTION
else
mem.correction = 0
end
return mem.correction
end
local function on_power_pass2(pos, mem, sum)
if sum > 0 then
mem.has_power = true
return 0
else
mem.has_power = false
return -mem.correction
end
end
minetest.register_node("techage:ta3_booster", {
description = I("TA3 Booster"),
tiles = {
-- up, down, right, left, back, front
"techage_filling_ta3.png^techage_appl_arrow.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_appl_hole_biogas.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_appl_hole_biogas.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_appl_compressor.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_appl_compressor.png^[transformFX^techage_frame_ta3.png",
},
on_construct = tubelib2.init_mem,
after_place_node = function(pos, placer)
local node = minetest.get_node(pos)
local indir = techage.side_to_indir("R", node.param2)
M(pos):set_int("indir", indir)
infotext(pos, "stopped")
end,
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2},
on_rotate = screwdriver.disallow,
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
minetest.register_node("techage:ta3_booster_on", {
tiles = {
-- up, down, right, left, back, front
"techage_filling_ta3.png^techage_appl_arrow.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_appl_hole_biogas.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_appl_hole_biogas.png^techage_frame_ta3.png",
{
image = "techage_filling4_ta3.png^techage_appl_compressor4.png^techage_frame4_ta3.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 0.2,
},
},
{
image = "techage_filling4_ta3.png^techage_appl_compressor4.png^[transformFX]^techage_frame4_ta3.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 0.2,
},
},
},
paramtype2 = "facedir",
groups = {not_in_creative_inventory = 1},
diggable = false,
on_rotate = screwdriver.disallow,
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
techage.power.register_node({"techage:ta3_booster", "techage:ta3_booster_on"}, {
on_power_pass1 = on_power_pass1,
on_power_pass2 = on_power_pass2,
power_network = Power,
conn_sides = {"F", "B", "U", "D"},
})
-- for intra machine communication
techage.register_node({"techage:ta3_booster", "techage:ta3_booster_on"}, {
on_transfer = function(pos, in_dir, topic, payload)
--print("ta3_booster", topic, payload, in_dir)
if M(pos):get_int("indir") == in_dir then
local mem = tubelib2.get_mem(pos)
if topic == "power" then
return mem.has_power
elseif topic == "start" then
if mem.has_power then
mem.running = true
play_sound(pos)
swap_node(pos, "techage:ta3_booster_on")
infotext(pos, "running")
techage.power.power_distribution(pos)
else
infotext(pos, "no power")
end
elseif topic == "stop" then
mem.running = false
stop_sound(pos)
swap_node(pos, "techage:ta3_booster")
if mem.has_power then
infotext(pos, "stopped")
else
infotext(pos, "no power")
end
techage.power.power_distribution(pos)
end
end
end
})
minetest.register_craft({
output = "techage:ta3_booster",
recipe = {
{"basic_materials:steel_bar", "default:wood", "basic_materials:steel_bar"},
{"techage:steam_pipeS", "basic_materials:gear_steel", "techage:steam_pipeS"},
{"basic_materials:steel_bar", "default:wood", "basic_materials:steel_bar"},
},
})
techage.register_help_page(I("TA3 Booster"),
I([[Part of the TA3 Furnace and further machines.
Used to increase the air/gas pressure.]]), "techage:ta3_booster")
minetest.register_lbm({
label = "[techage] Booster sound",
name = "techage:booster",
nodenames = {"techage:ta3_booster_on"},
run_at_every_load = true,
action = function(pos, node)
play_sound(pos)
end
})

118
furnace/cooking.lua Normal file
View File

@ -0,0 +1,118 @@
--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
LGPLv2.1+
See LICENSE.txt for more information
Cooking routines for furnace
]]--
-- 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
-- Load support for intllib.
local MP = minetest.get_modpath("techage")
local I,_ = dofile(MP.."/intllib.lua")
local Recipes = {} -- registered recipes
local KeyList = {} -- index to Recipes key translation
local NumRecipes = 0
techage.furnace = {}
-- move recipe src items to output inventory
local function process(inv, recipe)
local res
-- check if all ingredients are available
for _,item in ipairs(recipe.input) do
if not inv:contains_item("src", item) then
return false
end
end
-- remove items
for _,item in ipairs(recipe.input) do
inv:remove_item("src", item)
end
-- add to dst
local stack = ItemStack(recipe.output)
stack:set_count(recipe.number)
inv:add_item("dst", stack)
return true
end
function techage.furnace.smelting(pos, mem, elapsed)
local inv = M(pos):get_inventory()
local state = techage.STANDBY
if inv and not inv:is_empty("src") then
local key = KeyList[mem.recipe_idx or 1] or KeyList[1]
local recipe = Recipes[key]
-- check dst inv
local item = ItemStack(recipe.output)
if not inv:room_for_item("dst", item) then
return techage.BLOCKED
end
elapsed = elapsed + (mem.leftover or 0)
while elapsed >= recipe.time do
if process(inv, recipe) == false then
mem.leftover = 0
return techage.STANDBY
else
state = techage.RUNNING
end
elapsed = elapsed - recipe.time
end
mem.leftover = elapsed
return state
end
return techage.STANDBY
end
function techage.furnace.get_output(idx)
local key = KeyList[idx] or KeyList[1]
return Recipes[key].output
end
function techage.furnace.get_num_recipes()
return NumRecipes
end
function techage.furnace.reset_cooking(mem)
mem.leftover = 0
end
if minetest.global_exists("unified_inventory") then
unified_inventory.register_craft_type("ta3_melting", {
description = I("TA3 Melting"),
icon = "techage_concrete.png^techage_appl_furnace.png^techage_frame_ta3.png",
width = 2,
height = 2,
})
end
function techage.furnace.register_recipe(recipe)
local output = string.split(recipe.output, " ")
local number = tonumber(output[2] or 1)
table.insert(KeyList, output)
Recipes[output] = {
input = recipe.recipe,
output = output[1],
number = number,
time = math.max((recipe.time or 3) * number, 2),
}
NumRecipes = NumRecipes + 1
if minetest.global_exists("unified_inventory") then
recipe.items = recipe.recipe
recipe.type = "ta3_melting"
unified_inventory.register_craft(recipe)
end
end

212
furnace/firebox.lua Normal file
View File

@ -0,0 +1,212 @@
--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
LGPLv2.1+
See LICENSE.txt for more information
TA3 Industrial Furnace 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
-- Load support for intllib.
local MP = minetest.get_modpath("techage")
local I,_ = dofile(MP.."/intllib.lua")
local firebox = techage.firebox
local CYCLE_TIME = 2
local function has_fuel(pos, mem)
return mem.burn_cycles > 0 or firebox.has_fuel(pos)
end
local function stop_firebox(pos, mem)
mem.running = false
firebox.swap_node(pos, "techage:furnace_firebox")
minetest.get_node_timer(pos):stop()
M(pos):set_string("formspec", firebox.formspec(mem))
end
local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos)
if mem.running then
mem.burn_cycles = (mem.burn_cycles or 0) - 1
if mem.burn_cycles <= 0 then
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
else
stop_firebox(pos, mem)
return false
end
end
return true
end
end
local function start_firebox(pos, mem)
if not mem.running then
mem.running = true
node_timer(pos, 0)
firebox.swap_node(pos, "techage:furnace_firebox_on")
minetest.get_node_timer(pos):start(CYCLE_TIME)
M(pos):set_string("formspec", firebox.formspec(mem))
end
end
local function booster_cmnd(pos, cmnd)
return techage.transfer(
pos,
"L", -- outdir
cmnd, -- topic
nil, -- payload
nil, -- network
{"techage:ta3_booster", "techage:ta3_booster_on"})
end
minetest.register_node("techage:furnace_firebox", {
description = I("TA3 Furnace Firebox"),
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",
"techage_concrete.png^techage_appl_hole_biogas.png^techage_frame_ta3.png",
"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,
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,
on_construct = function(pos)
local mem = tubelib2.init_mem(pos)
mem.running = false
mem.burn_cycles = 0
local meta = M(pos)
meta:set_string("formspec", firebox.formspec(mem))
local inv = meta:get_inventory()
inv:set_size('fuel', 1)
end,
})
minetest.register_node("techage:furnace_firebox_on", {
description = I("TA3 Furnace Firebox"),
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",
{
image = "techage_concrete4.png^techage_appl_firehole4.png^techage_frame4_ta3.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,
diggable = false,
groups = {not_in_creative_inventory = 1},
is_ground_content = false,
sounds = default.node_sound_stone_defaults(),
drop = "techage:furnace_firebox",
on_timer = node_timer,
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,
})
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"}, {
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 mem = tubelib2.get_mem(pos)
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, topic, payload)
if topic == "state" then
local meta = minetest.get_meta(pos)
return techage.get_inv_state(meta, "fuel")
else
return "unsupported"
end
end,
-- called from furnace_top
on_transfer = function(pos, in_dir, topic, payload)
--print("on_transfer", topic, payload)
if topic == "fuel" then
local mem = tubelib2.get_mem(pos)
return has_fuel(pos, mem) and booster_cmnd(pos, "power")
elseif topic == "start" then
local mem = tubelib2.get_mem(pos)
start_firebox(pos, mem)
booster_cmnd(pos, "start")
elseif topic == "stop" then
local mem = tubelib2.get_mem(pos)
stop_firebox(pos, mem)
booster_cmnd(pos, "stop")
end
end
})
minetest.register_lbm({
label = "[techage] Furnace firebox",
name = "techage:furnace",
nodenames = {"techage:furnace_firebox_on"},
run_at_every_load = true,
action = function(pos, node)
minetest.get_node_timer(pos):start(CYCLE_TIME)
end
})

667
furnace/furnace__.lua Normal file
View File

@ -0,0 +1,667 @@
--[[
=======================================================================
Tubelib Biogas Machines Mod
by Micu (c) 2018, 2019
Copyright (C) 2018, 2019 Michal Cieslakiewicz
Biogas Jet Furnace is an upgraded version of standard Gas Furnace.
It works 2 times faster in both item cooking speed and Biogas
consumption. One unit of Biogas lasts for 20 seconds but items
are cooked twice as fast. However, this puts more stress on internal
parts so machine needs to be serviced more frequently.
Please see gasfurnace.lua for differences between Biogas and Coal
furnaces as this device is functionally identical to Gas Furnace.
The only extra upgrade is support for pulling whole stacks from
output tray (like HighPerf Chest), so its output can be paired with
HighPerf Pusher.
Note about implementation: to maintain timer at 1 sec while halving
cooking time a random factor has been introduced for all cooking
durations that are odd numbers. Such items will cook either longer or
quicker with 50/50 probability. Example: from 10 iron lumps that have
standard cooking time 3 sec each, ~5 items should cook for 2 sec and
~5 for 1 sec giving average cooking time 1.5 sec and using proper
amount of Biogas.
Tubelib v2 implementation info:
* device updates itself every tick, so cycle_time must be set to 1
even though production takes longer (start method sets timer to
this value)
* keep_running function is called every time item is produced
(not every processing tick - function does not accept neither 0
nor fractional values for num_items parameter)
* desired_state metadata allows to properly change non-running target
state during transition; when new state differs from old one, timer
is reset so it is guaranteed that each countdown starts from
COUNTDOWN_TICKS
* num_items in keep_running method is set to 1 (default value);
machine aging is controlled by aging_factor solely; tubelib item
counter is used to count production iterations not actual items
License: LGPLv2.1+
=======================================================================
]]--
--[[
---------
Variables
---------
]]--
-- Jet Furnace uses Biogas twice as fast so 1 Biogas unit burns for 20 sec
local BIOGAS_TICKS = 20
-- timing
local TIMER_TICK_SEC = 1 -- Node timer tick
local STANDBY_TICKS = 4 -- Standby mode timer frequency factor
local COUNTDOWN_TICKS = 4 -- Ticks to standby
-- machine inventory
local INV_H = 3 -- Inventory height
local INV_IN_W = 3 -- Input inventory width
local INV_OUT_W = (6 - INV_IN_W) -- Output inventory width
--[[
--------
Formspec
--------
]]--
-- static data for formspec
local fmxy = {
inv_h = tostring(INV_H),
inv_in_w = tostring(INV_IN_W),
mid_x = tostring(INV_IN_W + 1),
inv_out_w = tostring(INV_OUT_W),
inv_out_x = tostring(INV_IN_W + 2),
biogas_time = tostring(BIOGAS_TICKS * TIMER_TICK_SEC)
}
-- formspec
local function formspec(self, pos, meta)
local state = meta:get_int("tubelib_state")
local fuel_pct = tostring(100 * meta:get_int("fuel_ticks") / BIOGAS_TICKS)
local item_pct = tostring(100 * (1 - meta:get_int("item_ticks") / meta:get_int("item_total")))
return "size[8,8.25]" ..
default.gui_bg ..
default.gui_bg_img ..
default.gui_slots ..
"list[context;src;0,0;" .. fmxy.inv_in_w .. "," .. fmxy.inv_h .. ";]" ..
"list[context;cur;" .. fmxy.inv_in_w .. ",0;1,1;]" ..
"image[" .. fmxy.inv_in_w ..
",1;1,1;biogasmachines_gasfurnace_inv_bg.png^[lowpart:" ..
fuel_pct .. ":biogasmachines_gasfurnace_inv_fg.png]" ..
"image[" .. fmxy.mid_x .. ",1;1,1;gui_furnace_arrow_bg.png^[lowpart:" ..
item_pct .. ":gui_furnace_arrow_fg.png^[transformR270]" ..
"list[context;fuel;" .. fmxy.inv_in_w .. ",2;1,1;]" ..
"item_image[" .. fmxy.inv_in_w .. ",2;1,1;tubelib_addons1:biogas]" ..
"image_button[" .. fmxy.mid_x .. ",2;1,1;" ..
self:get_state_button_image(meta) .. ";state_button;]" ..
"item_image[2,3.25;0.5,0.5;biogasmachines:jetfurnace]" ..
"label[2.5,3.25;=]" ..
"item_image[2.75,3.25;0.5,0.5;default:furnace]" ..
"label[3.25,3.25;x 2]" ..
"item_image[4.5,3.25;0.5,0.5;tubelib_addons1:biogas]" ..
"tooltip[4.5,3.25;0.5,0.5;Biogas]" ..
"label[5,3.25;= " .. fmxy.biogas_time .. " sec]" ..
"list[context;dst;" .. fmxy.inv_out_x .. ",0;" .. fmxy.inv_out_w ..
"," .. fmxy.inv_h .. ";]" ..
"list[current_player;main;0,4;8,1;]" ..
"list[current_player;main;0,5.25;8,3;8]" ..
"listring[context;dst]" ..
"listring[current_player;main]" ..
"listring[context;src]" ..
"listring[current_player;main]" ..
"listring[context;fuel]" ..
"listring[current_player;main]" ..
(state == tubelib.RUNNING and
"box[" .. fmxy.inv_in_w .. ",0;0.82,0.88;#BF5F2F]" or
"listring[context;cur]listring[current_player;main]") ..
default.get_hotbar_bg(0, 4)
end
--[[
-------
Helpers
-------
]]--
-- reset processing data
local function state_meta_reset(pos, meta)
meta:set_int("item_ticks", -1)
meta:set_int("item_total", -1)
end
-- Wrapper for 'cooking' get_craft_result() function for specified ItemStack
-- Return values are as follows:
-- time - cooking time or 0 if not cookable
-- input - input itemstack (take it from source stack to get decremented input)
-- output - output itemstack array (all extra leftover products are also here)
-- decr_input - decremented input (without leftover products)
local function get_cooking_items(stack)
if stack:is_empty() then
return 0, nil, nil, nil
end
local cookout, decinp = minetest.get_craft_result({ method = "cooking",
width = 1, items = { stack } })
if cookout.time <= 0 or cookout.item:is_empty() then
return 0, nil, nil, nil
end
local inp = stack
local outp = { cookout.item }
local decp = decinp and decinp.items and decinp.items[1] or nil
if decp and not decp:is_empty() then
if decp:get_name() ~= stack:get_name() then
outp[#outp + 1] = decp
decp = ItemStack({})
else
inp = ItemStack(stack:get_name() .. " " ..
tostring(stack:get_count() - decp:get_count()))
end
end
return cookout.time, inp, outp, decp
end
-- calculates fast (jet) cooking time, adding randomly 1 (with 50/50 chance)
-- to odd durations to compensate halves
local function get_fast_cooking_time(time)
local otime = math.max(math.floor(time + 0.5), 2) -- rounding
local ntime = math.floor(otime / 2)
if otime % 2 == 0 then
return ntime
else
return math.random(ntime, ntime + 1)
end
end
--[[
-------------
State machine
-------------
]]--
local machine = tubelib.NodeStates:new({
node_name_passive = "biogasmachines:jetfurnace",
node_name_active = "biogasmachines:jetfurnace_active",
node_name_defect = "biogasmachines:jetfurnace_defect",
infotext_name = "Biogas Jet Furnace",
cycle_time = TIMER_TICK_SEC,
standby_ticks = STANDBY_TICKS,
has_item_meter = true,
aging_factor = 20,
on_start = function(pos, meta, oldstate)
meta:set_int("desired_state", tubelib.RUNNING)
state_meta_reset(pos, meta)
end,
on_stop = function(pos, meta, oldstate)
meta:set_int("desired_state", tubelib.STOPPED)
state_meta_reset(pos, meta)
end,
formspec_func = formspec,
})
-- fault function for convenience as there is no on_fault method (yet)
local function machine_fault(pos, meta)
meta:set_int("desired_state", tubelib.FAULT)
state_meta_reset(pos, meta)
machine:fault(pos, meta)
end
-- customized version of NodeStates:idle()
local function countdown_to_halt(pos, meta, target_state)
if target_state ~= tubelib.STANDBY and
target_state ~= tubelib.BLOCKED and
target_state ~= tubelib.STOPPED and
target_state ~= tubelib.FAULT then
return true
end
if machine:get_state(meta) == tubelib.RUNNING and
meta:get_int("desired_state") ~= target_state then
meta:set_int("tubelib_countdown", COUNTDOWN_TICKS)
meta:set_int("desired_state", target_state)
end
local countdown = meta:get_int("tubelib_countdown") - 1
if countdown >= -1 then
-- we don't need anything less than -1
meta:set_int("tubelib_countdown", countdown)
end
if countdown < 0 then
if machine:get_state(meta) == target_state then
return true
end
meta:set_int("desired_state", target_state)
-- workaround for switching between non-running states
meta:set_int("tubelib_state", tubelib.RUNNING)
if target_state == tubelib.FAULT then
machine_fault(pos, meta)
elseif target_state == tubelib.STOPPED then
machine:stop(pos, meta)
elseif target_state == tubelib.BLOCKED then
machine:blocked(pos, meta)
else
machine:standby(pos, meta)
end
return false
end
return true
end
-- countdown to one of two states depending on fuel availability
local function fuel_countdown_to_halt(pos, meta, target_state_fuel, target_state_empty)
local inv = meta:get_inventory()
if meta:get_int("fuel_ticks") == 0 and inv:is_empty("fuel") then
return countdown_to_halt(pos, meta, target_state_empty)
else
return countdown_to_halt(pos, meta, target_state_fuel)
end
end
--[[
---------
Callbacks
---------
]]--
-- do not allow to dig protected or non-empty machine
local function can_dig(pos, player)
if minetest.is_protected(pos, player:get_player_name()) then
return false
end
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("src") and inv:is_empty("dst")
and inv:is_empty("fuel")
end
-- cleanup after digging
local function after_dig_node(pos, oldnode, oldmetadata, digger)
tubelib.remove_node(pos)
end
-- init machine after placement
local function after_place_node(pos, placer, itemstack, pointed_thing)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
inv:set_size('src', INV_H * INV_IN_W)
inv:set_size('cur', 1)
inv:set_size('fuel', 1)
inv:set_size('dst', INV_H * INV_OUT_W)
meta:set_string("owner", placer:get_player_name())
meta:set_int("fuel_ticks", 0)
state_meta_reset(pos, meta)
local number = tubelib.add_node(pos, "biogasmachines:jetfurnace")
machine:node_init(pos, number)
end
-- validate incoming items
local function allow_metadata_inventory_put(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
if listname == "src" then
if stack:get_name() == "tubelib_addons1:biogas" then
return 0
else
return stack:get_count()
end
elseif listname == "cur" or listname == "dst" then
return 0
elseif listname == "fuel" then
if stack:get_name() == "tubelib_addons1:biogas" then
return stack:get_count()
else
return 0
end
end
return 0
end
-- validate items move
local function allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
local meta = minetest.get_meta(pos)
if to_list == "cur" or
(from_list == "cur" and machine:get_state(meta) == tubelib.RUNNING) then
return 0
end
local inv = meta:get_inventory()
local stack = inv:get_stack(from_list, from_index)
return allow_metadata_inventory_put(pos, to_list, to_index, stack, player)
end
-- validate items retrieval
local function allow_metadata_inventory_take(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
if listname == "cur" then
local meta = minetest.get_meta(pos)
if machine:get_state(meta) == tubelib.RUNNING then
return 0
end
end
return stack:get_count()
end
-- formspec callback
local function on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then
return
end
machine:state_button_event(pos, fields)
end
-- tick-based item production
local function on_timer(pos, elapsed)
local node = minetest.get_node(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local fuel = meta:get_int("fuel_ticks")
local recipe = {}
local inp
if inv:is_empty("cur") then
-- idle and ready, check for something to work with
if inv:is_empty("src") then
return fuel_countdown_to_halt(pos, meta,
tubelib.STANDBY, tubelib.STOPPED)
end
-- find item to cook/smelt that fits output tray
-- (parse list items as first choice is not always the best one)
local idx = -2
for i = 1, inv:get_size("src") do
inp = inv:get_stack("src", i)
if not inp:is_empty() then
recipe.time, recipe.input, recipe.output,
recipe.decremented_input = get_cooking_items(inp)
if recipe.time > 0 then
idx = -1
inv:set_list("dst_copy", inv:get_list("dst"))
local is_dst_ok = true
for _, stack in ipairs(recipe.output) do
local outp = inv:add_item("dst_copy", stack)
if not outp:is_empty() then
is_dst_ok = false
break
end
end
inv:set_size("dst_copy", 0)
if is_dst_ok then
idx = i
break
end
end
end
end
-- (idx == -2 - nothing cookable found in src)
-- (idx == -1 - cookable item in src but no space in dst)
if idx == -2 then
return fuel_countdown_to_halt(pos, meta,
tubelib.STANDBY, tubelib.STOPPED)
elseif idx == -1 then
if machine:get_state(meta) == tubelib.STANDBY then
-- adapt behaviour to other biogas machines
-- (standby->blocked should go through running)
machine:start(pos, meta, true)
return false
else
return fuel_countdown_to_halt(pos, meta,
tubelib.BLOCKED, tubelib.FAULT)
end
end
if machine:get_state(meta) == tubelib.STANDBY or
machine:get_state(meta) == tubelib.BLOCKED then
-- something to do, wake up and re-entry
machine:start(pos, meta, true)
return false
end
if fuel == 0 and inv:is_empty("fuel") then
return countdown_to_halt(pos, meta, tubelib.FAULT)
end
inv:set_stack("src", idx, recipe.decremented_input)
inv:set_stack("cur", 1, recipe.input)
recipe.time = get_fast_cooking_time(recipe.time)
meta:set_int("item_ticks", recipe.time)
meta:set_int("item_total", recipe.time)
else
-- production
inp = inv:get_stack("cur", 1)
if machine:get_state(meta) ~= tubelib.RUNNING or
inp:is_empty() then
-- exception, should not happen - oops
machine_fault(pos, meta)
return false
end
-- production tick
if fuel == 0 and inv:is_empty("fuel") then
return countdown_to_halt(pos, meta, tubelib.FAULT)
end
local itemcnt = meta:get_int("item_ticks")
local zzz -- dummy
if itemcnt < 0 then
-- interrupted - cook again
recipe.time, zzz, recipe.output = get_cooking_items(inp)
recipe.time = get_fast_cooking_time(recipe.time)
meta:set_int("item_total", recipe.time)
itemcnt = recipe.time
else
recipe.output = nil
end
itemcnt = itemcnt - 1
if itemcnt == 0 then
if not recipe.output then
zzz, zzz, recipe.output = get_cooking_items(inp)
end
for _, i in ipairs(recipe.output) do
inv:add_item("dst", i)
end
inv:set_stack("cur", 1, ItemStack({}))
state_meta_reset(pos, meta)
-- item produced, increase aging
machine:keep_running(pos, meta, COUNTDOWN_TICKS)
else
meta:set_int("item_ticks", itemcnt)
end
-- consume fuel tick
if fuel == 0 then
if not inv:is_empty("fuel") then
inv:remove_item("fuel",
ItemStack("tubelib_addons1:biogas 1"))
fuel = BIOGAS_TICKS
else
machine_fault(pos, meta) -- oops
return false
end
end
meta:set_int("fuel_ticks", fuel - 1)
end
meta:set_int("tubelib_countdown", COUNTDOWN_TICKS)
meta:set_int("desired_state", tubelib.RUNNING)
meta:set_string("formspec", formspec(machine, pos, meta))
return true
end
--[[
-----------------
Node registration
-----------------
]]--
minetest.register_node("biogasmachines:jetfurnace", {
description = "Tubelib Biogas Jet Furnace",
tiles = {
-- up, down, right, left, back, front
"biogasmachines_jetfurnace_top.png",
"biogasmachines_bottom.png",
"biogasmachines_jetfurnace_side.png",
"biogasmachines_jetfurnace_side.png",
"biogasmachines_jetfurnace_side.png",
"biogasmachines_jetfurnace_side.png",
},
drawtype = "nodebox",
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "facedir",
groups = { choppy = 2, cracky = 2, crumbly = 2 },
is_ground_content = false,
sounds = default.node_sound_metal_defaults(),
drop = "",
can_dig = can_dig,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
machine:after_dig_node(pos, oldnode, oldmetadata, digger)
after_dig_node(pos, oldnode, oldmetadata, digger)
end,
on_rotate = screwdriver.disallow,
on_timer = on_timer,
on_receive_fields = on_receive_fields,
allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_move = allow_metadata_inventory_move,
allow_metadata_inventory_take = allow_metadata_inventory_take,
after_place_node = after_place_node,
})
minetest.register_node("biogasmachines:jetfurnace_active", {
description = "Tubelib Biogas Jet Furnace",
tiles = {
-- up, down, right, left, back, front
{
image = "biogasmachines_jetfurnace_active_top.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 1.5,
},
},
"biogasmachines_bottom.png",
"biogasmachines_jetfurnace_side.png",
"biogasmachines_jetfurnace_side.png",
"biogasmachines_jetfurnace_side.png",
"biogasmachines_jetfurnace_side.png",
},
drawtype = "nodebox",
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "facedir",
groups = { crumbly = 0, not_in_creative_inventory = 1 },
is_ground_content = false,
light_source = 6,
sounds = default.node_sound_metal_defaults(),
drop = "",
can_dig = can_dig,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
machine:after_dig_node(pos, oldnode, oldmetadata, digger)
after_dig_node(pos, oldnode, oldmetadata, digger)
end,
on_rotate = screwdriver.disallow,
on_timer = on_timer,
on_receive_fields = on_receive_fields,
allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_move = allow_metadata_inventory_move,
allow_metadata_inventory_take = allow_metadata_inventory_take,
})
minetest.register_node("biogasmachines:jetfurnace_defect", {
description = "Tubelib Biogas Jet Furnace",
tiles = {
-- up, down, right, left, back, front
"biogasmachines_jetfurnace_top.png",
"biogasmachines_bottom.png",
"biogasmachines_jetfurnace_side.png^tubelib_defect.png",
"biogasmachines_jetfurnace_side.png^tubelib_defect.png",
"biogasmachines_jetfurnace_side.png^tubelib_defect.png",
"biogasmachines_jetfurnace_side.png^tubelib_defect.png",
},
drawtype = "nodebox",
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "facedir",
groups = { choppy = 2, cracky = 2, crumbly = 2, not_in_creative_inventory = 1 },
is_ground_content = false,
sounds = default.node_sound_metal_defaults(),
can_dig = can_dig,
after_dig_node = after_dig_node,
on_rotate = screwdriver.disallow,
allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_move = allow_metadata_inventory_move,
allow_metadata_inventory_take = allow_metadata_inventory_take,
after_place_node = function(pos, placer, itemstack, pointed_thing)
after_place_node(pos, placer, itemstack, pointed_thing)
machine:defect(pos, minetest.get_meta(pos))
end,
})
tubelib.register_node("biogasmachines:jetfurnace",
{ "biogasmachines:jetfurnace_active", "biogasmachines:jetfurnace_defect" }, {
on_push_item = function(pos, side, item)
local meta = minetest.get_meta(pos)
if item:get_name() == "tubelib_addons1:biogas" then
return tubelib.put_item(meta, "fuel", item)
end
return tubelib.put_item(meta, "src", item)
end,
on_pull_item = function(pos, side)
local meta = minetest.get_meta(pos)
return tubelib.get_item(meta, "dst")
end,
on_pull_stack = function(pos, side)
local meta = minetest.get_meta(pos)
return tubelib.get_stack(meta, "dst")
end,
on_unpull_item = function(pos, side, item)
local meta = minetest.get_meta(pos)
return tubelib.put_item(meta, "dst", item)
end,
on_recv_message = function(pos, topic, payload)
local meta = minetest.get_meta(pos)
if topic == "fuel" then
return tubelib.fuelstate(meta, "fuel")
end
local resp = machine:on_receive_message(pos, topic, payload)
if resp then
return resp
else
return "unsupported"
end
end,
on_node_load = function(pos)
machine:on_node_load(pos)
end,
on_node_repair = function(pos)
return machine:on_node_repair(pos)
end,
})
--[[
--------
Crafting
--------
]]--
minetest.register_craft({
output = "biogasmachines:jetfurnace",
recipe = {
{ "default:obsidian_block", "biogasmachines:gasfurnace", "" },
{ "biogasmachines:gasfurnace", "default:goldblock", "" },
{ "", "", "" },
},
})

259
furnace/furnace_top.lua Normal file
View File

@ -0,0 +1,259 @@
--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
LGPLv2.1+
See LICENSE.txt for more information
TA3 Industrial Furnace Top
]]--
-- 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
-- Consumer Related Data
local CRD = function(pos) return (minetest.registered_nodes[minetest.get_node(pos).name] or {}).consumer end
-- Load support for intllib.
local MP = minetest.get_modpath("techage")
local I,_ = dofile(MP.."/intllib.lua")
local STANDBY_TICKS = 6
local COUNTDOWN_TICKS = 6
local CYCLE_TIME = 2
local smelting = techage.furnace.smelting
local get_output = techage.furnace.get_output
local num_recipes = techage.furnace.get_num_recipes
local reset_cooking = techage.furnace.reset_cooking
local function formspec(self, pos, mem)
local idx = mem.recipe_idx or 1
local num, output = num_recipes(), get_output(idx)
return "size[8,7.2]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"list[context;src;0,0;2,2;]"..
"image[2,0.5;1,1;techage_form_arrow.png]"..
"image_button[2,2;1,1;".. self:get_state_button_image(mem) ..";state_button;]"..
"list[context;dst;3,0;2,2;]"..
"label[6,0;"..I("Outp")..": "..idx.."/"..num.."]"..
"item_image_button[6.5,0.5;1,1;"..output..";b1;]"..
"button[6,1.5;1,1;priv;<<]"..
"button[7,1.5;1,1;next;>>]"..
"list[current_player;main;0,3.5;8,4;]" ..
"listring[current_player;main]"..
"listring[context;src]" ..
"listring[current_player;main]"..
"listring[context;dst]" ..
"listring[current_player;main]"..
default.get_hotbar_bg(0, 4)
end
local function on_rightclick(pos, node, clicker)
local mem = tubelib2.get_mem(pos)
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, mem))
end
local function firebox_cmnd(pos, cmnd)
return techage.transfer(
{x=pos.x, y=pos.y-1, z=pos.z},
nil, -- outdir
cmnd, -- topic
nil, -- payload
nil, -- network
{"techage:furnace_firebox", "techage:furnace_firebox_on"})
end
local function cooking(pos, crd, mem, elapsed)
if firebox_cmnd(pos, "fuel") then
local state = smelting(pos, mem, elapsed)
--print("cooking", techage.StateStrings[state])
if state == techage.RUNNING then
crd.State:keep_running(pos, mem, COUNTDOWN_TICKS)
elseif state == techage.BLOCKED then
crd.State:blocked(pos, mem)
elseif state == techage.STANDBY then
crd.State:idle(pos, mem)
end
else
crd.State:fault(pos, mem)
end
end
local function keep_running(pos, elapsed)
local mem = tubelib2.get_mem(pos)
local crd = CRD(pos)
cooking(pos, crd, mem, elapsed)
return crd.State:is_active(mem)
end
local function allow_metadata_inventory_put(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
if listname == "src" then
CRD(pos).State:start_if_standby(pos)
return stack:get_count()
elseif listname == "dst" then
return 0
end
end
local function allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local stack = inv:get_stack(from_list, from_index)
return allow_metadata_inventory_put(pos, to_list, to_index, stack, player)
end
local function 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
local function on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then
return
end
local mem = tubelib2.get_mem(pos)
mem.recipe_idx = mem.recipe_idx or 1
if fields.next == ">>" then
mem.recipe_idx = math.min(mem.recipe_idx + 1, num_recipes())
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, mem))
reset_cooking(mem)
elseif fields.priv == "<<" then
mem.recipe_idx = math.max(mem.recipe_idx - 1, 1)
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, mem))
reset_cooking(mem)
end
CRD(pos).State:state_button_event(pos, mem, fields)
end
local function can_dig(pos, player)
if minetest.is_protected(pos, player:get_player_name()) then
return false
end
local inv = M(pos):get_inventory()
return inv:is_empty("dst") and inv:is_empty("src")
end
local function on_node_state_change(pos, old_state, new_state)
if new_state == techage.RUNNING then
firebox_cmnd(pos, "start")
else
firebox_cmnd(pos, "stop")
end
local mem = tubelib2.get_mem(pos)
reset_cooking(mem)
end
local tiles = {}
-- '#' will be replaced by the stage number
tiles.pas = {
-- up, down, right, left, back, front
"techage_concrete.png^techage_frame_ta#_top.png",
"techage_concrete.png^techage_frame_ta#_top.png",
"techage_concrete.png^techage_frame_ta#.png",
"techage_concrete.png^techage_frame_ta#.png",
"techage_concrete.png^techage_frame_ta#.png",
"techage_concrete.png^techage_appl_furnace.png^techage_frame_ta#.png",
}
tiles.act = tiles.pas
tiles.def = {
-- up, down, right, left, back, front
"techage_concrete.png^techage_frame_ta#_top.png",
"techage_concrete.png^techage_frame_ta#_top.png",
"techage_concrete.png^techage_frame_ta#.png^techage_appl_defect.png",
"techage_concrete.png^techage_frame_ta#.png^techage_appl_defect.png",
"techage_concrete.png^techage_frame_ta#.png^techage_appl_defect.png",
"techage_concrete.png^techage_appl_furnace.png^techage_frame_ta#.png^techage_appl_defect.png",
}
local tubing = {
on_pull_item = function(pos, in_dir, num)
local meta = minetest.get_meta(pos)
if meta:get_int("pull_dir") == in_dir then
local inv = M(pos):get_inventory()
return techage.get_items(inv, "dst", num)
end
end,
on_push_item = function(pos, in_dir, stack)
local meta = minetest.get_meta(pos)
if meta:get_int("push_dir") == in_dir or in_dir == 5 then
local inv = M(pos):get_inventory()
return techage.put_items(inv, "src", stack)
end
end,
on_unpull_item = function(pos, in_dir, stack)
local meta = minetest.get_meta(pos)
if meta:get_int("pull_dir") == in_dir then
local inv = M(pos):get_inventory()
return techage.put_items(inv, "dst", stack)
end
end,
on_recv_message = function(pos, topic, payload)
local resp = CRD(pos).State:on_receive_message(pos, topic, payload)
if resp then
return resp
else
return "unsupported"
end
end,
on_node_load = function(pos)
CRD(pos).State:on_node_load(pos)
end,
on_node_repair = function(pos)
return CRD(pos).State:on_node_repair(pos)
end,
}
local _, node_name_ta3, _ =
techage.register_consumer("furnace", I("TA3 Furnace Top"), tiles, {
drawtype = "normal",
cycle_time = CYCLE_TIME,
standby_ticks = STANDBY_TICKS,
has_item_meter = true,
aging_factor = 10,
formspec = formspec,
tubing = tubing,
on_state_change = on_node_state_change,
after_place_node = function(pos, placer)
local inv = M(pos):get_inventory()
inv:set_size("src", 2*2)
inv:set_size("dst", 2*2)
end,
can_dig = can_dig,
node_timer = keep_running,
on_receive_fields = on_receive_fields,
allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_move = allow_metadata_inventory_move,
allow_metadata_inventory_take = allow_metadata_inventory_take,
groups = {choppy=2, cracky=2, crumbly=2},
sounds = default.node_sound_wood_defaults(),
num_items = {0,1,1,1},
},
{false, false, true, false}) -- TA3 only
minetest.register_craft({
output = node_name_ta3,
recipe = {
{"", "techage:baborium_ingot", ""},
{"", "default:furnace", ""},
{"", "techage:vacuum_tube", ""},
},
})

56
furnace/recipes.lua Normal file
View File

@ -0,0 +1,56 @@
--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
LGPLv2.1+
See LICENSE.txt for more information
Cooking recipes for furnace
]]--
techage.furnace.register_recipe({
output = "techage:iron_ingot",
recipe = {"default:iron_lump"},
time = 2,
})
if techage.modified_recipes_enabled then
techage.ironage_register_recipe({
output = "default:bronze_ingot 4",
recipe = {"default:copper_ingot", "default:copper_ingot", "default:copper_ingot", "default:tin_ingot"},
time = 2,
})
techage.furnace.register_recipe({
output = "default:steel_ingot 4",
recipe = {"default:coal_lump", "default:iron_lump", "default:iron_lump", "default:iron_lump"},
time = 4,
})
end
minetest.after(1, function()
for key,_ in pairs(minetest.registered_items) do
if key ~= "" then
local tbl = minetest.get_all_craft_recipes(key)
if tbl then
for _,recipe in ipairs(tbl) do
if recipe and recipe.method == "cooking" then
--print(dump(idef), dump(recipe))
--print(key, recipe.width)
techage.furnace.register_recipe({
output = recipe.output,
recipe = recipe.items,
time = math.floor((recipe.width + 1) / 2),
})
end
end
end
end
end
end)

View File

@ -104,6 +104,13 @@ else
dofile(MP.."/coal_power_station/cooler.lua")
dofile(MP.."/coal_power_station/akkubox.lua")
-- Industrial Furnace
dofile(MP.."/furnace/firebox.lua")
dofile(MP.."/furnace/cooking.lua")
dofile(MP.."/furnace/furnace_top.lua")
dofile(MP.."/furnace/booster.lua")
dofile(MP.."/furnace/recipes.lua")
-- Lamps
dofile(MP.."/lamps/lib.lua")
dofile(MP.."/lamps/simplelamp.lua")

View File

@ -122,6 +122,6 @@ function techage.register_lamp(basename, ndef_off, ndef_on)
on_power_pass1 = on_power_pass1,
on_power_pass2 = on_power_pass2,
power_network = Power,
conn_sides = determine_power_side, -- will be handled by clbk function
conn_sides = ndef_off.conn_sides or determine_power_side, -- will be handled by clbk function
})
end

View File

@ -21,7 +21,7 @@ techage.register_lamp("techage:simplelamp", {
tiles = {
'techage_electric_button.png',
},
conn_sides = {"L", "R", "U", "D", "F", "B"},
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
@ -34,6 +34,7 @@ techage.register_lamp("techage:simplelamp", {
tiles = {
'techage_electric_button.png',
},
conn_sides = {"L", "R", "U", "D", "F", "B"},
paramtype = "light",
light_source = minetest.LIGHT_MAX,
sunlight_propagates = true,

View File

@ -1,31 +0,0 @@
local function formspec(self, pos, mem)
if not mem.tower_built then
return formspec0
end
local icon = "techage_oil_inv"
local depth = "1/480"
return "size[8,8]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"list[context;src;1,1;1,1;]"..
"label[1.3,0.5;IN]"..
"item_image[1,1;1,1;techage:oil_drillbit]"..
"label[1,2;"..I("Drill Bit").."]"..
"label[0.5,3;"..I("Depth")..": "..depth.."]"..
"image[3.5,0;1,1;"..techage.get_power_image(pos, mem).."]"..
"image[3.5,1;1,1;techage_form_arrow.png]"..
"image_button[3.5,2;1,1;".. self:get_state_button_image(mem) ..";state_button;]"..
"label[6.2,0.5;OUT]"..
"list[context;dst;6,1;1,1;]"..
"label[6.2,2;"..I("Oil").."]"..
"label[5.5,3;"..I("Extract")..": "..depth.."]"..
"item_image[6,1;1,1;techage:oil_source]"..
"button_exit[0,3.9;3,1;destroy;"..I("Destroy Tower").."]"..
"list[current_player;main;0,4;8,4;]"..
"listring[context;dst]"..
"listring[current_player;main]"..
"listring[context;src]"..
"listring[current_player;main]"..
default.get_hotbar_bg(0, 4)
end

BIN
sounds/techage_booster.ogg Normal file

Binary file not shown.

View File

@ -25,25 +25,6 @@ local firebox = techage.firebox
local CYCLE_TIME = 2
local function formspec(mem)
local fuel_percent = 0
if mem.running then
fuel_percent = ((mem.burn_cycles or 1) * 100) / (mem.burn_cycles_total or 1)
end
return "size[8,6]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"list[current_name;fuel;1,0.5;1,1;]"..
"image[3,0.5;1,1;default_furnace_fire_bg.png^[lowpart:"..
fuel_percent..":default_furnace_fire_fg.png]"..
"button[5,0.5;1.8,1;update;"..I("Update").."]"..
"list[current_player;main;0,2;8,4;]"..
"listring[current_name;fuel]"..
"listring[current_player;main]"..
default.get_hotbar_bg(0, 2)
end
local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos)
if mem.running then
@ -64,7 +45,7 @@ local function node_timer(pos, elapsed)
else
mem.running = false
firebox.swap_node(pos, "techage:firebox")
M(pos):set_string("formspec", formspec(mem))
M(pos):set_string("formspec", firebox.formspec(mem))
return false
end
end
@ -72,27 +53,11 @@ local function node_timer(pos, elapsed)
end
end
local function on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then
return
end
if fields.update then
local mem = tubelib2.get_mem(pos)
M(pos):set_string("formspec", formspec(mem))
end
end
local function on_rightclick(pos, node, clicker)
local mem = tubelib2.get_mem(pos)
M(pos):set_string("formspec", formspec(mem))
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_appl_open.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",
@ -109,15 +74,15 @@ minetest.register_node("techage:firebox", {
can_dig = firebox.can_dig,
allow_metadata_inventory_put = firebox.allow_metadata_inventory,
allow_metadata_inventory_take = firebox.allow_metadata_inventory,
on_receive_fields = on_receive_fields,
on_rightclick = on_rightclick,
on_receive_fields = firebox.on_receive_fields,
on_rightclick = firebox.on_rightclick,
on_construct = function(pos)
local mem = tubelib2.init_mem(pos)
mem.running = false
mem.burn_cycles = 0
local meta = M(pos)
meta:set_string("formspec", formspec(mem))
meta:set_string("formspec", firebox.formspec(mem))
local inv = meta:get_inventory()
inv:set_size('fuel', 1)
end,
@ -128,7 +93,7 @@ minetest.register_node("techage:firebox", {
-- activate the formspec fire temporarily
mem.burn_cycles = firebox.Burntime[stack:get_name()] / CYCLE_TIME
mem.burn_cycles_total = mem.burn_cycles
M(pos):set_string("formspec", formspec(mem))
M(pos):set_string("formspec", firebox.formspec(mem))
mem.burn_cycles = 0
firebox.swap_node(pos, "techage:firebox_on")
minetest.get_node_timer(pos):start(CYCLE_TIME)
@ -167,8 +132,8 @@ minetest.register_node("techage:firebox_on", {
can_dig = firebox.can_dig,
allow_metadata_inventory_put = firebox.allow_metadata_inventory,
allow_metadata_inventory_take = firebox.allow_metadata_inventory,
on_receive_fields = on_receive_fields,
on_rightclick = on_rightclick,
on_receive_fields = firebox.on_receive_fields,
on_rightclick = firebox.on_rightclick,
})
minetest.register_craft({
@ -184,10 +149,12 @@ 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
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
end
return false
end,

Binary file not shown.

After

Width:  |  Height:  |  Size: 296 B

View File

Before

Width:  |  Height:  |  Size: 575 B

After

Width:  |  Height:  |  Size: 575 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 597 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 985 B

After

Width:  |  Height:  |  Size: 398 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 985 B

After

Width:  |  Height:  |  Size: 398 B