From 2867cb434e60f1549f6907b40d2c0d382ae27769 Mon Sep 17 00:00:00 2001 From: Emerson Rosen-Jones Date: Sat, 20 Dec 2025 19:35:02 -0500 Subject: [PATCH 1/4] feat: implements main storage stock requests --- biofuel-manager.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/biofuel-manager.lua b/biofuel-manager.lua index 57a6267..1bfa83e 100644 --- a/biofuel-manager.lua +++ b/biofuel-manager.lua @@ -5,6 +5,8 @@ local STORAGE = "" local OIL_TANK = "" local FUEL_TANK = "" +local FACTORY_ADDRESS = "" + local MAIN_SEED_REQUEST = "minecraft:melon_seeds" local MAIN_PLANT_REQUEST = "minecraft:bamboo" @@ -103,10 +105,12 @@ local order = { local stock = { seeds = function (amt, requester) - -- TODO + requester.setRequest({ name = MAIN_SEED_REQUEST, count = amt }) + requester.request() end, plants = function (amt, requester) - -- TODO + requester.setRequest({ name = MAIN_PLANT_REQUEST, count = amt }) + requester.request() end, } @@ -135,6 +139,7 @@ end if arg ~= nil and arg[1] == "run" then local requester = peripheral.wrap(MAIN_REQUESTER) + requester.setAddress(FACTORY_ADDRESS) local ticker = peripheral.wrap(SUBNET_TICKER) run(requester, ticker) end From 0be62dbccc8a9367ae5614b6d173eafa0502c95e Mon Sep 17 00:00:00 2001 From: Emerson Rosen-Jones Date: Sat, 20 Dec 2025 22:02:37 -0500 Subject: [PATCH 2/4] feat: add error handling for unloaded peripherals Future work: cap the number of retries --- biofuel-manager.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/biofuel-manager.lua b/biofuel-manager.lua index 1bfa83e..a39c873 100644 --- a/biofuel-manager.lua +++ b/biofuel-manager.lua @@ -141,5 +141,10 @@ if arg ~= nil and arg[1] == "run" then local requester = peripheral.wrap(MAIN_REQUESTER) requester.setAddress(FACTORY_ADDRESS) local ticker = peripheral.wrap(SUBNET_TICKER) - run(requester, ticker) + local ran = false + while not ran do + ran, result = run(ticker, requester) + if not ran then print(result) end + os.sleep(SLEEP_T) + end end From 1be1a52a773d8b60060023aac49904028b98fce5 Mon Sep 17 00:00:00 2001 From: Emerson Rosen-Jones Date: Sat, 20 Dec 2025 22:05:22 -0500 Subject: [PATCH 3/4] feat: removes stocking storage from requirements --- biofuel-manager.lua | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/biofuel-manager.lua b/biofuel-manager.lua index a39c873..2a899e5 100644 --- a/biofuel-manager.lua +++ b/biofuel-manager.lua @@ -1,5 +1,5 @@ -- program to manage a biofuel factory with create and some addons + tweaks --- NOTE: this design does not handle stocking cinder flour or sugar +-- NOTE: this design does not handle stocking the system local STORAGE = "" local OIL_TANK = "" @@ -7,11 +7,7 @@ local FUEL_TANK = "" local FACTORY_ADDRESS = "" -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 @@ -114,36 +110,27 @@ local stock = { end, } -function getStockRequirements () - -- TODO -end function getOrders () -- TODO end -function run (requester, ticker) +function run (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) + return run(ticker) end if arg ~= nil and arg[1] == "run" then - local requester = peripheral.wrap(MAIN_REQUESTER) - requester.setAddress(FACTORY_ADDRESS) local ticker = peripheral.wrap(SUBNET_TICKER) local ran = false while not ran do - ran, result = run(ticker, requester) + ran, result = run(ticker) if not ran then print(result) end os.sleep(SLEEP_T) end From 4b0451254dbc2d2df21b5eccc214c399dfde2c57 Mon Sep 17 00:00:00 2001 From: Emerson Rosen-Jones Date: Sat, 20 Dec 2025 22:07:10 -0500 Subject: [PATCH 4/4] feat: implements ordering logic --- biofuel-manager.lua | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/biofuel-manager.lua b/biofuel-manager.lua index 2a899e5..f9ee1d2 100644 --- a/biofuel-manager.lua +++ b/biofuel-manager.lua @@ -110,9 +110,35 @@ local stock = { 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 () - -- TODO + local orders = {} + -- Oil + local oil_amt = table.remove(peripheral.call(OIL_TANK, "tanks")) + if oil_amt == nil then oil_amt = 0 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 end + local biofuel_needed = BIOFUEL_SETPOINT - biofuel_amt + if biofuel_needed > 0 then orders.biofuel = biofuel_needed end + return orders end function run (ticker)