-
-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
create attribute documentation #15
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"label": "Entities" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Attributes | ||
|
||
The attribute system is a system to provide values that are modifiable by multiple other things. | ||
Attributes can be used in a mod compatible way to change attack damage, maximum health and other things without each mod setting the value to something they expect and instead use modifications to e.g. add 2 hearts. | ||
|
||
## Existing Attributes | ||
|
||
Vanilla adds the following attributes: | ||
|
||
| Attribute | Description | | ||
|-------------------------------|----------------------------------------------------------------------------------------------| | ||
| `MAX_HEALTH` | how much health the entity has | | ||
| `FOLLOW_RANGE` | how far the entity can track something | | ||
| `KNOCKBACK_RESISTANCE` | how strong knockback is reduced. Ranged between 0 and 1, 1 cancelling all knockback. | | ||
| `MOVEMENT_SPEED` | how fast the entity moves | | ||
| `FLYING_SPEED` | The flying speed of the entity. Not applicable to players who fly with the elytra | | ||
| `ATTACK_DAMAGE` | how much damage the entity deals when attacking | | ||
| `ATTACK_KNOCKBACK` | how much knockback the entity causes when physically attacking | | ||
| `ATTACK_SPEED` | how many full damage attack the entity deals per second | | ||
| `ARMOR` | how many armor points the entity has and how resistant it is to attacks | | ||
| `ARMOR_TOUGHNESS` | how resistant the entity is to strong attacks | | ||
| `LUCK` | changes the chance for treasure, junk and normal fishing loottables | | ||
| `SPAWN_REINFORCEMENTS_CHANCE` | how likely a zombie spawns reinforcements when attacked | | ||
| `JUMP_STRENGTH` | how high the entity jumps. Only applicable for horse like mobs (including mules and camels). | | ||
|
||
NeoForge adds the following attributes: | ||
|
||
| Attribute | Description | | ||
|------------------------|------------------------------------------------------------------------| | ||
| `SWIM_SPEED` | how fast the entity swims | | ||
| `NAMETAG_DISTANCE` | how far the nametag can be seen for this entity | | ||
| `ENTITY_GRAVITY` | how fast the entity accelerates when not on ground | | ||
| `BLOCK_REACH` | how far the player can interact with the world | | ||
| `ENTITY_REACH` | how far the player can interact with entities | | ||
| `STEP_HEIGHT_ADDITION` | how high the entity can walk up blocks in addition to Entity#maxUpStep | | ||
|
||
## Attribute, AttributeInstance and AttributeModifier | ||
|
||
Attributes have to be [registered][registration] and are used to look up the current `AttributeInstance` for a given LivingEntity. The `AttributeInstance` holds all `AttributeModifier` currently active on the entity. | ||
AttributeModifiers require a UUID that should be unique to this modifier. It's used to ensure that an `AttributeModifier` can only be applied once to a LivingEntity. If you want to keep track of that modifier to remove it at a later point, then you should generate a random one once and then hardcode it. If you don't need to keep track of the modifier, it is sufficient to use a random UUID. | ||
They also require an Operation and an amount to perform the calculation. How the calculation works can be read in the next section. | ||
```java | ||
double maxHealth = livingentity.getAttribute(Attributes.MAX_HEALTH).getValue() | ||
``` | ||
|
||
### Calculation | ||
|
||
AttributeInstances can have 3 different operations, `ADDITION`, `MULTIPLY_BASE` and `MULTIPLY_TOTAL`. | ||
``` | ||
value = (base + sum(addition))*(1+sum(multiply_base))*(1+z1)*(1+z2)[...] | ||
``` | ||
The base value is set by the attributes default, but is sometimes set by the entity in some other events(e.g. Wolf taming). | ||
z1 and z2 are two multiply_total modifiers and more are calculated the same way. | ||
|
||
## Using AttributeModifiers | ||
|
||
AttributeModifiers can be applied for held items and worn armor. | ||
Changing the AttributeModifier for custom Items can be achieved by overriding IForgeItem#getAttributeModifiers. You can also apply AttributeModifiers to ItemStacks by calling ItemStack#addAttributeModifier. | ||
Another way to apply AttributeModifiers is by adding them with a `MobEffect`. For that you can call `MobEffect#addAttributeModifier` on the MobEffect to add AttributeModifiers when this MobEffect is applied. The applied AttributeModifier has an effect of x*(1+amplifier) with x being the amplifier value that was passed into `MobEffect#addAttributeModifier`. | ||
Attribute Modifiers can also be added and removed from/to LivingEntities directly: | ||
```java | ||
livingEntity.getAttribute(Attributes.MAX_HEALTH).addPermanentModifier(new AttributeModifier("health upgrade", 10, AttributeModifier.Operation.ADDITION)); | ||
livingEntity.getAttribute(Attributes.MAX_HEALTH).addTransientModifier(new AttributeModifier("health upgrade", 10, AttributeModifier.Operation.ADDITION)); | ||
livingEntity.getAttribute(Attributes.MAX_HEALTH).removeModifier(UUID.fromString("556E1665-8B10-40C8-8F9D-CF9B1667F295")); | ||
``` | ||
Transient modifiers are modifiers that are not serialized and saved, permanent modifiers are saved. | ||
|
||
[registration]: ../concepts/registries.md |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, same issue here. This one makes more sense though to have in the documentation.