Advertisement
KingKevin23

Miningv5

Aug 4th, 2023 (edited)
1,142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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, placeTorches)
  42.     for i = 1, x, 1 do
  43.         mine(3)
  44.         if i % 2 == 1 and placeTorches then
  45.             turtle.back()
  46.             placeTorch()
  47.             moveForward(2)
  48.         end
  49.  
  50.         turtle.turnRight()
  51.         mine(8)
  52.         if placeTorches then
  53.             placeTorch()
  54.         else
  55.             turtle.back()
  56.         end
  57.        
  58.         turnAround()
  59.         moveForward(7)
  60.         mine(8)
  61.         if placeTorches then
  62.             placeTorch()
  63.         else
  64.             turtle.back()
  65.         end
  66.        
  67.         turnAround()
  68.         moveForward(7)
  69.         turtle.turnLeft()
  70.         for j=1, 16, 1 do
  71.             local slot = turtle.getItemDetail(j)
  72.             if slot ~= nil then
  73.                 if slot["name"] == "minecraft:cobblestone" then
  74.                     turtle.select(j)
  75.                     turtle.drop()
  76.                 end
  77.             end
  78.         end
  79.     end
  80. end
  81.  
  82. local function calculateFuel(numberOfCorridors)
  83.     return (numberOfCorridors * 40) + (6 * math.ceil(numberOfCorridors / 2))
  84. end
  85.  
  86. local function calculateTorches(numberOfCorridors)
  87.     local additionalTorches = math.ceil(numberOfCorridors / 2)
  88.     return (numberOfCorridors * 2) + additionalTorches
  89. end
  90.  
  91. local function printWithConfirmation(string)
  92.     print(string)
  93.     local input = read()
  94.     if input ~= "y" and input ~= "yes" then
  95.         os.shutdown()
  96.     end
  97. end
  98.  
  99. print("Ultimate Miner by KingKevin23")
  100. print("How many corridors should be mined?")
  101. local numberOfCorridors = tonumber(read())
  102. print("Should I place torches? (y/n)")
  103. local placeTorches = read() == "y"
  104. local fuelNeeded = calculateFuel(numberOfCorridors) - turtle.getFuelLevel()
  105. if fuelNeeded > 0 then
  106.     printWithConfirmation("Please provide " .. math.ceil(fuelNeeded / 80) .. " coal items in slot 1. \n Alternatively you can manually fuel with " .. math.ceil(fuelNeeded / 1000) .. " lava!")
  107. end
  108.  
  109. if placeTorches then
  110.     printWithConfirmation("Please provide " .. calculateTorches(numberOfCorridors) .. " torches in slot 2.")
  111. end
  112. turtle.select(1)
  113. turtle.refuel()
  114. stripMine(numberOfCorridors, placeTorches)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement