Skip to content

[Version 4.0] Events

Alberto Del Villano edited this page Jun 4, 2024 · 3 revisions

You can execute stuff when certain actions happen by using the object events.

Events

  • events: Main object
    • on_attack: Triggered when the mob attacks
      • One OnHit Object
        • target: This is also the executioner of the mcfunction
          • "entity": targets the mob of the json
          • "other": targets the other entity
        • health_left: The effects will apply only if the mob has percentage health below this value. (This check only applies for on_attacked)
        • damage_type: if omitted the damage is applied with any damage type
          • "direct": effects will apply only if the damage source is direct (basically melee damage)
          • "indirect": effects will apply only if the damage source is indirect (e.g. projectiles)
        • damage_amount: Range Object defining the damage range at which the event should trigger (defaults to 0~Infinite)
        • potion_effects: a list of potion effects to apply on hit
        • damage_modifier: Modifier that applies to the damage dealt
        • damage_modifier_operation: A string value (allowed values: "add", "multiply") representing if the modifier should affect the damage additively or multiplicatively
    • on_attacked: Triggered when the mob is attacked
      • [Same properties as on_attack]
    • on_death: Triggered when the mob dies
      • One OnDeath Object
        • damage_type: if omitted the damage is applied with any damage type
          • "direct": effects will apply only if the damage source is direct (basically melee damage)
          • "indirect": effects will apply only if the damage source is indirect (e.g. projectiles)
        • target: This is also the executioner of the mcfunction
          • "entity": targets the mob of the json
          • "other": targets the other entity
    • on_tick: Triggered when the mob dies
      • One OnTick Object
        • update_speed: Defaults to 20, every many ticks is the event triggered

Notes

  • In case of on_attack, "target": "entity" refers to the attacking mob while in on_attacked, "target": "entity" refers to the attacked mob. Basically "entity" always refer to the json mob.
  • health_left always refers to the json mob and to the health left after the hit.

Event

A generic event which all the events inherith from, contains the following common properties

  • chance: Modifiable Value Object rapresenting the percentage chance (between 0 and 1) for the event to trigger. If omitted the effect will always be applied.
  • play_sound: Sound to play as the event triggers. Can be either a simple string with the resource location of the sound or an object as described below
    • sound: the sound id
    • volume: the volume of the sound played. Defaults to 1
    • pitch: the pitch of the sound played. Defaults to 1
  • function: an mcfunction executed when the event triggers. The function is executed as the mob and at the mob's position (unless specified otherwise by specific events)

Examples

This example makes Creeper get Speed V, Regeneration II and Resistance II for 10 secs after begin hit indirectly (e.g. from a projectile) and their health drops below 50%.

{
    "mob_id": "minecraft:creeper",
    "events": {
        "on_attacked": [{
            "target": "entity",
            "damage_type": "indirect",
            "health_left": 0.5,
            "potion_effects": [
                {
                    "id": "minecraft:speed",
                    "amplifier": 4,
                    "duration": 10
                },
                {
                    "id": "minecraft:regeneration",
                    "amplifier": 1,
                    "duration": 10
                },
                {
                    "id": "minecraft:resistance",
                    "amplifier": 1,
                    "duration": 10
                }
            ]
        }]
    }
}
Clone this wiki locally