Advertisement
robocyclone

wither skele farm.lua

Apr 2nd, 2023
685
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.15 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. local userSwitch = START_ON
  29. rs.setOutput(RS_OUT, switch)
  30. local eng = {
  31.     [true] = {"ON", "Running..."},
  32.     [false] = {"OFF", "Collecting drops"}
  33. } --Used to translate bools to ON/OFF for user readability
  34. local offTimer = os.startTimer(WITHER_ON_TIME)
  35. local onTimer --to be initialized later
  36.  
  37. local function termDraw()
  38.     term.clear()
  39.     term.setCursorPos(1,1)
  40.     write("Wither Skeleton Farm")
  41.     term.setCursorPos(4, 4)
  42.     write("\n STATUS: " .. eng[switch][2] .. "\n\n User Control: " .. eng[userSwitch][1])
  43. end
  44.  
  45. function Main() --Event handling and loop
  46.     termDraw()
  47.     rs.setOutput(RS_OUT, switch)
  48.     while true do
  49.         local e, p = os.pullEvent()
  50.         if e == "timer" and p == offTimer then
  51.             if switch and userSwitch then
  52.                 switch = false
  53.                 onTimer = os.startTimer(WITHER_OFF_TIME)
  54.                 Main()
  55.             end
  56.         elseif e == "timer" and p == onTimer then
  57.             if not switch and userSwitch then
  58.                 switch = true
  59.                 offTimer = os.startTimer(WITHER_ON_TIME)
  60.                 Main()
  61.             end
  62.         elseif e == "monitor_touch" then
  63.             userSwitch = not userSwitch
  64.             Main()
  65.         end
  66.     end
  67. end
  68. Main()
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement