crafter
This commit is contained in:
@@ -126,9 +126,20 @@ end
|
||||
function ChestAdapter:craftItems()
|
||||
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)
|
||||
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
|
||||
local amount = math.min(qty, stack.count)
|
||||
if amount > 0 then
|
||||
|
||||
@@ -20,7 +20,6 @@ local inventoryAdapter = ChestAdapter({ wrapSide = 'front', direction = 'north'
|
||||
local RESOURCE_FILE = 'usr/config/resources.db'
|
||||
local RECIPES_FILE = 'usr/etc/recipes2.db'
|
||||
|
||||
local craftingPaused = false
|
||||
local recipes = Util.readTable(RECIPES_FILE) or { }
|
||||
local resources
|
||||
local machines = { }
|
||||
@@ -148,7 +147,7 @@ local function craftItem(recipe, items, cItem, count)
|
||||
for key,qty in pairs(recipe.ingredients) do
|
||||
local item = itemDB:splitKey(key)
|
||||
inventoryAdapter:provide(item, count * qty, slot)
|
||||
if turtle.getItemCount(slot) ~= count then
|
||||
if turtle.getItemCount(slot) ~= count * qty then
|
||||
cItem.status = 'failed'
|
||||
return false
|
||||
end
|
||||
@@ -435,6 +434,7 @@ local learnPage = UI.Page {
|
||||
values = machines,
|
||||
disableHeader = true,
|
||||
columns = {
|
||||
{ heading = '', key = 'index', width = 2 },
|
||||
{ heading = 'Name', key = 'name'},
|
||||
},
|
||||
sortColumn = 'index',
|
||||
@@ -722,23 +722,21 @@ Event.on('turtle_abort', function()
|
||||
end)
|
||||
|
||||
Event.onInterval(30, function()
|
||||
if not craftingPaused then
|
||||
repeat until not turtle.forward()
|
||||
if turtle.getFuelLevel() < 100 then
|
||||
turtle.select(1)
|
||||
inventoryAdapter:provide({ name = 'minecraft:coal', damage = 1 }, 16, 1)
|
||||
turtle.refuel()
|
||||
end
|
||||
local items = inventoryAdapter:listItems()
|
||||
local craftList = watchResources(items)
|
||||
|
||||
jobListGrid:setValues(craftList)
|
||||
jobListGrid:update()
|
||||
jobListGrid:draw()
|
||||
jobListGrid:sync()
|
||||
|
||||
craftItems(craftList, items)
|
||||
repeat until not turtle.forward()
|
||||
if turtle.getFuelLevel() < 100 then
|
||||
turtle.select(1)
|
||||
inventoryAdapter:provide({ name = 'minecraft:coal', damage = 1 }, 16, 1)
|
||||
turtle.refuel()
|
||||
end
|
||||
local items = inventoryAdapter:listItems()
|
||||
local craftList = watchResources(items)
|
||||
|
||||
jobListGrid:setValues(craftList)
|
||||
jobListGrid:update()
|
||||
jobListGrid:draw()
|
||||
jobListGrid:sync()
|
||||
|
||||
craftItems(craftList, items)
|
||||
end)
|
||||
|
||||
UI:pullEvents()
|
||||
|
||||
Reference in New Issue
Block a user