[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

ItemType.WOOD_SWORD.getTemplate();

And then use data keys. This will help.

Keys.ATTACK_DAMAGE

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();
itemStackSnapshot.createStack().offer(Keys.ATTACK_DAMAGE,50.0d);

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

I come back on this post 7 month later to solve the problem. I used the the unsafe data of a container to create an itemStack with a modified attack damage.


            ItemStack itemStack = ItemStack.builder().itemType(ItemTypes.DIAMOND_SWORD).build();

            List<DataContainer> containers = new ArrayList();

            DataContainer dataContainer = DataContainer.createNew();
            dataContainer.set(DataQuery.of("AttributeName"),"generic.attackDamage");
            dataContainer.set(DataQuery.of("Name"),"generic.attackDamage");
            dataContainer.set(DataQuery.of("Amount"),15);
            dataContainer.set(DataQuery.of("Operation"),0);
            dataContainer.set(DataQuery.of("Slot"),"mainhand");
            dataContainer.set(DataQuery.of("UUIDMost"),58736);
            dataContainer.set(DataQuery.of("UUIDLeast"),617612);

            containers.add(dataContainer);

            DataContainer c = itemStack.toContainer();
            c.set(DataQuery.of("UnsafeData","AttributeModifiers"),containers);

            ItemStack modifiedItem = ItemStack.builder().fromContainer(c).build();

            ((Player) src).setItemInHand(HandTypes.MAIN_HAND, modifiedItem);