From bf75e00e9d6aa2a8eb8e3626e76a61b6643001b6 Mon Sep 17 00:00:00 2001 From: Emerson Rosen-Jones Date: Fri, 19 Dec 2025 23:31:02 -0500 Subject: [PATCH 01/17] chore: set up constants --- biofuel-manager.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 biofuel-manager.lua diff --git a/biofuel-manager.lua b/biofuel-manager.lua new file mode 100644 index 0000000..1f0a936 --- /dev/null +++ b/biofuel-manager.lua @@ -0,0 +1,19 @@ +-- 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" From 5d432c8c62c0019a332f56a9baf422d271a235af Mon Sep 17 00:00:00 2001 From: Emerson Rosen-Jones Date: Fri, 19 Dec 2025 23:31:36 -0500 Subject: [PATCH 02/17] feat: add different order primitives --- biofuel-manager.lua | 102 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/biofuel-manager.lua b/biofuel-manager.lua index 1f0a936..45ce77d 100644 --- a/biofuel-manager.lua +++ b/biofuel-manager.lua @@ -17,3 +17,105 @@ 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 + 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[1] == "run" then + local requester = peripheral.wrap(MAIN_REQUESTER) + local ticker = peripheral.wrap(SUBNET_TICKER) + run(requester, ticker) +end From 56c8335161cd6948e991837210be9e5ae4517fee Mon Sep 17 00:00:00 2001 From: Emerson Rosen-Jones Date: Fri, 19 Dec 2025 23:47:47 -0500 Subject: [PATCH 03/17] fix: remove syntax error --- biofuel-manager.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/biofuel-manager.lua b/biofuel-manager.lua index 45ce77d..0b6bb5e 100644 --- a/biofuel-manager.lua +++ b/biofuel-manager.lua @@ -51,6 +51,7 @@ local order = { ["minecraft:leaves"] = true, } }, } + } return ticker.requestFiltered(BIOMASS_PKG, request) end, biofuel = function (amt, ticker) From 65c3b4fe20e5cb450c59858553ea49de94672934 Mon Sep 17 00:00:00 2001 From: Emerson Rosen-Jones Date: Fri, 19 Dec 2025 23:48:04 -0500 Subject: [PATCH 04/17] fix: call recursive function properly --- biofuel-manager.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/biofuel-manager.lua b/biofuel-manager.lua index 0b6bb5e..335118a 100644 --- a/biofuel-manager.lua +++ b/biofuel-manager.lua @@ -80,6 +80,7 @@ local order = { amt_made = amt_made + count return make_order (amt_to_make, amt_made) end + return make_order (amt, 0) end, } From f688bdadf77113d850c2bd53495735f464c123c1 Mon Sep 17 00:00:00 2001 From: Emerson Rosen-Jones Date: Fri, 19 Dec 2025 23:48:22 -0500 Subject: [PATCH 05/17] fix: avoid erroring out when called from interpreter --- biofuel-manager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/biofuel-manager.lua b/biofuel-manager.lua index 335118a..c1424d6 100644 --- a/biofuel-manager.lua +++ b/biofuel-manager.lua @@ -116,7 +116,7 @@ function run (requester, ticker) return run(requester, ticker) end -if arg[1] == "run" then +if arg ~= nil and arg[1] == "run" then local requester = peripheral.wrap(MAIN_REQUESTER) local ticker = peripheral.wrap(SUBNET_TICKER) run(requester, ticker) From eeff05593f04157923011e5decf22847080aca0f Mon Sep 17 00:00:00 2001 From: Emerson Rosen-Jones Date: Fri, 19 Dec 2025 23:49:42 -0500 Subject: [PATCH 06/17] chore: prepare for further fixes Tested order.oil and order.biomass --- biofuel-manager.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/biofuel-manager.lua b/biofuel-manager.lua index c1424d6..de23200 100644 --- a/biofuel-manager.lua +++ b/biofuel-manager.lua @@ -30,6 +30,7 @@ local order = { 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", @@ -56,6 +57,7 @@ local order = { end, biofuel = function (amt, ticker) -- TODO + amt = math.floor(amt / 125) local request = function () local biomass = { name = "createaddition:biomass", @@ -71,6 +73,10 @@ local order = { } return biomass, sugar, cinder_flour end + local notEnoughMaterials = function () + -- TODO + -- use ticker to test ( biomass >= 32, sugar >= 16, and cinder flour >= 16 + 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 From c3e20db2c5e391610b9508a686a4aeebf7d6981a Mon Sep 17 00:00:00 2001 From: Emerson Rosen-Jones Date: Sat, 20 Dec 2025 18:57:13 -0500 Subject: [PATCH 07/17] feat: implements enoughMaterials function purpose: check for materials to craft 2b of biofuel --- biofuel-manager.lua | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/biofuel-manager.lua b/biofuel-manager.lua index de23200..0f3c5e3 100644 --- a/biofuel-manager.lua +++ b/biofuel-manager.lua @@ -73,13 +73,26 @@ local order = { } return biomass, sugar, cinder_flour end - local notEnoughMaterials = function () - -- TODO + 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 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 + if not enoughMaterials() 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 From 9fe8b3f78c4228a235bf18702d46b1b520a4ac85 Mon Sep 17 00:00:00 2001 From: Emerson Rosen-Jones Date: Sat, 20 Dec 2025 19:20:55 -0500 Subject: [PATCH 08/17] fix: reworks make_order Trying to make it recursive broke it --- biofuel-manager.lua | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/biofuel-manager.lua b/biofuel-manager.lua index 0f3c5e3..57a6267 100644 --- a/biofuel-manager.lua +++ b/biofuel-manager.lua @@ -57,7 +57,6 @@ local order = { end, biofuel = function (amt, ticker) -- TODO - amt = math.floor(amt / 125) local request = function () local biomass = { name = "createaddition:biomass", @@ -90,16 +89,15 @@ local order = { end return enough_materials end - local make_order = function (amt_to_make, amt_made) - if amt_to_make <= 0 then return amt_made end - if not enoughMaterials() 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) + + 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 make_order (amt, 0) + return amt_made end, } From 2867cb434e60f1549f6907b40d2c0d382ae27769 Mon Sep 17 00:00:00 2001 From: Emerson Rosen-Jones Date: Sat, 20 Dec 2025 19:35:02 -0500 Subject: [PATCH 09/17] 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 10/17] 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 11/17] 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 12/17] 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) From a9c31a3d3700ac241c14b82c7d2f875db1cab306 Mon Sep 17 00:00:00 2001 From: Emerson Rosen-Jones Date: Sat, 20 Dec 2025 22:11:10 -0500 Subject: [PATCH 13/17] chore: removes done TODO --- biofuel-manager.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/biofuel-manager.lua b/biofuel-manager.lua index f9ee1d2..0f4b2bb 100644 --- a/biofuel-manager.lua +++ b/biofuel-manager.lua @@ -54,7 +54,6 @@ local order = { return ticker.requestFiltered(BIOMASS_PKG, request) end, biofuel = function (amt, ticker) - -- TODO local request = function () local biomass = { name = "createaddition:biomass", From f3611c29ae1d85272cac59f494c468e0d3b9a3a9 Mon Sep 17 00:00:00 2001 From: Emerson Rosen-Jones Date: Sat, 20 Dec 2025 22:21:19 -0500 Subject: [PATCH 14/17] fix: removes unused variable --- biofuel-manager.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/biofuel-manager.lua b/biofuel-manager.lua index 0f4b2bb..af3c6c8 100644 --- a/biofuel-manager.lua +++ b/biofuel-manager.lua @@ -5,7 +5,6 @@ local STORAGE = "" local OIL_TANK = "" local FUEL_TANK = "" -local FACTORY_ADDRESS = "" local SPEEDOMETER = "" local SUBNET_TICKER = "" From 5dcfcdf77f26c49dc1419c33f15559ba48981e84 Mon Sep 17 00:00:00 2001 From: Emerson Rosen-Jones Date: Sat, 20 Dec 2025 22:21:35 -0500 Subject: [PATCH 15/17] fix: adds required constants --- biofuel-manager.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/biofuel-manager.lua b/biofuel-manager.lua index af3c6c8..bc3211d 100644 --- a/biofuel-manager.lua +++ b/biofuel-manager.lua @@ -5,6 +5,9 @@ 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 = "" From da0344ecb58d2c4f18c3c3bc847345514b43a8c4 Mon Sep 17 00:00:00 2001 From: Emerson Rosen-Jones Date: Sat, 20 Dec 2025 22:22:38 -0500 Subject: [PATCH 16/17] fix: fixes fluid tank handling Forgot to unpack the table --- biofuel-manager.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/biofuel-manager.lua b/biofuel-manager.lua index bc3211d..ff08bfd 100644 --- a/biofuel-manager.lua +++ b/biofuel-manager.lua @@ -124,7 +124,11 @@ function getOrders () local orders = {} -- Oil local oil_amt = table.remove(peripheral.call(OIL_TANK, "tanks")) - if oil_amt == nil then oil_amt = 0 end + 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 @@ -136,7 +140,11 @@ function getOrders () -- 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 + 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 From 341e0bf433b82fa7f6a0214ba8e1bc4b356117a4 Mon Sep 17 00:00:00 2001 From: Emerson Rosen-Jones Date: Sat, 20 Dec 2025 22:47:54 -0500 Subject: [PATCH 17/17] fix: properly requests biomass Fixes handling of tags --- biofuel-manager.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/biofuel-manager.lua b/biofuel-manager.lua index ff08bfd..1b90311 100644 --- a/biofuel-manager.lua +++ b/biofuel-manager.lua @@ -43,14 +43,14 @@ local order = { "minecraft:honeycomb" } } }, - { tags = { - ["minecraft:flowers"] = true, - ["c:crops"] = true, - ["createaddition:plant_foods"] = true, - ["createaddition:plants"] = true, - ["minecraft:saplings"] = true, - ["minecraft:leaves"] = true, - } }, + { 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)