track/client.lua
by hugeblank
1
local common = require("common")
2
local mods = peripheral.wrap("back")
3
assert(mods, "Must be used on a Neural Interface")
4
assert(mods.canvas3d, "Overlay Glasses required")
5
local canvas = mods.canvas3d()
6
canvas.clear()
7
local bc = canvas.create()
8
9
local modem = (function()
10
local ms = {peripheral.find("modem")}
11
for i = 1, #ms do
12
if ms[i].isWireless() then
13
return ms[i]
14
end
15
end
16
end)()
17
assert(modem, "Wireless Modem required")
18
modem.open(1080)
19
20
local blocks = {}
21
22
local function place(sx, sy, sz, name)
23
local box = bc.addBox(sx, sy, sz)
24
-- We're gonna wait for SwitchCraftCC/Plethora-Fabric#17
25
--[[local frame = bc.addFrame({sx-1, sy-1, sz-1})
26
local text = frame.addText({0,0}, name)
27
local textobj = {
28
setPosition = frame.setPosition,
29
setRotation = text.setRotation,
30
setScale = text.setScale,
31
setText = text.setText,
32
}]]
33
34
local r, g, b = math.random(0, 255), math.random(0, 255), math.random(0, 255)
35
local c = r*(16^6)+g*(16^4)+b*(16^2)+255
36
box.setColor(c)
37
box.setDepthTested(false)
38
--frame.setDepthTested(false)
39
return box, textobj
40
end
41
42
local function mscan()
43
while true do
44
local e, _, channel, _, data = os.pullEventRaw()
45
if e == "modem_message" and channel == 1080 and type(data) == "table" and data.from == 1751 and data.to == os.getComputerID() then
46
if data.type == "block" then
47
local pass, x, y, z = common.checkBounds(data.x, data.y, data.z)
48
if pass then
49
blocks[#blocks+1] = {
50
x = x,
51
y = y,
52
z = z,
53
name = data.name,
54
}
55
end
56
elseif data.type == "clear" then
57
blocks = {}
58
bc.clear()
59
end
60
elseif e == "terminate" then
61
bc.clear()
62
return
63
end
64
end
65
end
66
67
local function recenter()
68
while true do
69
local x, y, z = gps.locate()
70
if x then
71
bc.recenter(x-math.floor(x+0.5), y-math.floor(y+0.5), z-math.floor(z+0.5))
72
table.foreachi(blocks, function(_, block)
73
if not block.box then
74
block.box, block.text = place(block.x-x, block.y-y, block.z-z, block.name)
75
end
76
local bx, by, bz = block.x-x, block.y-y, block.z-z
77
block.box.setPosition(bx, by, bz)
78
local dist = math.sqrt(bx^2+by^2+bz^2)
79
block.box.setSize(dist/8, dist/8, dist/8)
80
--block.text.setPosition(bx, by, bz)
81
--block.text.setScale(math.sqrt(bx^2, by^2, bz^2)*2)
82
end)
83
end
84
sleep(2)
85
end
86
end
87
88
parallel.waitForAny(mscan, recenter)