Attribute Properties - CleverNucleus/data-attributes GitHub Wiki

Apart from attribute functions, the second thing added to entity attributes are attribute properties. Properties, in this context, are simply extra bits of information that can be appended to an attribute. These extra bits of information are structured as a map (a set of entries containing a key-value pair, for the illiterate among you).

Example 1

Say we have our examplemod, and we want to assign a rarity value to each attribute that would range from 0.0 to 1.0. We go to the directory data/examplemod/attributes/ and create the json file properties.json. Inside we add the following:

{
    "values": {
        "minecraft:generic.max_health": {
            "rarity": "0.5"
        },
        "minecraft:generic.armor": {
            "rarity": "0.6"
        },
        etc...
    }
}

Where etc... would be the rest of the attributes. Here we are adding the rarity property to the some Max Health and Armor and assigning each property a relevant value. Note how the value is a string: this is so that floating point numbers can be parsed without a loss in precision, but also so that other data can be appended to attributes - not just numbers.

Example 2

In this example we just want to assign a special boolean to a custom attribute examplemod:magic. If an attribute has the special property we can say it is true, if the attribute does not have the special property we can say it is false. Since it is just a case of having the property or not, the value doesn't matter and can just be 0.

{
    "values": {
        "examplemod:magic": {
            "special": "0.0"
        }
    }
}

Use cases

This feature has little use for pack creators, aside from editing mods attribute's properties. For mod developers however, this has the potential for more use. Perhaps you are creating a Trinkets addon, and you want to have your trinkets provide attribute bonuses like +30% damage or +4 max health. You need a rarity system for attributes, and rather than creating one from scratch, you can use attribute properties as the framework for this application.

This also serves me personally as a "Oh no I forgot to add this" feature. It allows me to just add a datapack to patch future mods. Finally, this serves as a configuration feature. By using datapacks, any mod that built with Data Attributes can be configured without the need for funky configuration magic - and this configuration can be solely server side as this is powered by datapacks.