brewing station auto learn
This commit is contained in:
@@ -100,7 +100,6 @@ end
|
|||||||
local context = {
|
local context = {
|
||||||
config = config,
|
config = config,
|
||||||
resources = loadResources(),
|
resources = loadResources(),
|
||||||
userRecipes = Util.readTable(Milo.RECIPES_FILE) or { },
|
|
||||||
|
|
||||||
craftingQueue = { },
|
craftingQueue = { },
|
||||||
|
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ local Util = require('util')
|
|||||||
local turtle = _G.turtle
|
local turtle = _G.turtle
|
||||||
|
|
||||||
local Milo = {
|
local Milo = {
|
||||||
RECIPES_FILE = 'usr/config/recipes.db',
|
|
||||||
RESOURCE_FILE = 'usr/config/resources.db',
|
RESOURCE_FILE = 'usr/config/resources.db',
|
||||||
}
|
}
|
||||||
|
|
||||||
function Milo:init(context)
|
function Milo:init(context)
|
||||||
self.context = context
|
self.context = context
|
||||||
|
context.userRecipes = Util.readTable(Craft.USER_RECIPES) or { }
|
||||||
end
|
end
|
||||||
|
|
||||||
function Milo:getContext()
|
function Milo:getContext()
|
||||||
@@ -158,7 +158,7 @@ function Milo:saveMachineRecipe(recipe, result, machine)
|
|||||||
|
|
||||||
-- save the recipe
|
-- save the recipe
|
||||||
self.context.userRecipes[key] = 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
|
-- save the machine association
|
||||||
Craft.machineLookup[key] = machine
|
Craft.machineLookup[key] = machine
|
||||||
|
|||||||
@@ -5,15 +5,15 @@ local device = _G.device
|
|||||||
local fs = _G.fs
|
local fs = _G.fs
|
||||||
local turtle = _G.turtle
|
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 = {
|
local Craft = {
|
||||||
STATUS_INFO = 'info',
|
STATUS_INFO = 'info',
|
||||||
STATUS_WARNING = 'warning',
|
STATUS_WARNING = 'warning',
|
||||||
STATUS_ERROR = 'error',
|
STATUS_ERROR = 'error',
|
||||||
STATUS_SUCCESS = 'success',
|
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)
|
local function clearGrid(inventoryAdapter)
|
||||||
@@ -367,7 +367,7 @@ end
|
|||||||
function Craft.loadRecipes()
|
function Craft.loadRecipes()
|
||||||
Craft.recipes = { }
|
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 { }
|
local config = Util.readTable('usr/config/recipeBooks.db') or { }
|
||||||
for _, book in pairs(config) do
|
for _, book in pairs(config) do
|
||||||
@@ -375,14 +375,14 @@ function Craft.loadRecipes()
|
|||||||
Util.merge(Craft.recipes, recipeFile.recipes)
|
Util.merge(Craft.recipes, recipeFile.recipes)
|
||||||
end
|
end
|
||||||
|
|
||||||
local recipes = Util.readTable(USER_RECIPES) or { }
|
local recipes = Util.readTable(Craft.USER_RECIPES) or { }
|
||||||
Util.merge(Craft.recipes, recipes)
|
Util.merge(Craft.recipes, recipes)
|
||||||
|
|
||||||
for k,v in pairs(Craft.recipes) do
|
for k,v in pairs(Craft.recipes) do
|
||||||
v.result = k
|
v.result = k
|
||||||
end
|
end
|
||||||
|
|
||||||
Craft.machineLookup = Util.readTable(MACHINE_LOOKUP) or { }
|
Craft.machineLookup = Util.readTable(Craft.MACHINE_LOOKUP) or { }
|
||||||
end
|
end
|
||||||
|
|
||||||
function Craft.canCraft(item, count, items)
|
function Craft.canCraft(item, count, items)
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ function listingPage:eventHandler(event)
|
|||||||
|
|
||||||
if context.userRecipes[key] then
|
if context.userRecipes[key] then
|
||||||
context.userRecipes[key] = nil
|
context.userRecipes[key] = nil
|
||||||
Util.writeTable(Milo.RECIPES_FILE, context.userRecipes)
|
Util.writeTable(Craft.USER_RECIPES, context.userRecipes)
|
||||||
Craft.loadRecipes()
|
Craft.loadRecipes()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ function PotionImportTask:cycle(context)
|
|||||||
if self.brewQueue[v.name] and list[1] then
|
if self.brewQueue[v.name] and list[1] then
|
||||||
local key = Milo:uniqueKey(list[1])
|
local key = Milo:uniqueKey(list[1])
|
||||||
if not Craft.findRecipe(key) then
|
if not Craft.findRecipe(key) then
|
||||||
debug('saving new recipe')
|
debug('saving new recipe')
|
||||||
Milo:saveMachineRecipe(self.brewQueue[v.name], list[1], v.name)
|
Milo:saveMachineRecipe(self.brewQueue[v.name], list[1], v.name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ local function learnRecipe()
|
|||||||
end
|
end
|
||||||
|
|
||||||
context.userRecipes[key] = newRecipe
|
context.userRecipes[key] = newRecipe
|
||||||
Util.writeTable(Milo.RECIPES_FILE, context.userRecipes)
|
Util.writeTable(Craft.USER_RECIPES, context.userRecipes)
|
||||||
Craft.loadRecipes()
|
Craft.loadRecipes()
|
||||||
|
|
||||||
turtle.emptyInventory()
|
turtle.emptyInventory()
|
||||||
|
|||||||
Reference in New Issue
Block a user