zPow

Turtle

Oct 7th, 2021 (edited)
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.28 KB | None | 0 0
  1. local function GoUp()
  2.     turtle.digUp();
  3.     turtle.up();
  4. end
  5.  
  6. local function GoDown()
  7.     turtle.digDown();
  8.     turtle.down();
  9. end
  10.  
  11. local function GoLeft()
  12.     turtle.turnLeft();
  13.     turtle.dig();
  14.     turtle.forward();
  15.     turtle.turnRight();
  16. end
  17.  
  18. local function GoRight()
  19.     turtle.turnRight();
  20.     turtle.dig();
  21.     turtle.forward();
  22.     turtle.turnLeft();
  23. end
  24.  
  25. local function PlaceTorch()
  26.     turtle.select(1);
  27.     turtle.placeDown();
  28. end
  29.  
  30. local direction = true; -- true = same as start, false = opposite
  31. local turnBool = true; -- False go left, True go right
  32.  
  33. local function TurnAround()
  34.     turtle.turnLeft();
  35.     turtle.turnLeft();
  36.     direction = not direction;
  37. end
  38.  
  39. local function GoToStart(length, width, height, startDirection)
  40.     for i = 1, height do
  41.         if i ~= height then
  42.             GoDown();
  43.         end
  44.     end
  45.  
  46.     for i = 1, width do
  47.         if i ~= width then
  48.             GoLeft();
  49.         end
  50.     end
  51.  
  52.     if direction == true then -- True = same as start
  53.         for i = 1, length do
  54.             if i ~= length then
  55.                 turtle.back();
  56.             end
  57.         end
  58.     end
  59. end
  60.  
  61. local function checkFuel(length, width, height)
  62.     local neededFuel = (length * 2 * width) * (height * 2);
  63.     if turtle.getFuelLevel() < neededFuel then
  64.         turtle.select(2);
  65.         if turtle.refuel() ~= false then
  66.             turtle.refuel();
  67.             print("Success! Fuel level is " .. turtle.getFuelLevel() .. ". Starting mining...");
  68.         else
  69.             term.clear();
  70.             print("Unable to refuel,\nCurrent fuel is " .. turtle.getFuelLevel() .. "\nNeeded fuel is " .. neededFuel ..
  71.                       "\nPlease fill slot 2 with at least " .. ((neededFuel - turtle.getFuelLevel()) / 80) ..
  72.                       " Coal.\nor at least " .. (neededFuel / 1000) .. " Lava Buckets.");
  73.             checkFuel(length, width, height);
  74.         end
  75.     end
  76. end
  77.  
  78. local function stripMine(length, width, height)
  79.     local startDirection = turnBool;
  80.     local canStart = false;
  81.     local neededFuel = (length * 2 * width) * (height * 2);
  82.  
  83.     if turtle.getFuelLevel() < neededFuel then
  84.         checkFuel(length, width, height);
  85.         stripMine(length, width, height);
  86.     else
  87.         for p = 1, height do
  88.             for i = 1, width do -- width
  89.                 local t = 0;
  90.                 for j = 1, length do -- Length
  91.                     if t == 5 and turnBool == true and p == 2 then
  92.                         PlaceTorch();
  93.                         t = 0;
  94.                     end
  95.                     turtle.dig();
  96.                     turtle.forward();
  97.                     t = t + 1;
  98.                 end
  99.                 if i ~= width then
  100.                     if turnBool == true then
  101.                         GoRight();
  102.                     elseif turnBool == false then
  103.                         GoLeft();
  104.                     end
  105.                     turnBool = not turnBool;
  106.                 end
  107.                 TurnAround();
  108.             end
  109.             print("New direction: " .. tostring(turnBool) .. " - False left, True right");
  110.             if p ~= height then
  111.                 GoUp();
  112.             end
  113.         end
  114.         GoToStart(length, width, height, startDirection);
  115.     end
  116. end
  117.  
  118. stripMine(60, 11, 3);
  119.  
Add Comment
Please, Sign In to add comment