Advertisement
guitarplayer616

Turtle Refill

Dec 10th, 2015
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.27 KB | None | 0 0
  1. local chestOrder = 1
  2. local enderchest1 = 15
  3. local enderchest2 = 16
  4.  
  5.  
  6. function scanInv()
  7.     local invList = {}
  8.     for i = 1,16 do
  9.         turtle.select(i)
  10.         local item = turtle.getItemDetail()
  11.         if item then
  12.             invList[i] = item.name
  13.         end
  14.     end
  15.     return invList
  16. end
  17.  
  18.  
  19. function ParseInv(invList)
  20.     turtle.select(16)
  21.     turtle.dropUp()
  22.     while turtle.suck() do
  23.         local item = turtle.getItemDetail()
  24.         for i =1,16 do
  25.             if item.name == invList[i] then
  26.                 turtle.transferTo(i)
  27.                 break
  28.             end
  29.             if item.name == "minecraft:lava_bucket" or item.name == "minecraft:coal" then
  30.                 turtle.refuel(64)
  31.             end
  32.         end
  33.         turtle.dropUp()
  34.     end
  35. end
  36.  
  37. function EnderChests(action)
  38.     --action = 'set' or 'gather'
  39.     if action == "set" then
  40.         turtle.select(enderchest1)
  41.         turtle.place()
  42.         turtle.select(enderchest2)
  43.         turtle.placeUp()
  44.     elseif action == "gather" then
  45.         if chestOrder == 1 then
  46.             turtle.select(enderchest1)
  47.             turtle.digUp()
  48.             turtle.select(enderchest2)
  49.             turtle.dig()
  50.             chestOrder = 2
  51.         elseif chestOrder == 2 then
  52.             turtle.select(enderchest1)
  53.             turtle.dig()
  54.             turtle.select(enderchest2)
  55.             turtle.digUp()
  56.             chestOrder = 1
  57.         end
  58.     end
  59. end
  60.  
  61.  
  62. local inventory = scanInv()
  63. for i = 1,4 do
  64.     EnderChests("set")
  65.     ParseInv(inventory)
  66.     EnderChests("gather")
  67. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement