Advertisement
KingKevin23

Miningv4

Feb 21st, 2022 (edited)
682
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.45 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.         if i % 2 == 1 then
  45.             turtle.back()
  46.             placeTorch()
  47.             moveForward(2)
  48.         end
  49.  
  50.         turtle.turnRight()
  51.         mine(8)
  52.         placeTorch()
  53.         turnAround()
  54.         moveForward(7)
  55.         mine(8)
  56.         placeTorch()
  57.         turnAround()
  58.         moveForward(7)
  59.         turtle.turnLeft()
  60.         for j=1, 16, 1 do
  61.             local slot = turtle.getItemDetail(j)
  62.             if slot ~= nil then
  63.                 if slot["name"] == "minecraft:cobblestone" then
  64.                     turtle.select(j)
  65.                     turtle.drop()
  66.                 end
  67.             end
  68.         end
  69.     end
  70. end
  71.  
  72. local function calculateFuel(number_of_corridors)
  73.     local fields_to_move = (number_of_corridors * 40) + (6 * math.ceil(number_of_corridors / 2))
  74.     return math.ceil(fields_to_move / 80)
  75. end
  76.  
  77. local function calculateTorches(number_of_corridors)
  78.     local additionalTorches = math.ceil(number_of_corridors / 2)
  79.     return (number_of_corridors * 2) + additionalTorches
  80. end
  81.  
  82. local function printWithConfirmation(string)
  83.     print(string)
  84.     local input = read()
  85.     if input ~= "y" and input ~= "yes" then
  86.         os.shutdown()
  87.     end
  88. end
  89.  
  90. print("Ultimate Miner by KingKevin23")
  91. print("How many corridors should be mined?")
  92. local number_of_corridors = tonumber(read())
  93. printWithConfirmation("Please provide " .. calculateFuel(number_of_corridors) .. " coal items in slot 1.")
  94. printWithConfirmation("Please provide " .. calculateTorches(number_of_corridors) .. " torches in slot 2.")
  95. turtle.select(1)
  96. turtle.refuel()
  97. stripMine(number_of_corridors)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement