Advertisement
Grexxity

turtle test

May 17th, 2025 (edited)
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.73 KB | None | 0 0
  1. local lampName = "projectred-illumination:lamp"
  2. local minFuel = 10  -- Minimum fuel threshold
  3.  
  4. local validFuel = {
  5.     ["minecraft:coal"] = true,
  6.     ["minecraft:charcoal"] = true,
  7.     ["minecraft:blaze_rod"] = true,
  8.     ["minecraft:coal_block"] = true,
  9.     ["minecraft:lava_bucket"] = true,
  10.     ["minecraft:stick"] = true
  11. }
  12.  
  13. local function findLampSlot()
  14.     for i = 1, 16 do
  15.         local item = turtle.getItemDetail(i)
  16.         if item and item.name == lampName then
  17.             return i
  18.         end
  19.     end
  20.     return nil
  21. end
  22.  
  23. local function autoRefuel()
  24.     if turtle.getFuelLevel() == "unlimited" or turtle.getFuelLevel() >= minFuel then
  25.         return true
  26.     end
  27.  
  28.     for i = 1, 16 do
  29.         local item = turtle.getItemDetail(i)
  30.         if item and validFuel[item.name] then
  31.             turtle.select(i)
  32.             if turtle.refuel(1) then
  33.                 print("Refueled using", item.name)
  34.                 return true
  35.             end
  36.         end
  37.     end
  38.  
  39.     print("No fuel found! Halting.")
  40.     return false
  41. end
  42.  
  43. local function smartForward()
  44.     if turtle.detect() then
  45.         print("Wall detected. Stopping.")
  46.         return false
  47.     end
  48.  
  49.     if not turtle.forward() then
  50.         print("Failed to move forward. Possibly an entity or world edge.")
  51.         return false
  52.     end
  53.  
  54.     return true
  55. end
  56.  
  57. -- Main loop
  58. while true do
  59.     if not autoRefuel() then break end
  60.  
  61.     if not turtle.detectDown() then
  62.         local slot = findLampSlot()
  63.         if slot then
  64.             turtle.select(slot)
  65.             turtle.placeDown()
  66.         else
  67.             print("No lamps left. Stopping.")
  68.             break
  69.         end
  70.     end
  71.  
  72.     if not smartForward() then break end
  73.  
  74.     sleep(0.25)
  75. end
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement