Templates

Templates are snippets of json that can be reused over and over in your entities. Echo:NPC itself uses these snippets to create its default behavior. These snippets can be found in settings.json. Users are encouraged to write their own templates however! Simply place the new templates into custom_settings.json and you can call them from any template.

Entity:

When using Echo:NPC, it can be convenient to base an entity off an existing template entity. Echo:NPC itself provides a default entity, which makes creating simple Dialogue entities very simple. Simply make call to default namespace:entity_name instead of the entity definition in the template.

Transitions:

Echo:NPC defines many transitions in the settings.json. Transitions are simply components that can be called from transition_types (and benefits from methods such as default_transition_types).

Components:

Echo:NPC does not define many custom components, but users are encouraged to define their own. An example custom component is found in settings.json. Custom components can be called from the custom_components list in the entity.

Calling Templates

Templates are called via a string, where the first word is the name of the snippet, and the rest of the word is passed in as arguments. Depending on where you call the snippet from, different template will be used:

  • Custom Components: Use component_templates
  • Entity call in the Template: Use entity_templates
  • Transition Types: Use `transition_templates

For example, a call like my_component 3 in custom_components will fetch the my_component component_template and pass in the variable 3

Variables

Templates contain a powerful variable system for maximum reusability. Let us take this transition_template from settings.json:

"has_tag": { 
    "minecraft:environment_sensor": {
        "triggers": [
                {
                "filters": {
                    "all_of": [
                        { "test": "has_tag", "value": "$1"}
                    ]
                },
                "event": "$2{next_event}"
            }
        ]
    }
}

The $ strings are placeholders which want variables. So to call this transition, we need to call the name, and then an argument: has_tag my_tag. The my_tag will be passed into $1. We can create as many $ arguments as we want. For each one we create, we simply need to pass in another argument like: my_template arg1 arg2 arg3 arg4 etc....

Defaults

We can create default values for the $ arguments by passing stuff into the curly-braces after the placeholder. For example, lets take a big custom component:

"big": {
    "minecraft:scale": {
        "value": "$1{5}"
    }
},

We can call this custom component like: big. We don’t need to pass an argument into the $1 since by default it will use the 5 value. Note that we CAN still pass in an argument: big 3 would return the component of scale 3.

Next Event

When we place the text next_event as the default in a placeholder, it is telling Echo:NPC to use the next event if no event is supplied. This is very useful, and is how all vanilla transitions are created. If you look above, you will see the has_tag transition uses the code like: $2{next_event}. That means we can call has_tag without typing out the actual event: Echo:NPC will infer it. Of course, like above, you can hard-code an event as well.

Creating templates

You can create your own templates! For examples, see the settings.json file. Of course, you should not edit this file directly! Rather, you should add templates into custom_settings.json. To begin, your custom_settings file will look like this:

{
    "component_templates": {
    },
    "entity_templates": {
    },
    "transition_templates": {
    }
}

To add more snippets, simple add new content into these three “lists”.

Example

{
    "component_templates": {
        //Always start with a name, and then {}
        "big": {
            //Place real components into here
            "minecraft:scale": {
                //Use the "argument" syntax to create complex behavior
                //Users can pass in a scale variable, or let it use the default
                //The default is scale of size three.
                "value": "$1{3}"
            }
        }
    },
    "entity_templates": {
        "my_cool_entity": {
            //Put entity code here
        }
    },
    "transition_templates": {
        "my_transition": {
            //Put transition code here
        }
    }
}

Using our new component

We can use our new snippets, exactly the same as if they came vanilla with Echo:NPC.

  • transition_templates can be used in transitions
  • component_templates can be used in custom_components
  • entity_templates can be used in the entity definition

Specific usage example

{
    "name": "main",
    "custom_components": {
        //Use set-land to pick which states gets our new component
        //Use the template name here
        "1": ["big"],

        //Pass in arguments:
        "2": ["big 2"]
    },
    "text": [
        "I am a big boy",
        "Now a bit smaller..."
    ] 
}