Advertisement
zeta0134

chip-package: move 0.1

May 27th, 2015
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.32 KB | None | 0 0
  1. {
  2.   name = "move",
  3.   version = "0.1",
  4.   files = {
  5.     [ "/_/apis/move" ] = {
  6.       contents = "--this is an api named move\
  7. \
  8. x = 0\
  9. y = 0\
  10. z = 0\
  11. \
  12. function getPosition()\
  13.  return x, y, z\
  14. end\
  15. \
  16. destructive = false\
  17. \
  18. facing = 0\
  19. \
  20. north = 0\
  21. east = 1\
  22. south = 2\
  23. west = 3\
  24. \
  25. function setDestructiveness(destroy_all_humans)\
  26.  destructive = destroy_all_humans\
  27. end\
  28. \
  29. function setOrigin(new_x, new_y, new_z)\
  30.  x = 1 - new_x\
  31.  y = 1 - new_y\
  32.  z = 1 - new_z\
  33. end\
  34. \
  35. \
  36. function setOriginHere()\
  37.  x = 0\
  38.  y = 0\
  39.  z = 0\
  40. end\
  41. \
  42. function left()\
  43.  turtle.turnLeft()\
  44.  facing = facing - 1\
  45.  if facing < 0 then\
  46.    facing = 3\
  47.  end\
  48. end\
  49. \
  50. function right()\
  51.  turtle.turnRight()\
  52.  facing = facing + 1\
  53.  if facing > 3 then\
  54.    facing = 0\
  55.  end\
  56. end\
  57. \
  58. function face(direction)\
  59.  delta = direction - facing\
  60.  if delta > 1 then\
  61.    delta = delta - 4\
  62.  end\
  63.  if delta < -2 then\
  64.    delta = delta + 4\
  65.  end\
  66.  while delta > 0 do\
  67.    right()\
  68.    delta = delta - 1\
  69.  end\
  70.  while delta < 0 do\
  71.    left()\
  72.    delta = delta + 1\
  73.  end\
  74.  return\
  75.  \
  76.  --while facing ~= direction do\
  77.    --right()\
  78.  --end\
  79. end\
  80. \
  81. function refuel()\
  82.  --stub\
  83.  print(\"Out of fuel!\")\
  84.  os.sleep(10)\
  85. end\
  86. \
  87. function stuck()\
  88.  if turtle.getFuelLevel() == 0 then\
  89.    while turtle.getFuelLevel() == 0 do\
  90.      refuel()\
  91.    end\
  92.    return\
  93.  end\
  94.  print(\"Stuck!\")\
  95.  os.sleep(10)\
  96. end\
  97. \
  98. function up()\
  99.  while not turtle.up() do\
  100.    if destructive then\
  101.      if not turtle.digUp() then\
  102.        stuck()\
  103.      end    \
  104.    else\
  105.      stuck()\
  106.    end\
  107.  end\
  108.  y = y + 1\
  109. end\
  110. \
  111. function down()\
  112.  while not turtle.down() do\
  113.    if destructive then\
  114.      if not turtle.digDown() then\
  115.        stuck()\
  116.      end\
  117.    else\
  118.      stuck()\
  119.    end\
  120.  end\
  121.  y = y - 1\
  122. end\
  123. \
  124. function forward()\
  125.  while not turtle.forward() do\
  126.    if destructive then\
  127.      if not turtle.dig() then\
  128.        stuck()\
  129.      end\
  130.    else\
  131.      stuck()\
  132.    end\
  133.  end\
  134.  if facing == north then\
  135.    z = z - 1\
  136.  end\
  137.  if facing == south then\
  138.    z = z + 1\
  139.  end\
  140.  if facing == east then\
  141.    x = x + 1\
  142.  end\
  143.  if facing == west then\
  144.    x = x - 1\
  145.  end\
  146. end\
  147. \
  148. function back()\
  149.  while not turtle.back() do\
  150.    if destructive then\
  151.      --you do the hokey pokey and you\
  152.      turtle.turnLeft()\
  153.      turtle.turnLeft()\
  154.      if not turtle.dig() then\
  155.        stuck()\
  156.      end  \
  157.      turtle.turnLeft()\
  158.      turtle.turnLeft()\
  159.    else\
  160.      stuck()\
  161.    end\
  162.  end\
  163.  if facing == north then\
  164.    z = z + 1\
  165.  end\
  166.  if facing == south then\
  167.    z = z - 1\
  168.  end\
  169.  if facing == east then\
  170.    x = x - 1\
  171.  end\
  172.  if facing == west then\
  173.    x = x + 1\
  174.  end\
  175. end\
  176. \
  177. function to(new_x, new_y, new_z)\
  178.  while new_y > y do\
  179.    up()\
  180.  end\
  181.  while new_y < y do\
  182.    down()\
  183.  end\
  184.  if new_x > x then\
  185.    face(east)\
  186.    while new_x > x do\
  187.      forward()\
  188.    end\
  189.  end\
  190.  if new_x < x then\
  191.    face(west)\
  192.    while new_x < x do\
  193.      forward()\
  194.    end\
  195.  end\
  196.  if new_z > z then\
  197.    face(south)\
  198.    while new_z > z do\
  199.      forward()\
  200.    end\
  201.  end\
  202.  if new_z < z then\
  203.    face(north)\
  204.    while new_z < z do\
  205.      forward()\
  206.    end\
  207.  end\
  208. end",
  209.     },
  210.   },
  211. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement