milo crafting improvements
This commit is contained in:
@@ -128,17 +128,22 @@ local function machineCraft(recipe, storage, machineName, request, count, item)
|
||||
return
|
||||
end
|
||||
|
||||
local pending = item.pending[recipe.result] or 0
|
||||
|
||||
local list = machine.adapter.list()
|
||||
for k in pairs(recipe.ingredients) do
|
||||
if list[k] then
|
||||
request.status = 'machine in use'
|
||||
request.statusCode = Craft.STATUS_WARNING
|
||||
if pending > 0 then
|
||||
request.status = 'processing'
|
||||
request.statusCode = Craft.STATUS_INFO
|
||||
else
|
||||
request.status = 'machine in use'
|
||||
request.statusCode = Craft.STATUS_WARNING
|
||||
end
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local pending = item.pending[recipe.result] or 0
|
||||
|
||||
if count > 0 then
|
||||
local xferred = { }
|
||||
for k,v in pairs(recipe.ingredients) do
|
||||
@@ -187,6 +192,10 @@ local function turtleCraft(recipe, storage, request, count)
|
||||
request.statusCode = Craft.STATUS_ERROR
|
||||
failed = true
|
||||
_G._syslog('failed to export: ' .. item.name)
|
||||
-- _G._p4 = recipe
|
||||
-- _G._p = storage
|
||||
-- _G._p2 = request
|
||||
--read()
|
||||
end
|
||||
end)
|
||||
end
|
||||
@@ -223,7 +232,7 @@ local function turtleCraft(recipe, storage, request, count)
|
||||
end
|
||||
|
||||
function Craft.processPending(item, storage)
|
||||
for _, key in pairs(Util.keys(item.pending)) do
|
||||
for _, key in pairs(Util.keys(item.pending)) do
|
||||
local count = item.pending[key]
|
||||
local imported = storage.activity[key]
|
||||
if imported then
|
||||
@@ -332,7 +341,7 @@ function Craft.craftRecipeInternal(recipe, count, storage, origItem, path)
|
||||
return 0
|
||||
end
|
||||
if origItem.forceCrafting and crafted < iqty then
|
||||
canCraft = math.floor((itemCount + crafted) / icount)
|
||||
canCraft = math.min(canCraft, math.floor((itemCount + crafted) / icount))
|
||||
end
|
||||
if crafted > 0 then
|
||||
craftedIngredient = true
|
||||
@@ -467,28 +476,29 @@ function Craft.getResourceList4(inRecipe, items, count)
|
||||
end
|
||||
|
||||
-- given a certain quantity, return how many of those can be crafted
|
||||
function Craft.getCraftableAmount(inRecipe, inCount, items, missing)
|
||||
local function sumItems(recipe, summedItems, count, path)
|
||||
function Craft.getCraftableAmount(inRecipe, limit, items)
|
||||
local allIngredients = { }
|
||||
|
||||
local function sumItems(recipe, count, path)
|
||||
local canCraft = 0
|
||||
|
||||
for _ = 1, count do
|
||||
for _, item in Craft.ingredients(recipe) do
|
||||
local summedItem = summedItems[item.key] or Craft.getItemCount(items, item.key)
|
||||
for iKey, iCount in pairs(Craft.sumIngredients(recipe)) do
|
||||
local quantity = allIngredients[iKey] or Craft.getItemCount(items, iKey)
|
||||
|
||||
local irecipe = findValidRecipe(item.key, path)
|
||||
if irecipe and summedItem <= 0 then
|
||||
local p = Util.shallowCopy(path)
|
||||
p[irecipe.result] = true
|
||||
summedItem = summedItem + sumItems(irecipe, summedItems, item.count, p)
|
||||
end
|
||||
if summedItem <= 0 then
|
||||
if missing and not irecipe then
|
||||
missing.name = item.key
|
||||
if quantity < iCount then
|
||||
local irecipe = findValidRecipe(iKey, path)
|
||||
if irecipe then
|
||||
local p = Util.shallowCopy(path)
|
||||
p[irecipe.result] = true
|
||||
quantity = quantity + sumItems(irecipe, iCount - quantity, p)
|
||||
end
|
||||
end
|
||||
if quantity < iCount then
|
||||
return canCraft
|
||||
end
|
||||
if not recipe.craftingTools or not recipe.craftingTools[item.key] then
|
||||
summedItems[item.key] = summedItem - item.count
|
||||
if not recipe.craftingTools or not recipe.craftingTools[iKey] then
|
||||
allIngredients[iKey] = quantity - iCount
|
||||
end
|
||||
end
|
||||
canCraft = canCraft + recipe.count
|
||||
@@ -498,7 +508,7 @@ function Craft.getCraftableAmount(inRecipe, inCount, items, missing)
|
||||
end
|
||||
|
||||
local path = { [ inRecipe.result ] = true }
|
||||
return sumItems(inRecipe, { }, math.ceil(inCount / inRecipe.count), path)
|
||||
return sumItems(inRecipe, math.ceil(limit / inRecipe.count), path)
|
||||
end
|
||||
|
||||
function Craft.loadRecipes()
|
||||
|
||||
@@ -238,6 +238,12 @@ function Milo:learnRecipe()
|
||||
return false, 'No recipe defined'
|
||||
end
|
||||
|
||||
for _,v in pairs(ingredients) do
|
||||
if v.count > 1 then
|
||||
return false, 'Too many items'
|
||||
end
|
||||
end
|
||||
|
||||
turtle.select(1)
|
||||
if not turtle.craft() then
|
||||
return false, 'Failed to craft'
|
||||
|
||||
@@ -25,9 +25,10 @@ local wizardPage = UI.WizardPage {
|
||||
},
|
||||
}
|
||||
|
||||
-- Brewing stand shows as Cauldron is Minecraft 1.10
|
||||
function wizardPage:isValidType(node)
|
||||
local m = device[node.name]
|
||||
return m and m.type == 'minecraft:brewing_stand'and {
|
||||
return m and (m.type == 'minecraft:brewing_stand' or m.type == 'Cauldron') and {
|
||||
name = 'Brewing Stand',
|
||||
value = 'brewingStand',
|
||||
category = 'machine',
|
||||
|
||||
@@ -132,11 +132,13 @@ local function createPage(node)
|
||||
v.index = #t
|
||||
for k2,v2 in pairs(v.ingredients or { }) do
|
||||
if v2.key ~= v.key --[[and v2.statusCode ]] then
|
||||
table.insert(t, v2)
|
||||
if not v2.displayName then
|
||||
v2.displayName = itemDB:getName(k2)
|
||||
if v2.need > 0 or v2.statusCode then
|
||||
table.insert(t, v2)
|
||||
if not v2.displayName then
|
||||
v2.displayName = itemDB:getName(k2)
|
||||
end
|
||||
v2.index = #t
|
||||
end
|
||||
v2.index = #t
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,12 +10,8 @@ local PotionImportTask = {
|
||||
brewQueue = { },
|
||||
}
|
||||
|
||||
local function filter(a)
|
||||
return a.adapter.type == 'minecraft:brewing_stand'
|
||||
end
|
||||
|
||||
function PotionImportTask:cycle(context)
|
||||
for bs in context.storage:filterActive('brewingStand', filter) do
|
||||
for bs in context.storage:filterActive('brewingStand') do
|
||||
if bs.adapter.getBrewTime() == 0 then
|
||||
local list = bs.adapter.list()
|
||||
|
||||
|
||||
123
milo/plugins/transferView.lua
Normal file
123
milo/plugins/transferView.lua
Normal file
@@ -0,0 +1,123 @@
|
||||
local Ansi = require('ansi')
|
||||
local Milo = require('milo')
|
||||
local Tasks = require('milo.taskRunner')
|
||||
local UI = require('ui')
|
||||
local Util = require('util')
|
||||
|
||||
local colors = _G.colors
|
||||
local device = _G.device
|
||||
|
||||
local context = Milo:getContext()
|
||||
|
||||
--[[ Configuration Screen ]]
|
||||
local wizardPage = UI.WizardPage {
|
||||
title = 'Transfer Inventory',
|
||||
index = 2,
|
||||
backgroundColor = colors.cyan,
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 2, ey = -2,
|
||||
values = context.storage.nodes,
|
||||
columns = {
|
||||
{ key = 'suffix', width = 4, align = 'right' },
|
||||
{ heading = 'Name', key = 'displayName' },
|
||||
{ heading = 'Type', key = 'mtype', width = 4 },
|
||||
{ heading = 'Pri', key = 'priority', width = 3 },
|
||||
},
|
||||
sortColumn = 'displayName',
|
||||
help = 'Double-click to set target',
|
||||
},
|
||||
}
|
||||
|
||||
function wizardPage:isValidType(node)
|
||||
local m = device[node.name]
|
||||
return m and m.pullItems and {
|
||||
name = 'Transfer',
|
||||
value = 'xfer',
|
||||
category = 'custom',
|
||||
help = 'Transfer contents',
|
||||
}
|
||||
end
|
||||
|
||||
function wizardPage:isValidFor(node)
|
||||
return node.mtype == 'xfer'
|
||||
end
|
||||
|
||||
function wizardPage:setNode(node)
|
||||
self.node = node
|
||||
|
||||
local t = Util.filter(context.storage.nodes, function(v)
|
||||
return v.mtype ~= 'ignore' and device[v.name] and v.mtype ~= 'hidden'
|
||||
end)
|
||||
|
||||
self.grid:setValues(t)
|
||||
end
|
||||
|
||||
function wizardPage.grid:getDisplayValues(row)
|
||||
row = Util.shallowCopy(row)
|
||||
local t = { row.name:match(':(.+)_(%d+)$') }
|
||||
if #t ~= 2 then
|
||||
t = { row.name:match('(.+)_(%d+)$') }
|
||||
end
|
||||
if t and #t == 2 then
|
||||
row.name, row.suffix = table.unpack(t)
|
||||
row.name = row.name .. '_' .. row.suffix
|
||||
end
|
||||
row.displayName = row.displayName or row.name
|
||||
return row
|
||||
end
|
||||
|
||||
function wizardPage.grid:getRowTextColor(row, selected)
|
||||
if row.name == self.parent.node.target then
|
||||
return colors.yellow
|
||||
end
|
||||
return UI.Grid:getRowTextColor(row, selected)
|
||||
end
|
||||
|
||||
function wizardPage:eventHandler(event)
|
||||
if event.type == 'grid_select' then
|
||||
self.node.target = event.selected.name
|
||||
self.grid:draw()
|
||||
end
|
||||
return UI.Page.eventHandler(self, event)
|
||||
end
|
||||
|
||||
UI:getPage('nodeWizard').wizard:add({ transferChest = wizardPage })
|
||||
|
||||
local function transfer(node)
|
||||
local tasks = Tasks({
|
||||
errorMsg = 'TRANSFER error: '
|
||||
})
|
||||
|
||||
local target = context.storage.nodes[node.target]
|
||||
if not target or not target.adapter or not target.adapter.online then
|
||||
error(string.format('TRANSFER: target %s is not online', node.target))
|
||||
end
|
||||
|
||||
for k in pairs(node.adapter.list()) do
|
||||
tasks:add(function()
|
||||
node.adapter.pushItems(node.target, k)
|
||||
end)
|
||||
end
|
||||
|
||||
function tasks:onError(msg)
|
||||
_G._syslog('TRANSFER error: ' .. msg)
|
||||
end
|
||||
tasks:run()
|
||||
end
|
||||
|
||||
--[[ Task ]]--
|
||||
local Task = {
|
||||
name = 'transfer',
|
||||
priority = 99,
|
||||
}
|
||||
|
||||
function Task:cycle()
|
||||
for node in context.storage:filterActive('xfer') do
|
||||
local s, m = pcall(transfer, node)
|
||||
if not s and m then
|
||||
_G._syslog('TRANSFER error:' .. m)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Milo:registerTask(Task)
|
||||
Reference in New Issue
Block a user