Barnet

CraftTreatedWood

Jun 5th, 2021 (edited)
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.99 KB | None | 0 0
  1. function SearchItem(target)
  2.   if turtle.getItemCount() > 0 and string.find(turtle.getItemDetail().name, target) ~= nil then
  3.     return
  4.   end
  5.   for i = 1, 16, 1 do
  6.     turtle.select(i)
  7.     if turtle.getItemCount() > 0 and string.find(turtle.getItemDetail().name, target) ~= nil then
  8.       return
  9.     end  
  10.   end
  11.   error("No " .. target .. " found")
  12. end
  13.  
  14. function CheckForGrid(i)
  15.   grid = {1, 2, 3, 5, 7, 9, 10, 11}
  16.   for j = 1, 8, 1 do
  17.     if grid[j] == i then
  18.     return true
  19.   end
  20.   end
  21.   return false
  22. end
  23.  
  24. function OrganizePlanks()
  25.   count = 0
  26.   slots = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  27.   for i = 1, 16, 1 do
  28.     turtle.select(i)  
  29.     if turtle.getItemCount() > 0 then
  30.       item = turtle.getItemDetail()
  31.       if string.find(item.name, "plank") ~= nil then
  32.         count = count + item.count
  33.         slots[i] = item.count
  34.       elseif i ~= 6 then
  35.         turtle.dropUp()
  36.       end
  37.     end
  38.   end
  39.  
  40.   x = count % 8
  41.   count = count - x
  42.   targetCount = count / 8
  43.   if targetCount > 64 then
  44.     targetCount = 64
  45.   end
  46.    
  47.   for i = 1, 11, 1 do
  48.     if CheckForGrid(i) then
  49.       if slots[i] < targetCount then
  50.         missing = targetCount - slots[i]
  51.         for j = 1, 16, 1 do
  52.           if i ~= j then
  53.             over = slots[j]
  54.             if CheckForGrid(j) then
  55.               over = over - targetCount
  56.             end
  57.        
  58.             if over > 0 then
  59.               transfer = missing
  60.               if missing > over then
  61.                 transfer = over
  62.               end
  63.               turtle.select(j)
  64.               turtle.transferTo(i, transfer)
  65.               slots[j] = slots[j] - transfer
  66.               slots[i] = slots[i] + transfer
  67.             end
  68.           end
  69.         end
  70.       end
  71.     end
  72.   end
  73.  
  74.   for i = 1, 16, 1 do
  75.     if i ~= 6 then
  76.       turtle.select(i)
  77.       c = turtle.getItemCount()
  78.       if c > targetCount then
  79.         turtle.dropUp(c - targetCount)
  80.       end
  81.     end
  82.   end
  83.  
  84.   return targetCount
  85. end
  86.  
  87. function RefillBucket()
  88.   turtle.select(6)
  89.   if turtle.getItemCount() > 0 and turtle.getItemDetail().name == "immersiveengineering:creosote_bucket" then
  90.     return true
  91.   end
  92.   turtle.drop()
  93.   while turtle.suck() do
  94.     if turtle.getItemCount() > 0 then
  95.       item = turtle.getItemDetail()
  96.       if string.find(item.name, "bucket") == nil then
  97.         turtle.dropUp()
  98.       else
  99.         return true
  100.       end
  101.     end
  102.   end
  103.   return false
  104. end
  105.  
  106. turtle.select(6)
  107. if turtle.getItemCount() > 0 and string.find(turtle.getItemDetail().name, "bucket") ~= nil then
  108.   for i = 1, 16, 1 do
  109.     turtle.select(i)
  110.   if turtle.getItemCount == 0 then
  111.     turtle.select(6)
  112.     turtle.transferTo(i)
  113.   end
  114.   end
  115. end
  116. SearchItem("bucket")
  117. if turtle.getSelectedSlot() ~= 6 then
  118.   turtle.transferTo(6)
  119. end
  120.  
  121. i = OrganizePlanks()
  122. while i > 0 do  
  123.   if not RefillBucket() then
  124.     error("No more creosote oil :(")
  125.   end
  126.   turtle.craft()
  127.   turtle.select(8)
  128.   turtle.dropUp()
  129.   i = i - 1
  130. end
  131. turtle.select(7)
  132. turtle.dropUp()
  133.  
  134.  
Add Comment
Please, Sign In to add comment