diff --git a/milo/apis/storage.lua b/milo/apis/storage.lua index 04617f6..ea6b2af 100644 --- a/milo/apis/storage.lua +++ b/milo/apis/storage.lua @@ -405,6 +405,7 @@ local function rawExport(source, target, item, qty, slot) end function Storage:export(target, slot, count, item) + local timer = Util.timer() local total = 0 local key = item.key or table.concat({ item.name, item.damage, item.nbtHash }, ':') @@ -414,9 +415,9 @@ function Storage:export(target, slot, count, item) if amount > 0 then self:updateCache(adapter, item, -amount) - _G._debug('EXT: %s(%d): %s -> %s%s', + _G._debug('EXT: %s(%d): %s -> %s%s in %s', item.displayName or item.name, amount, self:_sn(adapter.name), self:_sn(target.name), - slot and string.format('[%d]', slot) or '[*]') + slot and string.format('[%d]', slot) or '[*]', Util.round(timer(), 2)) end count = count - amount total = total + amount @@ -472,6 +473,7 @@ function Storage:import(source, slot, count, item) if not source then error('Storage:import: source is required') end if not slot then error('Storage:import: slot is required') end + local timer = Util.timer() local total = 0 local key = item.key or table.concat({ item.name, item.damage, item.nbtHash }, ':') @@ -498,9 +500,9 @@ function Storage:import(source, slot, count, item) if amount > 0 then self:updateCache(adapter, item, amount) - _G._debug('INS: %s(%d): %s[%d] -> %s', + _G._debug('INS: %s(%d): %s[%d] -> %s in %s', item.displayName or item.name, amount, - self:_sn(source.name), slot, self:_sn(adapter.name)) + self:_sn(source.name), slot, self:_sn(adapter.name), Util.round(timer(), 2)) -- record that we have imported this item into storage during this cycle self.activity[key] = (self.activity[key] or 0) + amount @@ -556,13 +558,14 @@ end -- When importing items into a locked chest, trash any remaining items if full -- TODO: use all available trashcans function Storage:trash(source, slot, count, item) + local timer = Util.timer() local target = Util.find(self.nodes, 'mtype', 'trashcan') local amount = 0 if target and target.adapter and target.adapter.online then local s, m = pcall(function() - _G._debug('TRA: %s(%d): %s%s -> %s', + _G._debug('TRA: %s(%d): %s%s -> %s in %s', item.displayName or item.name, count, self:_sn(source.name), - slot and string.format('[%d]', slot) or '[*]', self:_sn(target.name)) + slot and string.format('[%d]', slot) or '[*]', self:_sn(target.name), Util.round(timer(), 2)) --_G._debug('TRA: %s[%d] (%d)', self:_sn(source.name), slot, count or 64) if isValidTransfer(source.adapter, target.name) then diff --git a/milo/plugins/remote/deposit.lua b/milo/plugins/remote/deposit.lua index 7493ee0..4a49e6a 100644 --- a/milo/plugins/remote/deposit.lua +++ b/milo/plugins/remote/deposit.lua @@ -12,8 +12,8 @@ Event.addRoutine(function() local lastTransfer while true do local sleepTime = 1.5 - if lastTransfer and os.clock() - lastTransfer < 3 then - sleepTime = .25 + if lastTransfer and os.clock() - lastTransfer < 2 then + sleepTime = .1 end os.sleep(context.socket and sleepTime or 5) diff --git a/neural/Scanner.lua b/neural/Scanner.lua index 96a60b3..3a3915a 100644 --- a/neural/Scanner.lua +++ b/neural/Scanner.lua @@ -10,7 +10,6 @@ local glasses = device['plethora:glasses'] local scanner = device['plethora:scanner'] or error('Plethora scanner must be equipped') -local target local projecting = { } local function getPoint() @@ -47,7 +46,7 @@ local page = UI.Page { detail = UI.SlideOut { menuBar = UI.MenuBar { buttons = { - { text = 'Cancel', event = 'cancel' }, + { text = 'Back', event = 'cancel' }, }, }, grid = UI.ScrollingGrid { @@ -60,6 +59,9 @@ local page = UI.Page { { heading = ' Z', key = 'z', width = 3, align = 'right' }, }, sortColumn = 'name', + accelerators = { + grid_select = 'noop', + }, }, }, } @@ -107,9 +109,59 @@ end function page.detail:show(blocks, entry) self.grid:setValues(Util.filter(blocks, function(b) return b.key == entry.key end)) + self.target = entry + if canvas then + self.handler = Event.onInterval(.5, function() + if not self.target then + Event.off(self.handler) + projecting = { } + canvas.clear() + else + local t = self.target + local scanned = scanner.scan() + local pos = getPoint() + + blocks = Util.reduce(scanned, function(acc, b) + if b.name == t.name and b.metadata == t.damage then + -- track block's world position + b.id = table.concat({ + math.floor(pos.x + b.x), + math.floor(pos.y + b.y), + math.floor(pos.z + b.z) }, ':') + acc[b.id] = b + end + return acc + end, { }) + + for _, b in pairs(blocks) do + if not projecting[b.id] then + projecting[b.id] = b + b.box = canvas.addBox( + pos.x - offset.x + b.x + -(pos.x % 1) + .25, + pos.y - offset.y + b.y + -(pos.y % 1) + .25, + pos.z - offset.z + b.z + -(pos.z % 1) + .25, + .5, .5, .5) + b.box.setDepthTested(false) + end + end + + for _, b in pairs(projecting) do + if not blocks[b.id] then + b.box.remove() + projecting[b.id] = nil + end + end + end + end) + end return UI.SlideOut.show(self) end +function page.detail:hide() + self.target = nil + return UI.SlideOut.hide(self) +end + function page:eventHandler(event) if event.type == 'quit' then Event.exitPullEvents() @@ -117,62 +169,16 @@ function page:eventHandler(event) elseif event.type == 'scan' then self:scan() - elseif event.type == 'grid_select' then - target = self.grid:getSelected() + elseif event.type == 'grid_select' and event.element == page.grid then self.detail:show(self.blocks, self.grid:getSelected()) elseif event.type == 'cancel' then - if canvas then - canvas.clear() - target = nil - projecting = { } - end self.detail:hide() end UI.Page.eventHandler(self, event) end -if canvas then - Event.onInterval(.5, function() - if target then - local scanned = scanner.scan() - local pos = getPoint() - - local blocks = Util.reduce(scanned, function(acc, b) - if b.name == target.name and b.metadata == target.damage then - -- track block's world position - b.id = table.concat({ - math.floor(pos.x + b.x), - math.floor(pos.y + b.y), - math.floor(pos.z + b.z) }, ':') - acc[b.id] = b - end - return acc - end, { }) - - for _, b in pairs(blocks) do - if not projecting[b.id] then - projecting[b.id] = b - b.box = canvas.addBox( - pos.x - offset.x + b.x + -(pos.x % 1) + .25, - pos.y - offset.y + b.y + -(pos.y % 1) + .25, - pos.z - offset.z + b.z + -(pos.z % 1) + .25, - .5, .5, .5) - b.box.setDepthTested(false) - end - end - - for _, b in pairs(projecting) do - if not blocks[b.id] then - b.box.remove() - projecting[b.id] = nil - end - end - end - end) -end - UI:setPage(page) Event.onTimeout(0, function() diff --git a/neural/shootingGallery.lua b/neural/shootingGallery.lua index 3ab9e48..7377fb2 100644 --- a/neural/shootingGallery.lua +++ b/neural/shootingGallery.lua @@ -1,18 +1,35 @@ +local Angle = require('neural.angle') local Mobs = require('neural.mobs') -local ni = require('neural.interface') local Point = require('point') -local os = _G.os +local device = _G.device +local os = _G.os -if not ni.look then - error('neuralInterface required') +local sensor = device['plethora:sensor'] or error('Sensor is required') +local weapon = device['plethora:laser'] +local uid = '' + +local function shootAt(pt) + local yaw, pitch = Angle.towards(pt.x, pt.y, pt.z) + weapon.fire(yaw, pitch, 4) end -local uid = ni.getID and ni.getID() or error('Introspection module is required') +if not weapon then + weapon = device['plethora:introspection'] + if not weapon or not weapon.shoot then + error('Either a laser or a skeleton with introspection module is required') + end + uid = weapon.getID() + shootAt = function(pt) + local yaw, pitch = Angle.towards(pt.x, pt.y, pt.z) + weapon.look(yaw, pitch) + weapon.shoot(1) + end +end local function findTargets() local pos = { x = 0, y = 0, z = 0 } - local l = ni.sense() + local l = sensor.sense() table.sort(l, function(e1, e2) return Point.distance(e1, pos) < Point.distance(e2, pos) end) @@ -20,7 +37,7 @@ local function findTargets() local targets = { } for _,v in ipairs(l) do if v.id ~= uid and Mobs.getNames()[v.name] then - if math.abs(v.y) < 2 then -- pitch is broken + if v.y >= 0 and v.y < 1 then table.insert(targets, v) end end @@ -28,16 +45,11 @@ local function findTargets() return #targets > 0 and targets end -print('Targets:') -for _,v in pairs(ni.sense()) do - print(v.name) -end - while true do local targets = findTargets() if targets then for _, entity in ipairs(targets) do - ni.shootAt(entity, 1) + shootAt(entity, 1) end end os.sleep(.5)