milo: mass storage support (ae/rs)
This commit is contained in:
@@ -3,9 +3,12 @@ local Point = require('point')
|
|||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
|
|
||||||
local device = _G.device
|
local device = _G.device
|
||||||
|
local fs = _G.fs
|
||||||
local os = _G.os
|
local os = _G.os
|
||||||
local turtle = _G.turtle
|
local turtle = _G.turtle
|
||||||
|
|
||||||
|
local STARTUP_FILE = 'usr/autorun/spawner.lua'
|
||||||
|
|
||||||
local mobTypes = Util.transpose({ ... })
|
local mobTypes = Util.transpose({ ... })
|
||||||
|
|
||||||
local function equip(side, item, rawName)
|
local function equip(side, item, rawName)
|
||||||
@@ -41,19 +44,23 @@ local data = scanner.scan()
|
|||||||
local spawners = Util.findAll(data, 'name', 'minecraft:mob_spawner')
|
local spawners = Util.findAll(data, 'name', 'minecraft:mob_spawner')
|
||||||
local spawner = Point.closest(turtle.point, spawners) or error('spawner not in range')
|
local spawner = Point.closest(turtle.point, spawners) or error('spawner not in range')
|
||||||
|
|
||||||
turtle._goto(Point.below(spawner))
|
|
||||||
|
|
||||||
Util.filterInplace(data, function(b)
|
Util.filterInplace(data, function(b)
|
||||||
return b.name == 'minecraft:chest' or
|
return b.name == 'minecraft:chest' or
|
||||||
b.name == 'minecraft:dispenser' or
|
b.name == 'minecraft:dispenser' or
|
||||||
b.name == 'minecraft:hopper'
|
b.name == 'minecraft:hopper'
|
||||||
end)
|
end)
|
||||||
local chest = Point.closest(spawner, data) or error('missing drop off chest')
|
local chest = Point.closest(spawner, data) or error('missing drop off chest')
|
||||||
turtle._goto(Point.above(chest))
|
|
||||||
|
|
||||||
equip('right', 'plethora:sensor', 'plethora:module:3')
|
equip('right', 'plethora:sensor', 'plethora:module:3')
|
||||||
local sensor = device['plethora:sensor']
|
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.setMovementStrategy('goto')
|
||||||
turtle.setPolicy(turtle.policies.attack)
|
turtle.setPolicy(turtle.policies.attack)
|
||||||
|
|
||||||
@@ -128,13 +135,10 @@ while true do
|
|||||||
error('Out of fuel')
|
error('Out of fuel')
|
||||||
end
|
end
|
||||||
|
|
||||||
print(#mobs)
|
|
||||||
if #mobs == 0 then
|
if #mobs == 0 then
|
||||||
print('sleeping')
|
|
||||||
os.sleep(3)
|
os.sleep(3)
|
||||||
else
|
else
|
||||||
Point.eachClosest(turtle.point, mobs, function(b)
|
Point.eachClosest(turtle.point, mobs, function(b)
|
||||||
print('attack: ' .. b.id)
|
|
||||||
local strategy = getAttackStrategy(b.name)
|
local strategy = getAttackStrategy(b.name)
|
||||||
if strategy.attack(b) then
|
if strategy.attack(b) then
|
||||||
while true do
|
while true do
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ local SHIELD_SLOT = 2
|
|||||||
local STARTUP_FILE = 'usr/autorun/miloRemote.lua'
|
local STARTUP_FILE = 'usr/autorun/miloRemote.lua'
|
||||||
|
|
||||||
local context = {
|
local context = {
|
||||||
state = Config.load('miloRemote', { displayMode = 0 }),
|
state = Config.load('miloRemote', { displayMode = 0, deposit = true }),
|
||||||
}
|
}
|
||||||
|
|
||||||
local depositMode = {
|
local depositMode = {
|
||||||
@@ -441,6 +441,7 @@ shell.openForegroundTab('packages/milo/MiloRemote')]])
|
|||||||
self.filter = nil
|
self.filter = nil
|
||||||
end
|
end
|
||||||
self:applyFilter()
|
self:applyFilter()
|
||||||
|
self.grid:setIndex(1)
|
||||||
self.grid:draw()
|
self.grid:draw()
|
||||||
|
|
||||||
else
|
else
|
||||||
@@ -454,6 +455,7 @@ function page:enable()
|
|||||||
Util.merge(self.statusBar.depositToggle, depositMode[context.state.deposit])
|
Util.merge(self.statusBar.depositToggle, depositMode[context.state.deposit])
|
||||||
UI.Page.enable(self)
|
UI.Page.enable(self)
|
||||||
if not context.state.server then
|
if not context.state.server then
|
||||||
|
self.setup.form:setValues(context.state)
|
||||||
self.setup:show()
|
self.setup:show()
|
||||||
end
|
end
|
||||||
Event.onTimeout(.1, function()
|
Event.onTimeout(.1, function()
|
||||||
|
|||||||
46
milo/apis/massAdapter.lua
Normal file
46
milo/apis/massAdapter.lua
Normal 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
|
||||||
@@ -109,7 +109,11 @@ function Storage:initStorage()
|
|||||||
if v.adapter then
|
if v.adapter then
|
||||||
v.adapter.online = not not device[k]
|
v.adapter.online = not not device[k]
|
||||||
elseif device[k] and device[k].list and device[k].size and device[k].pullItems then
|
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.online = true
|
||||||
v.adapter.dirty = true
|
v.adapter.dirty = true
|
||||||
elseif device[k] then
|
elseif device[k] then
|
||||||
|
|||||||
@@ -63,9 +63,9 @@ function craftTask:cycle()
|
|||||||
local recipe = Craft.findRecipe(key)
|
local recipe = Craft.findRecipe(key)
|
||||||
if recipe then
|
if recipe then
|
||||||
|
|
||||||
if not item.playedSound then
|
if not item.notified then
|
||||||
Sound.play('entity.experience_orb.pickup')
|
Sound.play('entity.experience_orb.pickup')
|
||||||
item.playedSound = true
|
item.notified = true
|
||||||
end
|
end
|
||||||
|
|
||||||
self:craft(recipe, item)
|
self:craft(recipe, item)
|
||||||
|
|||||||
42
milo/plugins/massStorageView.lua
Normal file
42
milo/plugins/massStorageView.lua
Normal 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 })
|
||||||
Reference in New Issue
Block a user