Advertisement
Le_JuiceBOX

ComputerCraft_Turtle_LavaRefuel

Apr 18th, 2023 (edited)
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.85 KB | None | 0 0
  1. local SEPERATOR = "======================================="
  2. local BUCKET_ID = "minecraft:bucket"
  3. local FUELBUCKET_ID = "minecraft:lava_bucket"
  4.  
  5.  
  6. function MAIN()
  7.     clear()
  8.     welcomeMessage()
  9.     untilSuccess(waitForBucket)
  10.     clear()
  11.     say(SEPERATOR)
  12.     say("\nFueling up...\n")
  13.     say(SEPERATOR)
  14.     Refuel();
  15.     clear()
  16.     say(SEPERATOR)
  17.     say("\nFinished.\n")
  18.     say(SEPERATOR)
  19. end
  20.  
  21. function clear() shell.run("clear"); end
  22. function say(...) print(...); end
  23.  
  24. function untilSuccess(func,...)
  25.     local s = false
  26.     repeat s = func(...); until s;
  27. end
  28.  
  29. function waitForBucket()
  30.     turtle.select(1)
  31.     local dat = turtle.getItemDetail()
  32.     if not dat or dat.name ~= BUCKET_ID then say("Insert bucket in slot 1 to continue."); pause(); return false; end
  33.     return true;
  34. end
  35.  
  36. function pause()
  37.     print("\nPress ENTER to continue...");
  38.     local pX,pY = term.getCursorPos()
  39.     --term.setCursorPos(0,0);
  40.     io.read();
  41.     clear()
  42.     --term.setCursorPos(1,1)
  43.     welcomeMessage();
  44. end
  45.  
  46. function Refuel(dir)
  47.     local blocksMoved = 0
  48.     repeat
  49.         turtle.placeDown()
  50.         turtle.select(1)
  51.         local dat = turtle.getItemDetail()
  52.         if dat and dat.name == FUELBUCKET_ID then
  53.             turtle.refuel(1)
  54.         end
  55.         turtle.forward()
  56.         blocksMoved = blocksMoved + 1
  57.         print("Fuel: "..tostring(turtle.getFuelLevel()).."...")
  58.     until turtle.getFuelLevel() >= turtle.getFuelLimit() - 100;
  59.     repeat
  60.         turtle.back()
  61.         blocksMoved = blocksMoved - 1
  62.     until blocksMoved == 0
  63. end
  64.  
  65. function welcomeMessage()
  66.     say(SEPERATOR)
  67.     say("Welcome to Turtle Refill!")
  68.     say(SEPERATOR)
  69. end
  70.  
  71. function isValidDir(txt)
  72.     local t = string.upper(txt)
  73.     return not ( (t=="TOP") or (t=="BOTTOM") or (t=="LEFT") or (t=="RIGHT") or (t=="FRONT") or (t=="BACK") );
  74. end
  75.  
  76. MAIN()
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement