-- HerrStackhouse's Refuel Functions
--
-- (All credit to Elo for the concept and for inspiring me to figure
-- out how to reproduce it. ALL HAIL THE RED QUEEN.)
--
-- Composed of two functions. The first to be called, st_refuel(),
-- tests the current fuel levels in the turtle and places two calls
-- to the second function, st_manageFuelChest(Str). The first call,
-- "start", tests the surroundings for suitable placement locations
-- before deploying an Enderchest from slot 16. st_refuel() will then
-- take over again, sucking fuel from the chest, before passing
-- "finish" back to st_manageFuelChest(Str), which will take the chest back into inventory.
--
-- The two functions must be added in the order below, or st_refuel will
-- holler at you for calling nil. Leave nil alone, she's totally over you.
--
-- The while true do loop at the bottom is entirely useless and is only here
-- for testing purposes. Remove it before use.
function st_manageFuelChest(Str)
if Str == "start" then
--test for open spaces to place chest, place it, record its orientation, take fuel into slot 14
turtle.select(16)
if turtle.place() == true then
fuelChestLocation = 1
turtle.select(14)
turtle.suck()
elseif turtle.placeUp == true then
fuelChestLocation = 2
turtle.select(14)
turtle.suck()
elseif turtle.placeDown == true then
fuelChestLocation = 3
turtle.select(14)
turtle.suck()
else write("Something breaks when I try to place my fuel chest.\n")
end
elseif Str == "finish" then
-- retrieve location of fuel chest and dig that way
if fuelChestLocation == 1 then
turtle.dig()
elseif fuelChestLocation == 2 then
turtle.digUp()
elseif fuelChestLocation == 3 then
turtle.digDown()
else write("Something breaks when I try to retrieve my fuel chest.\n")
end
else write("st_manageFuelChest recieved a weird argument.\n")
end
end
function st_refuel()
while turtle.getFuelLevel() <= 5 do
write("Hungry.\n")
st_manageFuelChest("start") -- deploy chest and take fuel
for i=1,16 do -- now test each internal slot for consumable items
turtle.select(i)
if turtle.refuel(1) == true then
turtle.refuel()
end
end
st_manageFuelChest("finish") -- take chest
--check to see if that worked
if turtle.getFuelLevel() > 5 then
write("That's better.\n")
end
end
end
while true do
turtle.forward(10)
st_refuel()
turtle.back(10)
end