Advertisement
Smokefag

Test programs

Feb 22nd, 2023 (edited)
658
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.27 KB | None | 0 0
  1. function turtle.forwards(numForw)
  2.     for i = 1, numForw do
  3.         turtle.forward()
  4.     end
  5. end
  6.  
  7. function turtle.upwards(numUpw)
  8.     for i = 1, numUpw do
  9.         turtle.up()
  10.     end
  11. end
  12.  
  13. function turtle.downwards(numDownw)
  14.     for i = 1, numDownw do
  15.         turtle.down()
  16.     end
  17. end
  18.  
  19. function turtle.turns180()
  20.     for i = 1, 2 do
  21.         turtle.turnRight()
  22.     end
  23. end
  24.  
  25. function inventoryCheck()
  26.     for i = 1, 16 do
  27.         if turtle.getItemCount(i) ~= 0 then
  28.             return false
  29.         end
  30.     end
  31.     return true
  32. end
  33.  
  34. local startX, startY, startZ = 0, 0, 0
  35. local currX, currY, currZ = startX, startY, startZ
  36. local currDir = "north"
  37.  
  38. function updatePosition(newX, newY, newZ)
  39.     currX, currY, currZ = newX, newY, newZ
  40. end
  41.  
  42. function updateDirection(newDir)
  43.     currDir = newDir
  44. end
  45.  
  46. function turnTo(dir)
  47.     if dir == "north" then
  48.         if currDir == "east" then
  49.             turtle.turnLeft()
  50.         elseif currDir == "south" then
  51.             turtle.turn180()
  52.         elseif currDir == "west" then
  53.             turtle.turnRight()
  54.         end
  55.     elseif dir == "east" then
  56.         if currDir == "north" then
  57.             turtle.turnRight()
  58.         elseif currDir == "south" then
  59.             turtle.turnLeft()
  60.         elseif currDir == "west" then
  61.             turtle.turn180()
  62.         end
  63.     elseif dir == "south" then
  64.         if currDir == "north" then
  65.             turtle.turn180()
  66.         elseif currDir == "east" then
  67.             turtle.turnRight()
  68.         elseif currDir == "west" then
  69.             turtle.turnLeft()
  70.         end
  71.    elseif dir == "west" then
  72.         if currDir == "north" then
  73.             turtle.turnLeft()
  74.         elseif currDir == "east" then
  75.             turtle.turn180()
  76.         elseif currDir == "south" then
  77.             turtle.turnRight()
  78.         end
  79.    end
  80.    updateDirection(dir)
  81. end
  82.  
  83. function returnToStart()
  84.     while currX ~= startX or currY ~= startY or currZ ~= startZ do
  85.         if currY > startY then
  86.             turtle.down()
  87.             updatePosition(currX, currY - 1, currZ)
  88.         elseif currY < startY then
  89.             turtle.up()
  90.             updatePosition(currX, currY + 1, currZ)
  91.         elseif currZ > startZ then
  92.             turnTo("north")
  93.             turtle.forward()
  94.             updatePosition(currX, currY, currZ - 1)
  95.         elseif currZ < startZ then
  96.             turnTo("south")
  97.             turtle.forward()
  98.             updatePosition(currX, currY, currZ + 1)
  99.         elseif currX > startX then
  100.             turnTo("west")
  101.             turtle.forward()
  102.             updatePosition(currX - 1, currY, currZ)
  103.         elseif currX < startX then
  104.             turnTo("east")
  105.             turtle.forward()
  106.             updatePosition(currX + 1, currY, currZ)
  107.         end
  108.     end
  109. end
  110.  
  111.  
  112. function inventoryTest()
  113.     while true do
  114.         if inventoryCheck() then
  115.             returnToStart()
  116.             turtle.turns180()
  117.             for i = 1, 16 do
  118.                 turtle.select(i)
  119.                 if turtle.getItemCount() ~= 0 then
  120.                     turtle.drop()
  121.                 end
  122.             end
  123.             turtle.turns180()
  124.         else
  125.             sleep(0.1)
  126.         end
  127.     end
  128. end
  129.  
  130. turtle.forwards(5)
  131. turtle.turnLeft()
  132. turtle.forwards(2)
  133. inventoryTest()
  134.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement