Jump to content

Recommended Posts

Posted

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

 

Posted

I don't know how such a thing would be done, but you could try looking at the source for the hunger effect and see if there's anything useful in there. Don't know if it's the same on IDEs other than IntelliJ, but you should be able to view the implementation of any class, method or field via the context menu, or if not, some other way. Either way whatever IDE you're using should give you access to the decompiled source code in some way.

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.