Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- name = "move",
- version = "0.1",
- files = {
- [ "/_/apis/move" ] = {
- contents = "--this is an api named move\
- \
- x = 0\
- y = 0\
- z = 0\
- \
- function getPosition()\
- return x, y, z\
- end\
- \
- destructive = false\
- \
- facing = 0\
- \
- north = 0\
- east = 1\
- south = 2\
- west = 3\
- \
- function setDestructiveness(destroy_all_humans)\
- destructive = destroy_all_humans\
- end\
- \
- function setOrigin(new_x, new_y, new_z)\
- x = 1 - new_x\
- y = 1 - new_y\
- z = 1 - new_z\
- end\
- \
- \
- function setOriginHere()\
- x = 0\
- y = 0\
- z = 0\
- end\
- \
- function left()\
- turtle.turnLeft()\
- facing = facing - 1\
- if facing < 0 then\
- facing = 3\
- end\
- end\
- \
- function right()\
- turtle.turnRight()\
- facing = facing + 1\
- if facing > 3 then\
- facing = 0\
- end\
- end\
- \
- function face(direction)\
- delta = direction - facing\
- if delta > 1 then\
- delta = delta - 4\
- end\
- if delta < -2 then\
- delta = delta + 4\
- end\
- while delta > 0 do\
- right()\
- delta = delta - 1\
- end\
- while delta < 0 do\
- left()\
- delta = delta + 1\
- end\
- return\
- \
- --while facing ~= direction do\
- --right()\
- --end\
- end\
- \
- function refuel()\
- --stub\
- print(\"Out of fuel!\")\
- os.sleep(10)\
- end\
- \
- function stuck()\
- if turtle.getFuelLevel() == 0 then\
- while turtle.getFuelLevel() == 0 do\
- refuel()\
- end\
- return\
- end\
- print(\"Stuck!\")\
- os.sleep(10)\
- end\
- \
- function up()\
- while not turtle.up() do\
- if destructive then\
- if not turtle.digUp() then\
- stuck()\
- end \
- else\
- stuck()\
- end\
- end\
- y = y + 1\
- end\
- \
- function down()\
- while not turtle.down() do\
- if destructive then\
- if not turtle.digDown() then\
- stuck()\
- end\
- else\
- stuck()\
- end\
- end\
- y = y - 1\
- end\
- \
- function forward()\
- while not turtle.forward() do\
- if destructive then\
- if not turtle.dig() then\
- stuck()\
- end\
- else\
- stuck()\
- end\
- end\
- if facing == north then\
- z = z - 1\
- end\
- if facing == south then\
- z = z + 1\
- end\
- if facing == east then\
- x = x + 1\
- end\
- if facing == west then\
- x = x - 1\
- end\
- end\
- \
- function back()\
- while not turtle.back() do\
- if destructive then\
- --you do the hokey pokey and you\
- turtle.turnLeft()\
- turtle.turnLeft()\
- if not turtle.dig() then\
- stuck()\
- end \
- turtle.turnLeft()\
- turtle.turnLeft()\
- else\
- stuck()\
- end\
- end\
- if facing == north then\
- z = z + 1\
- end\
- if facing == south then\
- z = z - 1\
- end\
- if facing == east then\
- x = x - 1\
- end\
- if facing == west then\
- x = x + 1\
- end\
- end\
- \
- function to(new_x, new_y, new_z)\
- while new_y > y do\
- up()\
- end\
- while new_y < y do\
- down()\
- end\
- if new_x > x then\
- face(east)\
- while new_x > x do\
- forward()\
- end\
- end\
- if new_x < x then\
- face(west)\
- while new_x < x do\
- forward()\
- end\
- end\
- if new_z > z then\
- face(south)\
- while new_z > z do\
- forward()\
- end\
- end\
- if new_z < z then\
- face(north)\
- while new_z < z do\
- forward()\
- end\
- end\
- end",
- },
- },
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement