multiMiner improvements
This commit is contained in:
@@ -6,19 +6,20 @@ local Socket = require('socket')
|
|||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
local UI = require('ui')
|
local UI = require('ui')
|
||||||
|
|
||||||
local colors = _G.colors
|
local colors = _G.colors
|
||||||
local network = _G.network
|
local device = _G.device
|
||||||
local os = _G.os
|
local gps = _G.gps
|
||||||
local peripheral = _G.peripheral
|
local network = _G.network
|
||||||
|
local os = _G.os
|
||||||
|
|
||||||
UI:configure('multiMiner', ...)
|
UI:configure('multiMiner', ...)
|
||||||
|
|
||||||
local scanner = peripheral.find('neuralInterface')
|
local glasses = device['plethora:glasses']
|
||||||
if not scanner or not scanner.scan then
|
local scanner = device['plethora:scanner'] or
|
||||||
error('Plethora scanner must be equipped')
|
error('Plethora scanner must be equipped')
|
||||||
end
|
|
||||||
|
|
||||||
local canvas = scanner.canvas and scanner.canvas()
|
-- hud
|
||||||
|
local canvas = glasses and glasses.canvas()
|
||||||
if canvas then
|
if canvas then
|
||||||
canvas.group = canvas.addGroup({ 4, 90 })
|
canvas.group = canvas.addGroup({ 4, 90 })
|
||||||
canvas.bg = canvas.group.addRectangle(0, 0, 60, 24, 0x00000033)
|
canvas.bg = canvas.group.addRectangle(0, 0, 60, 24, 0x00000033)
|
||||||
@@ -27,6 +28,19 @@ if canvas then
|
|||||||
canvas.text.setScale(.75)
|
canvas.text.setScale(.75)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- container
|
||||||
|
local canvas3d = glasses and glasses.canvas3d().create()
|
||||||
|
local box, offset
|
||||||
|
|
||||||
|
local paused = false
|
||||||
|
|
||||||
|
local function inBox(pt)
|
||||||
|
if not box or not box.ex then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return Point.inBox(pt, box)
|
||||||
|
end
|
||||||
|
|
||||||
local function locate()
|
local function locate()
|
||||||
for _ = 1, 3 do
|
for _ = 1, 3 do
|
||||||
local pt = GPS.getPoint()
|
local pt = GPS.getPoint()
|
||||||
@@ -70,11 +84,13 @@ local function hijackTurtle(remoteId)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function getNextPoint(turtle)
|
local function getNextPoint(turtle)
|
||||||
local pt = Point.closest(turtle.getPoint(), queue)
|
if not paused then
|
||||||
if pt then
|
local pt = Point.closest(turtle.getPoint(), queue)
|
||||||
turtle.pt = pt
|
if pt then
|
||||||
queue[pt.pkey] = nil
|
turtle.pt = pt
|
||||||
return pt
|
queue[pt.pkey] = nil
|
||||||
|
return pt
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -216,6 +232,54 @@ local function run(member, point)
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function drawContainer(pos)
|
||||||
|
canvas3d.clear()
|
||||||
|
|
||||||
|
local function addBox(b)
|
||||||
|
canvas3d.addBox(
|
||||||
|
b.x - offset.x + .25,
|
||||||
|
b.y - offset.y + .25 ,
|
||||||
|
b.z - offset.z + .25 ,
|
||||||
|
.5, .5, .5).setDepthTested(false)
|
||||||
|
end
|
||||||
|
if box and box.ex then
|
||||||
|
addBox({ x = box.x, y = box.y, z = box.z })
|
||||||
|
addBox({ x = box.x, y = box.y, z = box.ez })
|
||||||
|
addBox({ x = box.ex, y = box.y, z = box.z })
|
||||||
|
addBox({ x = box.ex, y = box.y, z = box.ez })
|
||||||
|
addBox({ x = box.x, y = box.ey, z = box.z })
|
||||||
|
addBox({ x = box.x, y = box.ey, z = box.ez })
|
||||||
|
addBox({ x = box.ex, y = box.ey, z = box.z })
|
||||||
|
addBox({ x = box.ex, y = box.ey, z = box.ez })
|
||||||
|
elseif box then
|
||||||
|
canvas3d.recenter({ -(pos.x % 1), -(pos.y % 1), -(pos.z % 1) })
|
||||||
|
addBox(box)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local pauseResume = {
|
||||||
|
{ text = 'Pause', event = 'pause' },
|
||||||
|
{ text = 'Resume', event = 'resume' },
|
||||||
|
}
|
||||||
|
local containerText = {
|
||||||
|
[[Set a corner to contain mining area]],
|
||||||
|
[[Set ending corner]],
|
||||||
|
[[Set again to clear]],
|
||||||
|
}
|
||||||
|
|
||||||
|
local containTab = UI.Tab {
|
||||||
|
tabTitle = 'Contain',
|
||||||
|
button = UI.Button {
|
||||||
|
x = 2, y = 2,
|
||||||
|
text = 'Set corner',
|
||||||
|
event = 'contain'
|
||||||
|
},
|
||||||
|
textArea = UI.TextArea {
|
||||||
|
x = 2, y = 4,
|
||||||
|
value = containerText[1],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
local blocksTab = UI.Tab {
|
local blocksTab = UI.Tab {
|
||||||
tabTitle = 'Blocks',
|
tabTitle = 'Blocks',
|
||||||
grid = UI.ScrollingGrid {
|
grid = UI.ScrollingGrid {
|
||||||
@@ -248,12 +312,14 @@ local page = UI.Page {
|
|||||||
buttons = {
|
buttons = {
|
||||||
{ text = 'Scan', event = 'scan' },
|
{ text = 'Scan', event = 'scan' },
|
||||||
{ text = 'Abort', event = 'abort' },
|
{ text = 'Abort', event = 'abort' },
|
||||||
|
pauseResume[1],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
tabs = UI.Tabs {
|
tabs = UI.Tabs {
|
||||||
y = 2, ey = -2,
|
y = 2, ey = -2,
|
||||||
[1] = blocksTab,
|
[1] = blocksTab,
|
||||||
[2] = turtlesTab,
|
[2] = turtlesTab,
|
||||||
|
[3] = containTab,
|
||||||
},
|
},
|
||||||
info = UI.Window {
|
info = UI.Window {
|
||||||
y = -1,
|
y = -1,
|
||||||
@@ -312,10 +378,10 @@ function page:scan()
|
|||||||
b.y = gpt.y + b.y
|
b.y = gpt.y + b.y
|
||||||
b.z = gpt.z + b.z
|
b.z = gpt.z + b.z
|
||||||
b.pkey = table.concat({ b.x, b.y, b.z }, ':')
|
b.pkey = table.concat({ b.x, b.y, b.z }, ':')
|
||||||
if blockTypes[b.key] then
|
if blockTypes[b.key] and inBox(b) then
|
||||||
if not Util.any(turtles, function(t)
|
if not Util.any(turtles, function(t)
|
||||||
return t.pt and t.pt.pkey == b.pkey
|
return t.pt and t.pt.pkey == b.pkey
|
||||||
end) then
|
end) then
|
||||||
queue[b.pkey] = b
|
queue[b.pkey] = b
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@@ -388,6 +454,50 @@ function page:eventHandler(event)
|
|||||||
blocksTab.grid:draw()
|
blocksTab.grid:draw()
|
||||||
self.tabs:selectTab(blocksTab)
|
self.tabs:selectTab(blocksTab)
|
||||||
|
|
||||||
|
elseif event.type == 'pause' then
|
||||||
|
paused = true
|
||||||
|
Util.merge(event.button, pauseResume[2])
|
||||||
|
event.button:draw()
|
||||||
|
|
||||||
|
elseif event.type == 'resume' then
|
||||||
|
paused = false
|
||||||
|
Util.merge(event.button, pauseResume[1])
|
||||||
|
event.button:draw()
|
||||||
|
|
||||||
|
elseif event.type == 'contain' then
|
||||||
|
local pt = { gps.locate() }
|
||||||
|
local pos = {
|
||||||
|
x = pt[1],
|
||||||
|
y = pt[2],
|
||||||
|
z = pt[3],
|
||||||
|
}
|
||||||
|
|
||||||
|
if not box then
|
||||||
|
offset = {
|
||||||
|
x = math.floor(pos.x),
|
||||||
|
y = math.floor(pos.y),
|
||||||
|
z = math.floor(pos.z),
|
||||||
|
}
|
||||||
|
box = {
|
||||||
|
x = math.floor(pos.x),
|
||||||
|
y = math.floor(pos.y) - 1,
|
||||||
|
z = math.floor(pos.z),
|
||||||
|
}
|
||||||
|
containTab.textArea.value = containerText[2]
|
||||||
|
elseif not box.ex then
|
||||||
|
box.ex = math.floor(pos.x)
|
||||||
|
box.ey = math.floor(pos.y) - 1
|
||||||
|
box.ez = math.floor(pos.z)
|
||||||
|
box = Point.normalizeBox(box)
|
||||||
|
containTab.textArea.value = containerText[3]
|
||||||
|
else
|
||||||
|
box = nil
|
||||||
|
containTab.textArea.value = containerText[1]
|
||||||
|
end
|
||||||
|
|
||||||
|
containTab.textArea:draw()
|
||||||
|
drawContainer(pos)
|
||||||
|
|
||||||
elseif event.type == 'abort' then
|
elseif event.type == 'abort' then
|
||||||
for _, v in pairs(pool) do
|
for _, v in pairs(pool) do
|
||||||
v.abort = true
|
v.abort = true
|
||||||
@@ -401,7 +511,7 @@ function page:eventHandler(event)
|
|||||||
end
|
end
|
||||||
|
|
||||||
Event.onInterval(3, function()
|
Event.onInterval(3, function()
|
||||||
if not abort then
|
if not abort and not paused then
|
||||||
page:scan()
|
page:scan()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
@@ -456,5 +566,6 @@ end)
|
|||||||
Event.pullEvents()
|
Event.pullEvents()
|
||||||
|
|
||||||
if canvas then
|
if canvas then
|
||||||
|
canvas3d.clear()
|
||||||
canvas.group.remove()
|
canvas.group.remove()
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ local page = UI.Page {
|
|||||||
[ 'enter' ] = 'eject',
|
[ 'enter' ] = 'eject',
|
||||||
[ 'up' ] = 'grid_up',
|
[ 'up' ] = 'grid_up',
|
||||||
[ 'down' ] = 'grid_down',
|
[ 'down' ] = 'grid_down',
|
||||||
|
[ 'control-a' ] = 'eject_all',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
amount = UI.TextEntry {
|
amount = UI.TextEntry {
|
||||||
@@ -80,6 +81,7 @@ local page = UI.Page {
|
|||||||
backgroundFocusColor = colors.black,
|
backgroundFocusColor = colors.black,
|
||||||
accelerators = {
|
accelerators = {
|
||||||
[ 'enter' ] = 'eject_specified',
|
[ 'enter' ] = 'eject_specified',
|
||||||
|
[ 'control-a' ] = 'eject_all',
|
||||||
},
|
},
|
||||||
help = 'Request amount',
|
help = 'Request amount',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -224,8 +224,8 @@ function Milo:eject(item, count)
|
|||||||
total = total + amount
|
total = total + amount
|
||||||
count = count - amount
|
count = count - amount
|
||||||
|
|
||||||
Sound.play('ui.button.click')
|
--Sound.play('ui.button.click')
|
||||||
--Sound.play('entity.illusion_illager.death')
|
Sound.play('entity.illusion_illager.death', .3)
|
||||||
turtle.emptyInventory()
|
turtle.emptyInventory()
|
||||||
end
|
end
|
||||||
return total
|
return total
|
||||||
|
|||||||
Reference in New Issue
Block a user