coffedahl

mine

Nov 30th, 2020 (edited)
811
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --The local postition tracker, dont have any refrence to real world
  2. local posx = 0
  3. local posy = 0
  4. local posz = 0
  5. --The local direction set at start, 1 forward, 2 right, 3 back, 4 left
  6. local direction = 1
  7.  
  8. -- Move and update position
  9. function move()
  10.     if direction == 1 then
  11.         posx = posx + 1
  12.     elseif direction == 2 then
  13.         posz = posz + 1
  14.     elseif direction == 3 then
  15.         posx = posx - 1
  16.     elseif direction == 4 then
  17.         posz = posz - 1
  18.     end
  19.     turtle.forward()
  20. end
  21.  
  22. -- Turn and change direction
  23. function turnRight()
  24.     direction = direction + 1
  25.     turtle.turnRight()
  26. end
  27. -- Turn and change diretction
  28. function turnLeft()
  29.     direction = direction - 1
  30.     turtle.turnLeft()
  31. end
  32.  
  33. -- make a 3 high tunnel forward
  34. function tunnelForward()
  35.     if turtle.detect() then
  36.         turtle.dig()
  37.     end
  38.     move()
  39.     if turtle.detectUp() then
  40.         turtle.digUp()
  41.     end
  42.     if turtle.detectDown() then
  43.         turtle.digDown()
  44.     end
  45. end
  46.  
  47. -- Make the robot go to the startingposition
  48. function goHome()
  49.     if posx > 0 then
  50.         while(direction ~= 3) do
  51.             turnRight()
  52.         end
  53.         for k=1,math.abs(posx),1 do
  54.             move()
  55.         end
  56.     elseif posx < 0 then
  57.         while(direction ~= 1) do
  58.             turnRight()
  59.         end
  60.         for k=1,math.abs(posx),1 do
  61.             move()
  62.         end
  63.     end
  64.     if posz > 0 then
  65.         while(direction ~= 4) do
  66.             turnRight()
  67.         end
  68.         for k=1,math.abs(posz),1 do
  69.             move()
  70.         end
  71.     elseif posz < 0 then
  72.         while(direction ~= 2) do
  73.             turnRight()
  74.         end
  75.         for k=1,math.abs(posz),1 do
  76.             move()
  77.         end
  78.     end
  79. end
  80.  
  81.  
  82.  
  83. -----Main funtion-----
  84. print("Dig v101 by Coffedahl")
  85. sleep(10)
  86. print("Please have some chests in slot 1 and fuel in slot 2")
  87. --get size of tunnel
  88. print("Please enter length of tunnel:")
  89. local length = io.read()
  90. print("Please enter width of tunnel:")
  91. local width = io.read()
  92. print("Starting dig")
  93. --Refuel
  94. turtle.select(2)
  95. turtle.refuel()
  96. turtle.select(1)
  97.  
  98. local dig_direction = 1
  99. for i=1,width,1 do
  100.     for o=1,length,1 do
  101.         tunnelForward()
  102.         if turtle.getItemCount(16) > 0 then
  103.             turtle.select(1)
  104.             turtle.placeDown()
  105.             for e=2,16,1 do
  106.                 turtle.select(e)
  107.                 turtle.dropDown()
  108.             end
  109.             turtle.select(1)
  110.         end
  111.     end
  112.     if dig_direction == 1 then
  113.         turnRight()
  114.         tunnelForward()
  115.         turnRight()
  116.         dig_direction = 2
  117.     elseif dig_direction == 2 then
  118.         turnLeft()
  119.         tunnelForward()
  120.         turnLeft()
  121.         dig_direction = 1
  122.     end
  123.     if i == width - 1 then
  124.         dig_direction = 0
  125.     end
  126. end
  127. goHome()
  128. print("Done")
  129.  
RAW Paste Data