Bmorr

Untitled

Jul 17th, 2021 (edited)
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.39 KB | None | 0 0
  1. if not turtle then
  2.     printError("Requires a Turtle")
  3.     return
  4. end
  5.  
  6. local tArgs = { ... }
  7.  
  8. local doFull = true
  9. if (#tArgs == 1) then
  10.     local programName = arg[0] or fs.getName(shell.getRunningProgram())
  11.     print("Usage: " .. programName .. " <length>")
  12.     doFull = false
  13. end
  14.  
  15. -- Inventory Functions
  16. function checkIfSlotIsItem(slot, name)
  17.     local item = turtle.getItemDetail(slot)
  18.     if item ~= nil then
  19.         return item["name"] == name
  20.     end
  21.     return false
  22. end
  23.  
  24. function findItem(name)
  25.     for slot = 1, 16 do
  26.         if checkIfSlotIsItem(slot, name) then
  27.             return slot
  28.         end
  29.     end
  30.     return -1
  31. end
  32.  
  33. function checkIfHaveItem(name)
  34.     return findItem(name) ~= -1
  35. end
  36.  
  37. if not checkIfHaveItem("minecraft:bucket") then
  38.     print("Needs a bucket")
  39.     return
  40. end
  41.  
  42. local start_fuel = turtle.getFuelLevel()
  43. local toCollect = math.floor((turtle.getFuelLimit() - start_fuel) / 1000)
  44.  
  45. if not doFull then
  46.     toCollect = tArgs[1]
  47. end
  48.  
  49. for i = 1, toCollect / 2 do
  50.     turtle.placeDown()
  51.     turtle.refuel()
  52.     turtle.dig()
  53.     turtle.forward()
  54. end
  55. turtle.digDown()
  56. turtle.down()
  57. turtle.turnLeft()
  58. turtle.turnLeft()
  59. for i = 1, toCollect / 2 do
  60.     turtle.placeDown()
  61.     turtle.refuel()
  62.     turtle.dig()
  63.     turtle.forward()
  64. end
  65. turtle.up()
  66. turtle.turnLeft()
  67. turtle.turnLeft()
  68.  
  69. print("Fuel level is: "..turtle.getFuelLevel())
  70.  
Add Comment
Please, Sign In to add comment