Actions
An action is something that happens: healing an entity, applying an effect, playing a sound, spawning a particle. Actions never run on their own. Something fires them, usually a power such as apoli:action_on_hit, or a meta-action running them from inside another action.
The shape of an action
Like a power, an action is an object with a type:
{
"type": "apoli:heal",
"amount": 4
}Kinds of action
An action always acts on something, and what it acts on decides its kind. A field only accepts the kind of action it is typed for.
| Kind | Acts on | Examples |
|---|---|---|
| Entity | one entity | apoli:heal, apoli:apply_effect |
| Bi-entity | a pair of entities, an actor and a target | apoli:add_velocity, apoli:damage |
| Block | a block position | apoli:set_block, apoli:explode |
| Item | an item stack | apoli:modify, apoli:consume |
| Meta | other actions | apoli:if_else, apoli:and, apoli:random_chance |
So apoli:action_on_hit has a bientity_action field for the attacker and the victim, while apoli:action_over_time has an entity_action field for the entity with the power.
Meta-actions
Meta-actions run other actions. They branch, loop and combine actions without any code.
{
"type":"apoli:if_else",
"condition":{
"type":"apoli:on_fire"
},
"if_action":{
"type":"apoli:extinguish"
},
"else_action":{
"type":"apoli:apply_effect",
"effect":{
"effect":"minecraft:glowing",
"duration":40
}
}
}Common meta-actions:
apoli:andruns a list of actions in order.apoli:if_elseandapoli:if_else_listbranch on a condition.apoli:chanceruns an action with some probability.apoli:choicepicks one action from a list, andapoli:nothingdoes nothing.apoli:nothingis a meta type, so it also works as a condition and as a power.apoli:delayruns an action after a number of ticks.
Running an action from a power
Most actions run because a power fires them. For example, apoli:action_on_hit runs a bi-entity action whenever the entity hits something:
{
"type":"apoli:action_on_hit",
"bientity_action":{
"type":"apoli:add_velocity",
"space":"world",
"y":0.6
}
}