Advertisement
makmoud98

Untitled

Feb 28th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. ITEMS = {"IC2:itemUran235small", "IC2:itemUran238"}
  2.  
  3. CRAFT = {ITEMS[2], ITEMS[2], ITEMS[2], 0,
  4. ITEMS[1], ITEMS[1], ITEMS[1], 0,
  5. ITEMS[2], ITEMS[2], ITEMS[2], 0,
  6. 0, 0, 0, 0}
  7.  
  8. function craft()
  9. for j=1,16 do
  10. print('fixing slot ' .. j)
  11. turtle.select(j)
  12. local name = CRAFT[j]
  13. if name ~= 0 then
  14. local sum = 0
  15. local matches = {}
  16. for i=1,16 do
  17. local data = turtle.getItemDetail(i)
  18. if data and data.name == CRAFT[j] then
  19. sum = sum + data.count
  20. matches[#matches+1] = i
  21. end
  22. end
  23. local slots = 0
  24. for i=1,16 do
  25. if CRAFT[i] == name then
  26. slots = slots + 1
  27. end
  28. end
  29. if slots ~= 0 and sum >= slots then
  30. req = math.floor(sum/slots)
  31. if req > 64 then
  32. req = 64
  33. end
  34. data = turtle.getItemDetail(j)
  35. if data then
  36. found = false
  37. for i=1,16 do
  38. if data.name == CRAFT[i] then
  39. found = true
  40. break
  41. end
  42. end
  43. if not found then
  44. turtle.select(j)
  45. turtle.dropDown()
  46. print('detected useless item')
  47. return false
  48. end
  49. end
  50. if data and data.name ~= name then
  51. turtle.select(j)
  52. for i=j+1,16 do
  53. local d = turtle.getItemDetail(i)
  54. if not d then
  55. turtle.transferTo(i)
  56. break
  57. elseif d and d.name == name and d.count + data.count <= 64 then
  58. turtle.transferTo(i)
  59. break
  60. end
  61. end
  62. elseif data and data.name == name and data.count < req then
  63. local success = false
  64. for i=1,16 do
  65. local d = turtle.getItemDetail(i)
  66. if d and d.name == name then
  67. if d.name == CRAFT[i] and d.count > req then
  68. turtle.select(i)
  69. turtle.transferTo(j, d.count - req)
  70. elseif d.name ~= CRAFT[i] then
  71. turtle.select(i)
  72. turtle.transferTo(j)
  73. end
  74. end
  75. data = turtle.getItemDetail(j)
  76. if data.count >= req then
  77. success = true
  78. break
  79. end
  80. end
  81. if not success then
  82. print('a, could not transfer enough loot to slot: ' .. j)
  83. return false
  84. end
  85. elseif not data then
  86. local success = false
  87. for i=1,16 do
  88. local d = turtle.getItemDetail(i)
  89. if d and d.name == name then
  90. if d.name == CRAFT[i] and d.count > req then
  91. turtle.select(i)
  92. turtle.transferTo(j, d.count - req)
  93. elseif d.name ~= CRAFT[i] then
  94. turtle.select(i)
  95. turtle.transferTo(j)
  96. end
  97. end
  98. data = turtle.getItemDetail(j)
  99. if data and data.count >= req then
  100. success = true
  101. break
  102. end
  103. end
  104. if not success then
  105. print('b, could not transfer enough loot to slot: ' .. j)
  106. return false
  107. end
  108. end
  109. else
  110. return false
  111. end
  112. end
  113. end
  114. return true
  115. end
  116.  
  117. while true do
  118. turtle.suck()
  119. if craft() then
  120. print('true!!!!')
  121. turtle.craft()
  122. end
  123. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement