Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

2: Documentation: API Things to know (WIP)

TacoTechnica edited this page Oct 15, 2021 · 3 revisions

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