Lats339

TurtleDig

Dec 1st, 2020 (edited)
122
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --mine, itself dimensions--
  2. xMine = 0
  3. zMine = 0
  4. yMine = 0
  5.  
  6. posTot = 0
  7. --every forward movement in the X adds to this--
  8. posX = 0
  9.  
  10. --every forward movement in the Y adds to this--
  11. posZ = 0
  12.  
  13. --homeX and homeZ for custom coords later--
  14. homeX = 0
  15. homeZ = 0
  16.  
  17. -- for dirFind--
  18. --pos = forward in the x from home --
  19. --neg = backward in the x from the home--
  20. dirFind = 1
  21. height = 0
  22.  
  23.  
  24. fuelLevel = turtle.getFuelLevel()
  25.  
  26. function posZlayer()
  27.  
  28.     while (posZ < zMine) do
  29.     turtle.dig()
  30.     turtle.forward()
  31.     posZ = posZ + 1
  32.     print(posZ)
  33.     turtle.digUp()
  34.     end
  35.  
  36. end
  37.  
  38. function negZlayer()
  39.  
  40.     while (posZ > 0) do
  41.     turtle.dig()
  42.     turtle.forward()
  43.     posZ = posZ - 1
  44.     turtle.digUp()
  45.     print("finished negZ layer")
  46.     end
  47.  
  48.  
  49. end
  50.  
  51. function nextXlayer()
  52.     if(dirFind == 1) then
  53.         turtle.turnRight()
  54.         turtle.dig()
  55.         turtle.forward()
  56.         turtle.digUp()
  57.         turtle.turnRight()
  58.         posX = posX + 1
  59.     else
  60.         turtle.turnLeft()
  61.         turtle.dig()
  62.         turtle.forward()
  63.         turtle.digUp()
  64.         turtle.turnLeft()
  65.         posX = posX + 1
  66.  
  67.     end
  68.  
  69. end
  70.  
  71. function entries()
  72.  
  73. --height entry--
  74.     print "enter the current Y height"
  75.     height = tonumber(read())
  76.  
  77. --mine dimensions entry--
  78.     print("enter the x dimension of the mine")
  79.     xMine = tonumber(read())
  80.     print("enter the z dimension of the mine")
  81.     zMine = tonumber(read())
  82.     print("enter the ceiling height of the mine(even numbers only)")
  83.     yMine = tonumber(read())
  84.  
  85. end
  86.  
  87. function digDown()
  88.     while(height > 11) do
  89.     turtle.digDown()
  90.     turtle.dig()
  91.     turtle.down()
  92.     height = height - 1
  93.    end
  94. end
  95.  
  96.  
  97. function returnHome()
  98.    
  99.     if(dirFind == 1) then
  100.  
  101.         turtle.turnLeft()
  102.         else
  103.         turtle.turnRight()
  104. end
  105.  
  106. while(homeX < posX) do
  107.     turtle.forward()
  108.     posX = posX - 1
  109. end
  110.  
  111. while(homeZ < posZ) do
  112.     turtle.forward()
  113.     posZ = posZ - 1
  114.     end
  115.  
  116. end
  117.  
  118.  
  119. function diggydiggyhole()
  120.     entries()
  121.     digDown()
  122.    
  123.    
  124.  
  125.         while(posX <= xMine) do
  126.         posTot = posX + posZ
  127.             if(fuelLevel < posTot) then
  128.             returnHome()
  129.             end
  130.        
  131.         if(dirFind == 1) then
  132.             print("poslayer started")
  133.             posZlayer()
  134.             nextXlayer()
  135.             print("layer done")
  136.             dirFind = 2
  137.         else
  138.             print("neglayer started")
  139.             negZlayer()
  140.             nextXlayer()
  141.             dirFind = 1
  142.        
  143.          end
  144.     end
  145. end
  146.  
  147.  
  148. --order of operations--
  149.  
  150. diggydiggyhole()
  151.  
  152.  
RAW Paste Data