truh

adt

Oct 24th, 2012
1,369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.83 KB | None | 0 0
  1. --Advanced Turtle API
  2. --@author truh
  3.  
  4. function hungry()
  5.   fuelLevel = turtle.getFuelLevel()
  6.   if fuelLevel == "unlimited" then
  7.     return false
  8.   elseif fuelLevel < 1 then
  9.     return true
  10.   else
  11.     return false
  12.   end
  13. end
  14.  
  15. function eat(n)
  16.   if n==nil then
  17.     n=1
  18.   end
  19.   for i=1, 16 do
  20.     turtle.select(i)
  21.     if turtle.refuel(n) then
  22.       break
  23.     end
  24.   end
  25.   if hungry() then
  26.     return false
  27.   else
  28.     return true
  29.   end
  30. end
  31.  
  32. function autoEat()
  33.   while hungry() do
  34.     eat(1)
  35.     if hungry() then
  36.       os.sleep(10)
  37.     end
  38.   end
  39. end
  40.  
  41. function forward(n)
  42.   if n==nil then
  43.     n=1
  44.   end
  45.   autoEat()
  46.   for i=1, n do
  47.     while not turtle.forward() do end
  48.   end
  49. end
  50.        
  51. function back(n)
  52.   if n==nil then
  53.     n=1
  54.   end
  55.   autoEat()
  56.   for i=1, n do
  57.     while not turtle.back() do end
  58.   end  
  59. end
  60.  
  61. function up(n)
  62.   if n==nil then
  63.     n=1
  64.   end
  65.   autoEat()
  66.   for i=1, n do
  67.     while not turtle.up() do end
  68.   end  
  69. end
  70.  
  71. function down(n)
  72.   if n==nil then
  73.     n=1
  74.   end
  75.   autoEat()
  76.   for i=1, n do
  77.     while not turtle.down() do end
  78.   end  
  79. end
  80.        
  81. function turnLeft(n)
  82.   if n==nil then
  83.     n=1
  84.   end
  85.   for i=1, n do
  86.     turtle.turnLeft()
  87.   end    
  88. end
  89.        
  90. function turnRight(n)
  91.   if n==nil then
  92.     n=1
  93.   end
  94.   for i=1, n do
  95.     turtle.turnRight()
  96.   end    
  97. end
  98.  
  99. function place()
  100.   for i=1, 16 do
  101.     turtle.select(i)
  102.     if turtle.place() then
  103.       break
  104.     end
  105.   end
  106. end
  107.  
  108. function placeUp()
  109.   for i=1, 16 do
  110.     turtle.select(i)
  111.     if turtle.placeUp() then
  112.       break
  113.     end
  114.   end
  115. end
  116.  
  117. function placeDown()
  118.   for i=1, 16 do
  119.     turtle.select(i)
  120.     if turtle.placeDown() then
  121.       break
  122.     end
  123.   end
  124. end
  125.  
  126. function inventorySpace()
  127.   space=0
  128.   for i=1, 16 do
  129.     space=space+turtle.getItemSpace(i)
  130.   end
  131.   return space
  132. end
Advertisement
Add Comment
Please, Sign In to add comment