Actions
Actions are objects assigned to Action Holders. Actions consist of an Action Type, zero or more Condition Types, and zero or more Reward Types. When an action is triggered by its Action Type, all of its conditions are checked. If all conditions pass, all rewards are granted.
The Action Lifecycle
Understanding the flow of an action is key to using Arc Lib effectively:
- Event Trigger: An in-game event occurs, such as a player breaking a block, eating food, or taking damage. Arc Lib listens for these events.
- Action Data Creation: Arc Lib creates an ActionData object. This object contains the context of the event, such as the player involved, the block that was broken, or the item that was eaten.
- Send to Actions: This method is called on the ActionData object, initiating the processing logic.
- Filtering Actions: The system retrieves all "active" actions from the player's Action Holders. It filters this list to find only the actions whose type matches the event that was just triggered.
- Performing Actions: For each matching action, the
perform()
method is called. - Check Conditions: The
perform()
method goes through the action's conditions. If any condition returns false, the process stops for this action. - Apply Rewards: If all conditions pass, the
perform()
method goes through the action's rewards and applies each one.
JSON Format
data/<namespace>/arc/example.json
{
"holder": {
"type": "<namespace>:<action_holder_type_id>",
"id": "<namespace>:<action_holder_id>"
},
"type": "<namespace>:<action_type_id>",
"conditions": [
{
"type": "<namespace>:<condition_type_id>"
// Condition-specific data
}
],
"rewards": [
{
"type": "<namespace>:<reward_type_id>"
// Reward-specific data
}
]
}
note
The <namespace>
in the title should be replaced with your mod's or datapack's namespace. The <namespace>
in the JSON file can vary per entry. For example: arc
, jobsplus
, my_mod
, etc.
Components Explained
- holder: This object links the action to a specific Action Holder instance.
- type: The resource location of the Action Holder Type. For the default player holder, this is arc:player.
- id: The resource location of the specific Action Holder instance. For the default player holder, this is also arc:player.
- type: The resource location of the Action Type, which specifies the trigger event.
- conditions: An array of condition objects. All conditions in this list must be met for the rewards to be applied.
- rewards: An array of reward objects. If the conditions are met, all rewards in this list will be granted.
Example Action
In this example, the player will have a 1% change to receive a diamond when they mine a stone block.
data/my_datapack/arc/diamond_for_stone.json
{
"holder": {
"type": "arc:player",
"id": "arc:player"
},
"type": "arc:on_break_block",
"conditions": [
{
"type": "arc:block",
"block": "minecraft:stone"
}
],
"rewards": [
{
"type": "arc:item",
"chance": 1,
"item": {
"id": "minecraft:diamond"
}
}
]
}