brewing station auto learn
This commit is contained in:
@@ -248,6 +248,7 @@ function page:applyFilter()
|
|||||||
self.grid:setValues(t)
|
self.grid:setValues(t)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
debug(options.slot)
|
||||||
if options.slot.value then
|
if options.slot.value then
|
||||||
debug('Transfer items initialized')
|
debug('Transfer items initialized')
|
||||||
Event.onInterval(2, function()
|
Event.onInterval(2, function()
|
||||||
|
|||||||
@@ -153,6 +153,20 @@ function Milo:eject(item, qty)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Milo:saveMachineRecipe(recipe, result, machine)
|
||||||
|
local key = Milo:uniqueKey(result)
|
||||||
|
|
||||||
|
-- save the recipe
|
||||||
|
self.context.userRecipes[key] = recipe
|
||||||
|
Util.writeTable(Milo.RECIPES_FILE, self.context.userRecipes)
|
||||||
|
|
||||||
|
-- save the machine association
|
||||||
|
Craft.machineLookup[key] = machine
|
||||||
|
Util.writeTable(Craft.MACHINE_LOOKUP, Craft.machineLookup)
|
||||||
|
|
||||||
|
Craft.loadRecipes()
|
||||||
|
end
|
||||||
|
|
||||||
function Milo:mergeResources(t)
|
function Milo:mergeResources(t)
|
||||||
for _,v in pairs(self.context.resources) do
|
for _,v in pairs(self.context.resources) do
|
||||||
local item = self:getItem(t, v)
|
local item = self:getItem(t, v)
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ function NetworkedAdapter:insert(slot, qty, toSlot, item, source)
|
|||||||
if amount > 0 then
|
if amount > 0 then
|
||||||
debug('INS: %s(%d): %s[%d] -> %s',
|
debug('INS: %s(%d): %s[%d] -> %s',
|
||||||
item.name, amount,
|
item.name, amount,
|
||||||
source, slot, adapter.name)
|
source or self.localName, slot, adapter.name)
|
||||||
self.dirty = true
|
self.dirty = true
|
||||||
adapter.dirty = true
|
adapter.dirty = true
|
||||||
local entry = self.activity[key] or 0
|
local entry = self.activity[key] or 0
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
local Craft = require('turtle.craft')
|
|
||||||
local itemDB = require('itemDB')
|
local itemDB = require('itemDB')
|
||||||
local Milo = require('milo')
|
local Milo = require('milo')
|
||||||
local UI = require('ui')
|
local UI = require('ui')
|
||||||
@@ -8,8 +7,6 @@ local colors = _G.colors
|
|||||||
local device = _G.device
|
local device = _G.device
|
||||||
local turtle = _G.turtle
|
local turtle = _G.turtle
|
||||||
|
|
||||||
local MACHINE_LOOKUP = 'usr/config/machine_crafting.db'
|
|
||||||
|
|
||||||
local context = Milo:getContext()
|
local context = Milo:getContext()
|
||||||
|
|
||||||
local machineLearnWizard = UI.Page {
|
local machineLearnWizard = UI.Page {
|
||||||
@@ -117,17 +114,7 @@ function pages.confirmation:validate()
|
|||||||
recipe.ingredients[k] = Milo:uniqueKey(v)
|
recipe.ingredients[k] = Milo:uniqueKey(v)
|
||||||
end
|
end
|
||||||
|
|
||||||
local key = Milo:uniqueKey(result)
|
Milo:saveMachineRecipe(recipe, result, machine.name)
|
||||||
|
|
||||||
-- save the recipe
|
|
||||||
context.userRecipes[key] = recipe
|
|
||||||
Util.writeTable(Milo.RECIPES_FILE, context.userRecipes)
|
|
||||||
|
|
||||||
-- save the machine association
|
|
||||||
Craft.machineLookup[key] = machine.name
|
|
||||||
Util.writeTable(MACHINE_LOOKUP, Craft.machineLookup)
|
|
||||||
|
|
||||||
Craft.loadRecipes()
|
|
||||||
|
|
||||||
local listingPage = UI:getPage('listing')
|
local listingPage = UI:getPage('listing')
|
||||||
local displayName = itemDB:getName(result)
|
local displayName = itemDB:getName(result)
|
||||||
|
|||||||
@@ -1,21 +1,61 @@
|
|||||||
local Milo = require('milo')
|
local Craft = require('turtle.craft')
|
||||||
|
local Milo = require('milo')
|
||||||
|
|
||||||
local device = _G.device
|
local device = _G.device
|
||||||
|
|
||||||
local PotionImportTask = {
|
local PotionImportTask = {
|
||||||
name = 'potions',
|
name = 'potions',
|
||||||
priority = 30,
|
priority = 30,
|
||||||
|
brewQueue = { },
|
||||||
}
|
}
|
||||||
|
|
||||||
function PotionImportTask:cycle(context)
|
function PotionImportTask:cycle(context)
|
||||||
for _, v in pairs(device) do
|
for _, v in pairs(device) do
|
||||||
if v.type == 'minecraft:brewing_stand' and v.getBrewTime() == 0 then
|
if v.type == 'minecraft:brewing_stand' then
|
||||||
local list = v.list()
|
if v.getBrewTime() == 0 then
|
||||||
if not list[4] then
|
local list = v.list()
|
||||||
for slot = 1, 3 do
|
|
||||||
if list[slot] then
|
if list[1] and not list[4] then
|
||||||
context.storage:import(v.name, slot, 1, list[slot])
|
-- 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
|
end
|
||||||
|
for slot = 1, 3 do
|
||||||
|
if list[slot] then
|
||||||
|
context.storage:import(v.name, slot, 1, list[slot])
|
||||||
|
end
|
||||||
|
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
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
if valid() then
|
||||||
|
for i = 1, 4 do
|
||||||
|
recipe.ingredients[i] = Milo:uniqueKey(list[i])
|
||||||
|
end
|
||||||
|
|
||||||
|
self.brewQueue[v.name] = recipe
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user