-
Notifications
You must be signed in to change notification settings - Fork 15
Overrides
Entity attributes have five data points that can be overridden using json files; see the following.
- Fallback Value
fallbackValue
: the value that, should something go wrong, this attribute's instance defers to (this almost never has any actual impact in-game, other than setting the initial value if it isn't otherwise provided). - Minimum Value
minValue
: the minimum value that this attribute's instance is clamped to. - Maximum Value
maxValue
: the maximum value that this attribute's instance is clamped to. - Translation Key
translationKey
: the key that gets the display name of the attribute. - Stacking Behaviour
stackingBehaviour
: determines how different sources of the attribute's value add together (either FLAT or DIMINISHING).
Json overrides can be used to either override pre-existing attributes, either vanilla or modded, or if non exist a new attribute is created. Therefore, new entity attributes can be created using just json files. The json files follow a particular format; example 1 shows how armor would be formatted:
{
"fallbackValue": 0.0,
"minValue": 0.0,
"maxValue": 30.0,
"translationKey": "attribute.name.generic.armor",
"stackingBehaviour": "FLAT"
}
If you wanted to modify the maximum armor value, you would simply change maxValue
.
Minecraft's armor attribute has the following:
fallback value = 0.0
minimum value = 0.0
maximum value = 30.0
translation key = "attribute.name.generic.armor"
Say we want to change the maximum armor value to 100.0: we need to know the attribute's registry key, which is comprised of a namespace
and a path
. In this case, the registry key is minecraft:generic.armor
. In the directory data/minecraft/attributes/overrides/
we create a json file generic.armor.json
. Note how the registry key's namespace matches our directory's namespace, and the registry key's path matches our file name.
We add the following to generic.armor.json
:
{
"fallbackValue": 0.0,
"minValue": 0.0,
"maxValue": 100.0,
"translationKey": "attribute.name.generic.armor",
"stackingBehaviour": "FLAT"
}
That's it. Now the maximum value for armor is 100. Similarly, we can use this same methodology to create a new attribute - for example:
Say we have a mod with a modid examplemod
, and we want to add the attribute max_mana
. We create the directory data/examplemod/attributes/overrides/
and create the json file max_mana.json
. Inside the json file add the following:
{
"fallbacktValue": 0.0,
"minValue": 0.0,
"maxValue": 10000.0,
"translationKey": "examplemod.attribute.name.max_mana",
"stackingBehaviour": "FLAT"
}
We now have an attribute registered to the game. In our language file we can add the translation key entry like so:
"examplemod.attribute.name.max_mana": "Max Mana"
Although our attribute is registered to the game, it won't be present on any living entity yet. The next step is to attach it to an entity's attribute container - see Entity Types.