This api is two parts, with notes/documentation above, and functions below.
If you're confused by Minetest terminology (node, ItemStack, etc), read lua_api.txt
See README.md for basic setup.
Once you have a turtle, you need an init function such as:
function init(turtle)
turtle:moveForward()
endMany commands have directions. These come in sets like:
turtle:moveForward()
turtle:moveBackward()
turtle:moveRight()
turtle:moveLeft()
turtle:moveUp()
turtle:moveDown()This will be referred to as turtle:move[direction]()
Up and down are always the same, but orientation is changed with
turtle:turnLeft()
turtle:turnRight()The turtle has 16 'turtleslots' numbered 1-16. The top-left is slot 1, to the right is slot 2. The bottom left is slot 16.
Edit init.lua in the config object at the top to change the config. Actions take effect on restart/reload.
Many functions (ex: build,mine,scan,move) yield to prevent lag, balance the mod, and to prevent hanging.
You MUST have a yield in all time-consuming processes. For example:
function init(turtle)
while (true) do
turtle:yield("Being a good turtle")
end
end If this function didn't have the yield, it would crash the server (freeze the server thread)
If you don't yield, and your turtle takes too long, the entire server will lag/halt.
- Yields
See above for the importance of yielding!
The reason can be any string, and is visible in debug.txt (can turn on/off debugging in config)
- Yields
- Uses Fuel
The turtle will mine the block next to it and take the items of the block. It will take items from chests, too They return true if the block was removed
- Returns true if built
Places the block that's in the turtleslot.
Example: turtle:buildForward(1) builds the item in the top-left slot right in front of the turtle
- Returns scan result
Returns the node at the given position as table in the format{name="node_name", param1=0, param2=0}
Returns nil for unloaded areas
Example turtle:scanLeft().name=='default:stone_with_gold tells you there's gold ore to your left
If your fuel hits zero, with this on, your turtle will consume the first fuel-thing it sees in its inventory
-
Uses Fuel
Burns fuel. Once you run out of fuel, your turtle is stuck.
Returns the number actions you can take until needing to refuel.
If this is zero, you won't be able to do much except refuel.
Takes fuel from this turtleslot and increases the turtle's fuel
- Yields
- Uses Fuel
Moves one block in that direction, yields, and consumes fuel
The opposite of itemSuck. Push everything from the turtle's inventory that matches some filter into the nearby block inventory
Example: turtle:itemPushRight({"default:coal_lump","wood","tree"},true,'fuel') takes all coal lumps,wood-group, or tree-group items from the turtle. Puts them into the furnace-to-the-right's fuel slot.
Example: turtle:itemPushForward() pushes everything into the front chest
The opposite of itemPush. Takes everything from the node inventory that matches some filter into the turtle's inventory
Example: turtle:itemSuckRight({"default:sand","tree"},false) takes everything except sand or tree-group things (since false means blacklist)
Example: turtle:itemSuckForward() takes everything from the front chest
Example: turtle:itemSuckBackward({},'false','dst') takes output from the behind furnace (since src is input and dst is output)
Takes an item from a slot and puts it into the adjacent node
Get the ItemStack inside a turtleslot
Example: turtle:itemGet(4 ):get_name()=="default:stone"" tells you if there is stone in slot 4 (the top-right slot)
Example: turtle:itemGet(13):get_count() > 10 tells you if there is more than 10 items in slot 13 (the bottom-left slot)
Drops an item on the ground. Go to itemPush for putting into chests
Sets the turtle's name
Prints string to debug.txt (can be disabled in config)
I might be missing some, check out turtle.lua for more!
All functions that start with TurtleEntity are callable (although some shouldn't be such as the ones marked as helper functions)