Skip to content

[Version 4.10] Events

Insane96 edited this page Apr 14, 2024 · 3 revisions

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

Event

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

  • chance: (Modifiable Value Object) representing the percentage chance (between 0 and 1) for the event to trigger. If omitted the effect will always be applied.
  • play_sound: (Object) 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: (Resource Location) the sound id
    • volume: (Number) the volume of the sound played. Defaults to 1
    • pitch: (Number) the pitch of the sound played. Defaults to 1
  • function: (Resource Location) 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)
  • scale_pehkui: (Scale Pehkui Objects list) Scales applied when the event is triggered

Events

  • on_attack: (Object) Triggered when the mob attacks
    • OnHit Object
      • target: (String) This is also the executioner of the mcfunction
        • "this": targets the mob targeted by the json
        • "other": targets the attacked entity
      • damage_type: (String) 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: (Range Object) potion effects to apply on event trigger
      • set_fire: (Range Object) set the target on fire for this amount of seconds
      • additive_fire: (boolean) if true, set_fire will accumulate each trigger
      • set_freeze: (Range Object) set the target to freeze for this amount of seconds
      • additive_freeze: (boolean) if true, set_freeze will accumulate each trigger
      • damage_modifier: (Modifiable Value Object) Modifier that applies to the damage dealt
      • damage_modifier_operation: (String) (allowed values: "add", "multiply") representing if the modifier should affect the damage additively or multiplicatively
  • on_damaged: (Object) Triggered when the mob is attacked
    • Same as OnHit Object except for:
      • target: (String) This is also the executioner of the mcfunction
        • "this": targets the mob targeted by the json
        • "other": targets the entity that attacked the mob (if present)
      • health_left: (Range Object) The effects will apply only if the mob has percentage health between min and max.
  • on_death: (Object) Triggered when the mob dies
    • OnDeath Object
      • damage_type: (String) 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: (String) This is also the executioner of the mcfunction
        • "this": targets the mob targeted by the json
        • "other": targets the other entity
      • set_fire: (Range Object) set the target on fire for this amount of seconds. Only works for "other" target.
      • additive_fire: (boolean) if true, set_fire will accumulate each trigger
      • set_freeze: (Range Object) set the target to freeze for this amount of seconds. Only works for "other" target.
      • additive_freeze: (boolean) if true, set_freeze will accumulate each trigger
  • on_tick: (Object) Triggered when the mob dies
    • OnTick Object
      • update_speed: (Integer) Defaults to 20, every how many ticks is the event triggered

Notes

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

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": "this",
                "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