Advertisement
HarvDad

nuggets

Oct 22nd, 2014
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. inputFrom = "above"
  2. outputTo = "below"
  3. workSlot = 0
  4. workCount = 0
  5. craftCount = 0
  6. leftovers = 0
  7.  
  8. function intDiv(number, divisor)
  9. count = number
  10. result = 0
  11.  
  12. while count >= 9 do
  13. result = result+1
  14. count = count - divisor
  15. end
  16. return result
  17. end
  18.  
  19. function unloadTurtle()
  20. for i=1,16 do
  21. if turtle.getItemCount(i) > 0 then
  22. turtle.select(i)
  23. returnItems()
  24. end
  25. end
  26. end
  27.  
  28. function suckItems()
  29. if inputFrom == "above" then
  30. turtle.suckUp(9)
  31. else
  32. turtle.suck(9)
  33. end
  34. end
  35.  
  36. function returnItems(count)
  37. if count == nil then
  38. count = 64
  39. end
  40. if inputFrom == "above" then
  41. turtle.dropUp(count)
  42. else
  43. turtle.drop(count)
  44. end
  45. end
  46.  
  47. function unloadCraftedItems()
  48. if outputTo == "front" then
  49. turtle.drop()
  50. else
  51. turtle.dropDown()
  52. end
  53. end
  54.  
  55. print("Version 0.2")
  56.  
  57. while true do
  58.  
  59. -- Load items from input chest
  60.  
  61. for i=1,16 do
  62. turtle.select(i)
  63. suckItems()
  64. if turtle.getItemCount(i) == 9 then
  65. workSlot = i
  66. break
  67. end
  68. end
  69.  
  70. if workSlot > 0 then
  71. if workSlot > 0 then
  72. workCount = turtle.getItemCount(workSlot)
  73.  
  74. -- Unload all but the workSlot items
  75.  
  76. for i=1,16 do
  77. if i ~= workSlot then
  78. if turtle.getItemCount(i) > 0 then
  79. turtle.select(i)
  80. returnItems()
  81. end
  82. end
  83. end
  84.  
  85. -- Move work items to slot 16 temporarily
  86.  
  87. workCount = turtle.getItemCount(workSlot)
  88. turtle.select(workSlot)
  89. turtle.transferTo(16)
  90.  
  91. -- Work out the numbers
  92.  
  93. craftCount = intDiv(workCount, 9)
  94. leftovers = workCount - (craftCount * 9)
  95.  
  96.  
  97. -- Put the leftovers back
  98.  
  99. turtle.select(16)
  100. returnItems(leftovers)
  101.  
  102. -- Load up the crafting slots
  103.  
  104. turtle.transferTo(1, craftCount)
  105. turtle.transferTo(2, craftCount)
  106. turtle.transferTo(3, craftCount)
  107. turtle.transferTo(5, craftCount)
  108. turtle.transferTo(6, craftCount)
  109. turtle.transferTo(7, craftCount)
  110. turtle.transferTo(9, craftCount)
  111. turtle.transferTo(10, craftCount)
  112. turtle.transferTo(11, craftCount)
  113.  
  114. -- Craft it
  115.  
  116. turtle.craft()
  117. turtle.select(16)
  118. unloadCraftedItems()
  119. end
  120. else
  121. unloadTurtle()
  122. sleep(600)
  123. end
  124.  
  125. sleep(0)
  126. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement