Jump to content

[Forge 1.21.1] Help with custom MobEffect that affects appearance of the hunger bar GUI


Recommended Posts

I created a custom effect called "Fullness" that prevents the player from losing hunger when they get the effect. For this, I created a new java class called FullnessEffect. Everything is working fine, and the player isn't able to lose hunger, but I wanted to make it so that whenever you have the Fullness effect, your hunger bar changes color to gold, similar to how your hunger bar turns sickly green when you have the hunger effect. I searched online, but there seems to be no information regarding how to do this. Does anyone know how to do this? 

Here is the code for the FullnessEffect class in case anyone needs it (the import section is omitted): 

public class FullnessEffect extends MobEffect {
    public FullnessEffect (MobEffectCategory mobEffectCategory, int color) {
        super(mobEffectCategory, color);
    }

    @Override
    public boolean applyEffectTick (LivingEntity pLivingEntity, int pAmplifier) {
        if (!pLivingEntity.getCommandSenderWorld().isClientSide() && pLivingEntity instanceof Player player) {
            FoodData foodData = player.getFoodData();
            float exhaustionLevel = foodData.getExhaustionLevel();
            if (exhaustionLevel > 0.0F) {
                player.causeFoodExhaustion(-exhaustionLevel);
            }
        }
        super.applyEffectTick(pLivingEntity, pAmplifier);
        return true;
    }
    @Override
    public boolean shouldApplyEffectTickThisTick(int duration, int amplifier) {
        return true;
    }
}



I may sound a bit stupid because I'm a bit new to modding but any help would be greatly appreciated

 

Link to comment
Share on other sites

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.