Advertisement
robocyclone

wither skele farm.lua

Apr 2nd, 2023
643
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.00 KB | None | 0 0
  1. --[[USER CONFIG VARIABLES]]
  2.  
  3. MONITOR_NAME = "monitor_0" --gathered by using a wired modem; alternatively, directly connect the monitor to the computer
  4. WITHER_OFF_TIME = 5 --in seconds; how long the cooldown is before spawner turns on
  5. WITHER_ON_TIME = 10 --in seconds; how long the spawner stays on per cycle
  6. RS_OUT = "right" --string relative side
  7. START_ON = true
  8.  
  9. --[[----------------------------------------------------------------]]
  10.  
  11. local monitor = peripheral.wrap(MONITOR_NAME) --Initialize monitor
  12.  
  13. if not monitor then --Check if monitor is wired, adjacent, or missing
  14.     monitor = peripheral.find("monitor")
  15.     if not monitor then
  16.         error("Monitor not found! Double check peripheral name.")
  17.     end
  18. end
  19.  
  20.  
  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 = START_ON
  28. rs.setOutput(RS_OUT, switch)
  29. local eng = {[true] = "Running", [false] = "OFF"} --Used to translate bools to ON/OFF for user readability
  30. local offTimer = os.startTimer(WITHER_ON_TIME)
  31. local onTimer --to be initialized later
  32.  
  33. local function termDraw()
  34.     term.clear()
  35.     term.setCursorPos(1,1)
  36.     write("Wither Skeleton Farm")
  37.     term.setCursorPos(4, 4)
  38.     write("\n STATUS: " .. eng[switch])
  39. end
  40.  
  41. function Main() --Event handling and loop
  42.     termDraw()
  43.     rs.setOutput(RS_OUT, switch)
  44.     while true do
  45.         local e, p = os.pullEvent()
  46.         if e == "timer" and p == offTimer then
  47.             if switch then
  48.                 switch = not switch
  49.                 onTimer = os.startTimer(WITHER_OFF_TIME)
  50.                 Main()
  51.             end
  52.         elseif e == "timer" and p == onTimer then
  53.             if switch then
  54.                 switch = not switch
  55.                 offTimer = os.startTimer(WITHER_ON_TIME)
  56.                 Main()
  57.             end
  58.         elseif e == "monitor_touch" then
  59.             switch = not switch
  60.             Main()
  61.         end
  62.     end
  63. end
  64. Main()
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement