surferpup

Minecraft ComputerCraft 3x3 door v 2.4

Nov 13th, 2013
516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.04 KB | None | 0 0
  1. -- 3x3 rednet Piston Door with Monitor Functionality
  2. -- Using ComputerCraft Computer
  3. -- By Surferpup v. 2.4
  4. -- Turns all red net signals off
  5. function clearOutputs()
  6.     for i, side in ipairs(rs.getSides()) do
  7.         rs.setBundledOutput(side,0)
  8.         print(side)
  9.     end
  10. end
  11. -- Toggles Piston
  12. function pulseOnOff(side,color,pulseLength,wait)
  13.     pulseLength=pulseLength or 0
  14.     wait = wait or .08
  15.     local currentState = rs.getBundledOutput(side)
  16.     rs.setBundledOutput(side,currentState+color)
  17.     sleep(pulseLength)
  18.     rs.setBundledOutput(side,currentState)
  19.     sleep(wait)
  20. end
  21. -- New Line function for monitor
  22. function newline(monitor)
  23.     local _,lY=monitor.getSize()
  24.     local _,cY=monitor.getCursorPos()
  25.     print(cY .. " " .. lY)
  26.     if cY>=lY then
  27.        monitor.clear()
  28.        cY=0
  29.     end
  30.     monitor.setCursorPos(1,cY+1)
  31. end    
  32. -- Begin
  33. local mon = peripheral.wrap("monitor_0") -- Comment if no monitor
  34. mon.clear() -- Comment if no monitor
  35. mon.setCursorPos(1,1) -- Comment if no monitor
  36. mon.setTextScale(1) -- Comment if no monitor
  37. clearOutputs()
  38. local input="top"
  39. local side = "top"
  40. while true do
  41.     os.pullEvent("redstone")
  42.     if rs.testBundledInput(input,colors.red) then
  43.         local time = os.time()
  44.         print("Door Opening: " .. textutils.formatTime(time,false))
  45.         mon.write("Door Opening: " .. textutils.formatTime(time,false)) -- Comment if no monitor
  46.         newline(mon) -- Comment if no monitor
  47.         pulseOnOff(side,colors.orange+colors.gray,.09,.12) --3 & 1       --              1   gray
  48.         pulseOnOff(side,colors.blue,.12,.1)   --2                        --             323  orange/pink
  49.         pulseOnOff(side,colors.lightBlue) --5                            --              x   /blue
  50.         pulseOnOff(side,colors.gray+colors.purple,nil,.12) --2           --             BBB
  51.         pulseOnOff(side,colors.pink+colors.yellow,nil,.1) -- 3           --           3 BBB 3
  52.         pulseOnOff(side,colors.lime,.1)                                  --           3 BBB 3  /orange
  53.         pulseOnOff(side,colors.yellow)                                   --             B B
  54.         pulseOnOff(side,colors.purple)                                   --              y 4 lime/purple
  55.         sleep(10)                                                        --              5   lightBlue
  56.         pulseOnOff(side,colors.orange+colors.pink+colors.yellow,nil,.1)  --              6   yellow
  57.         pulseOnOff(side,colors.lime,nil,.1)
  58.         pulseOnOff(side,colors.yellow)
  59.         time = os.time()
  60.         print("Door Reset ".. textutils.formatTime(time,false))
  61.         mon.write("Door Reset ".. textutils.formatTime(time,false)) -- Comment if no monitor
  62.         newline(mon) -- Comment if no monitor
  63.     end
  64. end
  65.  
  66. -- Chart Key
  67. --  B  Door Block (Cobblestone, etc.)
  68. --  1  Sticky Piston gray
  69. --  2  Sticky Piston pink
  70. --  3  Sticky Piston orange
  71. --  4  Sticky Piston purple
  72. --  5  Sticky Piston lightBlue
  73. --  6  Sticky Piston yellow
  74. --  x  Rednet wire connection pink
  75. --  y  Rednet wire connection lime
Advertisement
Add Comment
Please, Sign In to add comment