Skip to content

Instantly share code, notes, and snippets.

@misode
Last active November 7, 2018 00:51
Show Gist options
  • Save misode/39e41674953ed6051afc2075a3da86e7 to your computer and use it in GitHub Desktop.
Save misode/39e41674953ed6051afc2075a3da86e7 to your computer and use it in GitHub Desktop.

The purpose of events is to have triggers without needing an advancement for it. This should go hand in hand with the current data driven files. We have been using advancements for a totally different reason than what they were intended for. And that's what we wanted to avoid from 1.13 onwards. A few advantages is they work for all entities, not only for players. They keep triggering, so you don't need to revoke the advancement.

Events are json files put in namespace/data/events Its structure is very similar to the current advancement structure of a criteria.

Event structure

This event would run namespace:foo for every zombie that hurts a player in a plains biome

{
  "event": {
    "trigger": "minecraft:hurt_entity",
    "conditions": {
      "entity": {
        "type": "minecraft:player",
        "location": {
          "biome": "minecraft:plains"
        }
    },
    "entity": {
      "type": "minecraft:zombie"
    }
  },
  "actions": {
    "function": "namespace:foo"
  }
}

The "event" component has an almost identical structure as a "criteria" component in an advancement. The only difference is the "entity" component which specifies the entity that is triggering the event. For advancements this would be the player. The "actions" component tells the event what function it should run. The function is ran executed as and at the entity that triggered the event. In this case the zombie

Notes

  • Advancements can reference an event in a criteria component by leaving out the "trigger" an including a "event": "namespace:foo" (where namespace:foo is the event)
  • Advancements can still have the triggers inside them. The "entity" component though cannot be changed because it defaults to players.
  • Some triggers like player_hurt_entity, placed_block, etc. only apply to players. The event would simply only run for players
  • Some more triggers need to be added, like hurt_entity and killed_entity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment