Le_JuiceBOX

ComputerCraft_Turtle_LavaRefuel

Apr 18th, 2023 (edited)
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.33 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 waitForMinimumFuel()
  37.     local f = turtle.getFuelLevel()
  38.     if f < 1 then
  39.         return false
  40.     end
  41. end
  42.  
  43. function pause()
  44.     print("\nPress ENTER to continue...");
  45.     local pX,pY = term.getCursorPos()
  46.     --term.setCursorPos(0,0);
  47.     io.read();
  48.     clear()
  49.     --term.setCursorPos(1,1)
  50.     welcomeMessage();
  51. end
  52.  
  53. function Refuel(dir)
  54.     local blocksMoved = 0
  55.     local stopEarly = false --
  56.     repeat
  57.         turtle.placeDown()
  58.         turtle.select(1)
  59.         local dat = turtle.getItemDetail()
  60.         if dat and dat.name == FUELBUCKET_ID then
  61.             turtle.refuel(1)
  62.         end
  63.         local moveTries = 0
  64.         repeat
  65.             local success = turtle.forward()
  66.             if success == false then moveTries = moveTries + 1 end
  67.         until success or moveTries > 3
  68.         if moveTries <= 3 then
  69.             blocksMoved = blocksMoved + 1
  70.             print("Fuel: "..tostring(turtle.getFuelLevel()).."...")
  71.         else
  72.             print("Ran into a wall, returning early...")
  73.             stopEarly = true
  74.         end
  75.     until turtle.getFuelLevel() == turtle.getFuelLimit() or stopEarly;
  76.     repeat
  77.         turtle.back()
  78.         blocksMoved = blocksMoved - 1
  79.     until blocksMoved == 0
  80. end
  81.  
  82. function welcomeMessage()
  83.     say(SEPERATOR)
  84.     say("Welcome to Turtle Refill!")
  85.     say(SEPERATOR)
  86. end
  87.  
  88. function isValidDir(txt)
  89.     local t = string.upper(txt)
  90.     return not ( (t=="TOP") or (t=="BOTTOM") or (t=="LEFT") or (t=="RIGHT") or (t=="FRONT") or (t=="BACK") );
  91. end
  92.  
  93. MAIN()
  94.  
Advertisement
Add Comment
Please, Sign In to add comment