overlay glasses
This commit is contained in:
@@ -1,21 +1,31 @@
|
||||
local Event = require('event')
|
||||
local itemDB = require('core.itemDB')
|
||||
local Project = require('neural.project')
|
||||
local UI = require('ui')
|
||||
local Util = require('util')
|
||||
local Event = require('event')
|
||||
local itemDB = require('core.itemDB')
|
||||
local UI = require('ui')
|
||||
local Util = require('util')
|
||||
|
||||
local peripheral = _G.peripheral
|
||||
local device = _G.device
|
||||
local gps = _G.gps
|
||||
local parallel = _G.parallel
|
||||
|
||||
local scanner =
|
||||
peripheral.find('neuralInterface') or
|
||||
peripheral.find('plethora:scanner') or
|
||||
peripheral.find('manipulator')
|
||||
|
||||
if not scanner or not scanner.scan then
|
||||
local glasses = device['plethora:glasses']
|
||||
local scanner = device['plethora:scanner'] or
|
||||
error('Plethora scanner must be equipped')
|
||||
|
||||
local target
|
||||
local projecting = { }
|
||||
|
||||
local function getPoint()
|
||||
local pt = { gps.locate() }
|
||||
return {
|
||||
x = pt[1],
|
||||
y = pt[2],
|
||||
z = pt[3],
|
||||
}
|
||||
end
|
||||
|
||||
local projecting
|
||||
local offset = getPoint()
|
||||
local canvas = glasses and glasses.canvas3d().create()
|
||||
--{ -(offset.x % 1), -(offset.y % 1), -(offset.z % 1) }
|
||||
|
||||
UI:configure('Scanner', ...)
|
||||
|
||||
@@ -106,7 +116,7 @@ end
|
||||
|
||||
function page.detail:eventHandler(event)
|
||||
if event.type == 'grid_select' then
|
||||
projecting = event.selected
|
||||
target = event.selected
|
||||
else
|
||||
return UI.SlideOut.eventHandler(self, event)
|
||||
end
|
||||
@@ -124,9 +134,10 @@ function page:eventHandler(event)
|
||||
self.detail:show(self.blocks, self.grid:getSelected())
|
||||
|
||||
elseif event.type == 'cancel' then
|
||||
if Project.canvas then
|
||||
Project.canvas.clear()
|
||||
projecting = nil
|
||||
if canvas then
|
||||
canvas.clear()
|
||||
target = nil
|
||||
projecting = { }
|
||||
end
|
||||
self.detail:hide()
|
||||
end
|
||||
@@ -134,17 +145,54 @@ function page:eventHandler(event)
|
||||
UI.Page.eventHandler(self, event)
|
||||
end
|
||||
|
||||
if scanner.canvas then
|
||||
Project:init(scanner.canvas())
|
||||
|
||||
if canvas then
|
||||
Event.onInterval(.5, function()
|
||||
if projecting then
|
||||
local blocks = scanner.scan()
|
||||
local pts = Util.filter(blocks, function(b)
|
||||
return b.name == projecting.name and b.metadata == projecting.metadata
|
||||
end)
|
||||
Project.canvas.clear()
|
||||
Project:drawPoints(scanner.getMetaOwner(), pts, true, 0xFFDF50AA)
|
||||
if target then
|
||||
local pos, scanned
|
||||
|
||||
parallel.waitForAll(
|
||||
function()
|
||||
pos = getPoint()
|
||||
end,
|
||||
function()
|
||||
scanned = scanner.scan()
|
||||
end
|
||||
)
|
||||
local blocks = Util.reduce(scanned, function(acc, b)
|
||||
if b.name == target.name and b.metadata == target.metadata then
|
||||
b.wx = math.floor(pos.x + b.x)
|
||||
b.wy = math.floor(pos.y + b.y)
|
||||
b.wz = math.floor(pos.z + b.z)
|
||||
b.id = table.concat({ math.floor(b.wx), math.floor(b.wy), math.floor(b.wz) }, ':')
|
||||
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
|
||||
projecting[b.id].box.remove()
|
||||
projecting[b.id] = nil
|
||||
end
|
||||
end
|
||||
|
||||
-- canvas.recenter({
|
||||
-- offset.x - pos.x,
|
||||
-- offset.y - pos.y,
|
||||
-- offset.z - pos.z,
|
||||
-- })
|
||||
end
|
||||
end)
|
||||
end
|
||||
@@ -152,6 +200,6 @@ end
|
||||
UI:setPage(page)
|
||||
UI:pullEvents()
|
||||
|
||||
if projecting then
|
||||
Project.canvas:clear()
|
||||
if canvas then
|
||||
canvas:clear()
|
||||
end
|
||||
|
||||
@@ -8,7 +8,6 @@ local module = device['plethora:kinetic'] or error('Missing kinetic')
|
||||
local Kinetic = Util.shallowCopy(module)
|
||||
|
||||
function Kinetic.lookAt(pt)
|
||||
--local x = pt.x < 0 and pt.x + .5 or pt.x - .5
|
||||
local yaw, pitch = Angle.towards(pt.x, pt.y, pt.z)
|
||||
return Kinetic.look(yaw, pitch)
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
local Array = require('array')
|
||||
local kinetic = require('plethora.kinetic')
|
||||
local kinetic = require('neural.kinetic')
|
||||
local Point = require('point')
|
||||
|
||||
local device = _G.device
|
||||
@@ -9,11 +9,11 @@ local pos = { x = 0, y = 0, z = 0 }
|
||||
local sensor = device['plethora:sensor'] or error('Missing sensor')
|
||||
local intro = device['plethora:introspection'] or error('Missing introspection module')
|
||||
|
||||
local ID = intro.getMetaOwner()
|
||||
local ownerId = intro.getMetaOwner().id
|
||||
|
||||
local function findTargets()
|
||||
local l = Array.filter(sensor.sense(), function(a)
|
||||
return math.abs(a.motionY) > 0 and ID ~= a.id
|
||||
return math.abs(a.motionY) > 0 and ownerId ~= a.id
|
||||
end)
|
||||
table.sort(l, function(e1, e2)
|
||||
return Point.distance(e1, pos) < Point.distance(e2, pos)
|
||||
|
||||
107
neural/ores.lua
Normal file
107
neural/ores.lua
Normal file
@@ -0,0 +1,107 @@
|
||||
local gps = _G.gps
|
||||
local keys = _G.keys
|
||||
local os = _G.os
|
||||
local parallel = _G.parallel
|
||||
local peripheral = _G.peripheral
|
||||
|
||||
local modules = peripheral.find('neuralInterface')
|
||||
if not modules then
|
||||
error('Plethora scanner must be equipped')
|
||||
elseif not modules.canvas then
|
||||
error('Overlay glasses module is required')
|
||||
elseif not modules.scan then
|
||||
error('Scanner module is required')
|
||||
end
|
||||
|
||||
local targets = {
|
||||
["minecraft:emerald_ore"] = 0x46FF26AA,
|
||||
["minecraft:diamond_ore"] = 0x50F8FFAA,
|
||||
["minecraft:gold_ore"] = 0xFFDF50AA,
|
||||
["minecraft:redstone_ore"] = 0xCC121566,
|
||||
["minecraft:lit_redstone_ore"] = 0xCC121566,
|
||||
["minecraft:iron_ore"] = 0xFFAC8766,
|
||||
["minecraft:lapis_ore"] = 0x0A107F66,
|
||||
["minecraft:coal_ore"] = 0x20202066,
|
||||
["quark:biotite_ore"] = 0x02051C66,
|
||||
["minecraft:quartz_ore"] = 0xCCCCCC66,
|
||||
["minecraft:glowstone"] = 0xFFDFA166
|
||||
}
|
||||
local projecting = { }
|
||||
|
||||
local function getPoint()
|
||||
local pt = { gps.locate() }
|
||||
return {
|
||||
x = pt[1],
|
||||
y = pt[2],
|
||||
z = pt[3],
|
||||
}
|
||||
end
|
||||
|
||||
local offset = getPoint()
|
||||
local canvas = modules.canvas3d().create()
|
||||
|
||||
local function run()
|
||||
while true do
|
||||
|
||||
-- order matters
|
||||
local scanned = modules.scan()
|
||||
local pos = getPoint()
|
||||
|
||||
local blocks = { }
|
||||
for _, b in pairs(scanned) do
|
||||
if targets[b.name] then
|
||||
b.wx = math.floor(pos.x + b.x)
|
||||
b.wy = math.floor(pos.y + b.y)
|
||||
b.wz = math.floor(pos.z + b.z)
|
||||
b.id = table.concat({ math.floor(b.wx), math.floor(b.wy), math.floor(b.wz) }, ':')
|
||||
blocks[b.id] = b
|
||||
end
|
||||
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, targets[b.name])
|
||||
b.box.setDepthTested(false)
|
||||
end
|
||||
end
|
||||
|
||||
for _, b in pairs(projecting) do
|
||||
if not blocks[b.id] then
|
||||
projecting[b.id].box.remove()
|
||||
projecting[b.id] = nil
|
||||
end
|
||||
end
|
||||
|
||||
if math.abs(pos.x - offset.x) +
|
||||
math.abs(pos.y - offset.y) +
|
||||
math.abs(pos.z - offset.z) > 16 then
|
||||
for _, b in pairs(projecting) do
|
||||
projecting[b.id].box.remove()
|
||||
projecting[b.id] = nil
|
||||
end
|
||||
offset = pos
|
||||
canvas.recenter()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
parallel.waitForAny(
|
||||
function()
|
||||
print('Ore visualization started')
|
||||
print('Press enter to exit')
|
||||
while true do
|
||||
local e, key = os.pullEventRaw('key')
|
||||
if key == keys.enter or e == 'terminate' then
|
||||
break
|
||||
end
|
||||
end
|
||||
end,
|
||||
run
|
||||
)
|
||||
|
||||
canvas:clear()
|
||||
Reference in New Issue
Block a user