lua/client.lua
2025-07-09 12:59:38 +00:00

88 lines
No EOL
2.8 KiB
Lua

local common = require("common")
local mods = peripheral.wrap("back")
assert(mods, "Must be used on a Neural Interface")
assert(mods.canvas3d, "Overlay Glasses required")
local canvas = mods.canvas3d()
canvas.clear()
local bc = canvas.create()
local modem = (function()
local ms = {peripheral.find("modem")}
for i = 1, #ms do
if ms[i].isWireless() then
return ms[i]
end
end
end)()
assert(modem, "Wireless Modem required")
modem.open(1080)
local blocks = {}
local function place(sx, sy, sz, name)
local box = bc.addBox(sx, sy, sz)
-- We're gonna wait for SwitchCraftCC/Plethora-Fabric#17
--[[local frame = bc.addFrame({sx-1, sy-1, sz-1})
local text = frame.addText({0,0}, name)
local textobj = {
setPosition = frame.setPosition,
setRotation = text.setRotation,
setScale = text.setScale,
setText = text.setText,
}]]
local r, g, b = math.random(0, 255), math.random(0, 255), math.random(0, 255)
local c = r*(16^6)+g*(16^4)+b*(16^2)+255
box.setColor(c)
box.setDepthTested(false)
--frame.setDepthTested(false)
return box, textobj
end
local function mscan()
while true do
local e, _, channel, _, data = os.pullEventRaw()
if e == "modem_message" and channel == 1080 and type(data) == "table" and data.from == 1751 and data.to == os.getComputerID() then
if data.type == "block" then
local pass, x, y, z = common.checkBounds(data.x, data.y, data.z)
if pass then
blocks[#blocks+1] = {
x = x,
y = y,
z = z,
name = data.name,
}
end
elseif data.type == "clear" then
blocks = {}
bc.clear()
end
elseif e == "terminate" then
bc.clear()
return
end
end
end
local function recenter()
while true do
local x, y, z = gps.locate()
if x then
bc.recenter(x-math.floor(x+0.5), y-math.floor(y+0.5), z-math.floor(z+0.5))
table.foreachi(blocks, function(_, block)
if not block.box then
block.box, block.text = place(block.x-x, block.y-y, block.z-z, block.name)
end
local bx, by, bz = block.x-x, block.y-y, block.z-z
block.box.setPosition(bx, by, bz)
local dist = math.sqrt(bx^2+by^2+bz^2)
block.box.setSize(dist/8, dist/8, dist/8)
--block.text.setPosition(bx, by, bz)
--block.text.setScale(math.sqrt(bx^2, by^2, bz^2)*2)
end)
end
sleep(2)
end
end
parallel.waitForAny(mscan, recenter)