Skip to content

3: Documentation: API Things to know (WIP)

MiranCZ edited this page Apr 8, 2024 · 1 revision

Please check out the example repo first which shows how to create custom commands + tasks.

Running a task

AltoClef altoClef = /* get from somewhere */;
altoClef.runUserTask(task, onTaskFinish);

Making a Task

  1. Extend Task
  2. Define the isEqual method. If a task instance returns true when passed to this method, the newer task will be discarded and the currently running task will keep going.
  3. Initialize stuff in onStart (this may often be left empty)
  4. Perform per-frame logic in onTick. Return other tasks to run sub-tasks (most of your work happens here)
  5. Clean up stuff in onStop (if onStart is empty, this is usually also empty.)

BotBehaviour (formerly ConfigState)

Use this when starting and stopping tasks to enable+disable certain behaviors.

Example:

@Override
protected void onStart(AltoClef altoClef) {
    altoClef.getBehaviour().push();
    altoClef.getBehaviour().addProtectedItems(Items.COBBLESTONE); // Do not throw out cobblestone/use for bridging while this task runs.
}
@Override
protected void onStop(AltoClef altoClef) {
    altoClef.getBehaviour().pop();
}

ALWAYS pair a push with a pop! Otherwise the entire system may break/bug out

TaskCatalogue

Use TaskCatalogue to get items in your commands.

Examples:

return TaskCatalogue.getItemTask(Items.COBBLESTONE, 4);
return TaskCatalogue.getItemTask("planks", 4); // Gets any kind of plank

InventoryTracker

Checks if we have items in our inventory.

Examples:

if (!altoClef.getInventoryTracker().hasItem(Items.CLOCK)) {
    return TaskCatalogue.getItemTask(Items.CLOCK, 1);
}
int numberOfSticks = altoClef.getInventoryTracker().getItemCount(Items.STICKS);
int numberOfFlowers = altoClef.getInventoryTracker().getItemCount(ItemHelper.FLOWER);

EntityTracker

TODO

BlockTracker

TODO

SimpleChunkTracker (and it's only use)

TODO

ContainerTracker (only really for checking cached chests)

TODO