Skip to main content

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:

  1. 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.
  2. 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.
  3. Send to Actions: This method is called on the ActionData object, initiating the processing logic.
  4. 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.
  5. Performing Actions: For each matching action, the perform() method is called.
  6. Check Conditions: The perform() method goes through the action's conditions. If any condition returns false, the process stops for this action.
  7. 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

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"
}
}
]
}