Advertisement
Guest User

Untitled

a guest
May 27th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.56 KB | None | 0 0
  1. x = 0
  2. y = 0
  3. z = 0
  4.  
  5. tx = -402
  6. ty = 200
  7. tz = -193
  8.  
  9. function fuel()
  10.     if turtle.getFuelLevel() == 0 then
  11.         turtle.select(4)
  12.         turtle.refuel()
  13.     end
  14. end
  15.  
  16. function up()
  17.     fuel()
  18.     while not turtle.up() do
  19.         turtle.digUp()
  20.         turtle.attackUp()
  21.     end
  22. end
  23.  
  24. function down()
  25.     fuel()
  26.     while not turtle.down() do
  27.         turtle.digDown()
  28.         turtle.attackDown()
  29.     end
  30. end
  31. function forward()
  32.     fuel()
  33.     while not turtle.forward() do
  34.         turtle.dig()
  35.         turtle.attack()
  36.     end
  37. end
  38.  
  39. function moveTo(x, y, z)
  40.     dx = 0
  41.     dy = 0
  42.     dz = 0
  43.     dir = 0 -- south
  44.  
  45.     while dy ~= y do
  46.         if y > dy then
  47.             up()
  48.             dy = dy + 1
  49.         end
  50.         if y < dy then
  51.             down()
  52.             dy = dy - 1
  53.         end
  54.     end
  55.  
  56.     if dz > z then
  57.         turtle.turnLeft()
  58.         turtle.turnLeft()
  59.         dir = 2
  60.     end
  61.  
  62.     while dz ~= z do
  63.         turtle.forward()
  64.         if dir == 0 then
  65.             dz = dz + 1
  66.         else
  67.             dz = dz - 1
  68.         end
  69.     end
  70.    
  71.     if dir == 0 then
  72.         if x > dx then
  73.             turtle.turnLeft()
  74.             dir = 3
  75.         elseif x < dx then
  76.             turtle.turnRight()
  77.             dir = 1
  78.         end
  79.     elseif dir == 2 then
  80.         if x > dx then
  81.             turtle.turnRight()
  82.             dir = 3
  83.         elseif x < dx then
  84.             turtle.turnLeft()
  85.             dir = 1
  86.         end
  87.     end
  88.  
  89.     while dx ~= x do
  90.         turtle.forward()
  91.         if dir == 3 then
  92.             dx = dx + 1
  93.         else
  94.             dx = dx - 1
  95.         end
  96.     end
  97. end
  98.  
  99. function nuke()
  100.     turtle.digUp()
  101.     turtle.digDown()
  102.     turtle.select(5)
  103.     turtle.placeUp()
  104.     turtle.select(1)
  105.     turtle.placeDown()
  106.     turtle.select(2)
  107.     turtle.dropDown()
  108.     turtle.select(3)
  109.     turtle.dropDown()
  110.     rs.setOutput("down", true)
  111.     rs.setOutput("up", true)
  112. end
  113.  
  114. moveTo(tx - x, ty - y, tz - z)
  115. nuke()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement