This commit is contained in:
kepler155c
2017-10-19 02:57:17 -04:00
parent 3622518b20
commit 6a1f72f957
2 changed files with 28 additions and 19 deletions

View File

@@ -126,9 +126,20 @@ end
function ChestAdapter:craftItems() function ChestAdapter:craftItems()
end end
local function rpairs(t)
local i = #t
return function()
local k,v = i, t[i]
i = i - 1
if v then
return k, v
end
end
end
function ChestAdapter:provide(item, qty, slot, direction) function ChestAdapter:provide(item, qty, slot, direction)
local stacks = self.list() local stacks = self.list()
for key,stack in pairs(stacks) do for key,stack in rpairs(stacks) do
if stack.name == item.name and stack.damage == item.damage then if stack.name == item.name and stack.damage == item.damage then
local amount = math.min(qty, stack.count) local amount = math.min(qty, stack.count)
if amount > 0 then if amount > 0 then

View File

@@ -20,7 +20,6 @@ local inventoryAdapter = ChestAdapter({ wrapSide = 'front', direction = 'north'
local RESOURCE_FILE = 'usr/config/resources.db' local RESOURCE_FILE = 'usr/config/resources.db'
local RECIPES_FILE = 'usr/etc/recipes2.db' local RECIPES_FILE = 'usr/etc/recipes2.db'
local craftingPaused = false
local recipes = Util.readTable(RECIPES_FILE) or { } local recipes = Util.readTable(RECIPES_FILE) or { }
local resources local resources
local machines = { } local machines = { }
@@ -148,7 +147,7 @@ local function craftItem(recipe, items, cItem, count)
for key,qty in pairs(recipe.ingredients) do for key,qty in pairs(recipe.ingredients) do
local item = itemDB:splitKey(key) local item = itemDB:splitKey(key)
inventoryAdapter:provide(item, count * qty, slot) inventoryAdapter:provide(item, count * qty, slot)
if turtle.getItemCount(slot) ~= count then if turtle.getItemCount(slot) ~= count * qty then
cItem.status = 'failed' cItem.status = 'failed'
return false return false
end end
@@ -435,6 +434,7 @@ local learnPage = UI.Page {
values = machines, values = machines,
disableHeader = true, disableHeader = true,
columns = { columns = {
{ heading = '', key = 'index', width = 2 },
{ heading = 'Name', key = 'name'}, { heading = 'Name', key = 'name'},
}, },
sortColumn = 'index', sortColumn = 'index',
@@ -722,7 +722,6 @@ Event.on('turtle_abort', function()
end) end)
Event.onInterval(30, function() Event.onInterval(30, function()
if not craftingPaused then
repeat until not turtle.forward() repeat until not turtle.forward()
if turtle.getFuelLevel() < 100 then if turtle.getFuelLevel() < 100 then
turtle.select(1) turtle.select(1)
@@ -738,7 +737,6 @@ Event.onInterval(30, function()
jobListGrid:sync() jobListGrid:sync()
craftItems(craftList, items) craftItems(craftList, items)
end
end) end)
UI:pullEvents() UI:pullEvents()