ItsNoah

setup

Apr 22nd, 2021 (edited)
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.18 KB | None | 0 0
  1. local tArgs = { ... }
  2.  
  3. local depth = 0
  4. local xPos,zPos = 0,0
  5. local xDir,zDir = 0,1
  6.  
  7. local goTo
  8.  
  9. local count = 0
  10. local chests = 0
  11.  
  12. local function amount(_name)
  13.     tName = "minecraft:" .. _name
  14.     local tCount = 0
  15.     for i=1,16 do
  16.         local item = turtle.getItemDetail(i)
  17.         if item ~= nil then
  18.             if item.count > 0 and item.name == tName then
  19.                 tCount = tCount + item.count
  20.             end
  21.         end
  22.     end
  23.     return tCount
  24. end
  25.  
  26. local function turnLeft()
  27.     turtle.turnLeft()
  28.     xDir, zDir = -zDir, xDir
  29. end
  30.  
  31. local function turnRight()
  32.     turtle.turnRight()
  33.     xDir, zDir = zDir, -xDir
  34. end
  35.  
  36. function goTo( x, y, z, xd, zd )
  37.     while depth > y do
  38.         if turtle.up() then
  39.             depth = depth - 1
  40.         else
  41.             turtle.digUp()
  42.         end
  43.     end
  44.  
  45.     if xPos > x then
  46.         while xDir ~= -1 do
  47.             turnLeft()
  48.         end
  49.         while xPos > x do
  50.             if turtle.forward() then
  51.                 xPos = xPos - 1
  52.             else
  53.                 turtle.dig()
  54.             end
  55.         end
  56.     elseif xPos < x then
  57.         while xDir ~= 1 do
  58.             turnLeft()
  59.         end
  60.         while xPos < x do
  61.             if turtle.forward() then
  62.                 xPos = xPos + 1
  63.             else
  64.                 turtle.dig()
  65.             end
  66.         end
  67.     end
  68.    
  69.     if zPos > z then
  70.         while zDir ~= -1 do
  71.             turnLeft()
  72.         end
  73.         while zPos > z do
  74.             if turtle.forward() then
  75.                 zPos = zPos - 1
  76.             else
  77.                 turtle.dig()
  78.             end
  79.         end
  80.     elseif zPos < z then
  81.         while zDir ~= 1 do
  82.             turnLeft()
  83.         end
  84.         while zPos < z do
  85.             if turtle.forward() then
  86.                 zPos = zPos + 1
  87.             else
  88.                 turtle.dig()
  89.             end
  90.         end
  91.     end
  92.  
  93.     while depth < y do
  94.         if turtle.down() then
  95.             depth = depth + 1
  96.         else
  97.             turtle.digDown()
  98.         end
  99.     end
  100.    
  101.     if zd ~= xd then
  102.         while zDir ~= zd or xDir ~= xd do
  103.             turnRight()
  104.         end
  105.     end
  106. end
  107.  
  108. -- start --
  109.  
  110. count = amount("hopper")
  111. chests = amount("chest")
  112.  
  113. if chests >= ((count * 2) + 2) then
  114.     goTo(1, 1, -1, 0, -1)
  115.     turtle.digUp() turtle.select(1) turtle.placeUp()
  116.     goTo(0, 1, -1, 0, -1)
  117.     turtle.digUp() turtle.placeUp()
  118.  
  119.     for i=1, count do
  120.         goTo(0, (i+1), -2, 0, -1)
  121.         turtle.digUp() turtle.placeUp()
  122.     end
  123.     goTo(0, (count+1), -1, 0, -1)
  124.     goTo(0, 1, -1, 0, -1)
  125.     goTo(1, 1, -1, 0, -1)
  126.     for i=1, count do
  127.         goTo(1, (i+1), -2, 0, -1)
  128.         turtle.digUp() turtle.placeUp()
  129.     end
  130.     goTo(1, count+1, 0, 0, -1)
  131.     goTo(1, 0, 0, 0, -1)
  132.     for i=1, count do
  133.         goTo(1, i, 0, 0, -1)
  134.         turtle.dig() turtle.select(2) turtle.place()
  135.     end
  136.     goTo(0, 0, 0, 0, 1)
  137.     turtle.select(1)
  138.  
  139.     print("Done!")
  140.  
  141.     if #tArgs > 0 then
  142.         if tArgs[1] == "exf" then
  143.             shell.run("exf 16")
  144.         elseif tArgs[1] == "exc" then
  145.             shell.run("excavate 16")
  146.         end
  147.     end
  148. else
  149.     print("Not enough chests!")
  150. end
Add Comment
Please, Sign In to add comment