Jump to content

Recommended Posts

Posted
@Mod.EventBusSubscriber(modid = HardSteel.modid, bus = Mod.EventBusSubscriber.Bus.FORGE )
public final class ModEventSubscriber {

    @SubscribeEvent
    public void onEquipmentChangeEvent(LivingEquipmentChangeEvent event)
    {
        if(event.getEntityLiving() instanceof PlayerEntity)
        {
            PlayerEntity player = (PlayerEntity) event.getEntityLiving();
            ItemStack head = player.getItemStackFromSlot(EquipmentSlotType.HEAD);
            ItemStack chest = player.getItemStackFromSlot(EquipmentSlotType.CHEST);
            ItemStack legs = player.getItemStackFromSlot(EquipmentSlotType.LEGS);
            ItemStack feet = player.getItemStackFromSlot(EquipmentSlotType.FEET);

            if(player.getAttributes().getAttributeInstanceByName("generic.movementSpeed").getModifier(UUID.fromString("031cd58c-2529-4c7f-ad1b-ae48df68d2c8")) != null &&
                    head.isEmpty() && chest.isEmpty() && legs.isEmpty() && feet.isEmpty()){
                player.getAttributes().getAttributeInstanceByName("generic.movementSpeed").removeModifier(UUID.fromString("031cd58c-2529-4c7f-ad1b-ae48df68d2c8"));
            }
            if(player.getAttributes().getAttributeInstanceByName("generic.knockbackResistance").getModifier(UUID.fromString("0663661e-a7f6-4a73-84ba-1b8214fb6eec")) != null &&
                    head.isEmpty() && chest.isEmpty() && legs.isEmpty() && feet.isEmpty()){
                player.getAttributes().getAttributeInstanceByName("generic.knockbackResistance").removeModifier(UUID.fromString("0663661e-a7f6-4a73-84ba-1b8214fb6eec"));
            }
        }

I'm trying to make sure certain modifiers added by armor are completely removed when not wearing armor, as my modifiers decrease as the player removes armor but not when the player removes the last piece.

Posted

The fix for this (or rather, the CORRECT way to do what I was trying to do) is to override getAttributeModifiers in the Armor class and then add the modifiers into that mapping system. Do not use onArmorTick in your Armor class for this purpose like I originally was doing.

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.