#How to add/modify the attribute on an item?

19 messages · Page 1 of 1 (latest)

glacial quartz
#

How does one add or modify an attribute on a diamond sword? For example, I want to modify the entity reach of a diamond sword, currently it has 3.5 but I would love to up the numbers to 4, to 5 etc.
And as far as I recall, there's not really any explanation about attributes on wiki other than mob effects which isn't exactly what I wanted to look for.

haughty mirageBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

ebon ore
#

^ im also trying to figure this out 😭

quick hare
#
let $Attributes = Java.loadClass('net.minecraft.world.entity.ai.attributes.Attributes')
let $AttributeModifier = Java.loadClass('net.minecraft.world.entity.ai.attributes.AttributeModifier')
ForgeEvents.onEvent('net.minecraftforge.event.ItemAttributeModifierEvent', event => 
{if (event.itemStack.id == "minecraft:diamond_sword" && event.slotType == 'chest') {
            
event.addModifier("minecraft:generic.armor", new $AttributeModifier(UUID.fromString('2df18b64-ac1b-4bf5-93ca-8a4ed7ee346a'), 'Armor modifier', 2, 'mainhand'))
    };    
})
#

just change the attribute id because I dont remember what it was for entity reach

glacial quartz
#

By the way, the entity reach ID is either 'minecraft:entity_interaction_range' or 'forge:entity_reach'. But I currently use 'forge:entity_reach' now.

quick hare
#

ye I am fucking stupid and changed the wrong thing

#
let $Attributes = Java.loadClass('net.minecraft.world.entity.ai.attributes.Attributes')
let $AttributeModifier = Java.loadClass('net.minecraft.world.entity.ai.attributes.AttributeModifier')
ForgeEvents.onEvent('net.minecraftforge.event.ItemAttributeModifierEvent', event => 
{if (event.itemStack.id == "minecraft:diamond_sword" && event.slotType == 'mainhand') {
            
event.addModifier("minecraft:generic.armor", new $AttributeModifier(UUID.fromString('2df18b64-ac1b-4bf5-93ca-8a4ed7ee346a'), 'Armor modifier', 2, 'addition'))
    };    
})
#

slot type is in the if statement @glacial quartz

glacial quartz
#

The pain is finally over

#

my god

glacial quartz
quick hare
#

I should also mention that there are mods that do it easier

#

kubejs is good if you want to add attributes to all items with a tag

#

but for specific items I think both alembic and CIA is better

glacial quartz
#

Alembic and CIA? I'll have to check them out, thanks once again.

ebon ore