Liquid Fuel Burner

This commit is contained in:
Evert Prants 2018-08-12 15:42:32 +03:00
parent ce47073b69
commit 18bc34b28f
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
10 changed files with 70 additions and 27 deletions

View File

@ -18,7 +18,7 @@ function elepm.register_craft(craftdef)
return nil
end
if craftdef.type == "cooking" then
if craftdef.type == "cooking" or craftdef.type == "fuel" then
minetest.register_craft(craftdef)
return
end

View File

@ -368,6 +368,16 @@ minetest.register_craft({
}
})
-- Liquid Fuel Combustion Generator
minetest.register_craft({
output = "elepower_machines:fuel_burner",
recipe = {
{"elepower_dynamics:wound_copper_coil", "elepower_dynamics:integrated_circuit", "elepower_dynamics:wound_copper_coil"},
{"default:brick", "elepower_dynamics:portable_tank", "default:brick"},
{"elepower_dynamics:servo_valve", "elepower_machines:generator", "elepower_dynamics:servo_valve"},
}
})
-- Alloy Furnace
minetest.register_craft({
output = "elepower_machines:alloy_furnace",

View File

@ -113,7 +113,7 @@ function elepm.register_crafter(nodename, nodedef)
-- Determine if there is enough power for this action
res_time = result.time
if result.time ~= 0 and storage >= usage then
if result.time ~= 0 and pow_buffer.storage >= usage then
power_operation = true
pow_buffer.usage = usage
end
@ -135,9 +135,7 @@ function elepm.register_crafter(nodename, nodedef)
status = "Active"
-- One step
storage = storage - usage
meta:set_int("storage", storage)
pow_buffer = {capacity = capacity, storage = storage, usage = usage}
pow_buffer.storage = pow_buffer.storage - usage
time = time + ele.helpers.round(machine_speed * 10)
if nodedef.ele_active_node then
@ -193,7 +191,9 @@ function elepm.register_crafter(nodename, nodedef)
meta:set_string("formspec", get_formspec(craft_type, pow_buffer, pct, pos, state))
meta:set_string("infotext", ("%s %s"):format(nodedef.description, status) ..
"\n" .. ele.capacity_text(capacity, storage))
meta:set_int("src_time", time)
meta:set_int("storage", pow_buffer.storage)
return refresh
end

View File

@ -16,20 +16,14 @@ end
-- A generator that creates power using a fuel
function ele.register_fluid_generator(nodename, nodedef)
local fuel = nodedef.fuel
local btime = nodedef.fuel_burn_time or 60
local btime = nodedef.fuel_burn_time or 8
local busage = nodedef.fuel_usage or 1000
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
if not fuel and data.accepts and type(data.accepts) == "table" then
fuel = data.accepts[1]
end
break
end
@ -68,7 +62,6 @@ function ele.register_fluid_generator(nodename, nodedef)
local status = "Idle"
while true do
if not flbuffer or flbuffer.fluid == "" then break end
if not is_enabled then
status = "Off"
break
@ -80,28 +73,38 @@ function ele.register_fluid_generator(nodename, nodedef)
break
end
storage = storage + generation
meta:set_int("storage", storage)
pow_buffer.storage = pow_buffer.storage + generation
pow_buffer.usage = generation
burn_time = burn_time - 1
meta:set_int("burn_time", burn_time)
refresh = true
end
status = "Active"
-- Burn another bucket of lava
if burn_time == 0 then
if not flbuffer or flbuffer.fluid == "" then break end
local inv = meta:get_inventory()
if flbuffer.amount >= 1000 then
if flbuffer.amount >= busage then
meta:set_int("burn_time", btime)
meta:set_int("burn_totaltime", btime)
-- Take lava
flbuffer.amount = flbuffer.amount - 1000
flbuffer.amount = flbuffer.amount - busage
pow_buffer.usage = generation
local active_node = nodename.."_active"
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
refresh = true
else
@ -116,9 +119,10 @@ function ele.register_fluid_generator(nodename, nodedef)
local percent = math.floor((burn_time / burn_totaltime) * 100)
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,
ele.capacity_text(capacity, storage), fluid_lib.buffer_to_string(flbuffer)))
ele.capacity_text(capacity, pow_buffer.storage), fluid_lib.buffer_to_string(flbuffer)))
meta:set_int(buffer_name .. "_fluid_storage", flbuffer.amount)
meta:set_int("storage", pow_buffer.storage)
return refresh
end,
@ -132,7 +136,8 @@ function ele.register_fluid_generator(nodename, nodedef)
end
}
nodedef.fuel = nil
nodedef.fuel_burn_time = nil
nodedef.fuel_usage = nil
for key,val in pairs(defaults) do
if not nodedef[key] then

View File

@ -63,10 +63,8 @@ function elepm.register_fuel_generator(nodename, nodedef)
return false
end
storage = storage + generation
pow_buffer.storage = storage
pow_buffer.storage = pow_buffer.storage + generation
pow_buffer.usage = generation
meta:set_int("storage", storage)
burn_time = burn_time - 1
meta:set_int("burn_time", burn_time)
@ -113,7 +111,9 @@ function elepm.register_fuel_generator(nodename, nodedef)
local percent = math.floor((burn_time / burn_totaltime) * 100)
meta:set_string("formspec", get_formspec(pow_buffer, percent, state))
meta:set_string("infotext", ("%s %s"):format(nodedef.description, status) ..
"\n" .. ele.capacity_text(capacity, storage))
"\n" .. ele.capacity_text(capacity, pow_buffer.storage))
meta:set_int("storage", pow_buffer.storage)
return refresh
end

View File

@ -1,5 +1,5 @@
dofile(elepm.modpath.."/machines/bases/crafter.lua")
dofile(elepm.modpath.."/machines/bases/generator.lua")
dofile(elepm.modpath.."/machines/bases/fluidgenerator.lua")
dofile(elepm.modpath.."/machines/bases/fluid_generator.lua")
dofile(elepm.modpath.."/machines/bases/storage.lua")

View File

@ -0,0 +1,27 @@
ele.register_fluid_generator("elepower_machines:fuel_burner", {
description = "Liquid Fuel Combustion Generator",
ele_usage = 8,
tiles = {
"elepower_machine_top.png", "elepower_machine_base.png", "elepower_machine_side.png",
"elepower_machine_side.png", "elepower_machine_side.png", "elepower_fuel_generator.png",
},
ele_active_node = true,
ele_active_nodedef = {
tiles = {
"elepower_machine_top.png", "elepower_machine_base.png", "elepower_machine_side.png",
"elepower_machine_side.png", "elepower_machine_side.png", "elepower_fuel_generator_active.png",
},
},
fluid_buffers = {
steam = {
capacity = 8000,
drainable = false,
accepts = {
"elepower_farming:biofuel_source",
},
}
},
fuel_burn_time = 4,
fuel_usage = 100,
})

View File

@ -8,6 +8,7 @@ dofile(mp .. "bases/init.lua")
dofile(mp .. "generator.lua")
dofile(mp .. "lava_generator.lua")
dofile(mp .. "steam_turbine.lua")
dofile(mp .. "fuel_burner.lua")
-- Storage
dofile(mp .. "storage.lua")

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB