robocyclone

wither farm pc.lua

Mar 28th, 2023
1,080
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.41 KB | None | 0 0
  1. --[[USER CONFIG VARIABLES]]
  2.  
  3. MONITOR_NAME = "monitor_2" --gathered by using a wired modem; alternatively, directly connect the monitor to the computer
  4. WITHER_SPAWN_DELAY = 2 --in seconds
  5. WITHER_HEAD_CLEAR_DELAY = 300 --in seconds
  6. --RELAY LOCATIONS: These must either be adjacent to the computer, or connected to that side of the computer in the world with redstone
  7. SOUL_SAND_RELAY = "bottom" --Replace these sides with whatever side your relays are on that will control each part of construction
  8. HEAD_RELAY = "right"
  9. CLEAR_RELAY = "left"
  10.  
  11. --[[]]
  12.  
  13. local monitor = peripheral.wrap(MONITOR_NAME) --Initialize monitor
  14.  
  15. if not monitor then --Check if monitor is wired, adjacent, or missing
  16.     monitor = peripheral.find("monitor")
  17.     if not monitor then
  18.         error("Monitor not found! Double check peripheral name.")
  19.     end
  20. end
  21.  
  22. term.clear()
  23. term.setCursorPos(1,1)
  24. term.write("Running!") --Give an output to computer before swapping print output to monitor
  25.  
  26. term.redirect(monitor)
  27. local switch = false
  28. local eng = {[true] = "ON", [false] = "OFF"} --Used to translate bools to ON/OFF for user readability
  29. local timer = os.startTimer(WITHER_SPAWN_DELAY)
  30. local headsTimer = os.startTimer(0) --set to 0 to immediately clear heads when run, just in case
  31.  
  32. local function oneThenTwo()
  33.     rs.setOutput(SOUL_SAND_RELAY, true) --Build frame
  34.     os.sleep(1)
  35.     rs.setOutput(SOUL_SAND_RELAY, false)
  36.     os.sleep(.5)
  37.     rs.setOutput(HEAD_RELAY, true) --Build head
  38.     os.sleep(1)
  39.     rs.setOutput(HEAD_RELAY, false)
  40. end
  41.  
  42. local function clearHeads()
  43.     rs.setOutput(CLEAR_RELAY, true)
  44.     os.sleep(3)
  45.     rs.setOutput(CLEAR_RELAY, false)
  46. end
  47.  
  48. local function termDraw()
  49.     term.clear()
  50.     term.setCursorPos(1,1)
  51.     write("Wither Farm")
  52.     term.setCursorPos(4, 4)
  53.     write("\n STATUS: " .. eng[switch])
  54. end
  55.  
  56. function Main() --Event handling and loop
  57.     termDraw()
  58.     while true do
  59.         local e, p = os.pullEvent()
  60.         if e == "timer" and p == timer then
  61.             if switch then
  62.                 oneThenTwo()
  63.             end
  64.             timer = os.startTimer(WITHER_SPAWN_DELAY)
  65.         elseif e == "timer" and p == headsTimer then
  66.             if switch then
  67.                 clearHeads()
  68.             end
  69.             headsTimer = os.startTimer(WITHER_HEAD_CLEAR_DELAY)
  70.         elseif e == "monitor_touch" then
  71.             switch = not switch
  72.             Main()
  73.         end
  74.     end
  75. end
  76. Main()
  77.  
Advertisement
Add Comment
Please, Sign In to add comment