Advertisement
Guest User

t

a guest
May 27th, 2015
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.21 KB | None | 0 0
  1. -- Better turtle API by Eriyn
  2.  
  3. -- Vars :
  4.  
  5. t = {}
  6. local facing = 0
  7. local x = 0
  8. local y = 0
  9. local z = 0
  10.  
  11. -- Functions :
  12.  
  13. function t:tR()
  14.   turtle.turnRight()
  15.   facing = (facing + 1) % 4
  16.   return facing
  17. end
  18.  
  19. function t:tL()
  20.   turtle.turnLeft()
  21.   facing = facing - 1
  22.   if facing < 0 then
  23.     facing = 3
  24.   end
  25.   return facing
  26. end
  27.  
  28. function t:up(fuelSlot)
  29.   while turtle.up() == false do
  30.     if turtle.detectUp() then
  31.       turtle.digUp()
  32.     elseif fuelSlot ~= nil then
  33.       t.refuel(fuelSlot)
  34.     elseif fuelSlot == nil or (fuelSlot < 1 or fuelSlot > 16) then
  35.       print("NOPE")
  36.       return
  37.     else
  38.       turtle.attackUp()
  39.     end  
  40.   end
  41.   y = y + 1
  42. end
  43.  
  44. function t:down()
  45.   if turtle.down() then
  46.     y = y - 1
  47.   end
  48. end
  49.  
  50. function t:refuel(fuelSlot)
  51.   lastSlot = turtle.getSelectedSlot()
  52.   if turtle.getFuelLevel() ~= "unlimited" and turtle.getFuelLevel() < 1 then
  53.     turtle.select(tonumber(fuelSlot))
  54.     refueled = turtle.refuel(1)
  55.     turtle.select(lastSlot)
  56.   end
  57.   return refueled
  58. end
  59.  
  60. -- Getters & Setters :
  61.  
  62. function t:getDir()
  63.   return facing
  64. end
  65.  
  66. function t:getX()
  67.   return x
  68. end
  69.  
  70. function t:getY()
  71.   return y
  72. end
  73.  
  74. function t:getZ()
  75.   return z
  76. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement