autocrafting improvements

This commit is contained in:
kepler155c
2018-01-03 02:41:56 -05:00
parent aa50b55ab1
commit 45bbc72fc3
13 changed files with 289 additions and 357 deletions

View File

@@ -6,11 +6,13 @@ local turtle = _G.turtle
local CRAFTING_TABLE = 'minecraft:crafting_table'
local function clearGrid(inventory)
print('clearing')
for i = 1, 16 do
local count = turtle.getItemCount(i)
if count > 0 then
inventory:insert(i, count)
if turtle.getItemCount(i) ~= 0 then
print('failed to insert')
return false
end
end
@@ -19,7 +21,7 @@ local function clearGrid(inventory)
end
function turtle.craftItem(item, count, inventoryInfo)
local success
local success, msg
local inventory = Adapter.wrap(inventoryInfo)
if not inventory then
@@ -46,7 +48,8 @@ function turtle.craftItem(item, count, inventoryInfo)
equipped = turtle.getItemDetail(slot.index)
end
success = Craft.craftRecipe(item, count or 1, inventory)
clearGrid(inventory)
success, msg = Craft.craftRecipe(item, count or 1, inventory)
if equipped then
turtle.selectOpenSlot()
@@ -54,7 +57,7 @@ function turtle.craftItem(item, count, inventoryInfo)
turtle.equip(side, equipped.name .. ':' .. equipped.damage)
end
return success
return success, msg
end
function turtle.canCraft(item, count, items)