Jump to content

[Solved] Attribute Not Removed When Armor is Removed


Recommended Posts

Posted (edited)

I made a type of armor that modifies the player speed attribute. The armor successfully adds the value to the player attribute, but when I take off the armor in game, the added value is not removed. How can I make it so that the attribute modifier is only applied while the armor is worn? Thanks in advance. 

 

My custom armor class:

public class DaegoniteArmor extends ItemArmor implements IHasModel{

	public final double speedBoost = 0.5F;
	
	public DaegoniteArmor(String name, ArmorMaterial materialIn, int renderIndexIn, EntityEquipmentSlot equipmentSlotIn) {
		super(materialIn, renderIndexIn, equipmentSlotIn);
		setUnlocalizedName(name);
		setRegistryName(name);
		setCreativeTab(CreativeTabs.COMBAT);
		
		ModItems.ITEMS.add(this);
	}
	
	@Override
	public void registerModels() {
		
		Main.proxy.registerItemRenderer(this,0, "inventory");
		
	}
	
	@Override
    public boolean getIsRepairable(ItemStack toRepair, ItemStack repair)
    {
        return false;
    }
	
    /**
     * Gets a map of item attribute modifiers, used by ItemSword to increase hit damage.
     */
	@Override
    public Multimap<String, AttributeModifier> getItemAttributeModifiers(EntityEquipmentSlot equipmentSlot)
    {
        Multimap<String, AttributeModifier> multimap = super.getItemAttributeModifiers(equipmentSlot);

        if (equipmentSlot == this.armorType)
        {
            multimap.put(SharedMonsterAttributes.MOVEMENT_SPEED.getName(), new AttributeModifier(SharedMonsterAttributes.MOVEMENT_SPEED.getName(), this.speedBoost, 1));
        }

        return multimap;
    }
	

	
	
}

 

Edited by Lumby
Posted
14 minutes ago, Lumby said:

IHasModel

14 minutes ago, Lumby said:

@Override public void registerModels() {

    Main.proxy.registerItemRenderer(this,0, "inventory");

}

On 9/17/2018 at 9:43 AM, Draco18s said:

IHasModel is stupid and pointless (I will beat this out of you cargo cult programmers eventually). ALL items need models and all the information necessary to register a model is public. Code Style #3.

 

Try using onArmorTick (or similar) to check if you have the full set and apply the effect

  • Thanks 2

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted

Got it, thanks for your help!

3 minutes ago, Cadiboo said:

I will beat this out of you cargo cult programmers eventually

lmao got it, will go ahead and fix that. Followed some dude's tutorial and he had it in so I thought this was the most efficient way. What does cargo cult mean?

Posted
4 minutes ago, Lumby said:

Followed some dude's tutorial

Don't follow youtube tutorials basically.

4 minutes ago, Lumby said:

What does cargo cult mean?

 https://en.wikipedia.org/wiki/Cargo_cult_programming

Basically just copy and pasting code without really thinking about why your doing it, if theres a better way or if its even needed at all

5 minutes ago, Lumby said:

he had it in so I thought

 

  • Thanks 1

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted

I've been trying to use the onArmorTick() method but it yielded the same result, being that the player's attribute map remains unchanged. In the end, I traced the call hierarchy of getItemAttributeModifiers() and found that it utilized specific UUIDs to determine whether or not remove the new AttributeModifier passed into the map. Hence, instead of using 

multimap.put(SharedMonsterAttributes.MOVEMENT_SPEED.getName(), new AttributeModifier(SharedMonsterAttributes.MOVEMENT_SPEED.getName(), this.speedBoost, 1));

I added the armorModifier UUIDs in the ItemArmor class and it did the trick

multimap.put(SharedMonsterAttributes.MOVEMENT_SPEED.getName(), new AttributeModifier(ARMOR_MODIFIERS[equipmentSlot.getIndex()],"Daegonite Tank", speedBoost, 1));

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.