diff --git a/milo/Milo.lua b/milo/Milo.lua index d927b17..da34037 100644 --- a/milo/Milo.lua +++ b/milo/Milo.lua @@ -81,8 +81,6 @@ context.storage.nodes[localName].adapter.name = localName Milo:init(context) context.storage:initStorage() - --- TODO: fix context.storage.turtleInventory = context.turtleInventory local function loadDirectory(dir) diff --git a/milo/apis/massAdapter.lua b/milo/apis/massAdapter.lua index 54c9c1a..7a42c57 100644 --- a/milo/apis/massAdapter.lua +++ b/milo/apis/massAdapter.lua @@ -12,7 +12,8 @@ function Adapter:init(args) self._rawList = self.list function self.list() - -- wait for up to 1 sec until any items that have been inserted into interface are added to the system + -- wait for up to 1 sec until any items that have been inserted + -- into interface are added to the system for _ = 0, 20 do if #self._rawList() == 0 then break @@ -35,12 +36,20 @@ function Adapter:init(args) end function self.pushItems(target, key, amount, slot) +_debug('pushing items') local item = self.findItem(itemDB:splitKey(key)) if item and item.export then return item.export(target, amount, slot) end return 0 end + + function self.pullItems(target, key, amount, slot) +_debug('pulling items') + _debug({target, key, amount, slot }) + return 0 + end + end return Adapter diff --git a/milo/apis/storage.lua b/milo/apis/storage.lua index 37ff1f1..9f469ff 100644 --- a/milo/apis/storage.lua +++ b/milo/apis/storage.lua @@ -342,7 +342,28 @@ end local function rawExport(source, target, item, qty, slot) local total = 0 - local push = isValidTransfer(source, target.name) + local transfer + + if isValidTransfer(source, target.name) then + transfer = function(key, amount) + return source.pushItems(target.name, key, amount, slot) + end + else --if isValidTransfer(target, source.name) then + transfer = function(key, amount) + return target.pullItems(source.name, key, amount, slot) + end + end + --[[ + -- TODO: mass storage will require a transfer chest (or something) + elseif isValidTransfer(source, 'minecraft:chest_0') then + transfer = function(key, amount) + local a = source.pushItems('minecraft:chest_0', key, amount, 1) + return target.pullItems('minecraft:chest_0', 1, amount, slot) + end + else + ... + end + ]] local s, m = pcall(function() local stacks = source.list() @@ -352,11 +373,7 @@ local function rawExport(source, target, item, qty, slot) stack.nbtHash == item.nbtHash then local amount = math.min(qty, stack.count) if amount > 0 then - if push then - amount = source.pushItems(target.name, key, amount, slot) - else - amount = target.pullItems(source.name, key, amount, slot) - end + amount = transfer(key, amount, slot) end qty = qty - amount total = total + amount @@ -380,12 +397,12 @@ function Storage:export(target, slot, count, item) local function provide(adapter) local amount = rawExport(adapter, target.adapter, item, count, slot) + + _G._debug('EXT: %s(%d): %s -> %s%s', + item.displayName or item.name, amount, self:_sn(adapter.name), self:_sn(target.name), + slot and string.format('[%d]', slot) or '[*]') + if amount > 0 then - - _G._debug('EXT: %s(%d): %s -> %s%s', - item.displayName or item.name, amount, self:_sn(adapter.name), self:_sn(target.name), - slot and string.format('[%d]', slot) or '[*]') - self:updateCache(adapter, item, -amount) end count = count - amount @@ -459,12 +476,12 @@ function Storage:import(source, slot, count, item) local function insert(adapter) local amount = rawInsert(adapter, source.adapter, slot, count) + + _G._debug('INS: %s(%d): %s[%d] -> %s', + item.displayName or item.name, amount, + self:_sn(source.name), slot, self:_sn(adapter.name)) + if amount > 0 then - - _G._debug('INS: %s(%d): %s[%d] -> %s', - item.displayName or item.name, amount, - self:_sn(source.name), slot, self:_sn(adapter.name)) - self:updateCache(adapter, item, amount) -- record that we have imported this item into storage during this cycle diff --git a/milo/plugins/manipulatorView.lua b/milo/plugins/manipulatorView.lua deleted file mode 100644 index 87bd2b2..0000000 --- a/milo/plugins/manipulatorView.lua +++ /dev/null @@ -1,78 +0,0 @@ -local Ansi = require('ansi') -local Milo = require('milo') -local UI = require('ui') - -local colors = _G.colors -local device = _G.device - ---[[ Configuration Screen ]]-- -local wizardPage = UI.Window { - title = 'Manipulator', - index = 2, - backgroundColor = colors.cyan, - form = UI.Form { - x = 2, ex = -2, y = 3, 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 = 3, ex = -2, y = 2, height = 2, - }, -} - -function wizardPage:isValidType(node) - local m = device[node.name] - return m and - m.type == 'manipulator' and - m.getEnder and - { - name = 'Manipulator', - value = 'manipulator', - category = 'custom', - help = 'Manipulator w/bound introspection mod' - } -end - -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, -} - -function task:cycle(context) - local function filter(v) - return v.adapter.getEnder and v.importEnder - end - - for manipulator in context.storage:filterActive('manipulator', filter) do - for slot, item in pairs(manipulator.adapter.getEnder().list()) do - context.storage:import('joebodo:enderChest', slot, item.count, item) - end - end -end - ---Milo:registerTask(task) diff --git a/milo/plugins/massStorageView.lua b/milo/plugins/massStorageView.lua index 554f767..c98701f 100644 --- a/milo/plugins/massStorageView.lua +++ b/milo/plugins/massStorageView.lua @@ -39,4 +39,5 @@ function wizardPage:validate() return true end -UI:getPage('nodeWizard').wizard:add({ inputChest = wizardPage }) +-- disable until a way is found to transfer between 2 non-transferrable nodes +-- UI:getPage('nodeWizard').wizard:add({ inputChest = wizardPage })