Compare commits

...
Sign in to create a new pull request.

17 commits

Author SHA1 Message Date
Emerson Rosen-Jones
341e0bf433 fix: properly requests biomass
Fixes handling of tags
2025-12-20 22:47:54 -05:00
Emerson Rosen-Jones
da0344ecb5 fix: fixes fluid tank handling
Forgot to unpack the table
2025-12-20 22:22:38 -05:00
Emerson Rosen-Jones
5dcfcdf77f fix: adds required constants 2025-12-20 22:21:35 -05:00
Emerson Rosen-Jones
f3611c29ae fix: removes unused variable 2025-12-20 22:21:19 -05:00
Emerson Rosen-Jones
a9c31a3d37 chore: removes done TODO 2025-12-20 22:11:10 -05:00
Emerson Rosen-Jones
4b0451254d feat: implements ordering logic 2025-12-20 22:07:10 -05:00
Emerson Rosen-Jones
1be1a52a77 feat: removes stocking storage from requirements 2025-12-20 22:05:22 -05:00
Emerson Rosen-Jones
0be62dbccc feat: add error handling for unloaded peripherals
Future work: cap the number of retries
2025-12-20 22:02:37 -05:00
Emerson Rosen-Jones
2867cb434e feat: implements main storage stock requests 2025-12-20 19:36:38 -05:00
Emerson Rosen-Jones
9fe8b3f78c fix: reworks make_order
Trying to make it recursive broke it
2025-12-20 19:20:55 -05:00
Emerson Rosen-Jones
c3e20db2c5 feat: implements enoughMaterials function
purpose: check for materials to craft 2b of biofuel
2025-12-20 18:57:13 -05:00
Emerson Rosen-Jones
eeff05593f chore: prepare for further fixes
Tested order.oil and order.biomass
2025-12-19 23:49:42 -05:00
Emerson Rosen-Jones
f688bdadf7 fix: avoid erroring out when called from interpreter 2025-12-19 23:48:22 -05:00
Emerson Rosen-Jones
65c3b4fe20 fix: call recursive function properly 2025-12-19 23:48:04 -05:00
Emerson Rosen-Jones
56c8335161 fix: remove syntax error 2025-12-19 23:47:47 -05:00
Emerson Rosen-Jones
5d432c8c62 feat: add different order primitives 2025-12-19 23:31:36 -05:00
Emerson Rosen-Jones
bf75e00e9d chore: set up constants 2025-12-19 23:31:02 -05:00

172
biofuel-manager.lua Normal file
View file

@ -0,0 +1,172 @@
-- program to manage a biofuel factory with create and some addons + tweaks
-- NOTE: this design does not handle stocking the system
local STORAGE = ""
local OIL_TANK = ""
local FUEL_TANK = ""
local OIL_SETPOINT = 64000
local BIOMASS_SETPOINT = 4 * 64
local BIOFUEL_SETPOINT = 128000
local SPEEDOMETER = ""
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)
-- TODO make order_amt calculation less naive
local order_amt = amt * 3
local request = {
_op = "any",
_requestCount = order_amt,
value = {
{ name = {
_op = "any",
value = {
"minecraft:stick",
"minecraft:honeycomb"
}
} },
{ tags = { _op = "any", value = {
{ ["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)
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 enoughMaterials = function ()
-- use ticker to test ( biomass >= 32, sugar >= 16, and cinder flour >= 16
local check = {}
check["createaddition:biomass"] = 32
check["minecraft:sugar"] = 16
check["create:cinder_flour"] = 16
for _, item in pairs(ticker.stock()) do
if check[item.name] then
check[item.name] = check[item.name] - item.count
end
end
local enough_materials = true
for name, count in pairs(check) do
if count > 0 then enough_materials = false end
end
return enough_materials
end
local amt_made = 0
while amt_made < amt do
if not enoughMaterials() then break end
ticker.requestFiltered(BIOFUEL_PKG, request())
amt_made = amt_made + 2000
os.sleep(1)
end
return amt_made
end,
}
local stock = {
seeds = function (amt, requester)
requester.setRequest({ name = MAIN_SEED_REQUEST, count = amt })
requester.request()
end,
plants = function (amt, requester)
requester.setRequest({ name = MAIN_PLANT_REQUEST, count = amt })
requester.request()
end,
}
function listItems (storage)
local tally = {}
for _, item in pairs(peripheral.call(storage, "list")) do
if tally[item.name] == nil then tally[item.name] = 0 end
tally[item.name] = tally[item.name] + item.count
end
return tally
end
function getOrders ()
local orders = {}
-- Oil
local oil_amt = table.remove(peripheral.call(OIL_TANK, "tanks"))
if oil_amt == nil then
oil_amt = 0
else
oil_amt = oil_amt.amount
end
local oil_needed = OIL_SETPOINT - oil_amt
if oil_needed > 0 then orders.oil = oil_needed end
-- Biomass
-- TODO use up excess material
local biomass_amt = listItems(STORAGE)["createaddition:biomass"]
if biomass_amt == nil then biomass_amt = 0 end
local biomass_needed = BIOMASS_SETPOINT - biomass_amt
if biomass_needed > 0 then orders.biomass = biomass_needed end
-- Biofuel
-- TODO use up excess material?
local biofuel_amt = table.remove(peripheral.call(FUEL_TANK, "tanks"))
if biofuel_amt == nil then
biofuel_amt = 0
else
biofuel_amt = biofuel_amt.amount
end
local biofuel_needed = BIOFUEL_SETPOINT - biofuel_amt
if biofuel_needed > 0 then orders.biofuel = biofuel_needed end
return orders
end
function run (ticker)
if peripheral.call(SPEEDOMETER, "getSpeed") ~= 0 then
local need_to_create = getOrders()
for type, amt in pairs(need_to_create) do
order[type](amt, ticker)
end
end
os.sleep(SLEEP_T)
return run(ticker)
end
if arg ~= nil and arg[1] == "run" then
local ticker = peripheral.wrap(SUBNET_TICKER)
local ran = false
while not ran do
ran, result = run(ticker)
if not ran then print(result) end
os.sleep(SLEEP_T)
end
end