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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • In the rapidly evolving landscape of cryptocurrency, scams are on the rise, leaving many investors vulnerable to fraudulent schemes. If you've found yourself a victim of a crypto scam, navigating the complex process of recovering your lost funds can be daunting and overwhelming. However, there are some professionals in cryptocurrency recovery, such as Captain WebGenesis, who have specific knowledge and experience in handling complex blockchain technology and comprehending how scammers function in the cryptocurrency space. Captain WebGenesis has extensive expertise helping people who have been duped by investment scams to effectively retrieve their stolen or lost cryptocurrency.  
    • Looking for a semi-vanilla Minecraft server? Maybe one with keep inventory and land claims? I have one for you! Let me introduce you to Safe Survival! Come on and join us at mc.safesurvival.net. It is bedrock supported too!
    • Hi. I'm trying to play RLCraft with Optifine but my game keeps crashing on startup with Exit Code 1. The modpack was working fine yesterday, not sure what changed to make it not wanna work anymore. I was hoping someone here could help me figure out what's going wrong. If I remove Optifine, nothing changes, I still get the same errors. Thanks in advance. Crash Report (I only included the errors+fatal, I’m not sure if more is needed, please let me know): https://pastebin.ai/66ivknz0f4  
    • I am trying to port my mod from 1.20.2 to 1.21, but I am encountering difficulties regarding the classes for rendering the GUI and related events. What are the equivalents of the following classes? net.minecraftforge.client.event.RenderGuiOverlayEvent net.minecraftforge.client.gui.overlay.NamedGuiOverlay net.minecraftforge.client.gui.overlay.ForgeGui net.minecraftforge.client.gui.overlay.GuiOverlayManager net.minecraftforge.client.gui.overlay.IGuiOverlay   thx
    • Hi all! Love the Custom npc mod, it is my favorite mod! That said, I have been using this mod since finding it a few years ago (I only play on 1.12.2) and instantly loved that I caould reskin all of the npc's I created. That worked great until recently. I got locked out of my outlook account, which is what I was logged into windows with at the time, and they locked me out of Windows 10. So, I had to reinstall, and since I have digital entitlements to Windows 10 ( I am part of the insider program) on all three of my outlook accounts, I ust swapped to the one I bought Minecraft for. Reinstalled everything, started MC, crerated my favorite fighter (set to kill everything) to clear an area) set up the stats, went back to the main screen, clicked skin so I can give him the grim reaper skin and crash . . . wtf? Thought it was another mod, so, over the course of the last 2 days, I removed every single mod, reinstalled forge 2860 and then 2859, replaced optifine G5 with G6 and vice versa, all with the same result. So, I created a new world, with only the two mods, and same thing. https://pastebin.com/8raJVHq1 That is the log, I have been through the visual settings and all sorts of stuff and can not figure this out, and being that I only just started a bachelors in software engineer / computer programming, I have no idea what I am looking at, so please, and thank you!  If any one of you know what is causing this, I will be forever grateful for the help! Mor9heus
  • Topics

×
×
  • Create New...

Important Information

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