gravitowl

mineshafter

Dec 9th, 2024
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.49 KB | None | 0 0
  1. local args = {...}
  2.  
  3. local version = "0.0.1";
  4.  
  5. local function help()
  6.     print(string.format("Welcome to MineShafter V%s!", version));
  7.     print("Here's how to use this program:");
  8.     print("");
  9.     print("This program digs 5 high, 3 wide tunnels downwards.");
  10.     print("After 15 blocks, it'll dig a 5 long 4 high platform");
  11.     print("Make sure to place the turtle in the bottom center of the place where you want the shaft.");
  12.     print("Usage:");
  13.     print("mineshafter <amountOfLevels> | help");
  14. end
  15.  
  16. local tunnelWidth = 3;
  17. local tunnelHeight = 5;
  18. local platformWidth = 3;
  19. local platformHeight = 4;
  20. local platformLength = 5;
  21. local platformInterval = 15;
  22.  
  23. local digDirection = {
  24.     front = turtle.dig,
  25.     up = turtle.digUp,
  26.     down = turtle.digDown
  27. }
  28.  
  29. local inspectDirection = {
  30.     front = turtle.inspect,
  31.     up = turtle.inspectUp,
  32.     down = turtle.inspectDown
  33. }
  34.  
  35. local Direction = {
  36.     front = "front",
  37.     up = "up",
  38.     down = "down"
  39. }
  40.  
  41. local function forceDig(direction)
  42.     if not Direction[direction] then return false end
  43.     while inspectDirection[direction]() do
  44.         digDirection[direction]();
  45.     end
  46.  
  47.     return true;
  48. end
  49.  
  50. local function refuel()
  51.     local oldSelectedSlot = turtle.getSelectedSlot();
  52.     for i = 1, 16, 1 do
  53.         turtle.select(i);
  54.         turtle.refuel();
  55.     end
  56.     turtle.select(oldSelectedSlot);
  57. end
  58.  
  59. local function checkForFuel(amountOfLevels)
  60.     local amountOfShaftSlices = platformInterval*amountOfLevels;
  61.     local amountToMovePerLevel = tunnelHeight*2-1;
  62.     local totalToMoveForShaft = amountToMovePerLevel * amountOfShaftSlices;
  63.  
  64.     local amountToMoveForPlatform = (platformHeight-1)*platformLength;
  65.     local totalToMoveForPlatforms = amountToMoveForPlatform * amountOfLevels;
  66.  
  67.     local totalToMoveUpShaft = amountOfShaftSlices*2;
  68.     local totalToMoveUpPlatforms = platformLength*amountOfLevels;
  69.  
  70.     local totalFuelUsage =
  71.         totalToMoveForShaft +
  72.         totalToMoveForPlatforms +
  73.         totalToMoveUpShaft +
  74.         totalToMoveUpPlatforms;
  75.  
  76.     if turtle.getFuelLevel() < totalFuelUsage then
  77.         refuel();
  78.     end
  79.  
  80.     if turtle.getFuelLevel() < totalFuelUsage then
  81.         return false, totalFuelUsage;
  82.     end
  83.  
  84.     return true;
  85. end
  86.  
  87. local function mineShaftSlice()
  88.     for i = 1, tunnelHeight-2, 1 do
  89.         turtle.up();
  90.     end
  91.  
  92.     forceDig(Direction.front);
  93.     turtle.forward();
  94.  
  95.     turtle.turnLeft();
  96.     forceDig(Direction.front);
  97.     turtle.turnRight();
  98.     turtle.turnRight();
  99.     forceDig(Direction.front);
  100.     turtle.turnLeft();
  101.  
  102.     for i = 1, tunnelHeight-1, 1 do
  103.         forceDig(Direction.down);
  104.         turtle.down();
  105.         turtle.turnLeft();
  106.         forceDig(Direction.front);
  107.         turtle.turnRight();
  108.         turtle.turnRight();
  109.         forceDig(Direction.front);
  110.         turtle.turnLeft();
  111.     end
  112. end
  113.  
  114. local function minePlatformSlice(i)
  115.     forceDig(Direction.front);
  116.     turtle.forward();
  117.     for j = 1, platformHeight-1 do
  118.         turtle.turnLeft();
  119.         forceDig(Direction.front);
  120.         turtle.turnRight();
  121.         turtle.turnRight();
  122.         forceDig(Direction.front);
  123.         turtle.turnLeft();
  124.         if i % 2 == 0 then
  125.             forceDig(Direction.down);
  126.             turtle.down();
  127.         else
  128.             forceDig(Direction.up);
  129.             turtle.up();
  130.         end
  131.     end
  132.     turtle.turnLeft();
  133.     forceDig(Direction.front);
  134.     turtle.turnRight();
  135.     turtle.turnRight();
  136.     forceDig(Direction.front);
  137.     turtle.turnLeft();
  138. end
  139.  
  140. local function minePlatform()
  141.     local i = 0;
  142.  
  143.     for i = 1, platformLength, 1 do
  144.         minePlatformSlice(i);
  145.     end
  146.  
  147.     for i = 1, platformHeight-1, 1 do
  148.         turtle.down();
  149.     end
  150. end
  151.  
  152.  
  153. local function mineshafter(amountOfLevels)
  154.     local hasEnoughFuel, requiredAmount = checkForFuel(amountOfLevels);
  155.     if not hasEnoughFuel then
  156.         print("Not enough fuel, please feed me UwU.")
  157.         print("Required amount: "..requiredAmount);
  158.         return false;
  159.     end
  160.  
  161.     for i = 1, amountOfLevels, 1 do
  162.         for i = 1, platformInterval, 1 do
  163.             mineShaftSlice();
  164.         end
  165.  
  166.         minePlatform();
  167.     end
  168.  
  169.     print("Done!");
  170. end
  171.  
  172. local function main()
  173.     if #args ~= 1 or not (tonumber(args[1]) ~= nil or args[1] == "help") then
  174.         print("Correct usage:")
  175.         print("mineshafter <amountOfLevels> | help")
  176.     end
  177.  
  178.     if args[1] == "help" then
  179.         help()
  180.     else
  181.         mineshafter(args[1])
  182.     end
  183. end
  184.  
  185. main();
Add Comment
Please, Sign In to add comment