astonish01

ComputerCraft Turtle Useful Fuctions

Nov 25th, 2020 (edited)
435
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- >> Useful functions
  2. -- >> Written by astonish01
  3.  
  4. --Slots for refuel function:
  5. --15 and 16 FUEL
  6.  
  7. -------------------------------------------
  8.  
  9. -- > Turning
  10.  
  11. -- none -> none
  12. function turnLeft()
  13.     turtle.turnLeft()
  14. end
  15.  
  16. -- none -> none
  17. function turnRight()
  18.     turtle.turnRight()
  19. end
  20.  
  21. -- none -> none
  22. function turnAround()
  23.     turnLeft()
  24.     turnLeft()
  25. end
  26.  
  27. -------------------------------------------
  28.  
  29. -- > Movement functions
  30.  
  31. -- int -> none
  32. function moveFront(n)
  33.     if n == 0 then
  34.         return
  35.     else
  36.         for i=1, n do
  37.             turtle.forward()
  38.         end
  39.     end
  40. end
  41.  
  42. -- int -> none
  43. function moveBack(n)
  44.     if n == 0 then
  45.         return
  46.     else
  47.         for i=1, n do
  48.             turtle.back()
  49.         end
  50.     end
  51. end
  52.  
  53. -- int -> none
  54. function moveUp(n)
  55.     if n == 0 then
  56.         return
  57.     else
  58.         for i=1, n do
  59.             turtle.up()
  60.         end
  61.     end
  62. end
  63.  
  64. -- int -> none
  65. function moveBown(n)
  66.     if n == 0 then
  67.         return
  68.     else
  69.         for i=1, n do
  70.             turtle.down()
  71.         end
  72.     end
  73. end
  74.  
  75. -- int -> none
  76. function moveRight(n)
  77.     if n == 0 then
  78.         return
  79.     else
  80.         for i=1, n do
  81.             turnRight()
  82.             moveFront()
  83.             turnLeft()
  84.         end
  85.     end
  86. end
  87.  
  88. -- int -> none
  89. function moveLeft(n)
  90.     if n == 0 then
  91.         return
  92.     else
  93.         for i=1, n do
  94.             turnLeft()
  95.             moveFront()
  96.             turnRight()
  97.         end
  98.     end
  99. end
  100.  
  101. -------------------------------------------
  102.  
  103. -- > Block placing/breaking/using/attacking
  104.  
  105. -- Placing
  106.  
  107. -- none -> none
  108. function placeFront()
  109.     turtle.place()
  110. end
  111.  
  112. -- none -> none
  113. function placeBack()
  114.     turnAround()
  115.     turtle.place()
  116.     turnAround()
  117. end
  118.  
  119. -- none -> none
  120. function placeRight()
  121.     turnRight()
  122.     turtle.place()
  123.     turnLeft()
  124. end
  125.  
  126. -- none -> none
  127. function placeLeft()
  128.     turnLeft()
  129.     turtle.place()
  130.     turnRight()
  131. end
  132.  
  133. -- none -> none
  134. function placeUp()
  135.     turtle.placeUp()
  136. end
  137.  
  138. -- none -> none
  139. function placeDown()
  140.     turtle.placeDown()
  141. end
  142.  
  143. -- Digging
  144.  
  145. -- none -> none
  146. function digFront()
  147.     turtle.dig()
  148. end
  149.  
  150. -- none -> none
  151. function digBack()
  152.     turnAround()
  153.     turtle.dig()
  154.     turnAround()
  155. end
  156.  
  157. -- none -> none
  158. function digRight()
  159.     turnRight()
  160.     turtle.dig()
  161.     turnLeft()
  162. end
  163.  
  164. -- none -> none
  165. function digLeft()
  166.     turnLeft()
  167.     turtle.dig()
  168.     turnRight()
  169. end
  170.  
  171. -- none -> none
  172. function digUp()
  173.     turtle.digUp()
  174. end
  175.  
  176. -- none -> none
  177. function digDown()
  178.     turtle.digDown()
  179. end
  180.  
  181. -- Attacking
  182.  
  183. -- none -> none
  184. function attackFront()
  185.     turtle.attack()
  186. end
  187.  
  188. -- none -> none
  189. function attackBack()
  190.     turnAround()
  191.     turtle.attack()
  192.     turnAround()
  193. end
  194.  
  195. -- none -> none
  196. function attackRight()
  197.     turnRight()
  198.     turtle.attack()
  199.     turnLeft()
  200. end
  201.  
  202. -- none -> none
  203. function attackLeft()
  204.     turnLeft()
  205.     turtle.attack()
  206.     turnRight()
  207. end
  208.  
  209. -- none -> none
  210. function attackUp()
  211.     turtle.attackUp()
  212. end
  213.  
  214. -- none -> none
  215. function attackDown()
  216.     turtle.attackDown()
  217. end
  218.  
  219. -------------------------------------------
  220.  
  221. -- > Refueling
  222.  
  223. -- none -> none
  224. function checkRefuel()
  225.     local slot = 15
  226.     if turtle.getFuelLevel() < 160 then
  227.         if turtle.getItemCount(15) >= 1 then
  228.             slot = 15
  229.         elseif turtle.getItemCount(16) >= 1 then
  230.             slot = 16
  231.         end
  232.         turtle.select(slot)
  233.         turtle.refuel(2)
  234.         turtle.select(1)
  235.     end
  236. end
  237.  
  238. -------------------------------------------
RAW Paste Data