heresjohnny32

minecraft_cc_tweek_mineing

Jul 16th, 2026
31,935
1
Never
5
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.12 KB | Gaming | 1 0
  1. -- Configuration
  2. local WIDTH = 32
  3. local LENGTH = 32
  4. local DEPTH = 32
  5.  
  6. -- State Tracking
  7. local x, y, z = 0, 0, 0
  8. local facing = 0 -- 0: Forward, 1: Right, 2: Back, 3: Left
  9. local returnX, returnY, returnZ, returnFacing
  10.  
  11. -- UI Functions
  12. local function drawUI(status)
  13.     term.clear()
  14.     term.setCursorPos(1, 1)
  15.     print("=== Advanced Mining Turtle ===")
  16.     print("Status: " .. status)
  17.     print(string.format("Pos   : X:%d Y:%d Z:%d", x, y, z))
  18.     print("Fuel  : " .. turtle.getFuelLevel() .. "/" .. turtle.getFuelLimit())
  19. end
  20.  
  21. -- Movement & Positioning
  22. local function turnRight()
  23.     turtle.turnRight()
  24.     facing = (facing + 1) % 4
  25. end
  26.  
  27. local function turnLeft()
  28.     turtle.turnLeft()
  29.     facing = (facing - 1) % 4
  30. end
  31.  
  32. local function moveForward()
  33.     while turtle.detect() do turtle.dig() end
  34.     if turtle.forward() then
  35.         if facing == 0 then z = z + 1
  36.         elseif facing == 1 then x = x + 1
  37.         elseif facing == 2 then z = z - 1
  38.         elseif facing == 3 then x = x - 1
  39.         end
  40.         return true
  41.     end
  42.     return false
  43. end
  44.  
  45. local function moveUp()
  46.     while turtle.detectUp() do turtle.digUp() end
  47.     if turtle.up() then y = y + 1; return true end
  48.     return false
  49. end
  50.  
  51. local function moveDown()
  52.     while turtle.detectDown() do turtle.digDown() end
  53.     if turtle.down() then y = y - 1; return true end
  54.     return false
  55. end
  56.  
  57. local function turnTo(targetFacing)
  58.     while facing ~= targetFacing do
  59.         turnRight()
  60.     end
  61. end
  62.  
  63. -- Maintenance Checks
  64. local function needsFuel()
  65.     local distanceHome = math.abs(x) + math.abs(y) + math.abs(z) + 5
  66.     return turtle.getFuelLevel() < distanceHome
  67. end
  68.  
  69. local function isFull()
  70.     for i = 1, 16 do
  71.         if turtle.getItemCount(i) == 0 then return false end
  72.     end
  73.     return true
  74. end
  75.  
  76. -- Navigation Home and Back
  77. local function goHome()
  78.     returnX, returnY, returnZ, returnFacing = x, y, z, facing
  79.     drawUI("Returning Home...")
  80.  
  81.     -- Rise to safety height first to avoid walls, then go home
  82.     while y < 0 do moveUp() end
  83.    
  84.     -- Align and move X
  85.     if x > 0 then turnTo(3) while x > 0 do moveForward() end
  86.     elseif x < 0 then turnTo(1) while x < 0 do moveForward() end
  87.     end
  88.  
  89.     -- Align and move Z
  90.     if z > 0 then turnTo(2) while z > 0 do moveForward() end
  91.     elseif z < 0 then turnTo(0) while z < 0 do moveForward() end
  92.     end
  93.  
  94.     -- Drop items behind
  95.     turnTo(2)
  96.     for i = 1, 15 do
  97.         turtle.select(i)
  98.         turtle.drop()
  99.     end
  100.    
  101.     -- Refuel from chest above
  102.     turtle.select(16)
  103.     turtle.suckUp()
  104.     turtle.refuel()
  105.    
  106.     turtle.select(1)
  107. end
  108.  
  109. local function resumePosition()
  110.     drawUI("Returning to Work...")
  111.     -- Move Z
  112.     if returnZ > 0 then turnTo(0) while z < returnZ do moveForward() end
  113.     end
  114.     -- Move X
  115.     if returnX > 0 then turnTo(1) while x < returnX do moveForward() end
  116.     end
  117.     -- Move Down
  118.     while y > returnY do moveDown() end
  119.     turnTo(returnFacing)
  120. end
  121.  
  122. local function checkMaintenance()
  123.     if needsFuel() or isFull() then
  124.         goHome()
  125.         resumePosition()
  126.     end
  127. end
  128.  
  129. -- Core Mining Logic
  130. local function mineLayer()
  131.     for i = 1, LENGTH do
  132.         for j = 1, WIDTH - 1 do
  133.             checkMaintenance()
  134.             moveForward()
  135.         end
  136.         if i < LENGTH then
  137.             if i % 2 == 1 then
  138.                 turnRight() moveForward() turnRight()
  139.             else
  140.                 turnLeft() moveForward() turnLeft()
  141.             end
  142.         end
  143.     end
  144. end
  145.  
  146. local function main()
  147.     turtle.select(1)
  148.     turtle.refuel() -- Initial fuel check
  149.    
  150.     for layer = 1, DEPTH do
  151.         drawUI("Mining Layer " .. layer)
  152.         mineLayer()
  153.        
  154.         if layer < DEPTH then
  155.             -- Return to start column of the layer before dropping down
  156.             drawUI("Resetting Column...")
  157.             while x > 0 do turnTo(3) moveForward() end
  158.             while z > 0 do turnTo(2) moveForward() end
  159.             turnTo(0)
  160.             moveDown()
  161.         end
  162.     end
  163.    
  164.     drawUI("Job Finished! Going Home.")
  165.     goHome()
  166.     turnTo(0)
  167.     drawUI("Done!")
  168. end
  169.  
  170. main()
  171.  
Advertisement