Advertisement
HerrStackhouse

Refuel Functions

Dec 14th, 2012
727
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.43 KB | None | 0 0
  1. -- HerrStackhouse's Refuel Functions
  2. --
  3. -- (All credit to Elo for the concept and for inspiring me to figure
  4. -- out how to reproduce it. ALL HAIL THE RED QUEEN.)   
  5. --
  6. -- Composed of two functions. The first to be called, st_refuel(),
  7. -- tests the current fuel levels in the turtle and places two calls
  8. -- to the second function, st_manageFuelChest(Str). The first call,
  9. -- "start", tests the surroundings for suitable placement locations
  10. -- before deploying an Enderchest from slot 16. st_refuel() will then
  11. -- take over again, sucking fuel from the chest, before passing
  12. -- "finish" back to st_manageFuelChest(Str), which will take the chest back into inventory.
  13. --
  14. -- The two functions must be added in the order below, or st_refuel will
  15. -- holler at you for calling nil. Leave nil alone, she's totally over you.
  16. --
  17. -- The while true do loop at the bottom is entirely useless and is only here
  18. -- for testing purposes. Remove it before use.
  19.  
  20.  
  21.  
  22. function st_manageFuelChest(Str)
  23.     if Str == "start" then
  24.         --test for open spaces to place chest, place it, record its orientation, take fuel into slot 14
  25.         turtle.select(16)
  26.         if turtle.place() == true then
  27.             fuelChestLocation = 1
  28.             turtle.select(14)
  29.             turtle.suck()
  30.         elseif turtle.placeUp == true then
  31.             fuelChestLocation = 2
  32.             turtle.select(14)
  33.             turtle.suck()
  34.         elseif turtle.placeDown == true then
  35.             fuelChestLocation = 3
  36.             turtle.select(14)
  37.             turtle.suck()
  38.         else write("Something breaks when I try to place my fuel chest.\n")
  39.         end
  40.     elseif Str == "finish" then
  41.         -- retrieve location of fuel chest and dig that way
  42.         if fuelChestLocation == 1 then
  43.             turtle.dig()
  44.         elseif fuelChestLocation == 2 then
  45.             turtle.digUp()
  46.         elseif fuelChestLocation == 3 then
  47.             turtle.digDown()
  48.         else write("Something breaks when I try to retrieve my fuel chest.\n")
  49.         end
  50.     else write("st_manageFuelChest recieved a weird argument.\n")
  51.     end
  52. end
  53. function st_refuel()
  54.     while turtle.getFuelLevel() <= 5 do
  55.         write("Hungry.\n")
  56.         st_manageFuelChest("start") -- deploy chest and take fuel
  57.         for i=1,16 do -- now test each internal slot for consumable items
  58.             turtle.select(i)
  59.             if turtle.refuel(1) == true then
  60.                 turtle.refuel()
  61.             end
  62.         end
  63.         st_manageFuelChest("finish") -- take chest
  64.         --check to see if  that worked
  65.         if turtle.getFuelLevel() > 5 then
  66.             write("That's better.\n")
  67.         end
  68.     end
  69. end
  70.    
  71. while true do
  72.     turtle.forward(10)
  73.     st_refuel()
  74.     turtle.back(10)
  75. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement