Jameelo

Turtle Lava Ocean Refuelling Program

Nov 16th, 2023 (edited)
1,010
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.34 KB | None | 0 0
  1. --[[
  2.     This project will make the turtle refuel x amount of times by wading through lava, because I'm lazy and don't want to constantly feed it coal
  3. ]]
  4.  
  5. term.clear()
  6.  
  7. os.loadAPI("common/systemLib.lua")
  8. os.loadAPI("common/storageLib.lua")
  9.  
  10. LENGTH = 0
  11. ODOMETER = 0
  12.  
  13. local args = {...}
  14.  
  15. print("Welcome to the lava swim refuel program.")
  16. os.sleep(1)
  17. print("I will move forwards and down to begin swimming.")
  18. os.sleep(1)
  19. print("After finishing, I'll make my way back to you :)\n")
  20. os.sleep(3)
  21.  
  22. term.clear()
  23.  
  24. local function setup()
  25.     if #args > 1 then
  26.         -- if the user specified a distance in the args
  27.         LENGTH = args[1]
  28.     else
  29.         local incompleteInput = true
  30.         while incompleteInput do
  31.             print("How many blocks of lava shall I eat?\n 0 means I will go until I'm full or hit an obstruction.")
  32.             LENGTH = tonumber(read())
  33.             if LENGTH then
  34.                 incompleteInput = false
  35.                 return
  36.             end
  37.             term.clear()
  38.             print("Error! Enter a proper value please!\n")
  39.         end
  40.     end
  41. end
  42.  
  43.  
  44. local function main()
  45.     setup()
  46.  
  47.     if LENGTH == 0 then
  48.         LENGTH = 65535
  49.     end
  50.  
  51.     local bucket = storageLib.findItemBF("minecraft:bucket")
  52.     if bucket > 0 then
  53.         turtle.select(bucket)
  54.     else
  55.         term.clear()
  56.         print("I don't have a bucket!!")
  57.         return
  58.     end
  59.  
  60.     -- Don't waste the lava below!
  61.     turtle.forward()
  62.     turtle.placeDown()
  63.     turtle.refuel()
  64.     turtle.down()
  65.  
  66.     for _ = 1,LENGTH-1,1 do -- Fill bucket, eat bucket contents, move forward.
  67.         turtle.place()
  68.         turtle.refuel()
  69.         turtle.forward()
  70.         if LENGTH > 0 then
  71.             ODOMETER = ODOMETER + 1
  72.         end
  73.     end
  74.  
  75.     -- return journey
  76.     turtle.up()
  77.     turtle.turnLeft()
  78.     turtle.turnLeft()
  79.  
  80.     if LENGTH > 0 then
  81.         for _ = 1,LENGTH,1 do
  82.             turtle.forward()
  83.         end
  84.     else
  85.         for _ = 1,ODOMETER,1 do
  86.             turtle.forward()
  87.         end
  88.     end
  89.  
  90.     write("Finished with new fuel level = ")
  91.     print(turtle.getFuelLevel())
  92.     print("")
  93. end
  94.  
  95.  
  96. if turtle.getFuelLevel() > 2 then -- You only need 1 fuel to start refueling.
  97.     main()
  98. else
  99.     print("You need some level of fuel to use this program. Please get at least 3 fuel to proceed.")
  100. end
Advertisement
Add Comment
Please, Sign In to add comment