minetest_bitumen/refinery.lua

499 lines
12 KiB
Lua
Raw Normal View History

2013-10-09 17:37:19 -07:00
-- need:
-- bottler?
2018-06-18 23:52:09 -07:00
local function mul(t, x)
local o = {}
for n,i in ipairs(t) do
o[n] = i * x
end
o[2] = o[2] / x
o[5] = o[5] / x
return o
end
2013-10-09 17:37:19 -07:00
2013-10-11 19:37:26 -07:00
2018-06-18 19:42:02 -07:00
--
-- usage: alternate distillation columns and dist. col. outlets
-- put boiler on the bottom
-- pipe various distillates out
--
--
minetest.register_node("bitumen:distillation_column", {
2013-10-11 19:37:26 -07:00
paramtype = "light",
description = "Distillation Column Segment",
2013-10-12 19:21:25 -07:00
tiles = {"bitumen_cracking_column.png", "bitumen_cracking_column.png", "bitumen_cracking_column.png",
"bitumen_cracking_column.png", "bitumen_cracking_column.png", "bitumen_cracking_column.png"},
2013-10-11 19:37:26 -07:00
node_box = {
type = "fixed",
fixed = {
2013-10-12 19:21:25 -07:00
--11.25
2018-06-18 23:52:09 -07:00
mul({-0.49, -0.5, -0.10, 0.49, 0.5, 0.10}, 1.5),
mul({-0.10, -0.5, -0.49, 0.10, 0.5, 0.49}, 1.5),
2013-10-12 19:21:25 -07:00
--22.5
2018-06-18 23:52:09 -07:00
mul({-0.46, -0.5, -0.19, 0.46, 0.5, 0.19}, 1.5),
mul({-0.19, -0.5, -0.46, 0.19, 0.5, 0.46}, 1.5),
2013-10-12 19:21:25 -07:00
-- 33.75
2018-06-18 23:52:09 -07:00
mul({-0.416, -0.5, -0.28, 0.416, 0.5, 0.28}, 1.5),
mul({-0.28, -0.5, -0.416, 0.28, 0.5, 0.416}, 1.5),
2013-10-12 19:21:25 -07:00
--45
2018-06-18 23:52:09 -07:00
mul({-0.35, -0.5, -0.35, 0.35, 0.5, 0.35}, 1.5),
2013-10-11 19:37:26 -07:00
},
},
selection_box = {
type = "fixed",
fixed = {
2018-06-18 23:52:09 -07:00
mul({-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, 1.5),
2013-10-11 19:37:26 -07:00
},
},
drawtype = "nodebox",
groups = {cracky=3,oddly_breakable_by_hand=3 },
2013-10-09 17:37:19 -07:00
legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(),
2013-10-11 19:37:26 -07:00
on_construct = function(pos)
2013-10-11 19:37:26 -07:00
end,
2013-10-09 17:37:19 -07:00
})
2013-10-11 19:37:26 -07:00
minetest.register_node("bitumen:distillation_column_outlet", {
paramtype = "light",
description = "Distillation Column Outlet",
tiles = {"bitumen_cracking_column.png", "bitumen_cracking_column_outlet.png", "bitumen_cracking_column_outlet.png",
"bitumen_cracking_column_outlet.png", "bitumen_cracking_column_outlet.png", "bitumen_cracking_column.png"},
node_box = {
type = "fixed",
fixed = {
--11.25
2018-06-18 23:52:09 -07:00
mul({-0.49, -0.5, -0.10, 0.49, 0.5, 0.10}, 1.5),
mul({-0.10, -0.5, -0.49, 0.10, 0.5, 0.49}, 1.5),
--22.5
2018-06-18 23:52:09 -07:00
mul({-0.46, -0.5, -0.19, 0.46, 0.5, 0.19}, 1.5),
mul({-0.19, -0.5, -0.46, 0.19, 0.5, 0.46}, 1.5),
-- 33.75
2018-06-18 23:52:09 -07:00
mul({-0.416, -0.5, -0.28, 0.416, 0.5, 0.28}, 1.5),
mul({-0.28, -0.5, -0.416, 0.28, 0.5, 0.416}, 1.5),
--45
2018-06-18 23:52:09 -07:00
mul({-0.35, -0.5, -0.35, 0.35, 0.5, 0.35}, 1.5),
},
},
selection_box = {
type = "fixed",
fixed = {
2018-06-18 23:52:09 -07:00
mul({-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, 1.0)
},
},
drawtype = "nodebox",
groups = {cracky=3,oddly_breakable_by_hand=3, petroleum_fixture=1},
legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(),
on_construct = function(pos)
-- connect to the pipe network
bitumen.pipes.on_construct(pos)
end,
})
bitumen.distillation_stack = {
"tar",
"heavy_oil",
"light_oil",
2013-10-11 19:37:26 -07:00
"diesel",
"kerosene",
2013-10-11 19:37:26 -07:00
"gasoline",
"mineral_spirits",
-- "lpg",
2013-10-11 19:37:26 -07:00
}
2018-06-18 23:52:09 -07:00
local function check_stack(opos)
2013-10-11 19:37:26 -07:00
local ret = { }
2018-06-18 23:52:09 -07:00
local oh = opos.y
local pos = {x=opos.x, y=opos.y+1, z=opos.z}
local height = 0
2013-10-11 19:37:26 -07:00
local n
2018-06-18 23:52:09 -07:00
while height < 7 do
local n = minetest.get_node(pos)
if n.name == "bitumen:distillation_column" then
-- noop
2018-06-18 23:52:09 -07:00
--print("col")
elseif n.name == "bitumen:distillation_column_outlet" then
height = height+1
2019-03-31 18:50:58 -07:00
--local t = bitumen.distillation_stack[height]
2019-03-31 18:50:58 -07:00
ret[height] = {x=pos.x, y=pos.y, z=pos.z}
2018-06-18 23:52:09 -07:00
--print(t.." at ".. (pos.y).. " - " .. height)
else
2018-06-18 23:52:09 -07:00
--print("n "..n.name)
-- end of the stack
break
end
2018-06-18 23:52:09 -07:00
2013-10-11 19:37:26 -07:00
pos.y = pos.y+1
end
2018-06-18 23:52:09 -07:00
--print("returning")
2013-10-11 19:37:26 -07:00
return ret
end
local function dcb_node_timer(pos, elapsed)
end
2018-06-18 23:52:09 -07:00
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
bitumen.register_burner({"bitumen:distillation_column_boiler_on"}, {
start_cook = function()
--print("starting")
return 2
end,
finish_cook = function(pos)
--print("y1 ".. pos.y)
local input = bitumen.pipes.take_fluid(pos, 64)
2020-04-16 08:32:03 -07:00
print(pos.x .. " crude taken: ".. input)
2018-06-18 23:52:09 -07:00
if input <= 0 then
return
end
--print("y2 ".. pos.y)
local stack = check_stack(pos)
--print("y3 ".. pos.y)
2019-03-31 18:50:58 -07:00
for i,p in ipairs(stack) do
local fluid = bitumen.distillation_stack[i]
2018-06-18 23:52:09 -07:00
local yield = bitumen.distillation_yield[fluid] * (input / 100) -- convert to levels
2019-03-31 18:50:58 -07:00
--print("pushing "..yield.. " " ..fluid.." at "..p.y)
2018-06-18 23:52:09 -07:00
bitumen.pipes.push_fluid(p, "bitumen:"..fluid, yield, 20)
end
end,
get_formspec_on = get_melter_active_formspec,
2019-03-09 06:08:34 -08:00
}, 5.0)
2018-06-18 23:52:09 -07:00
minetest.register_node("bitumen:distillation_column_boiler", {
description = "Distillation Column Boiler",
2018-06-18 23:52:09 -07:00
tiles = {
"default_bronze_block.png", "default_bronze_block.png",
"default_bronze_block.png", "default_bronze_block.png",
"default_bronze_block.png", "default_furnace_front.png",
},
2013-10-09 17:37:19 -07:00
paramtype2 = "facedir",
groups = {cracky=2, petroleum_fixture=1},
2018-06-18 23:52:09 -07:00
is_ground_content = false,
sounds = default.node_sound_stone_defaults(),
--can_dig = can_dig,
2018-06-18 23:52:09 -07:00
--on_timer = burner_on_timer,
2013-10-09 17:37:19 -07:00
on_construct = function(pos)
local meta = minetest.get_meta(pos)
2018-06-18 23:52:09 -07:00
meta:set_string("formspec", bitumen.get_melter_active_formspec())
2013-10-09 17:37:19 -07:00
local inv = meta:get_inventory()
2018-06-18 23:52:09 -07:00
inv:set_size('fuel', 4)
bitumen.pipes.on_construct(pos)
minetest.get_node_timer(pos):start(1.0)
2013-10-09 17:37:19 -07:00
end,
2018-06-18 23:52:09 -07:00
-- on_metadata_inventory_move = function(pos)
-- minetest.get_node_timer(pos):start(1.0)
-- end,
-- on_metadata_inventory_put = function(pos)
-- -- start timer function, it will sort out whether furnace can burn or not.
-- minetest.get_node_timer(pos):start(1.0)
-- end,
--
on_punch = function(pos)
swap_node(pos, "bitumen:distillation_column_boiler_on")
minetest.get_node_timer(pos):start(1.0)
end,
2018-06-18 23:52:09 -07:00
-- on_blast = function(pos)
-- local drops = {}
-- default.get_inventory_drops(pos, "src", drops)
-- default.get_inventory_drops(pos, "fuel", drops)
-- default.get_inventory_drops(pos, "dst", drops)
-- drops[#drops+1] = "machines:machine"
-- minetest.remove_node(pos)
-- return drops
-- end,
allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_move = allow_metadata_inventory_move,
allow_metadata_inventory_take = allow_metadata_inventory_take,
2013-10-09 17:37:19 -07:00
})
2018-06-18 23:52:09 -07:00
minetest.register_node("bitumen:distillation_column_boiler_on", {
description = "Distillation Column Boiler",
tiles = {
"default_tin_block.png", "default_bronze_block.png",
"default_bronze_block.png", "default_tin_block.png",
"default_tin_block.png",
{
image = "default_furnace_front_active.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 1.5
},
}
},
paramtype2 = "facedir",
groups = {cracky=2, petroleum_fixture=1, not_in_creative_inventory=1},
is_ground_content = false,
sounds = default.node_sound_stone_defaults(),
--can_dig = can_dig,
on_timer = bitumen.burner_on_timer,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", bitumen.get_melter_active_formspec())
local inv = meta:get_inventory()
inv:set_size('fuel', 4)
2018-06-18 23:52:09 -07:00
bitumen.pipes.on_construct(pos)
2018-06-18 23:52:09 -07:00
minetest.get_node_timer(pos):start(1.0)
2018-06-18 23:52:09 -07:00
end,
-- on_metadata_inventory_move = function(pos)
-- minetest.get_node_timer(pos):start(1.0)
-- end,
-- on_metadata_inventory_put = function(pos)
-- -- start timer function, it will sort out whether furnace can burn or not.
-- minetest.get_node_timer(pos):start(1.0)
-- end,
--
2013-10-11 19:37:26 -07:00
2018-06-18 23:52:09 -07:00
on_punch = function(pos)
swap_node(pos, "bitumen:distillation_column_boiler")
end,
allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_move = allow_metadata_inventory_move,
allow_metadata_inventory_take = allow_metadata_inventory_take,
})
-- must add up to 100
bitumen.distillation_yield = {
tar = 20,
heavy_oil = 20,
light_oil = 10,
diesel = 20,
kerosene = 15,
gasoline = 10,
mineral_spirits = 5,
}
2019-03-31 18:50:58 -07:00
-- TODO: more
bitumen.cracking_yield = {
["bitumen:tar"] = {
{"tar", 40},
{"heavy_oil", 30},
{"light_oil", 20},
{"diesel", 10},
},
["bitumen:heavy_oil"] = {
{"heavy_oil", 30},
{"light_oil", 30},
{"diesel", 30},
{"kerosene", 10},
},
["bitumen:light_oil"] = {
{"light_oil", 30},
{"diesel", 30},
{"kerosene", 20},
{"gasoline", 20},
},
["bitumen:diesel"] = {
{"diesel", 20},
{"kerosene", 30},
{"gasoline", 25},
{"mineral_spirits", 25},
},
2013-10-11 19:37:26 -07:00
2019-03-31 18:50:58 -07:00
["bitumen:kerosene"] = {
{"kerosene", 10},
{"gasoline", 30},
{"mineral_spirits", 30},
--lpg = 30,
},
["bitumen:gasoline"] = {
{"gasoline", 5},
{"mineral_spirits", 40},
-- lpg = 40,
-- ethane = 15,
},
["bitumen:mineral_spirits"] = {
{"mineral_spirits", 10},
-- lpg = 60,
-- ethane = 30,
},
}
2013-10-11 19:37:26 -07:00
2018-06-18 19:42:02 -07:00
2013-10-09 17:37:19 -07:00
2019-03-31 18:50:58 -07:00
-- cracking columns
bitumen.register_burner({"bitumen:cracking_boiler_on"}, {
start_cook = function()
return 2
end,
finish_cook = function(pos)
local input, influid = bitumen.pipes.take_fluid(pos, 64)
if input <= 0 then
return
2013-10-09 17:37:19 -07:00
end
2019-03-31 18:50:58 -07:00
local ytable = bitumen.cracking_yield[influid]
if not ytable then
2013-10-09 17:37:19 -07:00
return
end
2019-03-31 18:50:58 -07:00
local stack = check_stack(pos)
for i,p in ipairs(stack) do
local def = ytable[i]
if not def then
break
2013-10-09 17:37:19 -07:00
end
2019-03-31 18:50:58 -07:00
local yield = def[2] * (input / 100) -- convert to levels
bitumen.pipes.push_fluid(p, "bitumen:"..def[1], yield, 20)
2013-10-09 17:37:19 -07:00
end
2019-03-31 18:50:58 -07:00
end,
get_formspec_on = get_melter_active_formspec,
}, 5.0)
minetest.register_node("bitumen:cracking_boiler", {
description = "Cracking Column Boiler",
tiles = {
"default_bronze_block.png", "default_bronze_block.png",
"default_bronze_block.png", "default_bronze_block.png",
"default_bronze_block.png", "default_furnace_front.png",
},
paramtype2 = "facedir",
groups = {cracky=2, petroleum_fixture=1},
is_ground_content = false,
sounds = default.node_sound_stone_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", bitumen.get_melter_active_formspec())
local inv = meta:get_inventory()
inv:set_size('fuel', 4)
bitumen.pipes.on_construct(pos)
minetest.get_node_timer(pos):start(1.0)
end,
on_punch = function(pos)
swap_node(pos, "bitumen:cracking_boiler_on")
minetest.get_node_timer(pos):start(1.0)
end,
allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_move = allow_metadata_inventory_move,
allow_metadata_inventory_take = allow_metadata_inventory_take,
2013-10-09 17:37:19 -07:00
})
2019-03-31 18:50:58 -07:00
minetest.register_node("bitumen:cracking_boiler_on", {
description = "Cracking Column Boiler",
tiles = {
"default_tin_block.png", "default_bronze_block.png",
"default_bronze_block.png", "default_tin_block.png",
"default_tin_block.png",
{
image = "default_furnace_front_active.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 1.5
},
}
},
paramtype2 = "facedir",
groups = {cracky=2, petroleum_fixture=1, not_in_creative_inventory=1},
is_ground_content = false,
sounds = default.node_sound_stone_defaults(),
--can_dig = can_dig,
on_timer = bitumen.burner_on_timer,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", bitumen.get_melter_active_formspec())
local inv = meta:get_inventory()
inv:set_size('fuel', 4)
bitumen.pipes.on_construct(pos)
minetest.get_node_timer(pos):start(1.0)
end,
-- on_metadata_inventory_move = function(pos)
-- minetest.get_node_timer(pos):start(1.0)
-- end,
-- on_metadata_inventory_put = function(pos)
-- -- start timer function, it will sort out whether furnace can burn or not.
-- minetest.get_node_timer(pos):start(1.0)
-- end,
--
on_punch = function(pos)
swap_node(pos, "bitumen:cracking_boiler")
end,
allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_move = allow_metadata_inventory_move,
allow_metadata_inventory_take = allow_metadata_inventory_take,
})
2013-10-11 19:37:26 -07:00
2013-10-09 17:37:19 -07:00