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