milo: mass storage support (ae/rs)

This commit is contained in:
kepler155c@gmail.com
2019-01-08 04:42:43 -05:00
parent e07298a9c4
commit 004dac65ce
6 changed files with 108 additions and 10 deletions

View File

@@ -3,9 +3,12 @@ local Point = require('point')
local Util = require('util')
local device = _G.device
local fs = _G.fs
local os = _G.os
local turtle = _G.turtle
local STARTUP_FILE = 'usr/autorun/spawner.lua'
local mobTypes = Util.transpose({ ... })
local function equip(side, item, rawName)
@@ -41,19 +44,23 @@ local data = scanner.scan()
local spawners = Util.findAll(data, 'name', 'minecraft:mob_spawner')
local spawner = Point.closest(turtle.point, spawners) or error('spawner not in range')
turtle._goto(Point.below(spawner))
Util.filterInplace(data, function(b)
return b.name == 'minecraft:chest' or
b.name == 'minecraft:dispenser' or
b.name == 'minecraft:hopper'
end)
local chest = Point.closest(spawner, data) or error('missing drop off chest')
turtle._goto(Point.above(chest))
equip('right', 'plethora:sensor', 'plethora:module:3')
local sensor = device['plethora:sensor']
if not fs.exists(STARTUP_FILE) then
Util.writeFile(STARTUP_FILE,
[[os.sleep(1)
shell.openForegroundTab('spawner.lua')]])
print('Autorun program created: ' .. STARTUP_FILE)
end
turtle.setMovementStrategy('goto')
turtle.setPolicy(turtle.policies.attack)
@@ -128,13 +135,10 @@ while true do
error('Out of fuel')
end
print(#mobs)
if #mobs == 0 then
print('sleeping')
os.sleep(3)
else
Point.eachClosest(turtle.point, mobs, function(b)
print('attack: ' .. b.id)
local strategy = getAttackStrategy(b.name)
if strategy.attack(b) then
while true do

View File

@@ -17,7 +17,7 @@ local SHIELD_SLOT = 2
local STARTUP_FILE = 'usr/autorun/miloRemote.lua'
local context = {
state = Config.load('miloRemote', { displayMode = 0 }),
state = Config.load('miloRemote', { displayMode = 0, deposit = true }),
}
local depositMode = {
@@ -441,6 +441,7 @@ shell.openForegroundTab('packages/milo/MiloRemote')]])
self.filter = nil
end
self:applyFilter()
self.grid:setIndex(1)
self.grid:draw()
else
@@ -454,6 +455,7 @@ function page:enable()
Util.merge(self.statusBar.depositToggle, depositMode[context.state.deposit])
UI.Page.enable(self)
if not context.state.server then
self.setup.form:setValues(context.state)
self.setup:show()
end
Event.onTimeout(.1, function()

46
milo/apis/massAdapter.lua Normal file
View File

@@ -0,0 +1,46 @@
local class = require('class')
local itemDB = require('itemDB')
local Mini = require('miniAdapter')
local os = _G.os
local Adapter = class(Mini)
function Adapter:init(args)
Mini.init(self, 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
for _ = 0, 20 do
if #self._rawList() == 0 then
break
end
os.sleep(0)
end
local list = { }
for _, v in pairs(self.listAvailableItems()) do
list[itemDB:makeKey(v)] = v
end
return list
end
function self.getItemMeta(key)
local item = self.findItem(itemDB:splitKey(key))
if item and item.getMetadata then
return item.getMetadata()
end
end
function self.pushItems(target, key, amount, slot)
local item = self.findItem(itemDB:splitKey(key))
if item and item.export then
return item.export(target, amount, slot)
end
return 0
end
end
return Adapter

View File

@@ -109,7 +109,11 @@ function Storage:initStorage()
if v.adapter then
v.adapter.online = not not device[k]
elseif device[k] and device[k].list and device[k].size and device[k].pullItems then
v.adapter = Adapter({ side = k })
if v.adapterType then
v.adapter = require(v.adapterType)({ side = k })
else
v.adapter = Adapter({ side = k })
end
v.adapter.online = true
v.adapter.dirty = true
elseif device[k] then

View File

@@ -63,9 +63,9 @@ function craftTask:cycle()
local recipe = Craft.findRecipe(key)
if recipe then
if not item.playedSound then
if not item.notified then
Sound.play('entity.experience_orb.pickup')
item.playedSound = true
item.notified = true
end
self:craft(recipe, item)

View File

@@ -0,0 +1,42 @@
local Ansi = require('ansi')
local UI = require('ui')
local colors = _G.colors
local device = _G.device
--[[ Configuration Screen ]]
local template =
[[%sWarning%s
Must an interface for Refined Storage / Applied Energistics.
Add all speed upgrades possible.
]]
local wizardPage = UI.Window {
title = 'Mass Storage',
index = 2,
backgroundColor = colors.cyan,
[1] = UI.TextArea {
x = 2, ex = -2, y = 2, ey = -2,
value = string.format(template, Ansi.red, Ansi.reset),
},
}
function wizardPage:isValidFor(node)
if node.mtype == 'storage' then
local m = device[node.name]
return m and m.listAvailableItems
end
end
function wizardPage:setNode(node)
self.node = node
end
function wizardPage:validate()
self.node.adapterType = 'massAdapter'
return true
end
UI:getPage('nodeWizard').wizard:add({ inputChest = wizardPage })