Jump to content

[SOLVED] Forge 1.20 Custom Potion Effects


Recommended Posts

Posted (edited)

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.

 

Edited by AndroPupsi
Forgot to Edit Code to add colors, New edit to post solution
Link to comment
Share on other sites

  • AndroPupsi changed the title to [SOLVED] Forge 1.20 Custom Potion Effects

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.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.