autocrafting tools fix
This commit is contained in:
@@ -4,7 +4,6 @@ local Peripheral = require('peripheral')
|
||||
local Util = require('util')
|
||||
|
||||
local os = _G.os
|
||||
local peripheral = _G.peripheral
|
||||
|
||||
local convertNames = {
|
||||
name = 'id',
|
||||
@@ -13,14 +12,7 @@ local convertNames = {
|
||||
count = 'qty',
|
||||
displayName = 'display_name',
|
||||
maxDamage = 'max_dmg',
|
||||
}
|
||||
local keys = {
|
||||
'damage',
|
||||
'displayName',
|
||||
'maxCount',
|
||||
'maxDamage',
|
||||
'name',
|
||||
'nbtHash',
|
||||
nbtHash = 'nbt_hash',
|
||||
}
|
||||
|
||||
-- Strip off color prefix
|
||||
@@ -81,7 +73,6 @@ function MEAdapter:isValid()
|
||||
end
|
||||
|
||||
function MEAdapter:refresh()
|
||||
|
||||
self.items = self.getAvailableItems('all')
|
||||
for _,v in pairs(self.items) do
|
||||
Util.merge(v, v.item)
|
||||
@@ -103,7 +94,9 @@ end
|
||||
|
||||
function MEAdapter:getItemInfo(item)
|
||||
for _,i in pairs(self.items) do
|
||||
if item.name == i.name and item.damage == i.damage and item.nbtHash == i.nbtHash then
|
||||
if item.name == i.name and
|
||||
item.damage == i.damage and
|
||||
item.nbtHash == i.nbtHash then
|
||||
return i
|
||||
end
|
||||
end
|
||||
@@ -124,7 +117,6 @@ function MEAdapter:isCPUAvailable()
|
||||
end
|
||||
|
||||
function MEAdapter:craft(item, count)
|
||||
|
||||
if not self:isCPUAvailable() then
|
||||
return false
|
||||
end
|
||||
@@ -220,7 +212,8 @@ function MEAdapter:provide(item, count, slot, direction)
|
||||
local qty = math.min(count, 64)
|
||||
local s = self.exportItem({
|
||||
id = item.name,
|
||||
dmg = item.damage
|
||||
dmg = item.damage,
|
||||
nbt_hash = item.nbtHash,
|
||||
}, direction or self.direction, qty, slot)
|
||||
|
||||
if not s or s.size ~= qty then
|
||||
|
||||
@@ -122,13 +122,16 @@ function Craft.craftRecipe(recipe, count, inventoryAdapter)
|
||||
|
||||
for key,icount in pairs(Craft.sumIngredients(recipe)) do
|
||||
local itemCount = Craft.getItemCount(items, key)
|
||||
if itemCount < icount * count then
|
||||
local irecipe = Craft.recipes[key]
|
||||
local need = icount * count
|
||||
if recipe.craftingTools and recipe.craftingTools[key] then
|
||||
need = 1
|
||||
end
|
||||
if itemCount < need then
|
||||
local irecipe = Craft.findRecipe(key)
|
||||
if irecipe then
|
||||
local iqty = icount * count - itemCount
|
||||
local iqty = need - itemCount
|
||||
local crafted = Craft.craftRecipe(irecipe, iqty, inventoryAdapter)
|
||||
if crafted ~= iqty then
|
||||
|
||||
turtle.select(1)
|
||||
return 0
|
||||
end
|
||||
@@ -251,7 +254,7 @@ function Craft.getCraftableAmount(inRecipe, count, items, missing)
|
||||
for _,item in pairs(recipe.ingredients) do
|
||||
local summedItem = summedItems[item] or Craft.getItemCount(items, item)
|
||||
|
||||
local irecipe = Craft.recipes[item]
|
||||
local irecipe = Craft.findRecipe(item)
|
||||
if irecipe and summedItem <= 0 then
|
||||
summedItem = summedItem + sumItems(irecipe, summedItems, 1)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user