Advertisement
9551

Untitled

Jul 4th, 2021 (edited)
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.45 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. ---------SETUP------------
  55.   --  local test = c3d.addBox(1, 2, 1, 1, 1, 1)
  56.     local item = c3d.addItem({1,2,1,2},"computercraft:computer")
  57.     --test.setColor(RGB.conv(colors.red))
  58. --------------------------
  59.     while true do
  60.         local click = b.timetouch(0.1)
  61.         local pos = {gps.locate(0.05)}
  62.         if next(pos) then
  63.             pos = {
  64.                 math.min(math.floor(pos[1] - mid[1]), maxspace[1]),
  65.                 math.min(math.ceil(pos[2] - mid[2]), maxspace[2]),
  66.                 math.min(math.floor(pos[3] - mid[3]), maxspace[3])
  67.             }
  68.             pos = {
  69.                 math.max(pos[1], maxspace[1] - maxspace[1] * 2),
  70.                 math.max(pos[2], maxspace[2] - maxspace[2] * 2),
  71.                 math.max(pos[3], maxspace[3] - maxspace[3] * 2)
  72.             }
  73.         end
  74.         text.setText(table.concat(pos, " "))
  75.         term.clear()
  76.         term.setCursorPos(1,2)
  77.         print("if this doesnt work spam |exit VR| until it does")
  78.         if b.button(1, click, 1, 1, "exit VR") then
  79.             pers.canvas3d().clear()
  80.             center()
  81.             wallsrender()
  82.             for i = 1, 51 do
  83.                 for x = 1, 6 do
  84.                     walls[x].setAlpha(255 - i * 5)
  85.                 end
  86.                 sleep(0.05)
  87.             end
  88.             rednet.send(165, "l 0 0 0")
  89.             error("VR ENDED", 0)
  90.             term.clear()
  91.         end
  92.         -----------main-----------
  93.         local gp = {item.getPosition()}
  94.         if gp[1] > 3 then
  95.             state = false
  96.         elseif gp[1] < 1 then
  97.             state = true
  98.         end
  99.         if state then
  100.             item.setPosition(gp[1]+0.1,gp[2],gp[3])
  101.         else
  102.             item.setPosition(gp[1]-0.1,gp[2],gp[3])
  103.         end
  104.         --------------------------
  105.     end
  106. end
  107.  
  108. local ok, err = pcall(VR)
  109. if not ok then
  110.     term.clear()
  111.     print("VR has stopped:\n" .. err)
  112.     pers.canvas3d().clear()
  113.     pers.canvas().clear()
  114. end
  115.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement