Advertisement
melzneni

Turti

Sep 27th, 2021
1,149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.00 KB | None | 0 0
  1. local px = 0; local py = 0; local pz = 0
  2. local facing = 0
  3.  
  4. function digForward()
  5.     while turtle.detect() do
  6.         turtle.dig()
  7.     end
  8. end
  9.  
  10. function digUp()
  11.     while turtle.detectUp() do
  12.         turtle.digUp()
  13.     end
  14. end
  15.  
  16. function digDown()
  17.     while turtle.detectDown() do
  18.         turtle.digDown()
  19.     end
  20. end
  21.  
  22. function back(count)
  23.     for i = 1, count do
  24.         if not turtle.back() then
  25.             turnLeft(2)
  26.             forward(1)
  27.             turnLeft(2)
  28.         else
  29.             if facing == 0 then px = px - 1
  30.             elseif facing == 1 then py = py - 1
  31.             elseif facing == 2 then px = px + 1
  32.             elseif facing == 3 then py = py + 1
  33.             end
  34.         end
  35.     end
  36. end
  37.  
  38. function forward(count)
  39.     for i = 1, count do
  40.         digForward(1)
  41.         while not turtle.forward() do
  42.             if not digForward(1) then
  43.                 turtle.attack()
  44.             end
  45.         end
  46.     end
  47.     if facing == 0 then px = px + count
  48.     elseif facing == 1 then py = py + count
  49.     elseif facing == 2 then px = px - count
  50.     elseif facing == 3 then py = py - count
  51.     end
  52. end
  53.  
  54. function up(count)
  55.     for i = 1, count do
  56.         digUp(1)
  57.         while not turtle.up() do
  58.             if not digUp(1) then
  59.                 turtle.attackUp()
  60.             end
  61.         end
  62.     end
  63.     pz = pz + count
  64. end
  65.  
  66. function down(count)
  67.     for i = 1, count do
  68.         digDown(1)
  69.         while not turtle.down() do
  70.             if not digDown(1) then
  71.                 turtle.attackDown()
  72.             end
  73.         end
  74.     end
  75.     pz = pz - count
  76. end
  77.  
  78. function turnLeft(count)
  79.     for i = 1, count do
  80.         turtle.turnLeft()
  81.     end
  82.     facing = facing - count
  83.     while facing < 0 do facing = facing + 4 end
  84. end
  85.  
  86. function turnRight(count)
  87.     for i = 1, count do
  88.         turtle.turnRight()
  89.     end
  90.     facing = facing + count
  91.     while facing > 3 do facing = facing - 4 end
  92. end
  93.  
  94. function getPos()
  95.     return { px, py, pz, facing }
  96. end
  97.  
  98. function moveToPos(pos)
  99.     local lpx = pos[1]
  100.     local lpy = pos[2]
  101.     local lpz = pos[3]
  102.     local lfacing = pos[4]
  103.     if lpx ~= px then
  104.         if lpx > px then
  105.             setFacing(0)
  106.             forward(lpx - px)
  107.         else
  108.             setFacing(2)
  109.             forward(px - lpx)
  110.         end
  111.     end
  112.     if lpy ~= py then
  113.         if lpy > py then
  114.             setFacing(1)
  115.             forward(lpy - py)
  116.         else
  117.             setFacing(3)
  118.             forward(py - lpy)
  119.         end
  120.     end
  121.     if lpz ~= pz then
  122.         if lpz > pz then
  123.             up(lpz - pz)
  124.         else
  125.             down(pz - lpz)
  126.         end
  127.     end
  128.     setFacing(lfacing)
  129. end
  130.  
  131. function setFacing(lfacing)
  132.     while lfacing ~= facing do
  133.         turnLeft(1)
  134.     end
  135. end
  136.  
  137. function dropAll()
  138.     for i = 1, 16 do
  139.         turtle.select(i)
  140.         turtle.drop()
  141.     end
  142.     turtle.select(1)
  143. end
  144.  
  145. function refuelAll()
  146.     for i = 1, 16 do
  147.         turtle.select(i);
  148.         turtle.refuel()
  149.     end
  150. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement