Advertisement
McBaron

asgtyre

Jun 14th, 2025
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.68 KB | Gaming | 0 0
  1. -- Smart Filler: With Fuel Estimation & Direction Choice
  2.  
  3. -- Ask for numeric input
  4. local function askNumber(prompt)
  5.     print(prompt)
  6.     local val = tonumber(read())
  7.     while not val do
  8.         print("Please enter a valid number:")
  9.         val = tonumber(read())
  10.     end
  11.     return math.floor(val)
  12. end
  13.  
  14. -- Ask for direction choice
  15. local function askDirection()
  16.     print("Build direction? Type 'up' for bottom-to-top or 'down' for top-to-bottom:")
  17.     local dir = read()
  18.     while dir ~= "up" and dir ~= "down" do
  19.         print("Please type 'up' or 'down':")
  20.         dir = read()
  21.     end
  22.     return dir
  23. end
  24.  
  25. -- Prompt user
  26. local length = askNumber("Enter length:")
  27. local width = askNumber("Enter width:")
  28. local height = askNumber("Enter height:")
  29. local direction = askDirection()
  30.  
  31. -- Estimate fuel (very safe estimate: each block = move + turn + dig)
  32. local estimatedMoves = length * width * height * 2
  33. print("Estimated fuel needed: "..estimatedMoves)
  34.  
  35. -- Try refueling from slot 1
  36. turtle.select(1)
  37. if turtle.getFuelLevel() < estimatedMoves then
  38.     print("Refueling from slot 1...")
  39.     if not turtle.refuel(64) then
  40.         print("⚠️ Refuel failed or no valid fuel in slot 1.")
  41.     else
  42.         print("Refueled. Fuel level: "..turtle.getFuelLevel())
  43.     end
  44. end
  45.  
  46. -- Final check
  47. if turtle.getFuelLevel() < estimatedMoves then
  48.     print("❌ Not enough fuel. Need at least "..estimatedMoves..".")
  49.     return
  50. end
  51.  
  52. print("✅ Fuel OK. Starting build from "..direction.."...")
  53.  
  54. -- Block selection
  55. local function selectBlock()
  56.     for i = 2, 16 do
  57.         turtle.select(i)
  58.         if turtle.getItemCount() > 0 then return true end
  59.     end
  60.     return false
  61. end
  62.  
  63. -- Safe forward
  64. local function forward()
  65.     while not turtle.forward() do
  66.         turtle.dig()
  67.         sleep(0.2)
  68.     end
  69. end
  70.  
  71. -- Safe up/down
  72. local function moveUp()
  73.     while not turtle.up() do
  74.         turtle.digUp()
  75.         sleep(0.2)
  76.     end
  77. end
  78.  
  79. local function moveDown()
  80.     while not turtle.down() do
  81.         turtle.digDown()
  82.         sleep(0.2)
  83.     end
  84. end
  85.  
  86. -- Place block below
  87. local function place()
  88.     if not selectBlock() then
  89.         print("❌ Out of blocks!")
  90.         return false
  91.     end
  92.     if not turtle.detectDown() then
  93.         return turtle.placeDown()
  94.     end
  95.     return true
  96. end
  97.  
  98. -- Main fill logic
  99. local function buildLayer()
  100.     for w = 1, width do
  101.         for l = 1, length do
  102.             if not place() then return false end
  103.             if l < length then forward() end
  104.         end
  105.         if w < width then
  106.             if w % 2 == 1 then
  107.                 turtle.turnRight()
  108.                 forward()
  109.                 turtle.turnRight()
  110.             else
  111.                 turtle.turnLeft()
  112.                 forward()
  113.                 turtle.turnLeft()
  114.             end
  115.         end
  116.     end
  117.  
  118.     -- return to start of row
  119.     if width % 2 == 1 then
  120.         turtle.turnRight()
  121.         for i = 1, length - 1 do forward() end
  122.         turtle.turnRight()
  123.     else
  124.         turtle.turnLeft()
  125.         for i = 1, length - 1 do forward() end
  126.         turtle.turnLeft()
  127.     end
  128.  
  129.     return true
  130. end
  131.  
  132. -- Build loop
  133. local function build()
  134.     if direction == "up" then
  135.         for h = 1, height do
  136.             print("Building layer "..h.." / "..height)
  137.             if not buildLayer() then return end
  138.             if h < height then moveUp() end
  139.         end
  140.     else
  141.         for i = 1, height - 1 do moveUp() end
  142.         for h = height, 1, -1 do
  143.             print("Building layer "..h.." / "..height)
  144.             if not buildLayer() then return end
  145.             if h > 1 then moveDown() end
  146.         end
  147.     end
  148. end
  149.  
  150. build()
  151. print("✅ Build complete!")
  152.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement