Advertisement
ZGAMMAA

Stairs + Lights

Apr 10th, 2025 (edited)
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.43 KB | None | 0 0
  1. -- Straight Staircase Miner — Simpler Turtle Program
  2.  
  3. -- === CONFIG ===
  4. local TORCH_INTERVAL = 10
  5. local TORCH_SLOT = 16
  6. local FUEL_BUFFER = 100
  7.  
  8. -- === STATE ===
  9. local stepCount = 0
  10. local dir = 1 -- 1 = East
  11. local x, y, z = 0, 0, 0
  12. local startX, startY, startZ, startDir = 0, 0, 0, dir
  13.  
  14. -- === HELPERS ===
  15. local function update(dx, dy, dz) x, y, z = x + dx, y + dy, z + dz end
  16.  
  17. local function tryForward()
  18.   while not turtle.forward() do
  19.     turtle.dig()
  20.     sleep(0.2)
  21.   end
  22.   if dir == 0 then update(0, 0, -1)
  23.   elseif dir == 1 then update(1, 0, 0)
  24.   elseif dir == 2 then update(0, 0, 1)
  25.   elseif dir == 3 then update(-1, 0, 0) end
  26. end
  27.  
  28. local function tryDown()
  29.   while not turtle.down() do
  30.     turtle.digDown()
  31.     sleep(0.2)
  32.   end
  33.   update(0, -1, 0)
  34. end
  35.  
  36. local function tryUp()
  37.   while not turtle.up() do
  38.     turtle.digUp()
  39.     sleep(0.2)
  40.   end
  41.   update(0, 1, 0)
  42. end
  43.  
  44. local function face(d)
  45.   while dir ~= d do turtle.turnRight(); dir = (dir + 1) % 4 end
  46. end
  47.  
  48. local function goTo(tx, ty, tz)
  49.   while y > ty do tryUp() end
  50.   while y < ty do tryDown() end
  51.   if x < tx then face(1) while x < tx do tryForward() end end
  52.   if x > tx then face(3) while x > tx do tryForward() end end
  53.   if z < tz then face(2) while z < tz do tryForward() end end
  54.   if z > tz then face(0) while z > tz do tryForward() end end
  55. end
  56.  
  57. local function returnToOrigin()
  58.   goTo(startX, startY, startZ)
  59.   face(startDir)
  60. end
  61.  
  62. -- === INVENTORY ===
  63. local function isFull()
  64.   for i = 1, 15 do
  65.     if turtle.getItemCount(i) == 0 then return false end
  66.   end
  67.   return true
  68. end
  69.  
  70. local function unloadInventory()
  71.   print("📦 Inventory full. Returning to unload...")
  72.   local ox, oy, oz, od = x, y, z, dir
  73.   returnToOrigin()
  74.   face((startDir + 2) % 4)
  75.   for i = 1, 15 do turtle.select(i); turtle.drop() end
  76.   face(startDir)
  77.   goTo(ox, oy, oz); face(od)
  78. end
  79.  
  80. -- === FUEL ===
  81. local function refuelIfNeeded()
  82.   if turtle.getFuelLevel() == "unlimited" or turtle.getFuelLevel() > FUEL_BUFFER then return end
  83.   print("🔋 Fuel low. Returning to refuel...")
  84.   local ox, oy, oz, od = x, y, z, dir
  85.   returnToOrigin()
  86.   face((startDir - 1) % 4)
  87.   for i = 1, 16 do
  88.     turtle.select(i)
  89.     if turtle.suck() and turtle.refuel() then break end
  90.   end
  91.   face(startDir)
  92.   goTo(ox, oy, oz); face(od)
  93. end
  94.  
  95. -- === TORCH ===
  96. local function placeTorch()
  97.   if stepCount % TORCH_INTERVAL == 0 then
  98.     turtle.select(TORCH_SLOT)
  99.     turtle.placeUp()
  100.     print("🕯️ Placed torch.")
  101.   end
  102. end
  103.  
  104. -- === BEDROCK ===
  105. local function isBedrockBelow()
  106.   local ok, data = turtle.inspectDown()
  107.   return ok and data.name == "minecraft:bedrock"
  108. end
  109.  
  110. -- === MAIN ===
  111. print("Enter depth to dig (or 'bedrock'):")
  112. local input = read()
  113. input = input:lower()
  114. local toBedrock = (input == "bedrock")
  115. local targetY = tonumber(input)
  116. if not toBedrock and (not targetY or targetY <= 0) then print("❌ Invalid input.") return end
  117.  
  118. startX, startY, startZ, startDir = x, y, z, dir
  119.  
  120. print("⛏️ Starting straight staircase...")
  121. while true do
  122.   if toBedrock and isBedrockBelow() then print("🪨 Bedrock reached."); break end
  123.   if not toBedrock and y >= targetY then print("📉 Reached target depth."); break end
  124.  
  125.   turtle.dig()
  126.   tryForward()
  127.   turtle.digDown()
  128.   tryDown()
  129.  
  130.   stepCount = stepCount + 1
  131.   placeTorch()
  132.   if isFull() then unloadInventory() end
  133.   refuelIfNeeded()
  134. end
  135.  
  136. returnToOrigin()
  137. print("✅ Staircase complete. Turtle returned to start.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement