Add more
This commit is contained in:
parent
f7bb6c8137
commit
5769eca2f2
5 changed files with 194 additions and 57 deletions
134
client.lua
134
client.lua
|
|
@ -1,68 +1,88 @@
|
|||
local modules = {}
|
||||
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 function getIndex(tab, val)
|
||||
local index = nil
|
||||
for i, v in ipairs (tab) do
|
||||
if (v == val) then
|
||||
index = i
|
||||
local modem = (function()
|
||||
local ms = {peripheral.find("modem")}
|
||||
for i = 1, #ms do
|
||||
if ms[i].isWireless() then
|
||||
return ms[i]
|
||||
end
|
||||
end
|
||||
return index
|
||||
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 kinetic = peripheral.wrap("back")
|
||||
local canvas = peripheral.wrap("back").canvas()
|
||||
|
||||
timer = os.startTimer(0.5)
|
||||
canvas.clear()
|
||||
|
||||
local group = canvas.addGroup({ 0, 0 })
|
||||
local text = group.addText({ 5, 5 }, "")
|
||||
|
||||
text.setText("this is NOT a client")
|
||||
|
||||
local moduleText = group.addText({ 5, 15 }, table.concat(modules, "\n"))
|
||||
moduleText.setScale(0.5)
|
||||
local function enableModule(module)
|
||||
table.insert(modules, module)
|
||||
moduleText.setText(table.concat(modules, "\n"))
|
||||
end
|
||||
|
||||
local function disableModule(module)
|
||||
local idx = getIndex(modules, module)
|
||||
table.remove(modules, idx)
|
||||
moduleText.setText(table.concat(modules, "\n"))
|
||||
end
|
||||
|
||||
local function isModuleEnabled(module)
|
||||
local idx = getIndex(modules, module)
|
||||
return idx ~= nil
|
||||
end
|
||||
|
||||
function checkKey()
|
||||
while true do
|
||||
local event, key, is_held = os.pullEvent("key")
|
||||
if keys.getName(key) == "g" then
|
||||
if isModuleEnabled("flight") then
|
||||
disableModule("flight")
|
||||
else
|
||||
enableModule("flight")
|
||||
timer = os.startTimer(0.5)
|
||||
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
|
||||
end
|
||||
|
||||
function flyEvent()
|
||||
while true do
|
||||
local _, tid = os.pullEvent("timer")
|
||||
if tid == timer and isModuleEnabled("flight") then
|
||||
timer = os.startTimer(0.5)
|
||||
kinetic.launch(0, -90, 4);
|
||||
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
|
||||
end
|
||||
|
||||
parallel.waitForAll(checkKey, flyEvent)
|
||||
parallel.waitForAny(mscan, recenter)
|
||||
Loading…
Add table
Add a link
Reference in a new issue