Posted November 10, 20204 yr I'm new to modding, but I'm trying to make a mod that replaces the hunger effect with weakness. It should check if the player has received the hunger effect, then add a weakness effect of equal strength/duration, and then remove the hunger effect. However, for some reason it won't remove the hunger effect. I'm really hoping someone can explain why it doesn't work and give criticism if I have any bad practices. Below is the event handler class. Thanks in advance! @Mod.EventBusSubscriber(modid = StahTweaks.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT) public class ModClientEvents { @SubscribeEvent /** Theoretically checks if the effect gained is hunger and then replaces * it with a weakness effect of equal strength */ public static void onPlayerHungerEffect(PotionEvent.PotionAddedEvent event) { LivingEntity player = event.getEntityLiving(); EffectInstance effect = event.getPotionEffect(); if(effect.getPotion().equals(Effects.HUNGER)) { player.addPotionEffect(new EffectInstance(Effects.WEAKNESS, effect.getDuration(), effect.getAmplifier())); player.removePotionEffect(Effects.HUNGER); } } }
November 10, 20204 yr Because when the event is triggered the potion has not yet being applied to the entity. You can use PotionApplicableEvent instead, in there you can set the event result to DENY (see it's javadoc) and apply your own one.
November 10, 20204 yr Author 13 minutes ago, poopoodice said: Because when the event is triggered the potion has not yet being applied to the entity. You can use PotionApplicableEvent instead, in there you can set the event result to DENY (see it's javadoc) and apply your own one. Oh that makes a lot of sense, thank you!
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.