Advertisement
soee

movement

Sep 21st, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.89 KB | None | 0 0
  1. --file:movement
  2. --pastebin:CGxL2Ymr
  3.  
  4. -- Movement api.
  5.  
  6. moveSleep = 0.2
  7. paintSleep = 0.5
  8. blockedMoveSleep = 2
  9.  
  10. reservedSlots = 0
  11.  
  12. function turtleForward()
  13.     local moveSuccess = false
  14.     while (not moveSuccess) do
  15.         while turtle.detect() do
  16.             turtle.dig()
  17.             sleep(moveSleep)
  18.         end
  19.         moveSuccess = turtle.forward()
  20.         if (not moveSuccess) then
  21.             sleep(blockedMoveSleep)
  22.         end
  23.     end
  24. end
  25.  
  26. function turtleForwardX(count)
  27.     for i = 1, count do
  28.         turtleForward()
  29.     end
  30. end
  31.  
  32. function turtleUp()
  33.     local moveSuccess = false
  34.     while (not moveSuccess) do
  35.         while turtle.detectUp() do
  36.             turtle.digUp()
  37.             sleep(moveSleep)
  38.         end
  39.         moveSuccess = turtle.up()
  40.         if (not moveSuccess) then
  41.             sleep(blockedMoveSleep)
  42.         end
  43.     end
  44. end
  45.  
  46. function turtleUpX(count)
  47.     for i = 1, count do
  48.         turtleUp()
  49.     end
  50. end
  51.  
  52. function turtleDown()
  53.     local moveSuccess = false
  54.     while (not moveSuccess) do
  55.         while turtle.detectDown() do
  56.             turtle.digDown()
  57.             sleep(moveSleep)
  58.         end
  59.         moveSuccess = turtle.down()
  60.         if (not moveSuccess) then
  61.             sleep(blockedMoveSleep)
  62.         end
  63.     end
  64. end
  65.  
  66. function turtleDownX(count)
  67.     for i = 1, count do
  68.         turtleDown()
  69.     end
  70. end
  71.  
  72. function selectMaterial(typeSlot)
  73.     turtle.select(typeSlot)
  74.     if turtle.getItemCount(typeSlot) > 1 then
  75.         return true
  76.     else
  77.         for otherSlot = 16, 1, -1 do
  78.             if (turtle.compareTo(otherSlot)) then
  79.                 if otherSlot <= reservedSlots then
  80.                     if turtle.getItemCount(otherSlot) > 1 then
  81.                         turtle.select(otherSlot)
  82.                         return true
  83.                     end
  84.                 else
  85.                     turtle.select(otherSlot)
  86.                     return true
  87.                 end
  88.             end
  89.         end
  90.     end
  91.     return false
  92. end
  93.  
  94. function paintForward(typeSlot)
  95.     if selectMaterial(typeSlot) then
  96.         if not turtle.compare() then
  97.             while turtle.detect() do
  98.                 turtle.dig()
  99.                 sleep(paintSleep)
  100.             end
  101.             turtle.place()
  102.         end
  103.     end
  104. end
  105.  
  106. function paintDown(typeSlot)
  107.     if selectMaterial(typeSlot) then
  108.         if not turtle.compareDown() then
  109.             turtle.digDown()
  110.             turtle.placeDown()
  111.         end
  112.     end
  113. end
  114.  
  115. function paintUp(typeSlot)
  116.     if selectMaterial(typeSlot) then
  117.         if not turtle.compareUp() then
  118.             while turtle.detectUp() do
  119.                 turtle.digUp()
  120.                 sleep(paintSleep)
  121.             end
  122.             turtle.placeUp()
  123.         end
  124.     end
  125. end
  126.  
  127.  
  128. function turn(turnRight)
  129.     if turnRight then
  130.         turtle.turnRight()
  131.     else
  132.         turtle.turnLeft()
  133.     end
  134. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement