Minecraft – Stacking attribute modifiers

minecraft-commandsminecraft-java-edition

I'm making a Diablo-like loot system in my map, and it would be neat to have some sort of random modifiers on weapons, like:

Sharp knife: +10 (+2) Dmg

Dull knife +10 (-2) Dmg

Obviously, I don't care about the way it's going to look, I simply need it to work on items in chests/on mobs. So can I have 2 attribute modifiers to modify the same value?

So far I have this command:

/give @p minecraft:wooden_sword 1 0 {AttributeModifiers:[{AttributeName:"generic.attackDamage",Name:"generic.attackDamage",Amount:3,Operation:0,UUIDLeast:3,UUIDMost:3,Slot:"offhand"}]}

Now I want it to give more/less damage to player. And the item will probably be in the chest, or in mob's inventory.

Best Answer

Yes, you separate modifiers with a comma:

AttributeModifiers:[{<modifier 1>},{<modifier 2>},{<modifier 3>}]

However, you must ensure that the UUID pairs are unique across the items. For example, if the item(s) have the following UUIDs on the modifiers:

{UUIDLeast:1,UUIDMost:1}
{UUIDLeast:1,UUIDMost:1}

Then only one of the modifiers will be applied to the player. The fix is to use unique values. For example, all of the following will be applied as the pairs are unique:

{UUIDLeast:1,UUIDMost:1}
{UUIDLeast:1,UUIDMost:2}
{UUIDLeast:2,UUIDMost:1}
{UUIDLeast:2,UUIDMost:2}

Example item to provide (the first modifier has a UUID pair of 3,3 while the second modifier has a pair of 4,4):

/give @p minecraft:wooden_sword 1 0 {AttributeModifiers:[{AttributeName:"generic.attackDamage",Name:"generic.attackDamage",Amount:3,Operation:0,UUIDLeast:3,UUIDMost:3,Slot:"offhand"},{AttributeName:"generic.attackDamage",Name:"generic.attackDamage",Amount:6,Operation:0,UUIDLeast:4,UUIDMost:4,Slot:"offhand"}]}
Related Topic