2018-07-11 19:01:31 +00:00
|
|
|
|
2018-08-11 12:47:25 +00:00
|
|
|
local function get_formspec_default(power, percent, buffer, state)
|
2018-07-21 23:03:17 +00:00
|
|
|
return "size[8,8.5]"..
|
|
|
|
default.gui_bg..
|
|
|
|
default.gui_bg_img..
|
|
|
|
default.gui_slots..
|
|
|
|
ele.formspec.power_meter(power)..
|
2018-08-11 12:47:25 +00:00
|
|
|
ele.formspec.state_switcher(7, 2.5, state)..
|
2018-07-21 23:03:17 +00:00
|
|
|
ele.formspec.fluid_bar(7, 0, buffer)..
|
|
|
|
"image[3.5,1.5;1,1;default_furnace_fire_bg.png^[lowpart:"..
|
|
|
|
(percent)..":default_furnace_fire_fg.png]"..
|
|
|
|
"list[current_player;main;0,4.25;8,1;]"..
|
|
|
|
"list[current_player;main;0,5.5;8,3;8]"..
|
|
|
|
default.get_hotbar_bg(0, 4.25)
|
|
|
|
end
|
|
|
|
|
2018-07-11 19:01:31 +00:00
|
|
|
-- A generator that creates power using a fuel
|
|
|
|
function ele.register_fluid_generator(nodename, nodedef)
|
2018-08-12 12:42:32 +00:00
|
|
|
local btime = nodedef.fuel_burn_time or 8
|
|
|
|
local busage = nodedef.fuel_usage or 1000
|
2018-07-11 19:01:31 +00:00
|
|
|
local buffer_name = nil
|
|
|
|
|
|
|
|
-- Autodetect fluid buffer and the fuel if necessary
|
|
|
|
if not nodedef.fluid_buffers then return nil end
|
|
|
|
for buf,data in pairs(nodedef.fluid_buffers) do
|
|
|
|
buffer_name = buf
|
|
|
|
break
|
|
|
|
end
|
|
|
|
|
2018-07-28 14:29:56 +00:00
|
|
|
-- Allow for custom formspec
|
|
|
|
local get_formspec = get_formspec_default
|
|
|
|
if nodedef.get_formspec then
|
|
|
|
get_formspec = nodedef.get_formspec
|
|
|
|
nodedef.get_formspec = nil
|
|
|
|
end
|
|
|
|
|
2018-07-11 19:01:31 +00:00
|
|
|
local defaults = {
|
|
|
|
groups = {
|
|
|
|
fluid_container = 1,
|
|
|
|
ele_provider = 1,
|
|
|
|
oddly_breakable_by_hand = 1,
|
|
|
|
},
|
|
|
|
tube = false,
|
|
|
|
on_timer = function (pos, elapsed)
|
2018-08-04 19:45:04 +00:00
|
|
|
local refresh = false
|
2018-07-11 19:01:31 +00:00
|
|
|
local meta = minetest.get_meta(pos)
|
2018-12-12 13:04:53 +00:00
|
|
|
local nodename = minetest.get_node(pos).name
|
2018-07-11 19:01:31 +00:00
|
|
|
|
|
|
|
local burn_time = meta:get_int("burn_time")
|
|
|
|
local burn_totaltime = meta:get_int("burn_totaltime")
|
|
|
|
|
|
|
|
local capacity = ele.helpers.get_node_property(meta, pos, "capacity")
|
|
|
|
local generation = ele.helpers.get_node_property(meta, pos, "usage")
|
|
|
|
local storage = ele.helpers.get_node_property(meta, pos, "storage")
|
|
|
|
|
2018-08-11 12:47:25 +00:00
|
|
|
local state = meta:get_int("state")
|
|
|
|
local is_enabled = ele.helpers.state_enabled(meta, pos, state)
|
|
|
|
|
2018-07-11 19:01:31 +00:00
|
|
|
-- Fluid buffer
|
|
|
|
local flbuffer = fluid_lib.get_buffer_data(pos, buffer_name)
|
2018-08-11 12:47:25 +00:00
|
|
|
local pow_buffer = {capacity = capacity, storage = storage, usage = 0}
|
|
|
|
local status = "Idle"
|
2018-07-11 19:01:31 +00:00
|
|
|
|
2018-08-04 19:45:04 +00:00
|
|
|
while true do
|
2018-08-11 12:47:25 +00:00
|
|
|
if not is_enabled then
|
|
|
|
status = "Off"
|
|
|
|
break
|
|
|
|
end
|
|
|
|
|
2018-08-04 19:45:04 +00:00
|
|
|
-- If more to burn and the energy produced was used: produce some more
|
|
|
|
if burn_time > 0 then
|
|
|
|
if storage + generation > capacity then
|
|
|
|
break
|
|
|
|
end
|
2018-07-11 19:01:31 +00:00
|
|
|
|
2018-08-12 12:42:32 +00:00
|
|
|
pow_buffer.storage = pow_buffer.storage + generation
|
|
|
|
pow_buffer.usage = generation
|
2018-07-11 19:01:31 +00:00
|
|
|
|
2018-08-04 19:45:04 +00:00
|
|
|
burn_time = burn_time - 1
|
|
|
|
meta:set_int("burn_time", burn_time)
|
2018-08-12 12:42:32 +00:00
|
|
|
|
|
|
|
refresh = true
|
2018-08-04 19:45:04 +00:00
|
|
|
end
|
|
|
|
|
2018-08-11 12:47:25 +00:00
|
|
|
status = "Active"
|
2018-07-11 19:01:31 +00:00
|
|
|
|
2018-09-25 13:36:14 +00:00
|
|
|
-- Burn another bucket of fluid fuel
|
2018-08-04 19:45:04 +00:00
|
|
|
if burn_time == 0 then
|
2018-08-12 12:42:32 +00:00
|
|
|
if not flbuffer or flbuffer.fluid == "" then break end
|
|
|
|
|
2018-08-04 19:45:04 +00:00
|
|
|
local inv = meta:get_inventory()
|
2018-08-12 12:42:32 +00:00
|
|
|
if flbuffer.amount >= busage then
|
2018-08-04 19:45:04 +00:00
|
|
|
meta:set_int("burn_time", btime)
|
|
|
|
meta:set_int("burn_totaltime", btime)
|
2018-07-11 19:01:31 +00:00
|
|
|
|
2018-09-25 13:36:14 +00:00
|
|
|
-- Take fluid fuel
|
2018-08-12 12:42:32 +00:00
|
|
|
flbuffer.amount = flbuffer.amount - busage
|
2018-08-07 19:47:59 +00:00
|
|
|
pow_buffer.usage = generation
|
2018-07-11 19:01:31 +00:00
|
|
|
|
2018-08-12 12:42:32 +00:00
|
|
|
if nodedef.ele_active_node then
|
|
|
|
local active_node = nodename .. "_active"
|
|
|
|
if nodedef.ele_active_node ~= true then
|
|
|
|
active_node = nodedef.ele_active_node
|
|
|
|
end
|
|
|
|
|
|
|
|
ele.helpers.swap_node(pos, active_node)
|
|
|
|
end
|
2018-07-11 19:01:31 +00:00
|
|
|
|
2018-08-04 19:45:04 +00:00
|
|
|
refresh = true
|
|
|
|
else
|
2018-08-11 12:47:25 +00:00
|
|
|
status = "Idle"
|
2018-08-04 19:45:04 +00:00
|
|
|
ele.helpers.swap_node(pos, nodename)
|
2018-09-25 13:36:14 +00:00
|
|
|
|
|
|
|
refresh = false
|
2018-08-04 19:45:04 +00:00
|
|
|
end
|
2018-07-11 19:01:31 +00:00
|
|
|
end
|
2018-08-04 19:45:04 +00:00
|
|
|
if burn_totaltime == 0 then burn_totaltime = 1 end
|
|
|
|
break
|
2018-07-11 19:01:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local percent = math.floor((burn_time / burn_totaltime) * 100)
|
2018-08-11 12:47:25 +00:00
|
|
|
meta:set_string("formspec", get_formspec(pow_buffer, percent, flbuffer, state))
|
|
|
|
meta:set_string("infotext", ("%s %s\n%s\n%s"):format(nodedef.description, status,
|
2018-08-12 12:42:32 +00:00
|
|
|
ele.capacity_text(capacity, pow_buffer.storage), fluid_lib.buffer_to_string(flbuffer)))
|
2018-07-11 19:01:31 +00:00
|
|
|
|
|
|
|
meta:set_int(buffer_name .. "_fluid_storage", flbuffer.amount)
|
2018-08-12 12:42:32 +00:00
|
|
|
meta:set_int("storage", pow_buffer.storage)
|
2018-07-11 19:01:31 +00:00
|
|
|
|
2018-08-04 19:45:04 +00:00
|
|
|
return refresh
|
2018-07-11 19:01:31 +00:00
|
|
|
end,
|
|
|
|
on_construct = function (pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
|
|
|
|
local capacity = ele.helpers.get_node_property(meta, pos, "capacity")
|
|
|
|
local storage = ele.helpers.get_node_property(meta, pos, "storage")
|
|
|
|
|
2018-08-07 19:47:59 +00:00
|
|
|
meta:set_string("formspec", get_formspec({capacity = capacity, storage = storage, usage = 0}, 0))
|
2018-07-11 19:01:31 +00:00
|
|
|
end
|
|
|
|
}
|
|
|
|
|
2018-08-12 12:42:32 +00:00
|
|
|
nodedef.fuel_burn_time = nil
|
|
|
|
nodedef.fuel_usage = nil
|
2018-07-11 19:01:31 +00:00
|
|
|
|
|
|
|
for key,val in pairs(defaults) do
|
|
|
|
if not nodedef[key] then
|
|
|
|
nodedef[key] = val
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
ele.register_machine(nodename, nodedef)
|
|
|
|
end
|