rework milo crafting

This commit is contained in:
kepler155c
2018-11-10 21:01:53 -05:00
parent aff05f8587
commit bc9028f0c7
10 changed files with 131 additions and 85 deletions

View File

@@ -15,10 +15,11 @@ function craftTask:craft(recipe, item)
if Milo:isCraftingPaused() then
return
end
Craft.processPending(item, context.storage)
item.ingredients = Craft.getResourceList(recipe, Milo:listItems(), item.count - item.crafted)
--TODO: this needs to take into account what is pending
item.ingredients = Craft.getResourceList(
recipe, Milo:listItems(), item.requested - item.crafted, item.pending)
for k, v in pairs(item.ingredients) do
v.crafted = v.used
@@ -29,24 +30,39 @@ function craftTask:craft(recipe, item)
v.statusCode = Craft.STATUS_ERROR
end
end
item.ingredients[recipe.result] = Util.shallowCopy(item)
item.ingredients[recipe.result] = item
item.ingredients[recipe.result].total = item.count
item.ingredients[recipe.result].crafted = item.crafted
Craft.craftRecipe(recipe, item.count - item.crafted, context.storage, item)
Milo:clearGrid()
_G._p2 = item
if not item.history then
item.history = { }
end
local t = Util.shallowCopy(item)
t.history = { input = { }, output = { } }
for k,v in pairs(item.ingredients) do
t.history.input[k] = Util.shallowCopy(v)
end
table.insert(item.history, t)
Craft.craftRecipe(recipe, item.requested - item.crafted, context.storage, item)
for k,v in pairs(item.ingredients) do
t.history.output[k] = Util.shallowCopy(v)
end
end
function craftTask:cycle()
for _,key in pairs(Util.keys(context.craftingQueue)) do
local item = context.craftingQueue[key]
if item.count - item.crafted > 0 then
if item.requested - item.crafted > 0 then
local recipe = Craft.findRecipe(key)
if recipe then
sync(turtle, function()
self:craft(recipe, item)
end)
if item.callback and item.crafted >= item.count then
if item.callback and item.crafted >= item.requested then
item.callback(item) -- invoke callback
end
elseif not context.controllerAdapter then

View File

@@ -100,7 +100,7 @@ function craftPage.wizard.pages.resources:enable()
local count = tonumber(self.parent.quantity.count.value)
local recipe = Craft.findRecipe(craftPage.item)
if recipe then
local ingredients = Craft.getResourceList(recipe, items, count)
local ingredients = Craft.getResourceList4(recipe, items, count)
for _,v in pairs(ingredients) do
v.displayName = itemDB:getName(v)
end
@@ -117,11 +117,11 @@ function craftPage:eventHandler(event)
elseif event.type == 'accept' then
local item = Util.shallowCopy(self.item)
item.count = tonumber(self.wizard.pages.quantity.count.value)
item.requested = tonumber(self.wizard.pages.quantity.count.value)
item.forceCrafting = true
if self.wizard.pages.quantity.eject.value then
item.callback = function(request)
Milo:eject(item, request.count)
Milo:eject(item, request.requested)
end
end
Milo:requestCrafting(item)

View File

@@ -9,22 +9,35 @@ local function filter(a)
return a.imports
end
-- TODO: ignore damage/nbt
function ImportTask:cycle(context)
for inventory in context.storage:filterActive('machine', filter) do
for _, entry in pairs(inventory.imports) do
local function itemMatchesFilter(item)
if not entry.ignoreDamage and not entry.ignoreNbtHash then
return entry.filter[item.key]
end
for key in pairs(entry.filter) do
local v = Milo:splitKey(key)
if item.name == v.name and
(entry.ignoreDamage or item.damage == v.damage) and
(entry.ignoreNbtHash or item.nbtHash == v.nbtHash) then
return true
end
end
end
local function matchesFilter(item)
if not entry.filter then
return true
end
local key = Milo:uniqueKey(item)
if entry.blacklist then
return not entry.filter[key]
return not itemMatchesFilter(item)
end
return entry.filter[key]
return itemMatchesFilter(item)
end
local function importSlot(slotNo)

View File

@@ -47,9 +47,8 @@ function jobMonitor:updateList(craftList)
for _,v in pairs(craftList) do
table.insert(t, v)
v.index = #t
v.showRemaining = true
for k2,v2 in pairs(v.ingredients) do
if v2.key ~= v.key and v2.statusCode then
for k2,v2 in pairs(v.ingredients or { }) do
if v2.key ~= v.key --[[and v2.statusCode ]] then
table.insert(t, v2)
if not v2.displayName then
v2.displayName = itemDB:getName(k2)
@@ -67,12 +66,12 @@ end
function jobMonitor.grid:getDisplayValues(row)
row = Util.shallowCopy(row)
if row.showRemaining then
row.remaining = math.max(0, row.count - row.crafted)
if row.requested then
row.remaining = math.max(0, row.requested - row.crafted)
else
row.displayName = ' ' .. row.displayName
end
row.progress = string.format('%d/%d', row.crafted, row.count)
--row.progress = string.format('%d/%d', row.crafted, row.count)
return row
end

View File

@@ -95,7 +95,7 @@ local function client(socket)
local transferred = context.storage:export(
context.localName,
nil,
request.count,
request.requested,
data.item)
turtle.eachFilledSlot(function(slot)

View File

@@ -29,7 +29,7 @@ function ReplenishTask:cycle(context)
Milo:requestCrafting({
damage = res.ignoreDamage and 0 or item.damage,
nbtHash = nbtHash,
count = res.low - count,
requested = res.low - count,
name = item.name,
displayName = item.displayName,
replenish = true,
@@ -37,7 +37,7 @@ function ReplenishTask:cycle(context)
else
local request = context.craftingQueue[Milo:uniqueKey(item)]
if request and request.replenish then
request.count = request.crafted
--request.count = request.crafted
end
end
end