KingKevin23

Miningv3

Feb 18th, 2022 (edited)
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.90 KB | None | 0 0
  1. local function mine(x)
  2.     local counter = 0
  3.     repeat
  4.         turtle.dig()
  5.         moveForward(1)
  6.         turtle.digUp()
  7.         counter = counter + 1
  8.     until counter == x
  9. end
  10.  
  11. local function turnAround()
  12.     turtle.turnRight()
  13.     turtle.turnRight()
  14. end
  15.  
  16. function moveForward(x)
  17.     for i = 1, x, 1 do
  18.         if turtle.forward() then
  19.             -- nichts passiert
  20.         else
  21.             if turtle.detect() then
  22.                 while(turtle.detect()) do
  23.                     turtle.dig()
  24.                 end
  25.                 moveForward(1)
  26.             else
  27.                 os.shutdown()
  28.             end
  29.         end
  30.     end
  31. end
  32.  
  33. local function placeTorch()
  34.     turtle.up()
  35.     turtle.select(2)
  36.     turtle.back()
  37.     turtle.place()
  38.     turtle.down()
  39. end
  40.  
  41. local function stripMine(x)
  42.     for i = 1, x, 1 do
  43.         mine(3)
  44.         turtle.turnRight()
  45.         mine(8)
  46.         placeTorch()
  47.         turnAround()
  48.         moveForward(7)
  49.         mine(8)
  50.         placeTorch()
  51.         turnAround()
  52.         moveForward(7)
  53.         turtle.turnLeft()
  54.     end
  55. end
  56.  
  57. local function calculateFuel(number_of_corridors)
  58.     local fields_to_move = number_of_corridors * 40
  59.     return math.ceil(fields_to_move / 80)
  60. end
  61.  
  62. local function calculateTorches(number_of_corridors)
  63.     return number_of_corridors * 2
  64. end
  65.  
  66. local function printWithConfirmation(string)
  67.     print(string)
  68.     local input = read()
  69.     if input ~= "y" and input ~= "yes" then
  70.         os.shutdown()
  71.     end
  72. end
  73.  
  74. print("Ultimate Miner by KingKevin23")
  75. print("How many corridors should be mined?")
  76. local number_of_corridors = tonumber(read())
  77. printWithConfirmation("Please provide " .. calculateFuel(number_of_corridors) .. " coal items in slot 1.")
  78. printWithConfirmation("Please provide " .. calculateTorches(number_of_corridors) .. " torches in slot 2.")
  79. turtle.select(1)
  80. turtle.refuel()
  81. stripMine(number_of_corridors)
Add Comment
Please, Sign In to add comment