diff --git a/farms/farmer.lua b/farms/farmer.lua index 877d1a0..ac182f8 100644 --- a/farms/farmer.lua +++ b/farms/farmer.lua @@ -139,7 +139,7 @@ local function harvest(blocks) elseif b.action == 'bump' then if turtle.faceAgainst(b) then turtle.equip('right', 'plethora:module:3') - os.sleep(.5) + os.sleep(.3) -- search the ground for the dropped cactus local sensed = peripheral.call('right', 'sense') turtle.equip('right', 'minecraft:diamond_pickaxe') diff --git a/milo/apis/milo.lua b/milo/apis/milo.lua index aadd885..e071c23 100644 --- a/milo/apis/milo.lua +++ b/milo/apis/milo.lua @@ -154,16 +154,7 @@ function Milo:getMatches(items, item, ignoreDamage, ignoreNbtHash) end function Milo:clearGrid() - turtle.eachFilledSlot(function(slot) - self.context.storage:import(self.context.localName, slot.index, slot.count, slot) - end) - - for i = 1, 16 do - if turtle.getItemCount(i) ~= 0 then - return false - end - end - return true + return Craft.clearGrid(self.context.storage) end function Milo:getTurtleInventory() diff --git a/milo/apis/storage.lua b/milo/apis/storage.lua index da7cfac..dac5548 100644 --- a/milo/apis/storage.lua +++ b/milo/apis/storage.lua @@ -218,13 +218,14 @@ function Storage:updateCache(adapter, key, count) else -- TODO: all items imported should be updated in itemdb -- error here if not - local item = itemDB:get(key) or itemDB:splitKey(key) - if item.displayName then + local item = itemDB:get(key) + if item then entry = Util.shallowCopy(item) entry.count = count entry.key = key adapter.cache[key] = entry else +debug('STORAGE: item missing details') -- TODO: somehow update itemdb with this maybe new item adapter.dirty = true self.dirty = true @@ -243,7 +244,7 @@ local function sn(name) if #t ~= 2 then return name end - return table.concat(table.unpack(t), '_') + return table.concat(t, '_') end function Storage:export(target, slot, count, item) @@ -253,9 +254,11 @@ function Storage:export(target, slot, count, item) local function provide(adapter) local amount = adapter:provide(item, count, slot, target or self.localName) if amount > 0 then + _G._debug('EXT: %s(%d): %s -> %s%s', - item.name, amount, sn(adapter.name), sn(target or self.localName), + item.displayName or item.name, amount, sn(adapter.name), sn(target or self.localName), slot and string.format('[%d]', slot) or '') + self:updateCache(adapter, key, -amount) self:updateCache(self, key, -amount) end @@ -302,7 +305,7 @@ function Storage:import(source, slot, count, item) if amount > 0 then _G._debug('INS: %s(%d): %s[%d] -> %s', - item.name, amount, + item.displayName or item.name, amount, sn(source or self.localName), slot, sn(adapter.name)) self:updateCache(adapter, key, amount) diff --git a/milo/apis/turtle/craft.lua b/milo/apis/turtle/craft.lua index d27bc1b..819237b 100644 --- a/milo/apis/turtle/craft.lua +++ b/milo/apis/turtle/craft.lua @@ -4,6 +4,7 @@ local Util = require('util') local device = _G.device local fs = _G.fs local turtle = _G.turtle +local intro = device['plethora:introspection'] local Craft = { STATUS_INFO = 'info', @@ -16,20 +17,6 @@ local Craft = { MACHINE_LOOKUP = 'usr/config/machine_crafting.db', } -local function clearGrid(storage) - turtle.eachFilledSlot(function(slot) - storage:import(storage.localName, slot.index, slot.count, slot) - end) - - for i = 1, 16 do - if turtle.getItemCount(i) ~= 0 then - return false - end - end - - return true -end - local function splitKey(key) local t = Util.split(key, '(.-):') local item = { } @@ -48,6 +35,27 @@ local function makeRecipeKey(item) return table.concat({ item.name, item.damage or 0, item.nbtHash }, ':') end +function Craft.clearGrid(storage) + turtle.eachFilledSlot(function(slot) + local item = slot + if intro then + item = intro.getInventory().getItemMeta(slot.index) + if not itemDB:get(item) then + itemDB:add(item) + end + end + storage:import(storage.localName, slot.index, slot.count, item) + end) + + for i = 1, 16 do + if turtle.getItemCount(i) ~= 0 then + return false + end + end + + return true +end + function Craft.getItemCount(items, item) if type(item) == 'string' then item = splitKey(item) @@ -117,7 +125,7 @@ local function machineCraft(recipe, storage, machineName, request, count, item) end local function turtleCraft(recipe, storage, request, count) - if not clearGrid(storage) then + if not Craft.clearGrid(storage) then request.status = 'grid in use' request.statusCode = Craft.STATUS_ERROR return @@ -142,7 +150,7 @@ local function turtleCraft(recipe, storage, request, count) request.status = 'Failed to craft' request.statusCode = Craft.STATUS_ERROR end - clearGrid(storage) + Craft.clearGrid(storage) return request.statusCode == Craft.STATUS_SUCCESS end diff --git a/milo/plugins/manipulatorView.lua b/milo/plugins/manipulatorView.lua index 6fa7f76..66ac15c 100644 --- a/milo/plugins/manipulatorView.lua +++ b/milo/plugins/manipulatorView.lua @@ -7,20 +7,26 @@ local colors = _G.colors local device = _G.device local turtle = _G.turtle ---[[ Configuration Screen ]] -local template = -[[%sBound Manipulator%s - -Automatically import items into storage from your ender chest. -]] - +--[[ Configuration Screen ]]-- local wizardPage = UI.Window { title = 'Manipulator', index = 2, backgroundColor = colors.cyan, - [1] = UI.TextArea { - x = 2, ex = -2, y = 2, ey = -2, - value = string.format(template, Ansi.yellow, Ansi.reset), + form = UI.Form { + x = 1, y = 3, ex = -1, ey = -2, + manualControls = true, + [1] = UI.Checkbox { + formLabel = 'Import', formKey = 'importEnder', + help = 'Locks chest to a single item type', + pruneEmpty = true, + }, + [2] = UI.TextArea { + x = 13, ex = -2, y = 2, + value = 'Automatically import the user\'s ender chest contents', + }, + }, + userInfo = UI.TextArea { + x = 2, ex = -2, y = 2, height = 1, }, } @@ -36,8 +42,19 @@ function wizardPage:isValidFor(node) return node.mtype == 'manipulator' end +function wizardPage:setNode(node) + self.form:setValues(node) + self.userInfo.value = string.format('%sBound to: %s%s', + Ansi.black, Ansi.yellow, node.adapter.getName()) +end + +function wizardPage:validate() + return self.form:save() +end + UI:getPage('nodeWizard').wizard:add({ manipulator = wizardPage }) +--[[ Task ]]-- local task = { name = 'manipulator', priority = 15, @@ -45,7 +62,7 @@ local task = { function task:cycle(context) local function filter(v) - return v.adapter.getEnder + return v.adapter.getEnder and v.importEnder end for manipulator in context.storage:filterActive('manipulator', filter) do diff --git a/milo/plugins/replenishTask.lua b/milo/plugins/replenishTask.lua index eb4605e..3a8c36c 100644 --- a/milo/plugins/replenishTask.lua +++ b/milo/plugins/replenishTask.lua @@ -30,6 +30,7 @@ function ReplenishTask:cycle(context) damage = res.ignoreDamage and 0 or item.damage, nbtHash = nbtHash, requested = res.low - count, + count = count, name = item.name, displayName = item.displayName, replenish = true,