downwind

AE2 Crystal Growing program for Turtle

Apr 22nd, 2023 (edited)
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.21 KB | Gaming | 0 0
  1. --[[ AE2 Crystal Grower LiLRichy Edit - 04/22/2023 ]]--
  2. --[[ Change Log:
  3. Version 1.0.1
  4.     - Changed to use only the last inventory slot as the compare slot
  5.     - Increased inventory to all but the last slot
  6.     - Decreased the idle time a bit
  7.     - Added variable for the side to emit Redstone
  8.     - Fix items being left after one stack is picked up
  9.     - Fix "working" spam in terminal
  10.     - Code cleanup
  11.    
  12. Version 1.0.0
  13.     - Initial Edit
  14. ]]--
  15.  
  16. local side = "back"                 -- The side to emit the redstone signal when work is being done
  17. local iteration = 0
  18. rs.setOutput(side, false)           -- turn off redstone
  19. turtle.suckDown()                   -- clear the pool
  20. term.setBackgroundColor(colors.black)
  21. term.setTextColor(colors.white)
  22. term.clear()
  23. term.setCursorPos(2, 2)
  24.  
  25. local function checkForSource()     -- If anything is in slot 16 we have a crystal for comparison
  26.     if turtle.getItemCount(16) > 0 then return true
  27.     end
  28.   return false
  29. end
  30.  
  31. local function checkForWork()       -- If anything is in slots 1-15 we have work to do
  32.   for i = 1, 15 do
  33.     if turtle.getItemCount(i) > 0 then return true
  34.     end
  35.   end
  36.   return false
  37. end
  38.  
  39. local function checkWorkStatus()    -- Check the status of the work-in-progress
  40.   for i = 1, 15 do                  
  41.     turtle.select(i)
  42.     turtle.suckDown()
  43.       if turtle.compareTo(16) then turtle.dropUp() -- Puts finished items in inventory "UP"
  44.       end
  45.   end
  46. end
  47.  
  48. if not checkForSource() then
  49.   term.write("No comparison crystals")
  50.   term.setCursorPos(1, 4)
  51.   return
  52. end
  53.  
  54. term.write("Processing crystals...")
  55. term.setCursorPos(2, 4)
  56. term.write("Iteration")
  57.  
  58. while true do                       -- Main loop
  59.   iteration = iteration + 1
  60.   term.setCursorPos(12, 4)
  61.   if checkForWork() then            -- Now we can turn on the accelerators
  62.     rs.setOutput(side, true)
  63.     term.write(tostring(iteration) .. ": working")
  64.     for i = 1, 15 do                -- and run a cycle
  65.       turtle.select(i)
  66.       turtle.dropDown()             -- Since we have work, drop the items
  67.     end
  68.     os.sleep(10)                    -- now wait for it to process
  69.     checkWorkStatus()
  70.   else                              -- no more work to do
  71.     rs.setOutput(side, false)
  72.     term.write(tostring(iteration) .. ": idle   ")
  73.     os.sleep(3)                     -- wait to check again
  74.   end
  75. end
Add Comment
Please, Sign In to add comment