Advertisement
_DudeWhat_

cellfarm

Dec 7th, 2022 (edited)
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local rs = peripheral.find("redstoneIntegrator")
  2. if not rs then error("No redstone integrator") end
  3. local dandelifeon = "south"
  4. local destructor = "north"
  5. local constructor = "up"
  6. local placer = "east"
  7. local lever = "west"
  8. local cancellationPending = false
  9.  
  10. local function pulse(direction, duration)
  11.     if not duration then duration = 1 end
  12.     rs.setOutput(direction, true)
  13.     sleep(duration)
  14.     rs.setOutput(direction, false)
  15. end
  16.  
  17. local function initOutput(direction)
  18.     rs.setOutput(direction, false)
  19. end
  20.  
  21. initOutput(dandelifeon)
  22. initOutput(destructor)
  23. initOutput(constructor)
  24. initOutput(placer)
  25.  
  26. local function main()
  27.     print("Cellular Block Farm")
  28.     while not cancellationPending do
  29.         if rs.getInput(lever) then
  30.             print("Running Dandelifeon...")
  31.             pulse(placer)
  32.             pulse(dandelifeon, 50 + 2)
  33.             print("Dandelifon cycle finished")
  34.         else
  35.             pulse(destructor)
  36.             pulse(constructor)
  37.             pulse(dandelifeon, 2)
  38.         end
  39.     end
  40.     print("Okay, finished cleanup, goodbye...")
  41. end
  42.  
  43. local function canceller()
  44.     local oldPullEvent = os.pullEvent
  45.     os.pullEvent = os.pullEventRaw
  46.     print("Program is running now, hold Ctrl+T (terminate) to shutdown.")
  47.     while true do
  48.         local event = os.pullEventRaw("terminate")
  49.         if event == "terminate" then
  50.             os.pullEvent = oldPullEvent
  51.             print("Cancellation was requested, finishing up safely...")
  52.             cancellationPending = true
  53.             return
  54.         end
  55.     end
  56. end
  57.  
  58. parallel.waitForAll(main, canceller)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement