feat: add different order primitives
This commit is contained in:
parent
bf75e00e9d
commit
5d432c8c62
1 changed files with 102 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue