Skip to main content

Cookbook

The rest of the addon docs explain the API one piece at a time. This section answers questions in the shape people ask them, with code written against the real API.

Every recipe targets Fabric 1.21.1 with Mojang mappings, which is the main tree. Where another loader or version differs, the recipe says so, and loaders and versions collects the rest.

Powers

I want toRecipe
Check whether an entity has a power right nowPowers on an entity
Read the fields of whichever power matchedPowers on an entity
Grant or revoke a power from codePowers on an entity
Turn a power off without removing itPowers on an entity
List everything one source grantsPowers on an entity
Remember per-entity state for my powerPowers on an entity

Origins

I want toRecipe
Get all the powers of an originOrigins from Java
Find out which origin a player hasOrigins from Java
Do it without depending on OriginsOrigins from Java
React when a player's origin changesOrigins from Java

New types

I wantRecipe
A new entity actionWriting actions
An action that touches attacker and victimWriting actions
An action on a block or an item stackWriting actions, item action
An action that takes a nested actionWriting actions
A new entity conditionWriting conditions
A condition on an item stackWriting conditions
A condition comparing two entitiesWriting conditions
A condition on a damage source, fluid or biomeWriting conditions
A field a pack author can write as a number or a formulaWriting conditions

Hooking the game

I want toRecipe
Make a vanilla method respect a powerHooking the game
Avoid fighting other mods for the same instructionHooking the game
Only load a hook when another mod is presentHooking the game
Keep the hook off the hot pathHooking the game

Before you ship

Read performance. Apoli runs on servers with a lot of players and a lot of powers, and the difference between a recipe that returns early and one that doesn't is measured in whole ticks.