Advertisement
minecraft_storm

Doorcontrol

Jul 17th, 2025 (edited)
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.12 KB | None | 0 0
  1. -- Door control with bundled cable (More Red + Create + CC:Tweaked)
  2. local modemSide = "top"   -- Wireless modem side
  3. local bundledSide = "back" -- Bundled cable side
  4. local channel = 42         -- Wireless channel to listen on
  5.  
  6. -- Define color bits
  7. local RED   = colors.red
  8. local GREEN = colors.lime
  9. local ORANGE = colors.orange
  10. local BLUE = colors.blue
  11. local LIGHTBLUE = colors.lightBlue
  12. local MAGENTA = colors.magenta
  13. local YELLOW = colors.yellow
  14.  
  15. -- Pulse helper
  16. function pulse(color)
  17.     local output = redstone.getBundledOutput(bundledSide)
  18.     redstone.setBundledOutput(bundledSide, bit.bor(output, color))
  19.     sleep(0.2)
  20.     output = redstone.getBundledOutput(bundledSide)
  21.     redstone.setBundledOutput(bundledSide, bit.band(output, bit.bnot(color)))
  22. end
  23.  
  24. -- Status check
  25. function isDoorClosed()
  26.     local input = redstone.getBundledInput(bundledSide)
  27.     return bit.band(input, MAGENTA) ~= 0
  28. end
  29.  
  30. function isDoorOpen()
  31.     local input = redstone.getBundledInput(bundledSide)
  32.     return bit.band(input, YELLOW) ~= 0
  33. end
  34.  
  35. -- Open door sequence
  36. function openDoor()
  37.     if isDoorOpen() then
  38.         print("Door is already open.")
  39.         return "already_open"
  40.     end
  41.     print("Opening door...")
  42.     -- Set direction to OPEN (Red OFF)
  43.     local output = redstone.getBundledOutput(bundledSide)
  44.     redstone.setBundledOutput(bundledSide, bit.band(output, bit.bnot(RED)))
  45.     sleep(0.1)
  46.     -- start water clearing
  47.     pulse(LIGHTBLUE);
  48.     sleep(5)
  49.  
  50.     -- retract pistons
  51.     pulse(ORANGE)
  52.     sleep(7)
  53.  
  54.     -- Activate BLUE (start sliding door out)
  55.     pulse(BLUE)
  56.     sleep(1.5) -- wait for door to slide out
  57.  
  58.     -- rotate wall in
  59.     pulse(GREEN)
  60.     sleep(0.5) -- allow for piston extension
  61.  
  62.     print("Door opened.")
  63.     return "opened"
  64. end
  65.  
  66. -- Close door sequence
  67. function closeDoor()
  68.     if isDoorClosed() then
  69.         print("Door is already closed.")
  70.         return "already_closed"
  71.     end
  72.     print("Closing door...")
  73.     -- Set direction to CLOSE (Red ON)
  74.     local output = redstone.getBundledOutput(bundledSide)
  75.     redstone.setBundledOutput(bundledSide, bit.bor(output, RED))
  76.  
  77.     -- rotate wall out
  78.     pulse(GREEN)
  79.     sleep(1.5)
  80.     -- rotate pistons
  81.     pulse(BLUE)
  82.     sleep(1.5) -- wait for pistons rotate
  83.     -- extend pistons
  84.     pulse(ORANGE)
  85.     sleep(5) -- allow for door to slide closed
  86.  
  87.     print("Door closed.")
  88.     return "closed"
  89. end
  90.  
  91. -- Setup modem
  92. rednet.open(modemSide)
  93. rednet.host("door_control", "door_server")
  94.  
  95. print("Door controller listening on wireless channel " .. channel)
  96.  
  97. -- Main loop
  98.  
  99. while true do
  100.     local senderId, message = rednet.receive("door_control")
  101.  
  102.     local response = "unknown_command"
  103.     if message == "open" then
  104.         response = openDoor()
  105.     elseif message == "close" then
  106.         response = closeDoor()
  107.     elseif message == "status" then
  108.         if isDoorOpen() then
  109.             response = "door_open"
  110.         elseif isDoorClosed() then
  111.             response = "door_closed"
  112.         else
  113.             response = "door_inbetween"
  114.         end
  115.     end
  116.  
  117.     rednet.send(senderId, response, "door_control")
  118. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement