Minecraft problem with knockback resistance attribute

minecraft-commandsminecraft-java-edition

I am attempting to make one player immune to knockback. I have a command block with this in:

/replaceitem entity @p slot.inventory.0 minecraft:stone 1 0 {display:{Name:"Anti-Knockback",Lore:["Just so you arent affected by knockback"]},AttributeModifiers:[{AttributeName:"generic.knockbackResistance",Name:"generic.knockbackResistance",Amount:1,Operation:1,UUIDMost:82829,UUIDLeast:167220}]}

It gives me the stone block and it says "+100% knockback resistance" but I'm still knocked back the same as before.

I used this command generator for this command.

Is there something wrong with the command that I can fix or is this just not the way to go about removing knockback. If so, how can I do it?

Thanks

I'm doing this because I have a snowball that summons a massive amount of lightning and it's knocking me back. I thought it might just be that the attribute doesn't affect lightning but I tried it with a skeleton and the result was the same.

Best Answer

An operation of 1 is multiplying against your current base, which is 0. 100% of 0 is still 0. You'll want to use an operation of 0 instead, which is addition (and a generic.knockbackResistance of 1 is 100% chance to resist):

/replaceitem entity @p slot.inventory.0 minecraft:stone 1 0 {display:{Name:"Anti-Knockback",Lore:["Just so you arent affected by knockback"]},AttributeModifiers:[{AttributeName:"generic.knockbackResistance",Name:"generic.knockbackResistance",Amount:1,Operation:0,UUIDMost:82829,UUIDLeast:167220}]}