cc-stuff/biofuel-manager.lua
2025-12-19 23:48:22 -05:00

123 lines
3.5 KiB
Lua

-- program to manage a biofuel factory with create and some addons + tweaks
-- NOTE: this design does not handle stocking cinder flour or sugar
local STORAGE = ""
local OIL_TANK = ""
local FUEL_TANK = ""
local MAIN_SEED_REQUEST = "minecraft:melon_seeds"
local MAIN_PLANT_REQUEST = "minecraft:bamboo"
local SPEEDOMETER = ""
local MAIN_REQUESTER = ""
local SUBNET_TICKER = ""
local SLEEP_T = 10
local OIL_PKG = "Oil"
local BIOMASS_PKG = "Biomass"
local BIOFUEL_PKG = "Biofuel"
local order = {
oil = function (amt, ticker)
local orderCount = math.floor(amt / 100)
local request = {
tags = {
["c:seeds"] = true,
},
_requestCount = orderCount,
}
return ticker.requestFiltered(OIL_PKG, request)
end,
biomass = function (amt, ticker)
local order_amt = amt * 3
local request = {
_op = "any",
_requestCount = order_amt,
value = {
{ name = {
_op = "any",
value = {
"minecraft:stick",
"minecraft:honeycomb"
}
} },
{ tags = {
["minecraft:flowers"] = true,
["c:crops"] = true,
["createaddition:plant_foods"] = true,
["createaddition:plants"] = true,
["minecraft:saplings"] = true,
["minecraft:leaves"] = true,
} },
}
}
return ticker.requestFiltered(BIOMASS_PKG, request)
end,
biofuel = function (amt, ticker)
-- TODO
local request = function ()
local biomass = {
name = "createaddition:biomass",
_requestCount = 32
}
local sugar = {
name = "minecraft:sugar",
_requestCount = 16
}
local cinder_flour = {
name = "create:cinder_flour",
_requestCount = 16
}
return biomass, sugar, cinder_flour
end
local make_order = function (amt_to_make, amt_made)
if amt_to_make <= 0 then return amt_made end
if notEnoughMaterials() then return amt_made end
local count = ticker.requestFiltered(BIOFUEL_PKG, request())
if count == 0 then return amt_made end
amt_to_make = amt_to_make - count
amt_made = amt_made + count
return make_order (amt_to_make, amt_made)
end
return make_order (amt, 0)
end,
}
local stock = {
seeds = function (amt, requester)
-- TODO
end,
plants = function (amt, requester)
-- TODO
end,
}
function getStockRequirements ()
-- TODO
end
function getOrders ()
-- TODO
end
function run (requester, ticker)
if peripheral.call(SPEEDOMETER, "getSpeed") ~= 0 then
local need_to_stock = getStockRequirements()
local need_to_create = getOrders()
for type, amt in pairs(need_to_stock) do
stock[type](amt, requester)
end
for type, amt in pairs(need_to_create) do
order[type](amt, ticker)
end
end
os.sleep(SLEEP_T)
return run(requester, ticker)
end
if arg ~= nil and arg[1] == "run" then
local requester = peripheral.wrap(MAIN_REQUESTER)
local ticker = peripheral.wrap(SUBNET_TICKER)
run(requester, ticker)
end