I have been creating custom weapons for my my map and didn't realize until recently that the damage wasn't being calculated correctly. I'm not sure exactly what is going on but here is some examples of the issue:
I give a sharpness 7 sword:
/give @p minecraft:golden_sword 1 0 {ench:[{id:16,lvl:7}]}
When I attack a full-health zombie without jumping (no critical) I read its health as: Health:12.128f.
Now I give the same sword but with an attribute bonus of 2 damage in the offhand or mainhand:
/give @p minecraft:golden_sword 1 0 {ench:[{id:16,lvl:7}],AttributeModifiers:[{AttributeName:"generic.attackDamage",Name:"generic.attackDamage",Amount:2,Operation:0,UUIDLeast:438301,UUIDMost:924267,Slot:"mainhand"},{AttributeName:"generic.attackDamage",Name:"generic.attackDamage",Amount:2,Operation:0,UUIDLeast:438301,UUIDMost:924267,Slot:"offhand"}]}
I attack a newly summoned zombie 3 times. Every time LESS instead of more health is taken away and the zombie is as: Health:13.1119995f. What I would expect is that the zombie has 2 less health approximately. I am aware that zombies have 2 armor points but it still shouldn't cuase this discrepency right?
To test if this is just a bug with abnormal values of sharpness I retested with just damage modifiers and sharpness 1. The results were:
just sharpness I: Health:15.08f
sharpness I + 2 damage: 16.064f
So this is definitely bugged. My hypothesis is the damage modifier is canceling some of the bonus of the sharpness.
Another even odder example, that may be related, with diamond axes and attack speed (not even damage modifier). Adding an attack speed bonus seems to cancel the sharpness bonus as well:
I give a sharpness 7 diamond axe:
/give @p minecraft:diamond_axe 1 0 {ench:[{id:16,lvl:7}]}
When I attack a full-health zombie I read its health as: Health:7.207999f.
Now I give the same axe but with an attribute bonus of 5 attack speed in the offhand or mainhand:
/give @p minecraft:diamond_axe 1 0 {ench:[{id:16,lvl:7}],AttributeModifiers:[{AttributeName:"generic.attackSpeed",Name:"generic.attackSpeed",Amount:5,Operation:0,UUIDLeast:805601,UUIDMost:190395,Slot:"mainhand"},{AttributeName:"generic.attackSpeed",Name:"generic.attackSpeed",Amount:5,Operation:0,UUIDLeast:805601,UUIDMost:190395,Slot:"offhand"}]}
I attack a newly summoned zombie and its health is MUCH high at 15.08f health. This nerf is even worse then the one with attack damage, possibly because the attack damage partially covered the difference.
My hypothesis is that whenever you set an attribute on an item sharpness damage bonus stops working. This roughly agrees with the numbers. Can someone confirm or tell me if this is already reported? I could not find it and it seems like something people would realize right away in adventure maps.
Comments 6
thank you! You probably already know this, but I am reading their nbt using this command after each hit: /entitydata @e[r=5] {}
And I checked bows and bow power is unaffected by attributes. Seems to be only enchants that deal direct damage. If I knew how the damage from enchants was calculated relative to attributes I might be able to say more but I always figured they were seperate systems.
Just wanted to drop this here but:
I also noticed the "when in mainhand" tooltip that gives attack speed and damage for items disappears when any attribute is attached to it.
This is behaving correctly, and stems from the behavior you noted concerning the mere existence of AttributeModifiers
(see MC-88600 for details).
I should also mention that the display for default modifiers explicitly states the end result of the player's base attribute value when merged with the default modifier on the item. A default golden sword in the inventory states "4 attack damage", which in reality is a modifier value of 3 from the sword plus the player's base attribute of 1. When specifying AttributeModifiers
, it just states the operation and modifier value, rather than the end result.
So with the golden sword: the default generic.attackDamage
modifier for golden swords is 3. But when you use AttributeModifiers
, you are starting with a clean slate. An additive modifier of 2 is not adding 2 to the default modifier (which is now gone), it's adding 2 to the player's base attribute value (which is 1). So rather than the player's generic.attackDamage
becoming 4 via default modifier, it becomes 3 via custom modifier, thus the player will deal 1 less damage as a result. This is the same case of excluded default modifiers goes for the diamond axe, which is why you're seeing those numbers.
You will have to include generic.attackDamage
in all cases where you use AttributeModifiers
, as otherwise the default modifier will be excluded (resulting in lower damage). If you're intending for the item to deal more damage than its default modifier, you'll need to use larger values than that default modifier.
so the bug is not that sharpness isn't applied but that the base damage of the sword is canceled. Ok. This is misleading as it does say +X damage and +X attackSpeed. Is there no way to write to another attribute without deleting everything that is already on the item? It seems like there should be...
Also, the other issue with writing all the damage of the sword into generic.attackDamage is that it is applied to other items when in the offhand, but I guess i can just disable the damage part for that slot and only apply it in mainhand. Thanks!
*Update: *
Since this post I have done more testing. I have confirmed that sharpness damage doesn't appear to apply on any weapon that has ANY attribute applied even if it is not one that normally applies to players (like mob follow range), and this happens regardless of the mode of operation (addititive, multiplicative additive, or multiplicative) and whether or not I have a slot specified. Attributes other then attack damage always caused the weapon to do the damage that a similar weapon with no sharpness enchants did.
Could this be because sharpness has a hidden bonus to attack damage that is overwritten? I did not think it worked that way but it would explain why initializing the attributemodifiers list with some unrelated attribute might reset it. To test this hypothesis I threw down the sword with the attributes and removed the attribute list with commands with this command:
Sure enough, the sharpness damage still did not work although the tooltip info for attribute modifiers disappeared.
Also, I tested the effects of attributes on weapons with smite and bane of arthropods as well. The results were even more confusing:
attacking a zombie with a smite V sword always left them at Health:3.760f. However, attacking the zombie with the same smite V sword after applying an attribute caused the zombie to be left with Health:6.7159996f. So most of the smite damage bonus applied but a small portion of it was also added incorrectly. I got similar results for spiders and bane of arthropods: bane III sword left a spider at Health:4.5f, but bane III + 1 armor sword (or other attribute) left them at Health:7.5f. The incorrect damage seems to be related to the level of the enchant but that could be my imagination.
Can a mod please run these commands I posted and confirm so mojang can respond to this? This bug makes it impossible to make a weapon with attribute modifiers properly. Unless you want the weapon to be really bad at least. Damage modifier can be replaced by a few extra levels of sharpness but this is still a little annoying as it reduces flexibility (you can't use it as an offhand attribute booster)