Advertisement
9551

Untitled

Jul 5th, 2021
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.66 KB | None | 0 0
  1. local arg = ...
  2.  
  3. term.clear()
  4. term.setCursorPos(1, 1)
  5. term.write("loading VR")
  6. local mid = {285, 58, 1604}
  7. local maxspace = {4, 2, 4}
  8. local pers = peripheral.wrap("back")
  9. local c = pers.canvas()
  10. local RGB = require("cRGB")
  11. local b = require("button").terminal
  12. rednet.open("right")
  13. pers.canvas3d().clear()
  14. local function center()
  15.     c3d = pers.canvas3d().create()
  16.     local x, y, z = gps.locate()
  17.     local wanted = mid
  18.     c3d.recenter(
  19.         {
  20.             wanted[1] - x - 1,
  21.             wanted[2] - y - 3,
  22.             wanted[3] - z - 1
  23.         }
  24.     )
  25. end
  26. if not arg then
  27.     arg = "gray"
  28. end
  29. center()
  30. c.clear()
  31. sleep(1)
  32. local rect = c.addRectangle(1, 1, 42, 15)
  33. local text = c.addText({3, 5}, "")
  34. text.setColor(RGB.conv(colors.white))
  35. text.setText("loading...")
  36. local function VR()
  37.     rect.setColor(RGB.conv(colors.red))
  38.     local function renderroom()
  39.         rednet.send(165, "l 32 32 32")
  40.         sleep(3)
  41.         walls = {}
  42.         function wallsrender()
  43.             walls[1] = c3d.addBox(-3, 3.9, -3, 9, 0.1, 9)
  44.             walls[2] = c3d.addBox(6, 0.5, -3, -9.1, 3.9, 0.1)
  45.             walls[3] = c3d.addBox(6, 0.5, 5.9, -9, 3.9, 0.1)
  46.             walls[4] = c3d.addBox(5.8, 0.5, 6, 0.1, 3.9, -9)
  47.             walls[5] = c3d.addBox(-2.8, 0.5, 6, 0.1, 3.9, -9)
  48.             walls[6] = c3d.addBox(-3, 0.5, -3, 9, 0.1, 9)
  49.         end
  50.         wallsrender()
  51.         for i = 1, 51 do
  52.             for x = 1, 6 do
  53.                 walls[x].setAlpha(i * 5)
  54.                 walls[x].setColor(RGB.conv(colors[arg]))
  55.             end
  56.             sleep(0.05)
  57.         end
  58.     end
  59.     renderroom()
  60.     ---------SETUP------------
  61.     --  local test = c3d.addBox(1, 2, 1, 1, 1, 1)
  62.     local item = c3d.addItem({1, 1, 1, 2}, "minecraft:bed")
  63.     --test.setColor(RGB.conv(colors.red))
  64.     --------------------------
  65.     while true do
  66.         local click = b.timetouch(0.1)
  67.         local pos = {gps.locate(0.05)}
  68.         local safety = pos
  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.         term.setCursorPos(1, 2)
  84.         print("if this doesnt work spam |exit VR| until it does")
  85.         if b.button(1, click, 1, 1, "exit VR") then
  86.             pers.canvas3d().clear()
  87.             center()
  88.             wallsrender()
  89.             for i = 1, 51 do
  90.                 for x = 1, 6 do
  91.                     walls[x].setAlpha(255 - i * 5)
  92.                     walls[x].setColor(RGB.conv(colors[arg]))
  93.                 end
  94.                 sleep(0.05)
  95.             end
  96.             rednet.send(165, "l 0 0 0")
  97.             error("VR ENDED", 0)
  98.             term.clear()
  99.         end
  100.         -----------main-----------
  101.         local gp = {item.getPosition()}
  102.         if gp[1] > 3 then
  103.             state = false
  104.         elseif gp[1] < 1 then
  105.             state = true
  106.         end
  107.         if state then
  108.             item.setPosition(gp[1] + 0.1, gp[2], gp[3])
  109.         else
  110.             item.setPosition(gp[1] - 0.1, gp[2], gp[3])
  111.         end
  112.         --------------------------
  113.     end
  114. end
  115.  
  116. local ok, err = pcall(VR)
  117. if not ok then
  118.     term.clear()
  119.     print("VR has stopped:\n" .. err)
  120.     pers.canvas3d().clear()
  121.     pers.canvas().clear()
  122. end
  123.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement