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 to | Recipe |
|---|---|
| Check whether an entity has a power right now | Powers on an entity |
| Read the fields of whichever power matched | Powers on an entity |
| Grant or revoke a power from code | Powers on an entity |
| Turn a power off without removing it | Powers on an entity |
| List everything one source grants | Powers on an entity |
| Remember per-entity state for my power | Powers on an entity |
Origins
| I want to | Recipe |
|---|---|
| Get all the powers of an origin | Origins from Java |
| Find out which origin a player has | Origins from Java |
| Do it without depending on Origins | Origins from Java |
| React when a player's origin changes | Origins from Java |
New types
| I want | Recipe |
|---|---|
| A new entity action | Writing actions |
| An action that touches attacker and victim | Writing actions |
| An action on a block or an item stack | Writing actions, item action |
| An action that takes a nested action | Writing actions |
| A new entity condition | Writing conditions |
| A condition on an item stack | Writing conditions |
| A condition comparing two entities | Writing conditions |
| A condition on a damage source, fluid or biome | Writing conditions |
| A field a pack author can write as a number or a formula | Writing conditions |
Hooking the game
| I want to | Recipe |
|---|---|
| Make a vanilla method respect a power | Hooking the game |
| Avoid fighting other mods for the same instruction | Hooking the game |
| Only load a hook when another mod is present | Hooking the game |
| Keep the hook off the hot path | Hooking 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.