Electrolyzer, Gas registration, Gas containers

This commit is contained in:
Evert Prants 2018-08-29 15:45:31 +03:00
parent db44499501
commit 704281bb25
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
15 changed files with 311 additions and 5 deletions

View File

@ -324,6 +324,15 @@ minetest.register_craft({
}
})
minetest.register_craft({
output = "elepower_dynamics:gas_container 8",
recipe = {
{"elepower_dynamics:steel_plate", "", "elepower_dynamics:steel_plate"},
{"elepower_dynamics:steel_plate", "", "elepower_dynamics:steel_plate"},
{"", "elepower_dynamics:steel_plate", ""}
}
})
--------------
-- Smelting --
--------------

View File

@ -0,0 +1,42 @@
ele.gases = {}
function ele.register_gas(itemname, name, gas_source, image)
if itemname ~= nil then
minetest.register_craftitem(itemname, {
description = name .. " Gas Container",
inventory_image = image,
groups = {gas_container = 1}
})
end
ele.gases[gas_source] = {
itemname = itemname,
name = name,
source = gas_source,
}
end
function ele.get_gas_for_container(container)
for src,data in pairs(ele.gases) do
if data.itemname and data.itemname == container then
return src
end
end
return nil
end
minetest.register_craftitem("elepower_dynamics:gas_container", {
description = "Empty Gas Container",
inventory_image = "elepower_gas_container.png",
groups = {gas_container = 1}
})
ele.register_gas("elepower_dynamics:hydrogen_container", "Hydrogen",
"elepower_dynamics:hydrogen", "elepower_gas_hydrogen.png")
ele.register_gas("elepower_dynamics:oxygen_container", "Oxygen",
"elepower_dynamics:oxygen", "elepower_gas_oxygen.png")
ele.register_gas("elepower_dynamics:nitrogen_container", "Nitrogen",
"elepower_dynamics:nitrogen", "elepower_gas_nitrogen.png")

View File

@ -12,6 +12,7 @@ dofile(modpath.."/compat/init.lua")
dofile(modpath.."/tools.lua")
dofile(modpath.."/nodes.lua")
dofile(modpath.."/liquids.lua")
dofile(modpath.."/gas_container.lua")
dofile(modpath.."/tanks.lua")
dofile(modpath.."/components.lua")
dofile(modpath.."/worldgen.lua")

View File

@ -93,6 +93,24 @@ bucket.register_liquid("elepower_dynamics:etching_acid_source", "elepower_dynami
-- Virtual "fluid"
minetest.register_node("elepower_dynamics:steam", {
description = "Steam",
groups = {not_in_creative_inventory = 1},
groups = {not_in_creative_inventory = 1, gas = 1},
tiles = {"elepower_steam.png"},
})
minetest.register_node("elepower_dynamics:oxygen", {
description = "Oxygen",
groups = {not_in_creative_inventory = 1, gas = 1},
tiles = {"elepower_steam.png"},
})
minetest.register_node("elepower_dynamics:hydrogen", {
description = "Hydrogen",
groups = {not_in_creative_inventory = 1, gas = 1},
tiles = {"elepower_steam.png"},
})
minetest.register_node("elepower_dynamics:nitrogen", {
description = "Nitrogen",
groups = {not_in_creative_inventory = 1, gas = 1},
tiles = {"elepower_steam.png"},
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 396 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 626 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 616 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 613 B

View File

@ -543,3 +543,13 @@ minetest.register_craft({
{"elepower_dynamics:servo_valve", "elepower_dynamics:tin_gear", "elepower_dynamics:servo_valve"},
}
})
-- Electrolyzer
minetest.register_craft({
output = "elepower_machines:electrolyzer",
recipe = {
{"elepower_dynamics:copper_plate", "elepower_dynamics:integrated_circuit", "elepower_dynamics:zinc_plate"},
{"bucket:bucket_empty", "elepower_machines:machine_block", "elepower_dynamics:gas_container"},
{"elepower_dynamics:servo_valve", "elepower_dynamics:wound_copper_coil", "elepower_dynamics:servo_valve"},
}
})

View File

@ -44,9 +44,22 @@ local function on_timer(pos, elapsed)
local bucket_name = bucket_slot:get_name()
if is_enabled then
if mode == 0 and bucket_name == "bucket:bucket_empty" and buffer.amount >= 1000 then
if mode == 0 and (bucket_name == "bucket:bucket_empty" or
bucket_name == "elepower_dynamics:gas_container") and buffer.amount >= 1000 then
-- Fill bucket
local bitem = bucket.liquids[buffer.fluid]
local bitem
if minetest.get_item_group(buffer.fluid, "gas") > 0 then
bitem = ele.gases[buffer.fluid]
if bucket_name ~= "elepower_dynamics:gas_container" then
bitem = nil
end
else
bitem = bucket.liquids[buffer.fluid]
if bucket_name ~= "bucket:bucket_empty" then
bitem = nil
end
end
if bitem and bitem.itemname then
local bstack = ItemStack(bitem.itemname)
if inv:room_for_item("dst", bstack) then
@ -59,11 +72,24 @@ local function on_timer(pos, elapsed)
refresh = true
end
end
elseif mode == 1 and bucket.get_liquid_for_bucket(bucket_name) then
elseif mode == 1 and (bucket.get_liquid_for_bucket(bucket_name) or ele.get_gas_for_container(bucket_name)) then
-- Empty bucket
local fluid = bucket.get_liquid_for_bucket(bucket_name)
local fluid
local gas = false
if minetest.get_item_group(bucket_name, "gas_container") > 0 then
gas = true
fluid = ele.get_gas_for_container(bucket_name)
else
fluid = bucket.get_liquid_for_bucket(bucket_name)
end
if buffer.fluid == fluid or buffer.fluid == "" then
local bitem = ItemStack("bucket:bucket_empty")
if gas then
bitem = ItemStack("elepower_dynamics:gas_container")
end
if inv:room_for_item("dst", bitem) and buffer.amount + 1000 <= buffer.capacity then
buffer.amount = buffer.amount + 1000
buffer.fluid = fluid

View File

@ -0,0 +1,181 @@
elepm.electrolyzer_recipes = {
{
recipe = "default:water_source 1000",
output = {
"elepower_dynamics:hydrogen 600",
"elepower_dynamics:oxygen 400",
},
time = 20
},
{
recipe = "elepower_farming:biomass_source 1000",
output = {
"elepower_dynamics:nitrogen 400",
"elepower_dynamics:oxygen 600",
},
time = 16,
}
}
local function get_formspec(time, power, input, out1, out2, state)
local bar = "image[3.5,1;1,1;gui_furnace_arrow_bg.png^[transformR270]"
if time ~= nil then
bar = "image[3.5,1;1,1;gui_furnace_arrow_bg.png^[lowpart:"..
(time)..":gui_furnace_arrow_fg.png^[transformR270]"
end
return "size[8,8.5]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
ele.formspec.power_meter(power)..
ele.formspec.fluid_bar(1, 0, input)..
ele.formspec.state_switcher(3.5, 0, state)..
bar..
ele.formspec.fluid_bar(6, 0, out1)..
ele.formspec.fluid_bar(7, 0, out2)..
"list[current_player;main;0,4.25;8,1;]"..
"list[current_player;main;0,5.5;8,3;8]"..
"listring[current_player;main]"..
default.get_hotbar_bg(0, 4.25)
end
local function get_electrolysis_result(buffer)
local result = {time = 0}
if buffer.fluid == "" then return result end
for _,recipe in pairs(elepm.electrolyzer_recipes) do
local recipe_input = ItemStack(recipe.recipe)
if buffer.fluid == recipe_input:get_name() and
buffer.amount >= recipe_input:get_count() then
result.recipe = recipe.recipe
result.output = recipe.output
result.time = recipe.time
break
end
end
return result
end
local function electrolyzer_timer(pos)
local refresh = false
local meta = minetest.get_meta(pos)
local input = fluid_lib.get_buffer_data(pos, "input")
local out1 = fluid_lib.get_buffer_data(pos, "out1")
local out2 = fluid_lib.get_buffer_data(pos, "out2")
local capacity = ele.helpers.get_node_property(meta, pos, "capacity")
local usage = ele.helpers.get_node_property(meta, pos, "usage")
local storage = ele.helpers.get_node_property(meta, pos, "storage")
local pow_buffer = {capacity = capacity, storage = storage, usage = 0}
local time = meta:get_int("src_time")
local state = meta:get_int("state")
local status = "Idle"
local speed = 1
local is_enabled = ele.helpers.state_enabled(meta, pos, state)
local res_time = meta:get_int("src_time_max")
while true do
if not is_enabled then
status = "Off"
time = 0
break
end
local result = get_electrolysis_result(input)
if result.time == 0 then
break
end
if pow_buffer.storage < usage then
status = "Out of Power!"
break
end
local out1s = ItemStack(result.output[1])
local out2s = ItemStack(result.output[2])
if fluid_lib.can_insert_into_buffer(pos, "out1", out1s:get_name(), out1s:get_count()) ~= out1s:get_count() or
fluid_lib.can_insert_into_buffer(pos, "out2", out2s:get_name(), out2s:get_count()) ~= out2s:get_count() then
status = "Output Full!"
break
end
status = "Active"
res_time = result.time
pow_buffer.usage = usage
pow_buffer.storage = pow_buffer.storage - usage
time = time + ele.helpers.round(speed * 10)
refresh = true
if time <= ele.helpers.round(res_time * 10) then
break
end
local istack = ItemStack(result.recipe)
input.amount = input.amount - istack:get_count()
if input.amount == 0 then
input.fluid = ""
end
fluid_lib.insert_into_buffer(pos, "out1", out1s:get_name(), out1s:get_count())
fluid_lib.insert_into_buffer(pos, "out2", out2s:get_name(), out2s:get_count())
time = 0
break
end
meta:set_int("input_fluid_storage", input.amount)
meta:set_string("input_fluid", input.fluid)
meta:set_int("src_time", time)
meta:set_int("src_time_max", res_time)
meta:set_int("storage", pow_buffer.storage)
local time_percent = 0
if res_time > 0 then
time_percent = math.floor(100 * time / ele.helpers.round(res_time * 10))
end
meta:set_string("infotext", ("Electrolyzer %s\n%s"):format(status, ele.capacity_text(pow_buffer.capacity, pow_buffer.storage)))
meta:set_string("formspec", get_formspec(time_percent, pow_buffer, input, out1, out2, state))
return refresh
end
ele.register_machine("elepower_machines:electrolyzer", {
description = "Electrolyzer",
tiles = {
"elepower_machine_top.png", "elepower_machine_base.png", "elepower_machine_side.png",
"elepower_machine_side.png", "elepower_machine_side.png", "elepower_electrolyzer.png",
},
groups = {fluid_container = 1, cracky = 1, ele_user = 1},
on_timer = electrolyzer_timer,
fluid_buffers = {
input = {
accepts = {"default:water_source", "elepower_nuclear:heavy_water", "group:biomass"},
drainable = false,
capacity = 8000,
},
out1 = {
accepts = {"group:gas"},
drainable = true,
capacity = 8000,
},
out2 = {
accepts = {"group:gas"},
drainable = true,
capacity = 8000,
},
},
on_construct = function (pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", get_formspec())
end
})

View File

@ -25,6 +25,7 @@ dofile(mp .. "coal_alloy_furnace.lua")
dofile(mp .. "solderer.lua")
dofile(mp .. "compressor.lua")
dofile(mp .. "canning_machine.lua")
dofile(mp .. "electrolyzer.lua")
-- Other
dofile(mp .. "accumulator.lua")

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

View File

@ -87,6 +87,20 @@ elepm.register_craft({
time = 6,
})
-- Cold Coolant
minetest.register_craft({
output = "elepower_nuclear:bucket_coolant",
recipe = {
{"elepower_dynamics:nitrogen_container", "elepower_dynamics:nitrogen_container", "elepower_dynamics:nitrogen_container"},
{"", "bucket:bucket_water", ""},
{"", "elepower_dynamics:acidic_compound", ""},
},
replacements = {
{'elepower_dynamics:nitrogen_container', "elepower_dynamics:gas_container"},
{'bucket:bucket_water', "bucket:bucket_empty"}
}
})
------------------------
-- Enrichment recipes --
------------------------

View File

@ -30,6 +30,10 @@ minetest.register_node("elepower_nuclear:helium", {
tiles = {"elenuclear_helium.png"},
})
ele.register_gas(nil, "Tritium", "elepower_nuclear:tritium")
ele.register_gas(nil, "Deuterium", "elepower_nuclear:deuterium")
ele.register_gas(nil, "Helium", "elepower_nuclear:helium")
------------
-- Fluids --
------------