For the complete documentation index, see llms.txt. This page is also available as Markdown.

Template System

Introduction

The template system allows you to reuse configurations across blocks, furniture, stages and other sections of UnearthMechanic.

Templates are expanded before UnearthMechanic processes the configuration. Therefore, once they have been resolved, the system continues to use the same configuration format and behaviour as usual.

Creating a template

Templates can be declared at the root of any YAML file:

templates:
  unearth:brushable:
    base: "${base}"
    tool:
      - mc:brush
    transformation:
      stages:
        1:
          block_id: "${first_stage}"
        2:
          block_id: "${final_stage}"

It is also valid to declare them within undeath.templates:

unearth:
  templates:
    unearth:brushable:
      base: "${base}"
      tool:
        - mc:brush

The template identifier must be unique. We recommend using the following format:

Templates can be used from within other YAML files.

Using a template

To apply a template, use the `template` property:

The above configuration is processed as if it had been written as follows:

Arguments

Arguments replace placeholders in the format ${argument}

Arguments are processed in the order in which they are written. An argument may use one that has been declared previously

When a placeholder occupies the entire value, it retains its original type:

Default values

You can specify a default value using -

The default value is used when the argument has not been provided.

The following simple default values are currently supported:

  • Text.

  • Numbers.

  • Booleans.

  • null.

  • Numbers with the suffixes d and f.

Namespace and ID

Each configuration automatically receives two special arguments:

${__NAMESPACE__}

${__ID__}

Example:

Result:

If the identifier does not contain a namespace, unearth is used as the default namespace.

Text modifiers

Capitalising words

Result:

Convert to uppercase

Result:

Multiple templates

A configuration can use several templates:

Templates are applied from top to bottom:

  • Maps are combined recursively.

  • Lists are concatenated.

  • The individual values from the last template replace the previous ones.

Example:

The result will be:

Merges

merges allows you to add values to the generated configuration:

Maps are combined recursively and lists are appended to existing ones.

Overrides

'overrides' completely replaces the specified value:

Even if the template already contains tools, the list will be completely replaced:

Order of application

The configuration is built in the following order:

  1. Templates, in the order specified.

  2. Properties entered directly in the configuration.

  3. merges.

  4. overrides.

This means that overrides always take precedence.

Nested templates

A template can use another template:

Templates can also be used directly within stages, sequences or other nested sections.

UnearthMechanic detects circular references:

This configuration will be rejected and a warning will be displayed in the console.

Conditional arguments

The condition type selects a value based on a condition:

Selection using when

when allows you to transform a value using different cases:

Uppercase and lowercase conversion

Maps containing 'type'

A map used as an argument may contain a property called type. To prevent UnearthMechanic from interpreting this as a special type of argument, use:

The marker will not appear in the resulting settings.

Escaping placeholders

To write ${argument} as literal text, add a backslash:

Result:

Individual keys may also go missing:

Configuration errors

UnearthMechanic will display a warning and skip the affected settings when it encounters:

  • A non-existent template.

  • A circular reference.

  • A template whose content is not a YAML section.

  • An unsupported special argument.

  • An invalid value for merges, overrides or arguments.

If two files declare the same template identifier, the most recently loaded definition will override the previous one. You should not rely on this behaviour; always use unique identifiers.

Last updated