Advertisement
Guest User

craft

a guest
Feb 18th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.26 KB | None | 0 0
  1. local slots = {}
  2. for i = 1, 16 do
  3.   slots[i] = i
  4. end
  5. local matches = {}
  6. local itemCount = 0
  7. local numItems = 0
  8. local leastItems = 64
  9.  
  10. function clearOuterSlots()
  11.   for i=4,16,4 do
  12.     if turtle.getItemCount(i) > 0 then
  13.       turtle.select(i)
  14.       turtle.drop(i)
  15.     end
  16.   end
  17.   for i = 13,15 do
  18.     if turtle.getItemCount(i) > 0 then
  19.       turtle.select(i)
  20.       turtle.drop(i)
  21.     end
  22.   end
  23. end
  24.  
  25. clearOuterSlots()
  26.  
  27. while #slots > 0 do
  28.   local current = table.remove(slots, 1)
  29.     if turtle.getItemCount(current) > 0 then
  30.   local match = {current}
  31.   turtle.select(current)
  32.   for i = #slots, 1, -1 do
  33.     if turtle.compareTo(slots[i])  then
  34.       table.insert(match, table.remove(slots, i))
  35.     end
  36.   end
  37.   table.sort(match)
  38.   table.insert(matches, match)
  39.   end
  40. end
  41.  
  42. while true do
  43. clearOuterSlots()
  44. for i = 1,#matches do
  45.   for k = 1,#matches[i] do
  46.   itemCount = itemCount + turtle.getItemCount(matches[i][k])
  47.   numItems = k
  48.   end
  49. local perSlot = math.floor(itemCount/numItems)
  50.  
  51. for k = 1,#matches[i] do
  52.   local slotItemCount = turtle.getItemCount(matches[i][k])
  53.     if slotItemCount < perSlot then
  54.       for j = 1,#matches[i] do
  55.       if turtle.getItemCount(matches[i][j]) > perSlot then
  56.         local requiredItems = perSlot - turtle.getItemCount(matches[i][k])
  57.           if(turtle.getItemCount(matches[i][j]) - requiredItems) >= perSlot then
  58.             turtle.select(matches[i][j])
  59.             turtle.transferTo(matches[i][k], requiredItems)
  60.           else
  61.             for w=1,requiredItems do
  62.               while turtle.getItemCount(matches[i][j]) > perSlot do
  63.               turtle.select(matches[i][j])
  64.               turtle.transferTo(matches[i][k], 1)
  65.               end
  66.             end
  67.           end
  68.         print(requiredItems)
  69.       end
  70.     end
  71.   end
  72. end
  73. itemCount = 0
  74. numItems = 0
  75. end
  76. for i=1,3 do
  77.   if turtle.getItemCount(i) < leastItems then
  78.   leastItems = turtle.getItemCount(i)
  79.   end
  80. end
  81. for i=5,7 do
  82.   if turtle.getItemCount(i) < leastItems then
  83.   leastItems = turtle.getItemCount(i)
  84.   end
  85. end
  86. for i=9,11 do
  87.   if turtle.getItemCount(i) < leastItems then
  88.   leastItems = turtle.getItemCount(i)
  89.   end
  90. end
  91.  
  92. turtle.select(16)
  93. turtle.craft(leastItems-1)
  94. turtle.drop()
  95. print("Done")
  96. leastItems = 64
  97. os.sleep(2)
  98. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement