Conditions
A condition is a test that answers true or false. Apoli uses conditions to ask about the world, for example whether the entity is sneaking, whether it is raining or whether its health is below half. Powers use them to switch on and off, meta-actions branch on them, and actions use them to filter targets.
The shape of a condition
A condition is a typed object like everything else:
{ "type": "apoli:sneaking" }A condition only reports a result. Whatever checks it decides what to do with the answer.
Where conditions are used
- A power's shared
conditionfield makes the power active only while the test passes. apoli:if_elseand the other branching meta-actions pick an action based on a condition.- Many action powers, like
apoli:action_on_hit, take aconditionthat must hold before the action fires. - Meta-conditions combine several conditions into one.
Kinds of condition
Like actions, conditions have kinds based on what they test:
| Kind | Tests | Examples |
|---|---|---|
| Entity | one entity | apoli:sneaking, apoli:health |
| Bi-entity | a pair of entities | apoli:attacker, apoli:undirected |
| Block | a block | apoli:block_state, apoli:in_tag |
| Item | an item stack | apoli:enchantment, apoli:food |
| Damage | a damage source | apoli:type, apoli:amount |
| Biome | a biome | apoli:temperature, apoli:precipitation |
| Fluid | a fluid state | apoli:still, apoli:empty |
| Meta | other conditions | apoli:all_of, apoli:any_of |
Inverting
Add "inverted": true to flip any condition. There is no not_sneaking condition, so you invert sneaking:
{ "type": "apoli:sneaking", "inverted": true }Combining conditions
To test several things at once, wrap them in a meta-condition:
{
"type": "apoli:and",
"conditions": [
{ "type": "apoli:sneaking" },
{ "type": "apoli:on_fire", "inverted": true }
]
}| Meta-condition | Passes when |
|---|---|
apoli:and or apoli:all_of | every listed condition passes |
apoli:or or apoli:any_of | any listed condition passes |
apoli:constant | always returns the value you give it (true or false) |
Meta-conditions nest, so an apoli:or of two apoli:and conditions works.
Next
- Entity conditions has the most common tests.
- Meta-actions branch on conditions.