API Documentation/Adjust attributes
In this tutorial I will show you how it is possible to change some passive characteristics of an entity.
Attributes
An entity's attributes can be set once and will effect many other sections, including the AI and custom actions. Any attribute has a default value, based on the type of the entity.
The Attribute class
Attributes will be determined by an Attribute class. Each attribute has a name, a minimum, maximum and basis value. Attributes can be manipulated by:
- changing the basis value
- or attaching AttributeModifiers.
You can see all that stuff in the javadoc, I won't explain too much here.
The AttributeModifier class
An AttributeModifier can be attached to an Attribute to manipulate its basis value. Modifiers can be attached or detached at any time. An AttributeModifier has a modifier value and a ModifyOperation. There are three modify operations:
- adding to basis value
- multiplying the result of the first operation and adding all modified values up
- multiplying the result of the second operation
You can create an AttributeModifier using AttributeModifierFactory.create(). Make sure you use a hardcoded unique ID for each modifier! Again, everything is explained in the javadoc.
Managing attributes
You can change or retrieve attributes by using ControllableMob.getAttributes()
Here is a list of which attributes are available:
| attribute | ranged from - to | defaults | explanation |
|---|---|---|---|
| attack damage | 0 - ? | The entity's attack damage, in hearts per attack. | |
| knockback resistance | 0.0 - 1.0 | Resistance against being knocked back by attacks, where 1.0 is full resistance and 0.0 is no resistance at all. | |
| maximum health | 1 - ? | Maximum health, in hearts. | |
| movement speed | 0.0 - 2.0 | 0.7 for players, 0.25 for slow monsters |
Interesting property: the maximum navigation distance. By default, Minecraft limits the distance entities will move to 16 blocks. You can change it over here.
When you have made all changes you had in mind, continue by modifying the entity's AI!