#Adding Atrribute to armor

32 messages · Page 1 of 1 (latest)

raw wing
#

Trying to add an atrribute to armor and then also remove that attribute.

// priority: 0

PlayerEvents.tick(event => {
    const { player } = event;

    if (!(player.age % 20 === 0)) return;

    if (player.chestArmorItem.id === 'create:netherite_backtank')
    if (player.forgePersistentData.CreateFireImmune == 1)
        {player.chestArmorItem.addAttributeModifier("cold_sweat:heat_resistance", 1)}
    else {player.chestArmorItem.addAttributeModifier("cold_sweat:heat_resistance", 0)}
});
bold sierraBOT
#

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

tall minnowBOT
#

You sure you tried everything you possibly could to fix your issue? Perhaps not.

Make sure you have searched for issues similar to yours in #1047320998199955458 before posting. They might have the answer to your problem!

raw wing
#

tried and this doesnt work either ```js
player.chestArmorItem.addAttribute("cold_sweat:heat_resistance", 1))

marsh pine
#

because addAttribute works only for the Item, but chestArmorItem gives you the ItemStack. So player.chestArmorItem.addAttributeModifier is correct but you have to pass in the AttributeModifier as instance.

const AttributeModifier = Java.loadClass("net.minecraft.world.entity.ai.attributes.AttributeModifier");
player.chestArmorItem.addAttributeModifier("cold_sweat:heat_resistance", new AttributeModifier("resistance.heat", 1, "addition"), "chest")
#

the harder part is removing it. It's stored as a nbt in the itemstack, you have to loop through the item nbt and remove it by hand. Minecraft does not have a removeAttribute method for ItemStacks

raw wing
#

whats the best way to do that? im not to familar with coding.

marsh pine
#

tbh, there is no best way. It's just ugly to do

#

What is your end goal? is there a reason u don't directly give the player the heat resistance?

#

Or does the mod offers a potion effect for heat resistance too? Would probably use this instead

raw wing
#

i see what you mean by this not being ideal

#

it also removes all other attributes on the armor

marsh pine
#

yes. Because AttributeModifiers directly in the ItemStack is mostly used when people generate custom items via commands

raw wing
#

ah

#

is it at all possible to stop a potion effect from appearing in the player inventory?

marsh pine
#

I think there was a flag yeah

#

let me check

#
const MobEffectInstance = Java.loadClass("net.minecraft.world.effect.MobEffectInstance");

// ambient, visible and showIcon are booleans. Probably setting false for all three should work. 
player.addEffect(new MobEffectInstance("minecraft:strength", duration, amplifier, ambient, visible, showIcon));

player.removeEffect("minecraft:strength")
raw wing
#

hmmmm

#

let me see

#

well it hides it from the hud but not the inventory and i guess this is the best i can get without attributes and those arent very friendly for what im doing.

// priority: 0

PlayerEvents.tick(event => {
    const { player } = event;
    const MobEffectInstance = Java.loadClass("net.minecraft.world.effect.MobEffectInstance");

    if (!(player.age % 20 === 0)) return;

    if (player.chestArmorItem.id === 'create:netherite_backtank' || player.chestArmorItem.id === 'create_jetpack:netherite_jetpack')
    if (player.forgePersistentData.CreateFireImmune == 1)
        (player.addEffect(new MobEffectInstance("minecraft:fire_resistance", 20, 0, false, false, false)))
});
#

kinda ugly but what ever

#

i was really banking on those attributes working

marsh pine
#

move const MobEffectInstance = Java.loadClass("net.minecraft.world.effect.MobEffectInstance"); outside of the event. Just loading it once

raw wing
#

oh

#

that would make sense

#

it worked

#

thanks

#

nvm

#
// priority: 0
const MobEffectInstance = Java.loadClass("net.minecraft.world.effect.MobEffectInstance");

PlayerEvents.tick(event => {
    const { player } = event;

    if (!(player.age % 20 === 0)) return;

    if (player.chestArmorItem.id === 'create:netherite_backtank' || player.chestArmorItem.id === 'create_jetpack:netherite_jetpack')
    if (player.forgePersistentData.CreateFireImmune == 1)
        (player.addEffect(new MobEffectInstance("minecraft:fire_resistance", 20, 0, false, false, false)))
});
#

same thing no hud but in the inventory