The td library

Fuel and inventory.

Moving costs one fuel per block and the turtle has 16 slots. These helpers refuel, clear out junk and empty the inventory into chests, and this page explains where the built-in jobs unload when they fill up.

Fuel.

turtle.getFuelLevel() can return the string "unlimited"; the helpers below treat that as always full.

td.refuel(target)

Burn fuel items from the inventory until the level reaches target: one refuel call per stack with the count it needs (1.19.3; before, one item at a time).

Returnstrue when the level reached target.

td.takeFuel(target, { keep? })

Take fuel from the chest touching the turtle and burn it up to target, in as few pulls as it can: up to a stack a pull, more pulls only when the target needs them and there is room, and one refuel call per stack with the exact count. What it does not burn goes back into the chest (keep items stay on board as a reserve); anything that is not fuel goes back too. Needs one empty slot.

Returnsok, err, e.g. "the fuel chest is empty".

td.refuelAtDepot(target, opts?)

Travel to the shared fuel chest set on the deck, take fuel up to target there, and come back to where it was: td.useDepot("fuel", ...), so it waits its turn and never digs on the way. When there is no chest at that spot any more it says so in the Console instead of looking round for one.

Returnsok, err

td.useDepot(kind, action, { solo?, after?, back?, dig? })

Use a shared chest ("fuel", "unload" or "supply") without crowding it (1.19.3). The turtle asks the relay for its turn; it goes to the chest when a spot next to it is free (usually there is one) and otherwise waits at a queue spot a few blocks away until it is told to move up. There it faces the chest and runs action(). The trips to the chest, to the queue spot and away never dig: a turtle that finds no way waits, says so in the Console and tries again. solo: only when nobody else is at the chest. after: "back" (default: to back or where it started), "home", "park" (step aside and stay near the chest) or "leave". dig = "fallback" lets the trip home or back dig where there is no clear way, never near the chest.

Returnsok, err from action, or why it could not get there.

td.depots()

The shared chests this turtle knows (1.19.1 and later): where it stands, and which way it faces, to use each one. The relay sends them whenever they change on the deck, and again whenever the turtle reports different ones, so they match the Jobs, Shared chests panel. The inspector shows the fuel chest a turtle knows.

Returns{ fuel = { x, y, z, facing }, unload = ..., supply = ... }

td.fuelRescue({ x, y, z, need, name?, dig?, learn?, reserve? })

Bring fuel to another turtle (1.19.0 and later): go to the shared fuel chest, take enough of one kind of fuel for need fuel (coal is 80 a piece; an unknown fuel is measured by burning one), fly to a spot next to the turtle at x, y, z and drop it in: a turtle takes items into its inventory. It does not dig unless dig = "fallback" (the deck passes that, and the corridors to learn, when the stranded turtle is inside a mine it dug). The deck's fuel rescue runs this for you: automatically when a turtle cannot reach the fuel chest any more (Settings), or with Send fuel.

Returnstrue, count, item, or false, err, e.g. "the fuel chest is empty".

Inventory.

td.emptySlots()

Number of empty inventory slots.

Returnsa number from 0 to 16.

td.dropJunk()

Drop junk below the turtle: cobblestone, cobbled deepslate, dirt, gravel, stone, deepslate, netherrack, tuff, granite, diorite, andesite and flint. Items are matched by a fragment of their id, so for example minecraft:stone_bricks counts as stone too.

Chests and ender chests.

td.unload(keepFuel)

Empty the inventory into a chest or barrel touching the turtle: below, above, or in front (it turns to look). Chests, barrels, shulker boxes, hoppers, drawers and crates count. With keepFuel it keeps the first stack of fuel.

Returnstrue, or false, "no chest next to the turtle".

td.setEnderId(id)

Set the item id of the ender chest used by td.dumpViaEnder and by the jobs. The default is sc-goodies:ender_storage; the deck can also set it.

td.dumpViaEnder(keep)

Empty the inventory through a carried ender chest. Its other end is the deposit chest, which the storage station drains. The chest is placed above, or in front if there is no room above, and picked up again with its link intact.

It always keeps the ender chest itself and one stack of fuel. keep is an optional table of item ids to keep as well, e.g. { ["minecraft:torch"] = true }.

Returnstrue, or false, why.

Where jobs unload.

When a job (a mining job, td.build, or your own td.run through check()) finds the inventory full, it empties it in this order:

  1. A carried ender chest empties on the spot, and the job carries on right there.
  2. Otherwise it travels to the shared unload chest (the depot set on the deck), unloads keeping one stack of fuel, and comes back.
  3. With neither, it can only use a chest touching it where it stands. Deep in a mine there is none, so the job stops with "inventory full".
unload_at_home.lualua
-- Empty into the chest at home yourself, then go back to work.local here = td.pos()assert(td.goHome())td.unload(true)                 -- keep one stack of fuelassert(td.goTo(here.x, here.y, here.z))td.face(here.facing)