[need help] modify weapons damage( and other properties)


Hello everyone,
I know that since minecraft vanilla 1.9, there is the possibility to change among other the damage of weapons when they are equipped. Like showed on the picture below

Is there the possibility to create the same item programmatically with sponge?


Get/create the itemstack that you want


And then use data keys. This will help.


Im sure there is one for attack speed


thank you for your answer,
I tried this but is not effective

ItemStackSnapshot itemStackSnapshot = ItemTypes.WOODEN_SWORD.getTemplate();

this error occur

java.lang.NullPointerException: null
        at com.google.common.collect.ImmutableList.copyOf(ImmutableList.java:257) ~[minecraft_server.1.12.2.jar:?]
        at org.spongepowered.common.data.SpongeManipulatorRegistry.getDelegate(SpongeManipulatorRegistry.java:308) ~[SpongeManipulatorRegistry.class:1.12.2-7.1.0-BETA-5]
        at org.spongepowered.common.data.util.DataUtil.getBaseValueProcessor(DataUtil.java:375) ~[DataUtil.class:1.12.2-7.1.0-BETA-5]
        at net.minecraft.item.ItemStack.get(SourceFile:1313) ~[aip.class:?]
        at org.spongepowered.common.item.inventory.SpongeItemStackSnapshot.get(SpongeItemStackSnapshot.java:303) ~[SpongeItemStackSnapshot.class:1.12.2-7.1.0-BETA-5]
        at com.ylinor.itemizer.Itemizer.preInit(Itemizer.java:48)


Offer to the itemstacksnapshot and then create.


I’ts look like the key Keys.ATTACK_DAMAGE is not supported by the item unlike the display name key.

ItemStackSnapshot itemStackSnapshot = ItemTypes.WOODEN_SWORD.getTemplate();
		ItemStack item = itemStackSnapshot.createStack();
		logger.info(""+ item.supports(Keys.ATTACK_DAMAGE));
		logger.info(""+ item.supports(Keys.DISPLAY_NAME));

console :

[21:31:55 INFO] [itemizer]: false
[21:31:55 INFO] [itemizer]: true

there must be a solution it’s possible to change attributeModifier via a chat command :
/give @p minecraft:stone_sword 1 0 {AttributeModifiers:[{AttributeName:"generic.attackDamage",Name:"dégats",Slot:"mainhand",Amount:10,Operation:0,UUIDMost:77976,UUIDLeast:134898}]}


Just seen in the keys class that it says for projectiles (dont know why i didn’t see that before). However I can not see a key for item damage. I know its not the best idea but you could run a command to set the attributes