Advertisement
McBaron

Untitled

Jun 14th, 2025
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.92 KB | Gaming | 0 0
  1. -- Turtle Dirt Filler with Full Debug and Fuel Check
  2.  
  3. -- Function to prompt for numeric input
  4. local function askForNumber(prompt)
  5.     print(prompt)
  6.     local input = read()
  7.     local number = tonumber(input)
  8.     while not number do
  9.         print("Please enter a valid number.")
  10.         input = read()
  11.         number = tonumber(input)
  12.     end
  13.     return number
  14. end
  15.  
  16. -- Ask for area dimensions
  17. local length = askForNumber("Enter length:")
  18. local width = askForNumber("Enter width:")
  19. local height = askForNumber("Enter height:")
  20.  
  21. print("Preparing to build area of size "..length.." x "..width.." x "..height)
  22.  
  23. -- Check fuel
  24. local fuel = turtle.getFuelLevel()
  25. if fuel == "unlimited" then
  26.     print("Fuel: Unlimited (creative mode)")
  27. elseif fuel == 0 then
  28.     print("ERROR: Turtle has no fuel. Please refuel before running the script.")
  29.     return
  30. else
  31.     print("Fuel level: "..fuel)
  32. end
  33.  
  34. -- Function to select dirt in inventory
  35. local function selectDirt()
  36.     for i = 1, 16 do
  37.         turtle.select(i)
  38.         local item = turtle.getItemDetail()
  39.         if item and item.name:find("dirt") then
  40.             print("Selected dirt in slot "..i)
  41.             return true
  42.         end
  43.     end
  44.     print("No dirt found in inventory!")
  45.     return false
  46. end
  47.  
  48. -- Place dirt below turtle
  49. local function placeDown()
  50.     if turtle.detectDown() then
  51.         print("Block already exists below.")
  52.         return true
  53.     end
  54.  
  55.     if not turtle.placeDown() then
  56.         print("Trying to select dirt to place...")
  57.         if not selectDirt() then
  58.             print("ERROR: Out of dirt. Cannot continue.")
  59.             return false
  60.         end
  61.         if not turtle.placeDown() then
  62.             print("ERROR: Failed to place dirt even after selecting.")
  63.             return false
  64.         end
  65.     end
  66.  
  67.     print("Placed dirt below.")
  68.     return true
  69. end
  70.  
  71. -- Move forward with feedback and fuel check
  72. local function forward()
  73.     local tries = 0
  74.     while not turtle.forward() do
  75.         if turtle.getFuelLevel() == 0 then
  76.             print("ERROR: Out of fuel!")
  77.             return false
  78.         end
  79.         print("Blocked. Digging forward...")
  80.         turtle.dig()
  81.         sleep(0.5)
  82.         tries = tries + 1
  83.         if tries > 10 then
  84.             print("ERROR: Can't move forward after multiple attempts.")
  85.             return false
  86.         end
  87.     end
  88.     return true
  89. end
  90.  
  91. -- Move up with feedback and fuel check
  92. local function moveUp()
  93.     local tries = 0
  94.     while not turtle.up() do
  95.         if turtle.getFuelLevel() == 0 then
  96.             print("ERROR: Out of fuel!")
  97.             return false
  98.         end
  99.         print("Blocked above. Digging up...")
  100.         turtle.digUp()
  101.         sleep(0.5)
  102.         tries = tries + 1
  103.         if tries > 10 then
  104.             print("ERROR: Can't move up after multiple attempts.")
  105.             return false
  106.         end
  107.     end
  108.     return true
  109. end
  110.  
  111. -- Build one hori
  112.  
Tags: turtle fill
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement