JustJurt

Dig Area New

Jul 21st, 2024 (edited)
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.89 KB | Gaming | 0 0
  1. local depth = 0
  2. local width = 0
  3. local height = 0
  4. local total = 0
  5. local progress = 0
  6. local layersLeft = 0
  7.  
  8. local function progressUpdate()
  9.     progress = progress + 1
  10.     term.clear()
  11.     term.setCursorPos(1,2)
  12.     write('Operation progress: ')
  13.     write(math.floor((progress/total)*1000)/10)
  14.     write('%\nLayers left to mine: ')
  15.     write(layersLeft)
  16.     write('\nBlocks left to mine: ')
  17.     write(total-progress)
  18. end
  19.  
  20. local function isFallingBlock(direction)
  21.     local success = false
  22.     if direction == "forward" then success = turtle.detect() end
  23.     if direction == "up" then success = turtle.detectUp() end
  24.     if direction == "down" then success = turtle.detectDown() end
  25.     if success then
  26.         return true
  27.     end
  28.     return false
  29. end
  30.  
  31. local function dig(direction)
  32.     if direction == "forward" then turtle.dig() end
  33.     if direction == "up" then turtle.digUp() end
  34.     if direction == "down" then turtle.digDown() end
  35.     while isFallingBlock(direction) do
  36.         if direction == "forward" then turtle.dig() end
  37.         if direction == "up" then turtle.digUp() end
  38.         if direction == "down" then turtle.digDown() end
  39.     end
  40.     progressUpdate()
  41. end
  42.  
  43. local function Excavate()
  44.     local atTop = false
  45.     local atRight = false
  46.     local heightIsOdd = true
  47.     if math.floor(height/2) == height/2 then
  48.         heightIsOdd = false
  49.     end
  50.     for z = 1, depth, 1 do
  51.         layersLeft = depth - z
  52.         dig("forward")
  53.         turtle.forward()
  54.         if atRight then
  55.             turtle.turnLeft()
  56.         else
  57.             turtle.turnRight()
  58.         end
  59.         local doubleLayers = math.floor(height/2)
  60.        
  61.         for y = 1, doubleLayers, 1 do
  62.             for x = 1, width - 1, 1 do
  63.                 dig("forward")
  64.                 if atTop then
  65.                     dig("down")
  66.                 else
  67.                     dig("up")
  68.                 end
  69.                 turtle.forward()
  70.             end
  71.             height = height + 0
  72.             if y < doubleLayers then
  73.                 if atTop then
  74.                     dig("down")
  75.                     turtle.down()
  76.                     dig("down")
  77.                     turtle.down()
  78.                 else
  79.                     dig("up")
  80.                     turtle.up()
  81.                     dig("up")
  82.                     turtle.up()
  83.                 end
  84.                 turtle.turnRight()
  85.                 turtle.turnRight()
  86.             else
  87.                 if atTop then
  88.                     dig("down")
  89.                     turtle.down()
  90.                 else
  91.                     dig("up")
  92.                     turtle.up()
  93.                 end
  94.             end
  95.             atRight = not atRight
  96.  
  97.         end
  98.         if heightIsOdd then
  99.             turtle.turnRight()
  100.             turtle.turnRight()
  101.             for x = 1, width - 1, 1 do
  102.                 if atTop then
  103.                     dig("down")
  104.                 else
  105.                     dig("up")
  106.                 end
  107.                 turtle.forward()
  108.             end
  109.             if atTop then
  110.                 dig("down")
  111.                 turtle.down()
  112.             else
  113.                 dig("up")
  114.                 turtle.up()
  115.             end
  116.             atRight = not atRight
  117.         end
  118.  
  119.         if atRight then
  120.             turtle.turnLeft()
  121.         else
  122.             turtle.turnRight()
  123.         end
  124.         atTop = not atTop
  125.     end
  126. end
  127.  
  128. term.clear()
  129. term.setCursorPos(1,2)
  130. print('[EXCAVATOR]')
  131. write('Depth: ')
  132. depth = read()
  133. write('Width: ')
  134. width = read()
  135. write('Height: ')
  136. height = read()
  137. write('Total blocks to mine: ')
  138. total = width*height*depth
  139. print(total)
  140. write('Type "yes" to confirm: ')
  141. local confirm = read()
  142. term.clear()
  143. term.setCursorPos(1,2)
  144. if confirm == "yes" then
  145.     Excavate()
  146.     term.clear()
  147.     term.setCursorPos(1,2)
  148.     write('Operation complete.\n')
  149. else
  150.     write('Operation canceled\n')
  151. end
  152.  
Advertisement
Add Comment
Please, Sign In to add comment