stictt

tests

Aug 10th, 2020 (edited)
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.02 KB | None | 0 0
  1. VerticalDig = 3
  2. DistansDig  = 80
  3. WidthDig = 10
  4. x = 0
  5. y = 0
  6. z = 0
  7. side = "+X"
  8. local function Refuel()
  9.     if turtle.getFuelLevel() < 30 then
  10.         turtle.select(1)
  11.         turtle.refuel(1)
  12.     end
  13. end
  14. local function UnLoad()
  15.     for i = 2, 16, 1 do
  16.         turtle.select(i)
  17.         turtle.drop()
  18.     end
  19.     turtle.select(1)
  20. end
  21. local function TrueBreack(route)
  22.     Refuel()
  23.     value = false
  24.     if route == "Up" then
  25.         value = turtle.detectUp()
  26.     elseif route == "Forvard" then
  27.         value = turtle.detect()
  28.     elseif route == "Down" then
  29.         value = turtle.detectDown()
  30.     end
  31.     while value do
  32.         Refuel()
  33.         if route == "Up" then
  34.             turtle.digUp()
  35.             value = turtle.detectUp()
  36.         elseif route == "Forvard" then
  37.             turtle.dig()
  38.             value = turtle.detect()
  39.         elseif route == "Down" then
  40.             turtle.digDown()
  41.             value = turtle.detectDown()
  42.         end
  43.     end
  44. end
  45. local function Rotate(localSide)
  46.     if (string.sub(localSide,2,2) == string.sub(side,2,2)) and (not (string.sub(localSide,1,1) == string.sub(side,1,1))) then
  47.         turtle.turnLeft()
  48.         turtle.turnLeft()
  49.     else
  50.         if side == "+X" then
  51.             if localSide == "+Z" then  
  52.                 turtle.turnRight()  
  53.             elseif localSide == "-Z" then
  54.                 turtle.turnLeft()
  55.             end
  56.        
  57.         elseif side == "-X" then
  58.             if localSide == "+Z" then  
  59.                 turtle.turnLeft()  
  60.             elsif localSide == "-Z" then
  61.                 turtle.turnRight()
  62.             end
  63.         elseif side == "+Z" then
  64.             if localSide == "+X" then  
  65.                 turtle.turnLeft()  
  66.             elseif localSide == "-X" then
  67.                 turtle.turnRight()
  68.             end
  69.         elseif side == "-Z" then
  70.             if localSide == "+X" then  
  71.                 turtle.turnRight()  
  72.             elseif localSide == "-X" then
  73.                 turtle.turnLeft()
  74.             end
  75.         end
  76.     end
  77. end
  78. local function AnalogsMove(localSide,route)
  79.     Rotate(localSide)
  80.     TrueBreack(route)
  81.     if route == "Up" then
  82.         turtle.up()
  83.         y = y + 1
  84.     elseif route == "Forvard" then
  85.         turtle.forward()
  86.         if localSide == "+X"  then
  87.             x = x + 1
  88.         elseif localSide == "-X" then
  89.             x = x - 1
  90.         elseif  localSide == "+Z" then
  91.             z = z + 1
  92.         elseif  localSide == "-Z" then
  93.             z = z - 1
  94.         end
  95.         side = localSide
  96.     elseif route == "Down" then
  97.         y = y - 1
  98.         turtle.down()
  99.     end
  100.     side = localSide
  101. end
  102.  
  103. local function StepMove(localStep,cords)
  104.     localSide = side
  105.     route = "null"
  106.     if not (cords == "y") then
  107.         route = "Forvard"
  108.     elseif localStep > 0 and cords == "y" then
  109.         route = "Up"
  110.     elseif localStep < 0 and cords == "y" then
  111.         route = "Down"
  112.     end
  113.    
  114.     if localStep > 0 and cords == "x" then
  115.         localSide = "+X"
  116.     elseif localStep < 0 and cords == "x" then
  117.         localSide = "-X"
  118.     elseif localStep < 0 and cords == "z" then
  119.         localSide = "-Z"   
  120.     elseif localStep > 0 and cords == "z" then
  121.         localSide = "+Z"   
  122.     end
  123.     AnalogsMove(localSide,route)
  124. end
  125. local function MovePoint(localX,localY,localZ)
  126.     while not (localY == y) do
  127.         if localY > y then
  128.             StepMove(1,"y")
  129.         elseif localY < y then
  130.             StepMove(-1,"y")
  131.         end
  132.     end
  133.     while not (localZ == z) do
  134.         if localZ > z then
  135.             StepMove(1,"z")
  136.         elseif localZ < z then
  137.             StepMove(-1,"z")
  138.         end
  139.     end
  140.     while not (localX == x) do
  141.         if localX > x then
  142.             StepMove(1,"x")
  143.         elseif localX < x then
  144.             StepMove(-1,"x")
  145.         end
  146.     end
  147. end
  148. local function CheckOverflow()
  149.     turtle.select(16)
  150.     localX = x
  151.     localY = y
  152.     localZ = z
  153.     if  turtle.getItemCount() >= 1 then
  154.         turtle.select(1)
  155.         MovePoint(0,0,0)
  156.         Rotate("-X")
  157.         UnLoad()
  158.         MovePoint(localX,localY,localZ)
  159.     end
  160.     turtle.select(1)
  161. end
  162. local function DigArea()
  163.     targetX = DistansDig
  164.     targetZ = WidthDig
  165.     stepX = 1
  166.     stepZ = 1
  167.     for h = 1, VerticalDig, 1 do
  168.         while not (targetX == x) do
  169.             while not (targetZ == z) do
  170.                 MovePoint(x,y,z+stepZ)
  171.                 TrueBreack("Up")
  172.                 TrueBreack("Down")
  173.                 CheckOverflow()
  174.             end
  175.             stepZ = stepZ * -1
  176.             if stepZ == -1 then
  177.                 targetZ = 0
  178.             else
  179.                 targetZ = WidthDig
  180.             end
  181.             MovePoint(x+stepX,y,z)
  182.             TrueBreack("Up")
  183.             TrueBreack("Down")
  184.         end
  185.         stepX = stepX * -1
  186.         if stepX == -1 then
  187.             targetX = 0
  188.         else
  189.             targetX = DistansDig
  190.         end
  191.         if h < VerticalDig then MovePoint(x,y+3,z) end
  192.     end
  193.     MovePoint(0,0,0)
  194.     UnLoad()
  195. end
  196. DigArea()
  197.  
Add Comment
Please, Sign In to add comment