Advertisement
toxicfrazzles

Turtle Swarm Turtle Lib

Feb 12th, 2021 (edited)
799
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.35 KB | None | 0 0
  1. facing = 0
  2. xPos = 0
  3. yPos = 0
  4. zPos = 0
  5.  
  6.  
  7. local oldForward = turtle.forward
  8. function forward()
  9.     if oldForward() then
  10.         if facing == 0 then
  11.             xPos = xPos + 1
  12.         elseif facing == 1 then
  13.             zPos = zPos + 1
  14.         elseif facing == 2 then
  15.             xPos = xPos - 1
  16.         else
  17.             zPos = zPos - 1
  18.         end
  19.         return true
  20.     else
  21.         return false
  22.     end
  23. end
  24.  
  25.  
  26. local oldLeft = turtle.turnLeft
  27. function turnLeft()
  28.     oldLeft()
  29.     facing = facing + 1
  30.     facing = facing % 4
  31. end
  32.  
  33. local oldRight = turtle.turnRight
  34. function turnRight()
  35.     oldRight()
  36.     facing = facing - 1
  37.     facing = facing % 4
  38. end
  39.  
  40. local oldBack = turtle.back
  41. function back()
  42.     if oldBack() then
  43.         if facing == 0 then
  44.             xPos = xPos - 1
  45.         elseif facing == 1 then
  46.             zPos = zPos - 1
  47.         elseif facing == 2 then
  48.             xPos = xPos + 1
  49.         else
  50.             zPos = zPos + 1
  51.         end
  52.         return true
  53.     else
  54.         return false
  55.     end
  56. end
  57.  
  58. local oldDown = turtle.down
  59. function down()
  60.     if oldDown() then
  61.         yPos = yPos - 1
  62.         return true
  63.     else
  64.         return false
  65.     end
  66. end
  67.  
  68. local oldUp = turtle.up
  69. function up()
  70.     if oldUp() then
  71.         yPos = yPos + 1
  72.         return true
  73.     else
  74.         return false
  75.     end
  76. end
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement