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.
#How to add/modify the attribute on an item?
19 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
^ im also trying to figure this out 😭
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
For some reason the 'mainhand' crashes my game, it's an enum option, only available with addition, multiply_base and multiply_total. Any ideas how to add it as mainhand? Without mainhand, it's marked as On Body.
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.
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
Haha, no, you're not. Also this finally worked. Thank you so much
The pain is finally over
my god
@ebon ore See the codebase up there, it's all thanks to Pafeu.
Just replace "minecraft:diamond_sword" with any item you want. "minecraft:generic.armor" too with other attributes. Pinged you just in case you're still figuring it out.
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
Alembic and CIA? I'll have to check them out, thanks once again.
tysm! i'm just getting an error involving trying to add kubejs attributes now