crafter
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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,23 +722,21 @@ 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)
|
inventoryAdapter:provide({ name = 'minecraft:coal', damage = 1 }, 16, 1)
|
||||||
inventoryAdapter:provide({ name = 'minecraft:coal', damage = 1 }, 16, 1)
|
turtle.refuel()
|
||||||
turtle.refuel()
|
|
||||||
end
|
|
||||||
local items = inventoryAdapter:listItems()
|
|
||||||
local craftList = watchResources(items)
|
|
||||||
|
|
||||||
jobListGrid:setValues(craftList)
|
|
||||||
jobListGrid:update()
|
|
||||||
jobListGrid:draw()
|
|
||||||
jobListGrid:sync()
|
|
||||||
|
|
||||||
craftItems(craftList, items)
|
|
||||||
end
|
end
|
||||||
|
local items = inventoryAdapter:listItems()
|
||||||
|
local craftList = watchResources(items)
|
||||||
|
|
||||||
|
jobListGrid:setValues(craftList)
|
||||||
|
jobListGrid:update()
|
||||||
|
jobListGrid:draw()
|
||||||
|
jobListGrid:sync()
|
||||||
|
|
||||||
|
craftItems(craftList, items)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
UI:pullEvents()
|
UI:pullEvents()
|
||||||
|
|||||||
Reference in New Issue
Block a user