Advertisement
Alexr360

Turtle Fuel

Feb 24th, 2024 (edited)
969
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.85 KB | None | 0 0
  1. function refuel()
  2.     -- Loop over each slot in the turtle's inventory
  3.     for i = 1, 16 do
  4.         -- Select the slot
  5.         turtle.select(i)
  6.        
  7.         -- Get the count of items in the slot
  8.         local itemCount = turtle.getItemCount(i)
  9.  
  10.         -- While there are items in the slot and refueling hasn't reached 64 times
  11.         local refuelCount = 0
  12.         while itemCount > 0 and refuelCount < 64 do
  13.             if turtle.refuel(1) then
  14.                 refuelCount = refuelCount + 1
  15.                 itemCount = turtle.getItemCount(i) -- Update item count after refueling
  16.             else
  17.                 break -- Exit if unable to refuel
  18.             end
  19.         end
  20.     end
  21.  
  22.     -- Print out the turtle's current fuel level
  23.     print("Current fuel level: " .. turtle.getFuelLevel())
  24. end
  25.  
  26. -- Call the refuel function
  27. refuel()
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement