Kalgon

refueling miner

Nov 3rd, 2025
1,574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.19 KB | None | 0 0
  1. -- chunkminer.lua
  2. -- Mines a 16x16 chunk, auto-refuels from a chest behind it
  3.  
  4. -- === CONFIG ===
  5. local LENGTH = 16
  6. local WIDTH = 16
  7.  
  8. -- === STATE ===
  9. local x, y, z = 0, 0, 0 -- Position tracking
  10. local dir = 0 -- 0=north,1=east,2=south,3=west
  11. local layer = 0
  12.  
  13. -- === HELPERS ===
  14. local function turnLeft() turtle.turnLeft(); dir = (dir + 3) % 4 end
  15. local function turnRight() turtle.turnRight(); dir = (dir + 1) % 4 end
  16.  
  17. local function forward()
  18.     while not turtle.forward() do
  19.         turtle.dig()
  20.         turtle.attack()
  21.         sleep(0.4)
  22.     end
  23.     if dir == 0 then z = z - 1
  24.     elseif dir == 1 then x = x + 1
  25.     elseif dir == 2 then z = z + 1
  26.     elseif dir == 3 then x = x - 1 end
  27. end
  28.  
  29. local function up()
  30.     while not turtle.up() do
  31.         turtle.digUp()
  32.         turtle.attackUp()
  33.         sleep(0.4)
  34.     end
  35.     y = y + 1
  36. end
  37.  
  38. local function down()
  39.     while not turtle.down() do
  40.         turtle.digDown()
  41.         turtle.attackDown()
  42.         sleep(0.4)
  43.     end
  44.     y = y - 1
  45. end
  46.  
  47. -- === REFUELING ===
  48. local function refuel()
  49.     if turtle.getFuelLevel() == "unlimited" then return end
  50.     if turtle.getFuelLevel() > 100 then return end
  51.  
  52.     print("Refueling...")
  53.     local turned = false
  54.  
  55.     -- Turn around to face the chest
  56.     turnLeft()
  57.     turnLeft()
  58.     turned = true
  59.  
  60.     -- Try to suck fuel from chest
  61.     for slot = 1, 16 do
  62.         local detail = turtle.getItemDetail(slot)
  63.         if detail == nil then
  64.             turtle.suck()
  65.             detail = turtle.getItemDetail(slot)
  66.         end
  67.         if detail and turtle.refuel(1) then
  68.             while turtle.refuel(1) do end
  69.         end
  70.     end
  71.  
  72.     if turned then
  73.         turnLeft()
  74.         turnLeft()
  75.     end
  76.  
  77.     print("Fuel Level: " .. turtle.getFuelLevel())
  78. end
  79.  
  80. -- === MINING ===
  81. local function mineLayer()
  82.     for row = 1, WIDTH do
  83.         for col = 1, LENGTH - 1 do
  84.             refuel()
  85.             turtle.digDown()
  86.             turtle.dig()
  87.             forward()
  88.         end
  89.         if row < WIDTH then
  90.             if row % 2 == 1 then
  91.                 turnRight()
  92.                 turtle.dig()
  93.                 forward()
  94.                 turnRight()
  95.             else
  96.                 turnLeft()
  97.                 turtle.dig()
  98.                 forward()
  99.                 turnLeft()
  100.             end
  101.         end
  102.     end
  103.  
  104.     -- Return to start of this layer
  105.     if WIDTH % 2 == 1 then
  106.         turnRight()
  107.     else
  108.         turnLeft()
  109.     end
  110.     for i = 1, WIDTH - 1 do
  111.         forward()
  112.     end
  113.     if WIDTH % 2 == 1 then
  114.         turnRight()
  115.     else
  116.         turnLeft()
  117.     end
  118.     for i = 1, LENGTH - 1 do
  119.         forward()
  120.     end
  121. end
  122.  
  123. -- === MAIN ===
  124. local function main()
  125.     print("Starting 16x16 chunk mining...")
  126.     refuel()
  127.  
  128.     -- Go down until solid
  129.     while not turtle.detectDown() do
  130.         down()
  131.     end
  132.  
  133.     -- Mine layers upward until ceiling hit or full inventory
  134.     while true do
  135.         mineLayer()
  136.         print("Layer complete. Going up...")
  137.         up()
  138.  
  139.         if turtle.detectUp() then
  140.             print("Ceiling reached, stopping.")
  141.             break
  142.         end
  143.     end
  144.  
  145.     print("Chunk mining complete!")
  146. end
  147.  
  148. main()
  149.  
Advertisement
Add Comment
Please, Sign In to add comment