profezzional

refuel

Apr 21st, 2021 (edited)
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.13 KB | None | 0 0
  1. local NUM_SLOTS = 16
  2. local MAX_STACK_SIZE = 64
  3. local args = { ... }
  4.  
  5. function refuelFromLocalInventory()
  6.     print("Refueling...")
  7.  
  8.     for i = 1, NUM_SLOTS do
  9.         turtle.select(i)
  10.         turtle.refuel(MAX_STACK_SIZE)
  11.     end
  12.  
  13.     turtle.select(1)
  14.     fuelLevel = turtle.getFuelLevel()
  15.     print("Refueled to " .. fuelLevel .. "/" .. turtle.getFuelLimit())
  16.  
  17.     return fuelLevel
  18. end
  19.  
  20. function refuelFromContainer(suckDirection, dropDirection)
  21.     local sucks = {
  22.         ["front"] = turtle.suck,
  23.         ["up"] = turtle.suckUp,
  24.         ["down"] = turtle.suckDown
  25.     }
  26.     local suck = sucks[suckDirection]
  27.  
  28.     local drops = {
  29.         ["front"] = turtle.drop,
  30.         ["up"] = turtle.dropUp,
  31.         ["down"] = turtle.dropDown
  32.     }
  33.     local drop = drops[dropDirection]
  34.  
  35.     for i = 1, NUM_SLOTS do
  36.         drop() -- empty inventory into drop container
  37.     end
  38.  
  39.     -- refuel from suck container as much as possible
  40.     while suck() do
  41.         if not turtle.refuel(MAX_STACK_SIZE) then
  42.             drop() -- not combustible, so drop it
  43.         end
  44.     end
  45. end
  46.  
  47. refuelFromLocalInventory("front", "up")
Add Comment
Please, Sign In to add comment