Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mid = {285, 58, 1604}
- local maincompID = 165
- local dcolor = "white"
- local function setup()
- -- local test = c3d.addBox(1, 2, 1, 1, 1, 1)
- item = c3d.addItem({1, 2, 1, 2}, "computercraft:computer")
- --test.setColor(RGB.conv(colors.red))
- end
- local function main(safety)
- local gp = {item.getPosition()}
- if gp[1] > 3 then
- state = false
- elseif gp[1] < 1 then
- state = true
- end
- if state then
- item.setPosition(gp[1] + 0.05, gp[2], gp[3])
- else
- item.setPosition(gp[1] - 0.05, gp[2], gp[3])
- end
- if (safety[2] or 0) >= 1 then
- -- playSound("entity.ghast.death",3,3)
- end
- term.setCursorPos(1, 5)
- local pos = readposition()
- print("X: "..pos[1])
- print("Y: "..pos[2])
- print("Z: "..pos[3])
- end
- local arg = ...
- term.clear()
- term.setCursorPos(1, 1)
- term.write("loading VR")
- local maxspace = {4, 2, 4}
- local pers = peripheral.wrap("back")
- local c = pers.canvas()
- local RGB = require("./cRGB")
- local b = require("./button").terminal
- local lamp = require("./CLamp")
- rednet.open("right")
- pers.canvas3d().clear()
- local function center()
- c3d = pers.canvas3d().create()
- local x, y, z = gps.locate()
- local wanted = mid
- c3d.recenter(
- {
- wanted[1] - x - 1,
- wanted[2] - y - 3,
- wanted[3] - z - 1
- }
- )
- end
- if not arg then
- arg = dcolor
- end
- center()
- c.clear()
- sleep(1)
- local rect = c.addRectangle(1, 1, 42, 15)
- local text = c.addText({3, 5}, "")
- text.setColor(RGB.conv(colors.white))
- text.setText("loading...")
- local function VR()
- rect.setColor(RGB.conv(colors.red))
- local function renderroom()
- rednet.send(maincompID, "l 32 32 32")
- sleep(3)
- walls = {}
- function wallsrender()
- walls[1] = c3d.addBox(-3, 3.9, -3, 9, 0.1, 9)
- walls[2] = c3d.addBox(6, 0.5, -3, -9.1, 3.9, 0.1)
- walls[3] = c3d.addBox(6, 0.5, 5.9, -9, 3.9, 0.1)
- walls[4] = c3d.addBox(5.8, 0.5, 6, 0.1, 3.9, -9)
- walls[5] = c3d.addBox(-2.8, 0.5, 6, 0.1, 3.9, -9)
- walls[6] = c3d.addBox(-3, 0.5, -3, 9, 0.1, 9)
- end
- wallsrender()
- for i = 1, 51 do
- for x = 1, 6 do
- walls[x].setAlpha(i * 5)
- walls[x].setColor(RGB.conv(colors[arg]))
- end
- sleep(0.05)
- end
- end
- renderroom()
- setup()
- while true do
- local click = b.timetouch(0.1)
- local pos = {gps.locate(0.05)}
- local safety = pos
- --local safety = {(safety[1] or mid[1])-mid[1],(safety[2] or mid[2])-mid[2],(safety[3] or mid[3])-mid[3]}
- if next(pos) then
- pos = {
- math.min(math.floor(pos[1] - mid[1]), maxspace[1]),
- math.min(math.ceil(pos[2] - mid[2]), maxspace[2]),
- math.min(math.floor(pos[3] - mid[3]), maxspace[3])
- }
- pos = {
- math.max(pos[1], maxspace[1] - maxspace[1] * 2),
- math.max(pos[2], maxspace[2] - maxspace[2] * 2),
- math.max(pos[3], maxspace[3] - maxspace[3] * 2)
- }
- end
- text.setText(table.concat(pos, " "))
- term.clear()
- term.setCursorPos(1, 2)
- print("if this doesnt work spam |exit VR| until it does")
- term.setBackgroundColor(colors.red)
- if b.button(1, click, 1, 1, "exit VR") then
- term.setBackgroundColor(colors.black)
- pers.canvas3d().clear()
- center()
- wallsrender()
- for i = 1, 51 do
- for x = 1, 6 do
- walls[x].setAlpha(255 - i * 5)
- walls[x].setColor(RGB.conv(colors[arg]))
- end
- sleep(0.05)
- end
- error("VR ENDED", 0)
- term.clear()
- end
- term.setBackgroundColor(colors.black)
- main(pos)
- end
- end
- ---------------------APIs---------------------
- function playNote(ins, vol, pitch)
- rednet.send(maincompID, {"API", "speakern", ins, vol, pitch})
- end
- function playSound(ins, vol, pitch)
- rednet.send(maincompID, {"API", "speakers", ins, vol, pitch})
- end
- function setLamp(id, col, col2, col3)
- rednet.send(maincompID, {"API", "lamp", id, lamp.rgb(col, col2, col3)})
- end
- function readposition()
- local pos = {gps.locate()}
- if next(pos) then
- pos = {
- math.min(pos[1] - mid[1], maxspace[1]),
- math.min(pos[2] - mid[2], maxspace[2]),
- math.min(pos[3] - mid[3], maxspace[3])
- }
- pos = {
- math.max(pos[1], maxspace[1] - maxspace[1] * 2),
- math.max(pos[2], maxspace[2] - maxspace[2] * 2)+0.87999999999999545,
- math.max(pos[3], maxspace[3] - maxspace[3] * 2)
- }
- end
- return pos
- end
- ----------------------------------------------
- local ok, err = pcall(VR)
- if not ok then
- term.clear()
- print("VR has stopped:\n" .. err)
- pers.canvas3d().clear()
- if err ~= "VR ENDED" then
- center()
- wallsrender()
- for i = 1, 51 do
- for x = 1, 6 do
- walls[x].setAlpha(255 - i * 5)
- walls[x].setColor(RGB.conv(colors[arg]))
- end
- sleep(0.05)
- end
- end
- rednet.send(maincompID, "l 0 0 0")
- rednet.send(maincompID, "end")
- pers.canvas().clear()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement