2019-03-19 00:40:17 +03:00
|
|
|
--[[
|
|
|
|
|
|
|
|
TechAge
|
|
|
|
=======
|
|
|
|
|
|
|
|
Copyright (C) 2019 Joachim Stolberg
|
|
|
|
|
2019-08-22 21:49:47 +03:00
|
|
|
GPL v3
|
2019-03-19 00:40:17 +03:00
|
|
|
See LICENSE.txt for more information
|
|
|
|
|
|
|
|
Firebox basic functions
|
|
|
|
|
|
|
|
]]--
|
|
|
|
|
|
|
|
-- for lazy programmers
|
|
|
|
local P = minetest.string_to_pos
|
|
|
|
local M = minetest.get_meta
|
2019-07-02 22:33:12 +03:00
|
|
|
local S = techage.S
|
2019-03-19 00:40:17 +03:00
|
|
|
|
|
|
|
techage.firebox = {}
|
|
|
|
|
|
|
|
techage.firebox.Burntime = {
|
|
|
|
["techage:charcoal"] = true, -- will be replaced by burntime
|
|
|
|
["default:coal_lump"] = true,
|
|
|
|
["default:coalblock"] = true,
|
2019-11-10 01:36:28 +03:00
|
|
|
["techage:oil_source"] = true,
|
|
|
|
["techage:gas"] = true,
|
|
|
|
["techage:gasoline"] = true,
|
|
|
|
["techage:naphtha"] = true,
|
|
|
|
["techage:fueloil"] = true,
|
2019-03-19 00:40:17 +03:00
|
|
|
}
|
|
|
|
|
2019-11-10 01:36:28 +03:00
|
|
|
techage.firebox.ValidOilFuels = {
|
|
|
|
["techage:gasoline"] = 1, -- category
|
|
|
|
["techage:naphtha"] = 2,
|
|
|
|
["techage:fueloil"] = 3,
|
|
|
|
["techage:oil_source"] = 4,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-19 00:40:17 +03:00
|
|
|
local function determine_burntimes()
|
|
|
|
for k,_ in pairs(techage.firebox.Burntime)do
|
|
|
|
local fuel,_ = minetest.get_craft_result({method = "fuel", width = 1, items = {k}})
|
2019-06-08 23:57:01 +03:00
|
|
|
techage.firebox.Burntime[k] = fuel.time
|
2019-03-19 00:40:17 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
minetest.after(1, determine_burntimes)
|
|
|
|
|
2020-01-26 01:15:44 +03:00
|
|
|
function techage.firebox.formspec(nvm)
|
2019-03-19 00:40:17 +03:00
|
|
|
local fuel_percent = 0
|
2020-01-26 01:15:44 +03:00
|
|
|
if nvm.running then
|
|
|
|
fuel_percent = ((nvm.burn_cycles or 1) * 100) / (nvm.burn_cycles_total or 1)
|
2019-06-10 22:31:58 +03:00
|
|
|
end
|
2020-01-26 01:15:44 +03:00
|
|
|
return "size[8,6]"..
|
|
|
|
default.gui_bg..
|
|
|
|
default.gui_bg_img..
|
|
|
|
default.gui_slots..
|
|
|
|
"box[0,-0.1;7.8,0.5;#c6e8ff]"..
|
|
|
|
"label[3,-0.1;"..minetest.colorize( "#000000", S("Firebox")).."]"..
|
|
|
|
"list[current_name;fuel;3,1;1,1;]"..
|
|
|
|
"image[4,1;1,1;default_furnace_fire_bg.png^[lowpart:"..
|
|
|
|
fuel_percent..":default_furnace_fire_fg.png]"..
|
|
|
|
"list[current_player;main;0,2.3;8,4;]"..
|
|
|
|
"listring[current_name;fuel]"..
|
|
|
|
"listring[current_player;main]"..
|
|
|
|
default.get_hotbar_bg(0, 2.3)
|
2019-03-19 00:40:17 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
function techage.firebox.can_dig(pos, player)
|
|
|
|
local inv = M(pos):get_inventory()
|
2019-06-17 22:24:48 +03:00
|
|
|
return inv:is_empty("fuel")
|
2019-03-19 00:40:17 +03:00
|
|
|
end
|
|
|
|
|
2019-09-02 23:19:34 +03:00
|
|
|
function techage.firebox.allow_metadata_inventory_put(pos, listname, index, stack, player)
|
2019-03-19 00:40:17 +03:00
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
if techage.firebox.Burntime[stack:get_name()] then
|
|
|
|
return stack:get_count()
|
|
|
|
end
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
2019-09-02 23:19:34 +03:00
|
|
|
function techage.firebox.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
|
|
|
|
|
2019-03-19 00:40:17 +03:00
|
|
|
function techage.firebox.on_rightclick(pos, node, clicker)
|
2020-01-26 01:15:44 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
techage.set_activeformspec(pos, clicker)
|
|
|
|
M(pos):set_string("formspec", techage.firebox.formspec(nvm))
|
2019-03-19 00:40:17 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
function techage.firebox.swap_node(pos, name)
|
2019-10-07 01:09:39 +03:00
|
|
|
local node = techage.get_node_lvm(pos)
|
2019-03-19 00:40:17 +03:00
|
|
|
if node.name == name then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
node.name = name
|
|
|
|
minetest.swap_node(pos, node)
|
|
|
|
end
|
|
|
|
|
|
|
|
function techage.firebox.get_fuel(pos)
|
|
|
|
local inv = M(pos):get_inventory()
|
|
|
|
local items = inv:get_stack("fuel", 1)
|
|
|
|
if items:get_count() > 0 then
|
|
|
|
local taken = items:take_item(1)
|
|
|
|
inv:set_stack("fuel", 1, items)
|
|
|
|
return taken
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-10 22:31:58 +03:00
|
|
|
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
|