Compare commits
4 commits
9fe8b3f78c
...
4b0451254d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4b0451254d | ||
|
|
1be1a52a77 | ||
|
|
0be62dbccc | ||
|
|
2867cb434e |
1 changed files with 40 additions and 17 deletions
|
|
@ -1,15 +1,13 @@
|
||||||
-- 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 cinder flour or sugar
|
-- NOTE: this design does not handle stocking the system
|
||||||
|
|
||||||
local STORAGE = ""
|
local STORAGE = ""
|
||||||
local OIL_TANK = ""
|
local OIL_TANK = ""
|
||||||
local FUEL_TANK = ""
|
local FUEL_TANK = ""
|
||||||
|
|
||||||
local MAIN_SEED_REQUEST = "minecraft:melon_seeds"
|
local FACTORY_ADDRESS = ""
|
||||||
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
|
||||||
|
|
@ -103,38 +101,63 @@ local order = {
|
||||||
|
|
||||||
local stock = {
|
local stock = {
|
||||||
seeds = function (amt, requester)
|
seeds = function (amt, requester)
|
||||||
-- TODO
|
requester.setRequest({ name = MAIN_SEED_REQUEST, count = amt })
|
||||||
|
requester.request()
|
||||||
end,
|
end,
|
||||||
plants = function (amt, requester)
|
plants = function (amt, requester)
|
||||||
-- TODO
|
requester.setRequest({ name = MAIN_PLANT_REQUEST, count = amt })
|
||||||
|
requester.request()
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
function getStockRequirements ()
|
function listItems (storage)
|
||||||
-- TODO
|
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
|
end
|
||||||
|
|
||||||
function getOrders ()
|
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
|
end
|
||||||
|
|
||||||
function run (requester, ticker)
|
function run (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(requester, ticker)
|
return run(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)
|
||||||
run(requester, 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
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue