tompy90

Sorter

May 8th, 2013
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. local hibernationCount = 0 --variable to count the number of inactive cycles
  2.  
  3. function compare()
  4. if turtle.getItemCount(1) > 0 then --checks to see if there is an item in the active slot
  5. hibernationCount = 0 --resets hibernation count
  6. print("item in sorting slot...")
  7. for i=2,16 do --cycles through all sorting slots
  8. if turtle.compareTo(i) then --checks to see if item in active slot compares to sorting slots
  9. print("item is an ore")
  10. while not turtle.dropDown(turtle.getItemCount(1)) do --drops item down if it compares to sorting slot, if it returns false, it waits and emits a redstone signal
  11. redstone.setOutput("top", true)
  12. sleep(1)
  13. print("chest Full...")
  14. redstone.setOutput("top", false)
  15. sleep(1)
  16. end
  17. return
  18. end
  19. end
  20. while not turtle.drop(turtle.getItemCount(1)) do -- attemps to drop item forward, if it fails, it waits and emits a redstone signal
  21. print("jam ahead...")
  22. sleep(5)
  23. end
  24. print("item is NOT an ore")
  25. else
  26. print("waiting for item...")
  27. sleep(0.5)
  28. hibernationCount = hibernationCount + 1
  29. if hibernationCount > 10 then --if compare function runs more than 10x, the turtle hibernates for 5 seconds
  30. print("hibernating...")
  31. sleep(5)
  32. for i=2,16 do
  33. if turtle.getItemCount(i) > 1 then --turns any stacks of items in the sorting slots into single items, is a housekeeping function
  34. turtle.select(i)
  35. turtle.dropDown(turtle.getItemCount(i)-1)
  36. turtle.select(1)
  37. end
  38. end
  39. end
  40. end
  41. end
  42.  
  43. while true do
  44. compare()
  45. end
Advertisement
Add Comment
Please, Sign In to add comment