Advertisement
9551

VR

Jul 5th, 2021 (edited)
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.42 KB | None | 0 0
  1. local mid = {285, 58, 1604}
  2. local maincompID = 165
  3.  
  4. local dcolor = "white"
  5. local function setup()
  6.     --  local test = c3d.addBox(1, 2, 1, 1, 1, 1)
  7.     item = c3d.addItem({1, 2, 1, 2}, "computercraft:computer")
  8.     --test.setColor(RGB.conv(colors.red))
  9. end
  10.  
  11. local function main(safety)
  12.     local gp = {item.getPosition()}
  13.     if gp[1] > 3 then
  14.         state = false
  15.     elseif gp[1] < 1 then
  16.         state = true
  17.     end
  18.     if state then
  19.         item.setPosition(gp[1] + 0.05, gp[2], gp[3])
  20.     else
  21.         item.setPosition(gp[1] - 0.05, gp[2], gp[3])
  22.     end
  23.     if (safety[2] or 0) >= 1 then
  24.     --  playSound("entity.ghast.death",3,3)
  25.     end
  26.     term.setCursorPos(1, 5)
  27.     local pos = readposition()
  28.     print("X: "..pos[1])
  29.     print("Y: "..pos[2])
  30.     print("Z: "..pos[3])
  31. end
  32.  
  33. local arg = ...
  34. term.clear()
  35. term.setCursorPos(1, 1)
  36. term.write("loading VR")
  37. local maxspace = {4, 2, 4}
  38. local pers = peripheral.wrap("back")
  39. local c = pers.canvas()
  40. local RGB = require("./cRGB")
  41. local b = require("./button").terminal
  42. local lamp = require("./CLamp")
  43. rednet.open("right")
  44. pers.canvas3d().clear()
  45. local function center()
  46.     c3d = pers.canvas3d().create()
  47.     local x, y, z = gps.locate()
  48.     local wanted = mid
  49.     c3d.recenter(
  50.         {
  51.             wanted[1] - x - 1,
  52.             wanted[2] - y - 3,
  53.             wanted[3] - z - 1
  54.         }
  55.     )
  56. end
  57. if not arg then
  58.     arg = dcolor
  59. end
  60. center()
  61. c.clear()
  62. sleep(1)
  63. local rect = c.addRectangle(1, 1, 42, 15)
  64. local text = c.addText({3, 5}, "")
  65. text.setColor(RGB.conv(colors.white))
  66. text.setText("loading...")
  67. local function VR()
  68.     rect.setColor(RGB.conv(colors.red))
  69.     local function renderroom()
  70.         rednet.send(maincompID, "l 32 32 32")
  71.         sleep(3)
  72.         walls = {}
  73.         function wallsrender()
  74.             walls[1] = c3d.addBox(-3, 3.9, -3, 9, 0.1, 9)
  75.             walls[2] = c3d.addBox(6, 0.5, -3, -9.1, 3.9, 0.1)
  76.             walls[3] = c3d.addBox(6, 0.5, 5.9, -9, 3.9, 0.1)
  77.             walls[4] = c3d.addBox(5.8, 0.5, 6, 0.1, 3.9, -9)
  78.             walls[5] = c3d.addBox(-2.8, 0.5, 6, 0.1, 3.9, -9)
  79.             walls[6] = c3d.addBox(-3, 0.5, -3, 9, 0.1, 9)
  80.         end
  81.         wallsrender()
  82.         for i = 1, 51 do
  83.             for x = 1, 6 do
  84.                 walls[x].setAlpha(i * 5)
  85.                 walls[x].setColor(RGB.conv(colors[arg]))
  86.             end
  87.             sleep(0.05)
  88.         end
  89.     end
  90.     renderroom()
  91.     setup()
  92.     while true do
  93.         local click = b.timetouch(0.1)
  94.         local pos = {gps.locate(0.05)}
  95.         local safety = pos
  96.         --local safety = {(safety[1] or mid[1])-mid[1],(safety[2] or mid[2])-mid[2],(safety[3] or mid[3])-mid[3]}
  97.         if next(pos) then
  98.             pos = {
  99.                 math.min(math.floor(pos[1] - mid[1]), maxspace[1]),
  100.                 math.min(math.ceil(pos[2] - mid[2]), maxspace[2]),
  101.                 math.min(math.floor(pos[3] - mid[3]), maxspace[3])
  102.             }
  103.             pos = {
  104.                 math.max(pos[1], maxspace[1] - maxspace[1] * 2),
  105.                 math.max(pos[2], maxspace[2] - maxspace[2] * 2),
  106.                 math.max(pos[3], maxspace[3] - maxspace[3] * 2)
  107.             }
  108.         end
  109.         text.setText(table.concat(pos, " "))
  110.         term.clear()
  111.         term.setCursorPos(1, 2)
  112.         print("if this doesnt work spam |exit VR| until it does")
  113.         term.setBackgroundColor(colors.red)
  114.         if b.button(1, click, 1, 1, "exit VR") then
  115.             term.setBackgroundColor(colors.black)
  116.             pers.canvas3d().clear()
  117.             center()
  118.             wallsrender()
  119.             for i = 1, 51 do
  120.                 for x = 1, 6 do
  121.                     walls[x].setAlpha(255 - i * 5)
  122.                     walls[x].setColor(RGB.conv(colors[arg]))
  123.                 end
  124.                 sleep(0.05)
  125.             end
  126.             error("VR ENDED", 0)
  127.             term.clear()
  128.         end
  129.         term.setBackgroundColor(colors.black)
  130.         main(pos)
  131.     end
  132. end
  133.  
  134. ---------------------APIs---------------------
  135. function playNote(ins, vol, pitch)
  136.     rednet.send(maincompID, {"API", "speakern", ins, vol, pitch})
  137. end
  138. function playSound(ins, vol, pitch)
  139.     rednet.send(maincompID, {"API", "speakers", ins, vol, pitch})
  140. end
  141. function setLamp(id, col, col2, col3)
  142.     rednet.send(maincompID, {"API", "lamp", id, lamp.rgb(col, col2, col3)})
  143. end
  144. function readposition()
  145.     local pos = {gps.locate()}
  146.     if next(pos) then
  147.         pos = {
  148.             math.min(pos[1] - mid[1], maxspace[1]),
  149.             math.min(pos[2] - mid[2], maxspace[2]),
  150.             math.min(pos[3] - mid[3], maxspace[3])
  151.         }
  152.         pos = {
  153.             math.max(pos[1], maxspace[1] - maxspace[1] * 2),
  154.             math.max(pos[2], maxspace[2] - maxspace[2] * 2)+0.87999999999999545,
  155.             math.max(pos[3], maxspace[3] - maxspace[3] * 2)
  156.         }
  157.     end
  158.     return pos
  159. end
  160.  
  161. ----------------------------------------------
  162.  
  163. local ok, err = pcall(VR)
  164. if not ok then
  165.     term.clear()
  166.     print("VR has stopped:\n" .. err)
  167.     pers.canvas3d().clear()
  168.     if err ~= "VR ENDED" then
  169.         center()
  170.         wallsrender()
  171.         for i = 1, 51 do
  172.             for x = 1, 6 do
  173.                 walls[x].setAlpha(255 - i * 5)
  174.                 walls[x].setColor(RGB.conv(colors[arg]))
  175.             end
  176.             sleep(0.05)
  177.         end
  178.     end
  179.     rednet.send(maincompID, "l 0 0 0")
  180.     rednet.send(maincompID, "end")
  181.     pers.canvas().clear()
  182. end
  183.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement