Advertisement
9551

Untitled

Jul 4th, 2021 (edited)
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.08 KB | None | 0 0
  1. term.clear()
  2. term.setCursorPos(1, 1)
  3. term.write("loading VR")
  4. local mid = {285, 58, 1604}
  5. local maxspace = {4, 2, 4}
  6. local pers = peripheral.wrap("back")
  7. local c = pers.canvas()
  8. local RGB = require("cRGB")
  9. local b = require("button").terminal
  10. rednet.open("right")
  11. pers.canvas3d().clear()
  12. local function center()
  13.     c3d = pers.canvas3d().create()
  14.     local x, y, z = gps.locate()
  15.     local wanted = mid
  16.     c3d.recenter(
  17.         {
  18.             wanted[1] - x - 1,
  19.             wanted[2] - y - 3,
  20.             wanted[3] - z - 1
  21.         }
  22.     )
  23. end
  24. center()
  25. c.clear()
  26. sleep(1)
  27. local rect = c.addRectangle(1, 1, 42, 15)
  28. local text = c.addText({3, 5}, "")
  29. text.setColor(RGB.conv(colors.white))
  30. text.setText("loading...")
  31. local function VR()
  32.     rect.setColor(RGB.conv(colors.red))
  33.     local function renderroom()
  34.         rednet.send(165, "l 32 32 32")
  35.         sleep(3)
  36.         walls = {}
  37.         function wallsrender()
  38.             walls[1] = c3d.addBox(-3, 3.9, -3, 9, 0.1, 9)
  39.             walls[2] = c3d.addBox(6, 0.5, -3, -9.1, 3.9, 0.1)
  40.             walls[3] = c3d.addBox(6, 0.5, 5.9, -9, 3.9, 0.1)
  41.             walls[4] = c3d.addBox(5.8, 0.5, 6, 0.1, 3.9, -9)
  42.             walls[5] = c3d.addBox(-2.8, 0.5, 6, 0.1, 3.9, -9)
  43.             walls[6] = c3d.addBox(-3, 0.5, -3, 9, 0.1, 9)
  44.         end
  45.         wallsrender()
  46.         for i = 1, 51 do
  47.             for x = 1, 6 do
  48.                 walls[x].setAlpha(i * 5)
  49.             end
  50.             sleep(0.05)
  51.         end
  52.     end
  53.     renderroom()
  54.     local test = c3d.addBox(1, 2, 1, 1, 1, 1)
  55.     test.setColor(RGB.conv(colors.red))
  56.     while true do
  57.         for i = 1,30 do
  58.             local gp = test.getPosition()
  59.             test.setPostition(gp[1],gp[2],gp[3]+0.1)
  60.             sleep(0.1)
  61.         end
  62.         for i = 1,30 do
  63.             local gp = test.getPosition()
  64.             test.setPostition(gp[1],gp[2],gp[3]-0.1)
  65.             sleep(0.1)
  66.         end
  67.         local click = b.timetouch(0.2)
  68.         local pos = {gps.locate(0.5)}
  69.         if next(pos) then
  70.             pos = {
  71.                 math.min(math.floor(pos[1] - mid[1]), maxspace[1]),
  72.                 math.min(math.ceil(pos[2] - mid[2]), maxspace[2]),
  73.                 math.min(math.floor(pos[3] - mid[3]), maxspace[3])
  74.             }
  75.             pos = {
  76.                 math.max(pos[1], maxspace[1] - maxspace[1] * 2),
  77.                 math.max(pos[2], maxspace[2] - maxspace[2] * 2),
  78.                 math.max(pos[3], maxspace[3] - maxspace[3] * 2)
  79.             }
  80.         end
  81.         text.setText(table.concat(pos, " "))
  82.         term.clear()
  83.         if b.button(1, click, 1, 1, "exit VR") then
  84.             pers.canvas3d().clear()
  85.             center()
  86.             wallsrender()
  87.             for i = 1, 51 do
  88.                 for x = 1, 6 do
  89.                     walls[x].setAlpha(255 - i * 5)
  90.                 end
  91.                 sleep(0.05)
  92.             end
  93.             rednet.send(165, "l 0 0 0")
  94.             error("VR ENDED", 0)
  95.             term.clear()
  96.         end
  97.     end
  98. end
  99.  
  100. local ok, err = pcall(VR)
  101. if not ok then
  102.     term.clear()
  103.     print("VR has stopped:\n" .. err)
  104.     pers.canvas3d().clear()
  105.     pers.canvas().clear()
  106. end
  107.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement