forked from MarvionKirito/altoclef
-
Notifications
You must be signed in to change notification settings - Fork 4
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.
AltoClef altoClef = /* get from somewhere */;
altoClef.runUserTask(task, onTaskFinish);
- Extend
Task
- 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. - Initialize stuff in
onStart
(this may often be left empty) - Perform per-frame logic in
onTick
. Return other tasks to run sub-tasks (most of your work happens here) - Clean up stuff in
onStop
(ifonStart
is empty, this is usually also empty.)
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
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
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);
TODO
TODO
TODO
TODO