Compare commits

..

No commits in common. "4b0451254dbc2d2df21b5eccc214c399dfde2c57" and "9fe8b3f78c4228a235bf18702d46b1b520a4ac85" have entirely different histories.

View file

@ -1,13 +1,15 @@
-- program to manage a biofuel factory with create and some addons + tweaks -- program to manage a biofuel factory with create and some addons + tweaks
-- NOTE: this design does not handle stocking the system -- NOTE: this design does not handle stocking cinder flour or sugar
local STORAGE = "" local STORAGE = ""
local OIL_TANK = "" local OIL_TANK = ""
local FUEL_TANK = "" local FUEL_TANK = ""
local FACTORY_ADDRESS = "" local MAIN_SEED_REQUEST = "minecraft:melon_seeds"
local MAIN_PLANT_REQUEST = "minecraft:bamboo"
local SPEEDOMETER = "" local SPEEDOMETER = ""
local MAIN_REQUESTER = ""
local SUBNET_TICKER = "" local SUBNET_TICKER = ""
local SLEEP_T = 10 local SLEEP_T = 10
@ -101,63 +103,38 @@ local order = {
local stock = { local stock = {
seeds = function (amt, requester) seeds = function (amt, requester)
requester.setRequest({ name = MAIN_SEED_REQUEST, count = amt }) -- TODO
requester.request()
end, end,
plants = function (amt, requester) plants = function (amt, requester)
requester.setRequest({ name = MAIN_PLANT_REQUEST, count = amt }) -- TODO
requester.request()
end, end,
} }
function listItems (storage) function getStockRequirements ()
local tally = {} -- TODO
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 end
function getOrders () function getOrders ()
local orders = {} -- TODO
-- 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 end
function run (ticker) function run (requester, ticker)
if peripheral.call(SPEEDOMETER, "getSpeed") ~= 0 then if peripheral.call(SPEEDOMETER, "getSpeed") ~= 0 then
local need_to_stock = getStockRequirements()
local need_to_create = getOrders() 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 for type, amt in pairs(need_to_create) do
order[type](amt, ticker) order[type](amt, ticker)
end end
end end
os.sleep(SLEEP_T) os.sleep(SLEEP_T)
return run(ticker) return run(requester, ticker)
end end
if arg ~= nil and arg[1] == "run" then if arg ~= nil and arg[1] == "run" then
local requester = peripheral.wrap(MAIN_REQUESTER)
local ticker = peripheral.wrap(SUBNET_TICKER) local ticker = peripheral.wrap(SUBNET_TICKER)
local ran = false run(requester, ticker)
while not ran do
ran, result = run(ticker)
if not ran then print(result) end
os.sleep(SLEEP_T)
end
end end