Xmann1

miner.lua

Apr 21st, 2025 (edited)
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.22 KB | None | 0 0
  1. local max_depth = 64
  2. local max_width = 64
  3.  
  4. local fuel_estimate = max_depth * 2 + 2 * max_width
  5.  
  6. function forward(dig)
  7.   while not turtle.forward() do
  8.     if dig then
  9.       block, data = turtle.inspect()
  10.       if block and data.name ~= "computercraft:turtle_normal" then
  11.         turtle.dig()
  12.       end
  13.     else
  14.       print("Waiting in queue......")
  15.     end
  16.   end
  17. end
  18.  
  19. function up(dig)
  20.   while not turtle.up() do
  21.     if dig then
  22.       turtle.digUp()
  23.     else
  24.       print("Waiting in queue......")
  25.     end
  26.   end
  27. end
  28.  
  29. function down(dig)
  30.   while not turtle.down() do
  31.     if dig then
  32.       turtle.digDown()
  33.     else
  34.       print("Waiting in queue......")
  35.     end
  36.   end
  37. end
  38.  
  39. print("Waiting for fuel...")
  40.  
  41. while true do
  42.   turtle.suckDown(1)
  43.   turtle.refuel(1)
  44.  
  45.   if turtle.getFuelLevel() >= fuel_estimate then
  46.     print("We have enough fuel to go mining!")
  47.     break
  48.   end
  49. end
  50.  
  51. local width = 0
  52.  
  53. for i=1, max_width / 2 do
  54.   forward(true)
  55.  
  56.   width = width + 1
  57.   print("Looking for free mining spot at width=" .. width)
  58.  
  59.   if turtle.detectDown() then
  60.     print("Free spot at width=" .. width .. "!")
  61.     break
  62.   end
  63. end
  64.  
  65. turtle.digDown()
  66. up()
  67.  
  68. local highspot = width % 2 == 1
  69.  
  70. if highspot then
  71.   print("Going up to high mining spot")
  72.  
  73.   for i=1, 3 do
  74.     up(true)
  75.   end
  76. end
  77.  
  78. turtle.turnLeft()
  79.  
  80. for depth=1, max_depth do
  81.   forward(true)
  82.  
  83.   turtle.digUp()
  84.   turtle.digDown()
  85.  
  86.   print("Mining out, depth=" .. depth)
  87. end
  88.  
  89. print("Gone far enough out, mining back")
  90.  
  91. if highspot then
  92.   turtle.turnLeft()
  93.  
  94.   forward(true)
  95.   width = width - 1
  96.  
  97.   turtle.turnLeft()
  98. else
  99.   turtle.turnRight()
  100.  
  101.   forward(true)
  102.   width = width + 1
  103.  
  104.   turtle.turnRight()
  105. end
  106.  
  107. for i=1, max_depth do
  108.   turtle.digUp()
  109.   turtle.digDown()
  110.  
  111.   forward(true)
  112.  
  113.   print("Mining back, depth=" .. (max_depth - i))
  114. end
  115.  
  116. turtle.digUp()
  117. turtle.digDown()
  118.  
  119. print("Mining done, returning to station")
  120. turtle.turnRight()
  121.  
  122. if highspot then
  123.   print("Going down from high mining spot")
  124.  
  125.   for i=1, 3 do
  126.     down()
  127.   end
  128. end
  129.  
  130. for i=1, width do
  131.   forward()
  132. end
  133.  
  134. for i=1, 16 do
  135.   turtle.select(i)
  136.   turtle.dropUp()
  137. end
  138.  
  139. turtle.select(1)
  140.  
  141. turtle.turnRight()
  142. turtle.turnRight()
  143.  
  144. down()
  145.  
  146. os.reboot()
  147.  
Advertisement
Add Comment
Please, Sign In to add comment