DabDaddy6223

airlock_controller

Jun 23rd, 2026 (edited)
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.88 KB | None | 0 0
  1. -- API --------------------------------------------------
  2.  
  3. local w, h = term.getSize()
  4.  
  5. function printCentered(y, str)
  6.    local x = math.floor((w - string.len(str)) / 2)
  7.    term.setCursorPos(x, y)
  8.    term.clearLine()
  9.    term.write(str)
  10. end
  11.  
  12. function printThird(y, third, str)
  13.     local third_width = w / 3
  14.  
  15.     -- Centre position of the requested third
  16.     local centre_x = (third - 0.5) * third_width
  17.  
  18.     local x = math.floor(centre_x - (#str / 2))
  19.  
  20.     term.setCursorPos(x, y)
  21.     term.write(str)
  22. end
  23.  
  24. function hasValue (tab, val)
  25.     for index, value in ipairs(tab) do
  26.         if value == val then
  27.             return true
  28.         end
  29.     end
  30.  
  31.     return false
  32. end
  33.  
  34. function printKeys(tab)
  35.     -- Source - https://stackoverflow.com/a/12674376
  36.     -- Posted by lhf
  37.     -- Retrieved 2026-06-11, License - CC BY-SA 3.0
  38.  
  39.     local keyset={}
  40.     local n=0
  41.  
  42.     for k,v in pairs(tab) do
  43.         n=n+1
  44.         keyset[n]=k
  45.     end
  46.  
  47.     print(textutils.serialise(keyset))
  48. end
  49.  
  50. function printTable(tab)
  51.     for key, val in pairs(tab) do
  52.         print(tostring(key) .. ": " .. tostring(val))
  53.     end
  54. end
  55.  
  56. ---------------------------------------------------------
  57.  
  58. -- State here is defined as false=closed,true=open
  59. -- The Airlock door that transitions from planet to airlock
  60. local airlock_enter_state = false
  61. -- The Airlock door that transitions from airlock to inside
  62. local airlock_exit_state = false
  63.  
  64. function main()
  65.     local airlock_enter_state_reader = peripheral.find("blockReader")
  66.     printTable(airlock_enter_state_reader.getBlockStates())
  67.     airlock_enter_state = airlock_enter_state_reader.getBlockStates()["open"]
  68.  
  69.     print(airlock_enter_state)
  70.  
  71.     while true do
  72.         if redstone.getInput("back") == true then
  73.             print("Button Pressed!")
  74.             break
  75.         end
  76.  
  77.         os.sleep(0.1)
  78.     end
  79. end
  80.  
  81. main()
Advertisement
Add Comment
Please, Sign In to add comment