brewing station auto learn

This commit is contained in:
kepler155c
2018-10-28 04:23:24 -04:00
parent b96c064431
commit 9d45460a3b
6 changed files with 12 additions and 13 deletions

View File

@@ -100,7 +100,6 @@ end
local context = {
config = config,
resources = loadResources(),
userRecipes = Util.readTable(Milo.RECIPES_FILE) or { },
craftingQueue = { },

View File

@@ -6,12 +6,12 @@ local Util = require('util')
local turtle = _G.turtle
local Milo = {
RECIPES_FILE = 'usr/config/recipes.db',
RESOURCE_FILE = 'usr/config/resources.db',
}
function Milo:init(context)
self.context = context
context.userRecipes = Util.readTable(Craft.USER_RECIPES) or { }
end
function Milo:getContext()
@@ -158,7 +158,7 @@ function Milo:saveMachineRecipe(recipe, result, machine)
-- save the recipe
self.context.userRecipes[key] = recipe
Util.writeTable(Milo.RECIPES_FILE, self.context.userRecipes)
Util.writeTable(Craft.USER_RECIPES, self.context.userRecipes)
-- save the machine association
Craft.machineLookup[key] = machine

View File

@@ -5,15 +5,15 @@ local device = _G.device
local fs = _G.fs
local turtle = _G.turtle
local RECIPES_DIR = 'usr/etc/recipes'
local USER_RECIPES = 'usr/config/recipes.db'
local MACHINE_LOOKUP = 'usr/config/machine_crafting.db'
local Craft = {
STATUS_INFO = 'info',
STATUS_WARNING = 'warning',
STATUS_ERROR = 'error',
STATUS_SUCCESS = 'success',
RECIPES_DIR = 'usr/etc/recipes',
USER_RECIPES = 'usr/config/recipes.db',
MACHINE_LOOKUP = 'usr/config/machine_crafting.db',
}
local function clearGrid(inventoryAdapter)
@@ -367,7 +367,7 @@ end
function Craft.loadRecipes()
Craft.recipes = { }
Util.merge(Craft.recipes, (Util.readTable(fs.combine(RECIPES_DIR, 'minecraft.db')) or { }).recipes)
Util.merge(Craft.recipes, (Util.readTable(fs.combine(Craft.RECIPES_DIR, 'minecraft.db')) or { }).recipes)
local config = Util.readTable('usr/config/recipeBooks.db') or { }
for _, book in pairs(config) do
@@ -375,14 +375,14 @@ function Craft.loadRecipes()
Util.merge(Craft.recipes, recipeFile.recipes)
end
local recipes = Util.readTable(USER_RECIPES) or { }
local recipes = Util.readTable(Craft.USER_RECIPES) or { }
Util.merge(Craft.recipes, recipes)
for k,v in pairs(Craft.recipes) do
v.result = k
end
Craft.machineLookup = Util.readTable(MACHINE_LOOKUP) or { }
Craft.machineLookup = Util.readTable(Craft.MACHINE_LOOKUP) or { }
end
function Craft.canCraft(item, count, items)

View File

@@ -203,7 +203,7 @@ function listingPage:eventHandler(event)
if context.userRecipes[key] then
context.userRecipes[key] = nil
Util.writeTable(Milo.RECIPES_FILE, context.userRecipes)
Util.writeTable(Craft.USER_RECIPES, context.userRecipes)
Craft.loadRecipes()
end

View File

@@ -21,7 +21,7 @@ function PotionImportTask:cycle(context)
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')
debug('saving new recipe')
Milo:saveMachineRecipe(self.brewQueue[v.name], list[1], v.name)
end
end

View File

@@ -96,7 +96,7 @@ local function learnRecipe()
end
context.userRecipes[key] = newRecipe
Util.writeTable(Milo.RECIPES_FILE, context.userRecipes)
Util.writeTable(Craft.USER_RECIPES, context.userRecipes)
Craft.loadRecipes()
turtle.emptyInventory()