mrkirby153

[TURTLE] Refuel

Mar 7th, 2015
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.01 KB | None | 0 0
  1. local tArgs = { ... }
  2.  
  3.  
  4. local item = "coal"
  5.  
  6. if #tArgs > 0 then
  7.     item = tArgs[1]
  8. end
  9.  
  10. local slotWithEnderChest = 16
  11. currentSlot = turtle.getSelectedSlot()
  12. print("Refuelling")
  13. if turtle.detectUp() then
  14.     turtle.digUp()
  15. end
  16. -- Place the ender chest
  17. turtle.select(slotWithEnderChest)
  18. turtle.placeUp()
  19. turtle.select(currentSlot)
  20. chest = peripheral.wrap("top")
  21.  
  22. inventorySize = chest.getInventorySize()
  23. for i=1,inventorySize do
  24.     currentItem = chest.getStackInSlot(i)
  25.     if currentItem == nil then
  26.         break
  27.     end
  28.     if currentItem["name"] == item then
  29.         -- Find the first inventory slot in the turtle
  30.         freeSlot = -1
  31.         for j=1,16 do
  32.             print("Checking slot "..j..":"..turtle.getItemCount(j))
  33.             if turtle.getItemCount(j) == 0 then
  34.                 freeSlot = j
  35.                 print("Found free slot "..j)
  36.                 break
  37.             end
  38.         end
  39.         chest.pushItemIntoSlot("down", i, 64, freeSlot)
  40.         turtle.select(i)
  41.         turtle.refuel()
  42.     end
  43. end
  44. turtle.select(slotWithEnderChest)
  45. turtle.digUp()
  46. turtle.select(currentSlot)
  47. print(turtle.getFuelLevel())
Advertisement
Add Comment
Please, Sign In to add comment