Advertisement
ZGAMMAA

Chunk Wireless

Apr 13th, 2025 (edited)
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.89 KB | None | 0 0
  1. -- ✅ CHUNK EATER (No rednet, includes left-chest refueling)
  2.  
  3. -- === CONFIG ===
  4. local CHUNK_SIZE = 16
  5. local LAYER_HEIGHT = 3
  6. local FUEL_BUFFER = 100
  7.  
  8. -- === POSITION TRACKING ===
  9. local x, y, z = 0, 0, 0
  10. local dir = 1 -- 0=north, 1=east, 2=south, 3=west
  11. local startX, startY, startZ, startDir = x, y, z, dir
  12.  
  13. -- === DIRECTION HELPERS ===
  14. local function turnRight() turtle.turnRight(); dir = (dir + 1) % 4 end
  15. local function turnLeft() turtle.turnLeft(); dir = (dir - 1) % 4 end
  16. local function face(target) while dir ~= target do turnRight() end end
  17. local function faceExact(targetDir) while dir ~= targetDir do turnRight() end end
  18. local function updatePosition(dx, dy, dz) x, y, z = x + dx, y + dy, z + dz end
  19.  
  20. -- === INVENTORY CHECK ===
  21. local function isFull()
  22.   for i = 1, 16 do
  23.     if turtle.getItemCount(i) == 0 then return false end
  24.   end
  25.   return true
  26. end
  27.  
  28. -- === GO TO COORDINATES ===
  29. local function goTo(xT, yT, zT)
  30.   while y < yT do turtle.down(); updatePosition(0, 1, 0) end
  31.   while y > yT do turtle.up(); updatePosition(0, -1, 0) end
  32.  
  33.   face(1) while x < xT do turtle.forward(); updatePosition(1, 0, 0) end
  34.   face(3) while x > xT do turtle.forward(); updatePosition(-1, 0, 0) end
  35.  
  36.   face(2) while z < zT do turtle.forward(); updatePosition(0, 0, 1) end
  37.   face(0) while z > zT do turtle.forward(); updatePosition(0, 0, -1) end
  38. end
  39.  
  40. -- === UNLOAD & REFUEL AT ORIGIN ===
  41. local function returnToStartAndUnload()
  42.   print("📦 Returning to original start point to dump items...")
  43.   goTo(startX, startY, startZ)
  44.   faceExact(startDir)
  45.  
  46.   -- Dump behind
  47.   turnLeft(); turnLeft()
  48.   for i = 1, 16 do
  49.     turtle.select(i)
  50.     turtle.drop()
  51.   end
  52.   turnLeft(); turnLeft()
  53. end
  54.  
  55. local function refuelFromInventory()
  56.   for i = 1, 16 do
  57.     turtle.select(i)
  58.     if turtle.refuel(0) then
  59.       turtle.refuel()
  60.       return true
  61.     end
  62.   end
  63.   return false
  64. end
  65.  
  66. local function refuelFromLeftChest()
  67.   turnLeft()
  68.   print("⛽ Attempting to refuel from left chest...")
  69.   for i = 1, 16 do
  70.     turtle.select(i)
  71.     if turtle.getFuelLevel() < turtle.getFuelLimit() then
  72.       turtle.suck()
  73.       if turtle.refuel(0) then
  74.         turtle.refuel()
  75.       else
  76.         turtle.drop() -- not fuel, drop it
  77.       end
  78.     end
  79.   end
  80.   turnRight()
  81.   print("✅ Refueled from left chest")
  82. end
  83.  
  84. local function checkFuel()
  85.   local estReturn = math.abs(x - startX) + math.abs(y - startY) + math.abs(z - startZ) + FUEL_BUFFER
  86.   if turtle.getFuelLevel() < estReturn then
  87.     local sx, sy, sz, sd = x, y, z, dir
  88.     print("⚠️ Low fuel. Returning to refuel...")
  89.     returnToStartAndUnload()
  90.     if not refuelFromInventory() then
  91.       refuelFromLeftChest()
  92.     end
  93.     goTo(sx, sy, sz)
  94.     faceExact(sd)
  95.   end
  96. end
  97.  
  98. -- === MOVEMENT ===
  99. local function tryForward()
  100.   if isFull() then
  101.     print("📦 Inventory full. Returning to dump...")
  102.     local sx, sy, sz, sd = x, y, z, dir
  103.     returnToStartAndUnload()
  104.     checkFuel()
  105.     goTo(sx, sy, sz)
  106.     faceExact(sd)
  107.   end
  108.  
  109.   checkFuel()
  110.   while not turtle.forward() do
  111.     turtle.dig()
  112.     sleep(0.3)
  113.   end
  114.   turtle.digUp()
  115.   turtle.digDown()
  116.   if dir == 0 then updatePosition(0, 0, -1)
  117.   elseif dir == 1 then updatePosition(1, 0, 0)
  118.   elseif dir == 2 then updatePosition(0, 0, 1)
  119.   elseif dir == 3 then updatePosition(-1, 0, 0)
  120.   end
  121. end
  122.  
  123. local function tryUp()
  124.   checkFuel()
  125.   while not turtle.up() do
  126.     turtle.digUp()
  127.     sleep(0.3)
  128.   end
  129.   updatePosition(0, -1, 0)
  130. end
  131.  
  132. local function tryDown()
  133.   checkFuel()
  134.   while not turtle.down() do
  135.     turtle.digDown()
  136.     sleep(0.3)
  137.   end
  138.   updatePosition(0, 1, 0)
  139. end
  140.  
  141. -- === DIG LAYER ===
  142. local function digLayer()
  143.   print("⛏ Digging layer at Y=" .. y)
  144.   for row = 1, CHUNK_SIZE do
  145.     for col = 1, CHUNK_SIZE - 1 do
  146.       tryForward()
  147.     end
  148.     if row < CHUNK_SIZE then
  149.       if row % 2 == 1 then
  150.         turnRight(); tryForward(); turnRight()
  151.       else
  152.         turnLeft(); tryForward(); turnLeft()
  153.       end
  154.     end
  155.   end
  156.  
  157.   -- Return to origin column
  158.   if x > 0 then face(3) while x > 0 do turtle.forward(); updatePosition(-1, 0, 0) end end
  159.   if x < 0 then face(1) while x < 0 do turtle.forward(); updatePosition(1, 0, 0) end end
  160.   if z > 0 then face(0) while z > 0 do turtle.forward(); updatePosition(0, 0, -1) end end
  161.   if z < 0 then face(2) while z < 0 do turtle.forward(); updatePosition(0, 0, 1) end end
  162.   face(1)
  163. end
  164.  
  165. -- === MAIN ===
  166. startX, startY, startZ, startDir = x, y, z, dir
  167.  
  168. print("Enter depth to dig:")
  169. local depth = tonumber(read())
  170. if not depth or depth <= 0 then
  171.   print("❌ Invalid depth.")
  172.   return
  173. end
  174.  
  175. print("🚧 Beginning chunk excavation to depth " .. depth)
  176.  
  177. for layer = 1, depth, LAYER_HEIGHT do
  178.   digLayer()
  179.   if layer + LAYER_HEIGHT <= depth then
  180.     print("⬇️ Descending to next layer...")
  181.     for i = 1, LAYER_HEIGHT do tryDown() end
  182.   end
  183. end
  184.  
  185. returnToStartAndUnload()
  186. print("✅ Chunk excavation complete.")
  187.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement