#Adding an attribute to an item

47 messages · Page 1 of 1 (latest)

gloomy mantle
#

For some reason this doesn't work ```js
Item.of('minecraft:diamond_chestplate').addAttributeModifier("minecraft:generic.armor",new Internal.AttributeModifier('Armor',5,Internal.AttributeModifier$Operation.ADDITION),Internal.EquipmentSlot.MAINHAND)

``````[09:02:54] [ERROR] ! leveling.js#47: Error in 'ItemEvents.rightClicked': ReferenceError: "Internal" is not defined.```

lethal lightBOT
#

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

lofty wyvern
#

internal doesn't exist

#

is the error not clear enough

#

you gotta import that class ig

#

Internal. is just for the type defs

gloomy mantle
#

How is the class called?

#

Cause I looked up internal on lexxies javadocs, imported it and it said could not import class

#

const Internal = Java.loadClass('net.minecraftforge.internal')```
swift hornet
#

Internal is just a typedef thing

gloomy mantle
#

Ah alr

gloomy mantle
#

I imported the classes sucessfully, but this ```js
console.log(Item.of('minecraft:diamond_chestplate').addAttributeModifier("minecraft:generic.armor",new AttributeModifier('Armor',5,AttributeModifier$Operation.ADDITION),EquipmentSlot.MAINHAND))

#

Logging only the contents of the .addAttributeModifier looks fine

#
[11:06:10] [INFO] leveling.js#50: AttributeModifier{amount=5.0, operation=ADDITION, name='Armor', id=3d354d25-0c70-4d39-bbeb-f188841fba59} [net.minecraft.world.entity.ai.attributes.AttributeModifier]
[11:06:10] [INFO] leveling.js#50: MAINHAND [net.minecraft.world.entity.EquipmentSlot]
swift hornet
#

did you check what addAttributeModifier returns?

#

if it's void, how it should log anything? confused

gloomy mantle
#

I don't log the outcome of the attribute modifier, I log the item

swift hornet
#

no you dont

#

from the code u posted

#

you are loggin Item.of(..).addAttributeModifier(...)

gloomy mantle
#

I also tried giving myself the item, it just gives me air

swift hornet
#

How u did it? I assume with addAttributeModifier? Check what this method returns, if it returns void it will not work

#

because void returns nothing

gloomy mantle
#

Yep, returns void

#

And I just tried to setMainhandItem what I am logging

swift hornet
#

show code

gloomy mantle
#
e.entity.setMainHandItem(Item.of('minecraft:diamond_chestplate').addAttributeModifier("minecraft:generic.armor",new AttributeModifier('Armor',5,AttributeModifier$Operation.ADDITION),EquipmentSlot.MAINHAND))
swift hornet
#

....

#

you still give you "void"

#

if the method returns nothing, you will get nothing

#

split it into multiple parts

gloomy mantle
#

So let item = Item.of()

swift hornet
#

create the item, add the modifier, put the item into the hand

gloomy mantle
#

And then call the modifier on that variable?

gloomy mantle
#

That works

#

Is there a way to clear all attribute modifiers?

#

Other than through the nbt?

swift hornet
#

not in vanilla irc

gloomy mantle
#

What about kubejs?

swift hornet
#

probejs rooBlankGun

gloomy mantle
#

That didn't find anything

swift hornet
#

then probably no

gloomy mantle
#

Alr

#

Thanks