-
Notifications
You must be signed in to change notification settings - Fork 0
Attribute Modifiers
Attribute modifiers are things you can apply to items to modify a players' attributes (like attack damage, for example). If you're not familiar with how these work, there are some niches to understand to make sure you're getting the most out of them.
This wiki page should cover everything you need to know about attribute modifiers, as well as how to create and use them with SkCheez, but if you want some more in-depth information, the Minecraft Wiki's page on attributes is really useful.
Anyway, let's get into it.
You might be used to seeing attribute modifiers like this, in NBT format:
{AttributeName:"generic.attack_damage", Name:"generic.attack_damage", Amount:20.0, Operation:0, Slot:"mainhand", UUID:[I; -192596, -61963, -161679, -10288428]}In Minecraft, this kind of compound is how you would apply a modifier to an item via the /give command.
This might seem like a lot, but it's really quite simple. In the above example, we see an attribute modifier which is modifying the attack damage attribute of a player by an amount of 20, with an operation of 0, when they're holding the item in their main hand. Now, you probably won't ever have to worry about reading one of these, but in case you do, SkCheez displays them in a slightly nicer, more readable, way.
Anyway, if you're a bit confused, don't worry! This next section, about what each of the components do and how they can interact with each other, will hopefully clear things up a bit.
There are six components that make up a modifier, and you really only need to worry about five of them.
This is, arguably, the most important part of the modifier - it's the attribute that the modifier modifies. This can, to my knowledge anyway, be any of the vanilla attribute types. Here's a list of all the attribute types that you can use:
armor, armor toughness, attack damage, attack knockback, attack speed, flying speed, follow range, knockback resistance, luck, max absorption, max health, movement speed, spawn reinforcements
# fancy new types that are coming in 1.20.5
scale, step height, jump strength, block interaction range, entity interaction range, block break speed, gravity, safe fall distance, fall damage multiplier
It's important to note that not all of these attribute types can be applied to players. As an example, the spawn reinforcements attribute applies exclusively to zombies (and zombie variants). Additionally, all of the attributes have a minimum and maximum value, and a base value. For a more detailed guide on all the attributes and what they do, head on over to the Minecraft Wiki's attribute page!
The amount is also very important. As you can probably guess, it helps define the amount that the modifier will modify the attribute by. Make sure you understand how the operation component works as well, because the amount and operation work together to dictate how the attribute is modified.
This one works with the amount to change how the attribute is modified. There are three different options for this component: add number, add scalar, and multiply scalar 1.
-
add number: this one is fairly simple - it adds the total
amountto the base value of the attribute. For example, let's say you have an item with twoattack speedattribute modifiers, the first with an amount of4, the second with an amount of11. This would result in theattack speedattribute of the player having a total of4 + 11 = 15added to it. -
add scalar: this is another fairly simple operation - it multiplies the
total amount + 1by the current value of the attribute. Let's have a look at another example. Say we have the same item from theadd numberexample, but this time with the add scalar operation. Theattack speedattribute of the player would be multiplied by4 * 11 + 1 = 45. -
multiply scalar 1: this is the trickiest operation of the bunch - for each modifier, it multiplies the current value of the attribute by it's amount. Once again, we'll use the same modifiers from the
add numberexample, but with the multiply scalar operation. In this case, theattack speedattribute of the player would be multiplied by(1 + 4) * (1 + 11) = 60.
The equipment slot of a modifier can be specified to limit the modifier to only work in a certain slot. The options you have for this component are hand slot, head slot, chest slot, legs slot, feet slot, and off hand slot. You could use this to create custom armour pieces, or change an attribute when a player is holding an item, just to name a few.
The UUID of a modifier is quite important to understand, as it can have potentially unintended consequences. For each attribute type, there can be as many attribute modifiers as you want, but each of the modifiers have to have a unique UUID. If you try to apply a modifier to an item which has the same attribute type and UUID, the new one will simply replace the old one.
The name of the modifier is, objectively, the least important part. It makes literally no difference what this is set to, other than for descriptive purposes.
SkCheez makes creating and using attribute modifiers super simple.
The syntax for creating an attribute modifier is as follows:
[new] %attributetype% [attribute] modifier (named|with name|with id) %string% with amount %number% [with operation %-attributemodifieroperation%] [with uuid %-string%] [for [equipment] slot %-equipmentslot%]As you can see, the only parts you have to provide here are the attribute type, the name, and the amount. The other components have default values; the operation will default to add number, the UUID will default to a random UUID, and the slot will default to nothing (would apply the modifier to all slots).
In case you're still a bit confused on how to create a modifier, here are a few valid examples:
set {-m} to new attack damage modifier named "damage-example" with amount 4
set {-m} to attack speed attribute modifier named "speed-example" with amount 11 with operation multiply number for slot hand slot
set {-m} to new luck attribute modifier named "luck-example" with amount 44 with operation add number for slot off hand slotSkCheez also has a properties expression to modify a certain component of a modifier. Here's a list of all the syntaxes you can use:
[attribute[ ]]modifier attribute of %attributemodifiers%
[attribute[ ]]modifier name of %attributemodifiers%
[attribute[ ]]modifier (amount|increment) of %attributemodifiers%
[attribute[ ]]modifier operat(or|ion) of %attributemodifiers%
[attribute[ ]]modifier slot of %attributemodifiers%
[attribute[ ]]modifier uuid of %attributemodifiers%And here are a few examples of how to use those syntax:
set modifier attribute of {-m} to %attributetype%
set modifier name of {-m} to %string%
set modifier amount of {-m} to %number%
set modifier operation of {-m} to %attributemodifieroperation%
set modifier slot of {-m} to %equipmentslot%
set modifier uuid of {-m} to %string/uuid%Finally, you can access an item's attribute modifiers using the following syntax:
[attribute[ ]]modifiers of %itemtypes%Let's have a look at some examples of this as well:
set {_modifiers::*} to attribute modifiers of player's tool
set {_attackSpeed::*} to modifiers of player's tool where [modifier attribute of input is attack speed]
add {_modifier} to modifiers of {_item}
add {_modifiers::*} to modifiers of {_item}
set modifiers of {_item} to {_modifiers::*}
remove {_modifier} from modifiers of {_item}
clear modifiers of {_item}