milo storage filter + crafting fixes

This commit is contained in:
kepler155c
2018-10-28 15:24:12 -04:00
parent 9d45460a3b
commit 1c70085450
8 changed files with 177 additions and 168 deletions

View File

@@ -1,62 +1,61 @@
local Craft = require('turtle.craft')
local Milo = require('milo')
local device = _G.device
local PotionImportTask = {
name = 'potions',
priority = 30,
brewQueue = { },
}
local function filter(a)
return a.adapter.type == 'minecraft:brewing_stand'
end
function PotionImportTask:cycle(context)
for _, v in pairs(device) do
if v.type == 'minecraft:brewing_stand' then
if v.getBrewTime() == 0 then
local list = v.list()
for bs in context.storage:filterActive('machine', filter) do
if bs.adapter.getBrewTime() == 0 then
local list = bs.adapter.list()
if list[1] and not list[4] then
-- brewing has completd
if list[1] and not list[4] then
-- brewing has completd
if self.brewQueue[v.name] and list[1] then
local key = Milo:uniqueKey(list[1])
if not Craft.findRecipe(key) then
debug('saving new recipe')
Milo:saveMachineRecipe(self.brewQueue[v.name], list[1], v.name)
end
end
for slot = 1, 3 do
if list[slot] then
context.storage:import(v.name, slot, 1, list[slot])
end
if self.brewQueue[bs.name] and list[1] then
local key = Milo:uniqueKey(list[1])
if not Craft.findRecipe(key) then
Milo:saveMachineRecipe(self.brewQueue[bs.name], list[1], bs.name)
end
end
self.brewQueue[v.name] = nil
elseif not self.brewQueue[v.name] then
local recipe = {
count = 3,
ingredients = { },
maxCount = 3,
}
local list = v.list()
local function valid()
for i = 1, 4 do
if not list[i] then
return false
end
for slot = 1, 3 do
if list[slot] then
context.storage:import(bs.name, slot, 1, list[slot])
end
return true
end
end
self.brewQueue[bs.name] = nil
elseif not self.brewQueue[bs.name] then
local recipe = {
count = 3,
ingredients = { },
maxCount = 3,
}
local list = bs.adapter.list()
local function valid()
for i = 1, 4 do
if not list[i] then
return false
end
end
return true
end
if valid() then
for i = 1, 4 do
recipe.ingredients[i] = Milo:uniqueKey(list[i])
end
if valid() then
for i = 1, 4 do
recipe.ingredients[i] = Milo:uniqueKey(list[i])
end
self.brewQueue[v.name] = recipe
end
self.brewQueue[bs.name] = recipe
end
end
end