willisshek

[Minecraft] Mass Crafter

Oct 29th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. ----------------------------------------
  2. -- First argument is the number of craft per time.
  3. -- The following arguments are the slots that you want to skip based on turtle slot index.
  4. ----------------------------------------
  5.  
  6. local args = {...}
  7. local iterations = 1
  8. local numOfItemsPerCraft = tonumber(args[1]) or 64
  9. if numOfItemsPerCraft > 64 then numOfItemsPerCraft = 64 end
  10.  
  11. local defaultSlots = {1,2,3,5,6,7,9,10,11} -- Minecraft default crafting slots
  12. local craftingSlots = {} -- actual slot that craft
  13. local slotsToSkip = {}
  14. if args[2] then
  15. for i = 2, #args do
  16. slotsToSkip[i-1] = args[2]
  17. end
  18. local skipIndex = 1
  19. for i = 1, 9 do
  20. if defaultSlots[i] == slotsToSkip[skipIndex] then
  21. skipIndex = skipIndex + 1
  22. else
  23. craftingSlots[#craftingSlots+1] = defaultSlots[i]
  24. end
  25. end
  26. else
  27. craftingSlots = defaultSlots
  28. end
  29.  
  30.  
  31. function suckItems()
  32. --print("Start sucking items")
  33. for i = 1, #craftingSlots do
  34. turtle.select(craftingSlots[i])
  35. local itemCount = turtle.getItemCount()
  36. while itemCount < numOfItemsPerCraft do
  37. local isSuccess = turtle.suckDown(numOfItemsPerCraft-itemCount)
  38. if isSuccess then itemCount = turtle.getItemCount()
  39. else sleep(3) end
  40. end
  41. end
  42. craftAndDropItems()
  43. end
  44.  
  45. function craftAndDropItems()
  46. --print("Start crafting items")
  47. turtle.select(16)
  48. turtle.craft()
  49. turtle.drop()
  50. iterations = iterations + 1
  51. if iterations > 64 then
  52. os.reboot() -- to avoid bug
  53. else
  54. suckItems()
  55. end
  56. end
  57.  
  58. suckItems()
Add Comment
Please, Sign In to add comment