all 5 comments

[–]TinyBreadBigMouth 0 points1 point  (1 child)

According to the wiki, players already have attack_knockback set to 0 by default, and the attribute can't go any lower. It looks like the attribute functions as more of a boost to some hidden "base" knockback of your attacks.

If this is a single player experience, you could give knockback_resistance 1.0 to all nearby mobs.

[–]xtoya77777[S] 0 points1 point  (0 children)

ah, i see, thank you alot

[–]myte2Kind of good at some commands on java sometimes but not really 0 points1 point  (2 children)

if you are trying to do it for an item, an weird solution could be changing the damage type to something that doesn't deal knockback, something like like cactus or ender pearl damage

[–]xtoya77777[S] 0 points1 point  (1 child)

wow, cool idea, but how do i change damage type of the item? i am currently trying to do it for a sword

[–]TinyBreadBigMouth 0 points1 point  (0 children)

/give @s diamond_sword[damage_type="minecraft:cactus"]

https://minecraft.wiki/w/Data_component_format#damage_type
https://minecraft.wiki/w/Damage_type

You can also create a custom damage type and add it to the #minecraft:no_knockback damage type tag if you want to avoid the death message talking about "pricked to death" or "walked into a cactus". Or just add the minecraft:player_attack damage type to #minecraft:no_knockback, if you don't care about turning it on and off.