Hello, new coder and first time posting, sorry if I get stuff wrong
Been having a really difficult time trying to figure out this potion effect. I want to give a potion effect that denies the wither effect on the player. I've looked over a lot of different tutorials, and through some other mods and made something that sort of works but it was based on applyEffectTick and the players would still take a tick of damage before the potion effect kicked in.
When looking up other ways to do this I saw there was like the PotionEvent but whenever I try to use it, I get errors of how it cannot be defined.
This is my code right now that doesn't work
package io.github.AndroPups.tsmp_models.effect;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectCategory;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.LivingEntity;
public class NoWitherEffect extends MobEffect {
public NoWitherEffect(MobEffectCategory mobEffectCategory, int color) {
super(mobEffectCategory.BENEFICIAL, color);
}
public static void onPotionAdded(PotionEvent.PotionAddedEvent event) {
LivingEntity entity = event.getEntityLiving();
MobEffect potionEffect = event.getPotionEffect().getEffect();
if (potionEffect == MobEffects.WITHER); {
entity.removeEffect(MobEffects.WITHER);
}
}
@Override
public boolean isDurationEffectTick(int duration, int amplifier) {
return true;
}
}
And this code works but occasionally still applies damage because of ticking effect.
package io.github.AndroPups.tsmp_models.effect;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectCategory;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.LivingEntity;
public class NoWitherEffect extends MobEffect {
public NoWitherEffect(MobEffectCategory mobEffectCategory, int color) {
super(mobEffectCategory.BENEFICIAL, color);
}
@Override
public void applyEffectTick(LivingEntity pLivingEntity, int pAmplifier) {
if (!pLivingEntity.level().isClientSide()) {
if (pLivingEntity.hasEffect(MobEffects.WITHER)); {
pLivingEntity.getEffect(MobEffects.WITHER);
}
}
}
@Override
public boolean isDurationEffectTick(int duration, int amplifier) {
return true;
}
}
I've tried to see if PotionEvent was removed from recent Forge updates but can't really find any information on it. Any information at all would be helpful! Thanks!
EDIT:
I found a solution, instead of trying to stop the effects I instead made an event that applies effects to the player in the water then made a potion that when it's active the water event would just skip the negative effects. A lot more simpler to use than my round about code. Works like a dream.