v1.31
NOTICE: This API is now released as stable with exception to the travel() function still being experimental. All else should be fine.
So, what is MoveAPI? Well, moveAPI is a full toolset allowing you to easily navigate/move and get your turtle around the map as smoothly as possible with as little code as possible. It offers everything from simple dig replacements which automatically handle falling sand/gravel/gravity blocks, to advanced customization moveTo() of specific coordinates using relative or specific. Want to say, "Eh, go to these coordinates and if something gets in the way, break it or attack it until it's not and keep going till you get there", you can!
How to use: When you download the program, just os.loadAPI("apiName"). It should download and be named 'move', but if you choose to rename it, you will import under that name, instead. Any functions you want to call MUST START WITH turtle.functionName() (yes, vanilla turtle functions have been overwritten while move is loaded.)
One thing to note, MoveAPI is setup so if you plan to use any of the GPS/coordinate tracking features, ALL TURTLE MOVEMENT COMMANDS in your programs must use move. As long as all programs running on the turtle import move, coordinates should always persist properly. Just don't get into the shell and type "go forward 3" or whatever because on next load it will wipe your GPS data due to inaccuracy.
Random note: coordinates are reboot/chunkload persistent so as long as you have a program using move as startup, move will always know where it is at. If you pick it up and place it back down, be sure to delete move's config file in /api/moveLoc. If the turtle's fuel changes by more than 1 when off, he will auto-reset upon re-import of move (coords will overwrite and store as 0,0,0,"north"). If you plan to place autoexecuting turtles back down, ensure your program running move uses turtle.setCoords() accordingly. The only time you may get some corruption of your coordinates is in the event of a server crash, the server not saving block locations properly, and move saving, thus putting him however many blocks back the server failed to. This can't be fixed on my end so: Try not to crash your server :P/>
Downloads
Planned Features for 1.33
-Turn optimization (turns in fastest route)
-Cleaning up param input for travel and moveTo to accept GPS and a little more dynamic stuffs
-Adding turtle.back to overwrite list (woops)
-Notice: I will be deprecating the function turtle.turnToDir() and switching it out with turtle.turnTo(), new version will give you a chance to switch everything over. 1.34 will not support turtle.turnToDir()
-Additionally, I will be removing collision handling from the feature list. After a little more introspection, I don't feel it fits within the scope of this project. I may create a pathfinding API later on down the line but for now, I'd like to limit moveAPI to just the movements provided.
Changelogs
Spoiler
v1.32-Fixed a couple minor bugs, sped up mining. Mostly bugfixes.
v1.31
-Fixed a tiny mishap with turtle.refuel()
-Optimized turtle.digDown() so it doesn't have the same lag-time the other dig's do waiting for things to fall (since they won't)
v1.3
-Persistence of holding coordinates through reboots
-Fixes to forward/up/down so they return false with obstructions
-Added navigate() for chunkload hacking around the map
-Cleaning up some old code in the the moveTo()'s, still need to do more of that, they're messy.
-travel() will pickup where it left off if server restarts and get to the destination once chunks reload.
-For travel(), moveTo's, you can pass in a table of x,y,z and dir (if you want) or pass in just x/y/z/dir by itself.
-For travel() and moveTo's, further options CAN be passed in to specify order of axis the turtle solves for. Just enter "x", "z", "y" (must include all three) in whatever order you want the turtle to nav
Documentation/How-To
Spoiler
DiggingSpoiler
dig()-Pretty self-explanatory, digs in front (automatically handles sand/gravel)
digUp()
-Digs upwards, will handle sand/gravel falling
digDown()
-Same as turtle.dig(), here so you never have to use turtle.etc when executing similar commands.
NOTE: If you need vanilla digging mechanics for any reason (only mine just one block, no gravity blocks), use move.dig()/digUp/digDown() instead.
Movement
Spoiler
forward([distance])-Moves forward (1 forward if no arg given, will move x forward if an int provided)
–Returns false if something in the way
up([distance])
-Moves up (1 up if no arg given, will move x up if an int provided)
–Returns false if something in the way
down([distance])
-Moves down (1 forward if no arg given, will move x down if an int provided)
–Returns false if something in the way
fForward([distance])
-Moves forward (1 forward if no arg given, will move x forward if an int provided). Will break blocks in front and move if they are in way. Will attack monsters if they are in way.
–Returns false if unable to break block (ie. bedrock/warded block)
fDown([distance])
-Moves down (1 down if no arg given, will move x down if an int provided) Will break blocks in above and move if they are in way. Will attack monsters if they are in way.
–Returns false if unable to break block (ie. bedrock/warded block)
fUp([distance])
-Moves up (1 up if no arg given, will move x up if an int provided) Will break blocks in below and move if they are in way. Will attack monsters if they are in way.
–Returns false if unable to break block (ie. bedrock/warded block)
move(direction, distance)
-Moves in the given direction and removes objects if in the way (viable examples of dir are "north", "south", "east", "west")
–Returns false if something unbreakable in the way
Turning
turnLeft()
-Turns left, updates GPS dir
turnRight()
-Turns right, updates GPS dir
turnAround()
-Turns around, updates GPS dir
turnToDir(dir)
-Turns to direction specified (north, south, east, west <- As strings)
GPS/Location
Spoiler
Note: Upon importing moveAPI for the first time, your coordinates will start as: 0,0,0,"north". This is for those who wish to build programs which only abide by relative coordinates more useful. (ie, going to starting location would be move.goto(0,0,0,"north")setCoords(x,y,z,dir)
-Sets the coordinates to those provided (used for exact coordinate systems)
getCoords()
–Returns the x,y,z,dir of the turtle's current coordinates
getCoordsTbl()
–Returns the x,y,z,dir table (great for easily setting locations you can pass into moveTo and travel())
getX()
–Returns current X coordinate
getY()
–Returns current Y coordinate
getZ()
–Returns current Z coordinate
getDir()
–Returns current Direction
getFront()
–Returns x,y,z of space immediately in front of turtle
getFrontTbl()
–Returns table containing x,y,z of space immediately in front of turtle
Advanced Movement
Spoiler
Note: moveTo() and travel() CAN utilize pathfinding. To deactivate it, move.setPathFinding(false). By doing this, at any obstacle the turtle cannot overcome, it will return false for that function, instead.moveTo(x,y,z, , dir[axisCustomize if you want])
-Goes to the coordinates provided. If you enter 4 coordinate requirements into a table, you can pass the table in as replacement. Proper usage if using a coordinate table is:
–Returns true or false
coords = {xInt, yInt, zInt, dirString}
moveTo(coords)
or if you want to customize whether the turtle solves for which axis in which order (default is x, then y, then z)
moveTo(xCoord, yCoord, zCoord, dir, "x", "z", "y") --Goes to specified coordinates, then follows x axis, then z axis, then y axis.
or
home = {0,0,0,"north"}
moveTo(home, "y","z","x") --Goes to coordinates in home table but follows y axis first, then z, then x to get there
fMoveTo(x,y,z, dir, [axisCustomize if you want])
-Goes to the coordinates provided. Digs/attacks things out of the way if needed. For further usage instructions, follow moveTo() instructions
–Returns false if cannot move.
move(direction, distance)
-Goes in the direction specified for the number of blocks specified (accepted directions are "north", "south", "east", "west")
–Returns false if cannot move.
navigate(x,y,z,dir)
-A chunkload hack used to move anywhere on a map regardless of loaded chunks. Requires turtle have a ChickenChunks chunkloader.
-!Notice: If the server reboots when the turtle is moving and no chunkloader is placed, the turtle will cease. If you have your programs auto-restart, just reexecute travel and you should be fine. Check your turtle has his loader, first before continuing (look up)
-Notice 2: I highly suggest you have the turtle navigate to a y-level out of range first (or just moveTo if that area will be loaded), THEN run your travel() to whereever. Less stuff to run into that way.
Example:
turtle.moveTo(turtle.getX(),120, turtle.getZ())
turtle.travel(location)
–Returns false if it gets stuck (warded blocks or bedrock, likely)
setChunkSlot(slotNum)
-Sets the slot the turtle will look for the chunkloader in.
setPathFinding(setting)
-Turns on or off pathfinding for moveTo and travel() (only two functions which utilize it). On by default.
Random
Spoiler
refuel(refuelAmount)-Attempts to refuel from selected slot. Returns false if failed.
Credits
-Sangar who I found out (85% into this project), had made something extremely similar for an older version. Sangar, I am borrowing your awesome idea to use fuel-level checks to compare for persistence. Thank you, much!
-Inari in IRC: Your help in various questions I had (I learned as I went) was greatly appreciated (and your massive code condensation help).
-Random IRC/forum people I poked regarding various aspects of stuff, mostly about how the heck Lua does function table overwrites