recipe nbts + item get/add helper

This commit is contained in:
kepler155c@gmail.com
2019-01-04 00:29:03 -05:00
parent d0a7a6e488
commit 6606975f5b
7 changed files with 62 additions and 41 deletions

View File

@@ -131,6 +131,7 @@ local function turtleCraft(recipe, storage, request, count)
if storage:export(storage.turtleInventory, k, count, item) ~= count then
request.status = 'unknown error'
request.statusCode = Craft.STATUS_ERROR
_debug('failed to export: ' .. item.name)
return
end
@@ -203,18 +204,11 @@ local function adjustCounts(recipe, count, ingredients, storage)
-- increment crafted
local result = ingredients[recipe.result]
result.count = result.count + (count * recipe.count)
end
function Craft.craftRecipeInternal(recipe, count, storage, origItem)
local request = origItem.ingredients[recipe.result]
if request.aborted then
_debug('aborted')
return 0
end
if origItem.pending[recipe.result] then
request.status = 'processing'
request.statusCode = Craft.STATUS_INFO
@@ -281,6 +275,12 @@ _G._p = origItem.ingredients
canCraft = canCraft - maxCount
end
if request.aborted then
origItem.aborted = true
_debug('aborted')
return 0
end
return crafted * recipe.count
end

View File

@@ -75,7 +75,7 @@ function Milo:resetCraftingStatus()
for _,key in pairs(Util.keys(self.context.craftingQueue)) do
local item = self.context.craftingQueue[key]
if item.crafted >= item.requested then
if item.crafted >= item.requested or item.aborted then
self.context.craftingQueue[key] = nil
end
end
@@ -135,12 +135,10 @@ end
function Milo:getTurtleInventory()
local list = { }
for i in pairs(self.context.turtleInventory.adapter.list()) do
local item = self.context.turtleInventory.adapter.getItemMeta(i)
if item and not itemDB:get(item) then
itemDB:add(item)
end
list[i] = item
for i, v in pairs(self.context.turtleInventory.adapter.list()) do
list[i] = itemDB:get(v, function()
return self.context.turtleInventory.adapter.getItemMeta(i)
end)
end
itemDB:flush()

View File

@@ -25,15 +25,7 @@ function Adapter:listItems(throttle)
local entry = cache[key]
if not entry then
local cached = itemDB:get(v)
if cached then
cached = Util.shallowCopy(cached)
else
cached = self.getItemMeta(k)
if cached then
cached = Util.shallowCopy(itemDB:add(cached))
end
end
local cached = itemDB:get(v, function() return self.getItemMeta(k) end)
if cached then
entry = cached
entry.count = 0