Jharii

turtleShell

Jan 21st, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.72 KB | None | 0 0
  1. -- turtleShell API
  2.  
  3. -- fuelUp()
  4. -- distance - int - if it is necessary for the turtle to return to a specific
  5. -- location - int - pass the distance from that location to the function.
  6. -- verbose - bool - provides information to the screen
  7. -- broadcast - bool - broadcasts messages to listening computers
  8. function fuelUp(distance,verbose,broadcast)
  9.   distance = distance or 0
  10.   verbose = verbose or true
  11.   broadcast = broadcast or false
  12.   previousFuelLevel = turtle.getFuelLevel()
  13.   currentFuelLevel = previousFuelLevel
  14.   success = false
  15.   slot = 1
  16.   messageOne = ""
  17.   messageTwo = ""
  18.  
  19.   if currentFuelLevel <= distance then
  20.     if verbose or broadcast then
  21.       messageOne = "Attempting to refuel..."
  22.     end
  23.     if verbose then
  24.       print(messageOne)
  25.     end
  26.     if broadcast then
  27.       rednet.open("right")
  28.       rednet.broadcast(messageOne)
  29.       rednet.close("right")
  30.     end
  31.     while not(success) and slot < 17 do
  32.       turtle.select(slot)
  33.       if turtle.refuel(slot) then
  34.         success = true
  35.         currentFuelLevel = turtle.getFuelLevel()
  36.       else
  37.         slot = slot + 1
  38.       end
  39.     end
  40.     if success and (verbose or broadcast) then
  41.       messageOne = "Refueling successful."
  42.       messageTwo = "Increased fuel by " .. currentFuelLevel - previousFuelLevel .. " from slot " .. slot .. "."
  43.     elseif verbose or broadcast then
  44.       messageOne = "No fuel source found."
  45.     end
  46.     if success and verbose then
  47.       print(messageOne)
  48.       print(messageTwo)
  49.     elseif verbose then
  50.       print(messageOne)
  51.     end
  52.     if broadcast then
  53.       rednet.open("right")
  54.       if success then
  55.         rednet.broadcast(messageOne)
  56.         rednet.broadcast(messageTwo)
  57.       else
  58.         rednet.broadcast(messageOne)
  59.       end
  60.     end
  61.   else
  62.     success = true
  63.   end
  64.   return success
  65. end
  66.  
  67. function betterDig()
  68.   success = false
  69.   while turtle.detect() do
  70.     if turtle.dig() then
  71.       success = true
  72.     elseif turtle.attack() then
  73.     else
  74.       return success
  75.     end    
  76.     -- waits for falling blocks
  77.     sleep(.5)
  78.   end
  79.   return success
  80. end
  81.  
  82. function betterDigUp()
  83.   success = false
  84.   while turtle.detectUp() do
  85.     if turtle.digUp() then
  86.       success = true
  87.     elseif turtle.attackUp() then
  88.     else
  89.       return success
  90.     end
  91.     -- waits for falling blocks
  92.     sleep(.5)
  93.   end
  94.   return success
  95. end
  96.  
  97. function betterDigDown()
  98.   success = false
  99.   while turtle.detectDown() do
  100.     if turtle.digDown() then
  101.       success = true
  102.     elseif  turtle.attackDown() then
  103.     else
  104.       return success
  105.     end
  106.   end
  107.   return success
  108. end
  109.  
  110. function checkInventory()
  111.   full = true
  112.   for i = 1,16 do
  113.     if turtle.getItemCount(i) == 0 then
  114.       full = false
  115.     end
  116.   end
  117.   return full
  118. end
Advertisement
Add Comment
Please, Sign In to add comment