robocyclone

wither skele farm.lua

Apr 2nd, 2023
677
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.04 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_OFF_TIME = 2 --in seconds; how long the cooldown is before spawner turns on
  5. WITHER_ON_TIME = 25 --in seconds; how long the spawner stays on per cycle
  6. RS_OUT = "right"
  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. --[[on by default w switch
  21. off every 16sec for 4 sec
  22. ]]
  23.  
  24. term.clear()
  25. term.setCursorPos(1,1)
  26. term.write("Running!") --Give an output to computer before swapping print output to monitor
  27.  
  28. term.redirect(monitor)
  29. local switch = START_ON
  30. rs.setOutput(RS_OUT, switch)
  31. local eng = {[true] = "Running", [false] = "Collecting drops..."} --Used to translate bools to ON/OFF for user readability
  32. local offTimer = os.startTimer(WITHER_ON_TIME)
  33. local onTimer --to be initialized later
  34.  
  35. local function termDraw()
  36.     term.clear()
  37.     term.setCursorPos(1,1)
  38.     write("Wither Skeleton Farm")
  39.     term.setCursorPos(4, 4)
  40.     write("\n STATUS: " .. eng[switch])
  41. end
  42.  
  43. function Main() --Event handling and loop
  44.     termDraw()
  45.     rs.setOutput(RS_OUT, switch)
  46.     while true do
  47.         local e, p = os.pullEvent()
  48.         if e == "timer" and p == offTimer then
  49.             if switch then
  50.                 switch = not switch
  51.                 onTimer = os.startTimer(WITHER_OFF_TIME)
  52.                 Main()
  53.             end
  54.         elseif e == "timer" and p == onTimer then
  55.             if switch then
  56.                 switch = not switch
  57.                 offTimer = os.startTimer(WITHER_ON_TIME)
  58.                 Main()
  59.             end
  60.         elseif e == "monitor_touch" then
  61.             switch = not switch
  62.             Main()
  63.         end
  64.     end
  65. end
  66. Main()
  67.  
Advertisement
Add Comment
Please, Sign In to add comment