đ Templates [MUST READ]
This page mainly explains how to add new templates to your server.
Introduction
The plugin boasts an exceptionally high degree of customization, but it's impossible to configure it without providing any settings. Even a very brief option requires a line in your YAML file. With numerous such options, a configuration file can become excessively long. Therefore, the plugin has introduced a template system, allowing you to define a base template and use parameters and overrides to fill in or overwrite certain parameters, significantly simplifying the process and reducing the time spent on repetitive configurations. Below, I will guide you through several examples to familiarize you with how the template system operates.
How to Create a Template?
Create a Basic Template
To configure a template, you need to use templates
as the root key in your YAML file.
namespace:template_id
serves as the unique identifier for your template. This name must be used whenever referencing or invoking this template elsewhere.
The configuration area under namespace:template_id
is entirely customizable, as long as it adheres to YAML syntax. You have complete freedom to define it according to your needs.
Create a Template with Aruguments
If you wish to create a custom parameter, simply enclose it with {}
. For example, here {value_1}
is used as a placeholder for a parameter.
How to Apply a Template?
Apply a Basic Template
Now, let's assume we are creating an item configuration test:item_1
. Without using a template, its configuration might look like the following:
However, when we utilize a template, the configuration would appear as follows:
These two configurations are entirely equivalent. You can think of a template as a pre-packed box. When you use this template in a specific section, the box is opened, and the parameters inside are unpacked and placed into the corresponding configuration area.
You cannot use both a template and normal configuration within the same section simultaneously! The correct approach is to use overrides
to configure options within the same area.
Apply a Template with Arguments
The following example demonstrates how to assign values to custom placeholders registered within a template:
Here, we employ the simplest method of direct value assignment, which means the corresponding parameter will be directly inserted into the target option. Of course, besides direct value assignment, we also offer a variety of other practical parameter types, such as auto-incrementing IDs. You can explore all the available parameter types here đĸ Argument Types
Apply a Template with Overrides
However, there are times when a template's configuration may lack a specific option. If you need to add or override an option, you can use the overrides
feature. Refer to the following configuration for guidance:
In this case, the original template had the value of option_1
set to true
. We have overridden it to false
and additionally introduced a new parameter missing_option
, assigning it the value 2025
.
Using overrides
does not have the restrictions of arguments
regarding data type.
Apply Multiple Templates
If you are an ardent fan of Rust, you will undoubtedly appreciate this design pattern. The composition of an object is based on combination rather than inheritance. By combining multiple templates, we can amalgamate the characteristics of various elements.
If you have multiple templates with overlapping parameters, they will be applied in sequential order, with later parameters overriding the earlier ones.
Config
Result
Combine all the features!
Config
Result
Examples
Ore
In this example, both arguments
and overrides
are utilized to populate the loot
and settings
sections with the template.
Bow
In this example, we use a template to create an auto-generated model configuration for a 2D bow.
Summary
Overall, the introduction of templates has significantly enhanced users' ability to customize configurations. If the plugin's original configuration format is akin to C, then using templates is more like programming in Python. Writing in C can be headache-inducing and complex, but using Python is quick and straightforward. The plugin will continue to integrate practical templates in future versions, and you are also welcome to contribute your templates by opening a PR on GitHub!
Last updated