Jump to content

[SOLVED][1.10.2] Poison and Nausea not working


lukas2005

Recommended Posts

hello i am using code to give player a potion effect but Poison And Nausea are not working

 

Poison colors my heart bar to green but does not deals damage and nausea is appearing as active effect in inventory but nothing happens

 

heres code:

public void onPlayerTick(PlayerTickEvent event) { 
utils.addPotionEffect(event.player, PotionID.NAUSEA, 20, 1, true);
}

 

PotionID class:

 

public class PotionID {

public static int SPEED = 1;
public static int SLOWNESS = 2;
public static int HASTE = 3;
public static int MININGFATIGUE = 4;
public static int STRENGTH = 5;
public static int INSTANTHEALTH = 6;
public static int INSTANTDAMAGE = 7;
public static int JUMPBOOST = 8;
public static int NAUSEA = 9;
public static int REGENERATION = 10;
public static int RESISTANCE = 11;
public static int FIRERESISANCE = 12;
public static int WATERBREATHING = 13;
public static int INVISIBILITY = 14;
public static int BLINDNESS = 15;
public static int NIGHTVISION = 16;
public static int HUNGER = 17;
public static int WEAKNESS = 18;
public static int POISON = 19;
public static int WITHER = 20;
public static int HEALTHBOOST = 21;
public static int ABSORPTION = 22;
public static int SATURATION = 23;
public static int GLOWING = 24;
public static int LEVITATION = 25;
public static int LUCK = 26;
public static int BADLUCK = 27;

}

 

and addPotionEffect Function:

public static void addPotionEffect(EntityLivingBase entity, int potionid, int duration, int amplifier, boolean showParticles) {

	entity.addPotionEffect(new PotionEffect(Potion.getPotionById(potionid), duration, amplifier, false, showParticles)); 

}

 

Link to comment
Share on other sites

It sounds like you're adding the potion effects on the client instead of the server, but I'd have to see more of your code (specifically the full method containing the call to

utils.addPotionEffect

) to be sure.

 

Do not use numeric IDs for potions or anything else, these are automatically assigned and can change between saves. Vanilla stores its

Potion

instances in the

MobEffects

class, use these.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

i am calling utils.addPotionEffect in tick player event therse nothing more

 

Oh, so you're adding a potion effect to the player every tick.  THERES YOUR PROBLEM.  Potion duration actually means something: it's a timer.  Every time the potion duration is

durationRemainting % 20 == 0

the effect (healing, damage) activates and is applied.

 

If you constantly reset the potion duration then those effects never trigger.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

ok so i need to check if player arelady has a potion to make it work

 

EDIT:

 

i changed my utils.addPotionEffect function to:

public static boolean addPotionEffect(EntityLivingBase entity, Potion potion, int duration, int amplifier, boolean showParticles) {
	if (!entity.isPotionActive(potion)) {

		entity.addPotionEffect(new PotionEffect(potion, duration, amplifier, false, showParticles)); 

		return true;
	}
	return false;

and still not works maybe resaon is that i am giving the potion on 1 sec

 

Link to comment
Share on other sites

Potions like Poison and Regeneration only apply their effect every X ticks, determined by

Potion#isReady

. I suggest you look at this method to see the minimum duration required for the effect to be applied.

 

Nausea requires the duration to be greater than 60 for the wobbling effect to start rendering.

 

Potion effects should only be added on the server (when

World#isRemote

is

false

).

 

PlayerTickEvent

and all other subclasses of

TickEvent

are fired twice per tick of their corresponding system: once at the start with

Phase.START

and once at the end with

Phase.END

. Always check the event's

Phase

to ensure you're not running your code twice per tick.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Potions like Poison and Regeneration only apply their effect every X ticks, determined by

Potion#isReady

. I suggest you look at this method to see the minimum duration required for the effect to be applied.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

in the Potion#isReady method is only

    /**
     * checks if Potion effect is ready to be applied this tick.
     */
    public boolean isReady(int duration, int amplifier)
    {
        if (this == MobEffects.REGENERATION)
        {
            int k = 50 >> amplifier;
            return k > 0 ? duration % k == 0 : true;
        }
        else if (this == MobEffects.POISON)
        {
            int j = 25 >> amplifier;
            return j > 0 ? duration % j == 0 : true;
        }
        else if (this == MobEffects.WITHER)
        {
            int i = 40 >> amplifier;
            return i > 0 ? duration % i == 0 : true;
        }
        else
        {
            return this == MobEffects.HUNGER;
        }
    }

what i shloud do with this?

 

Link to comment
Share on other sites

Gosh, I wonder what this part does.

if (this == MobEffects.POISON)
        {
            int j = 25 >> amplifier;
            return j > 0 ? duration % j == 0 : true;
        }

 

Every time the potion duration is

durationRemainting % 20 == 0

the effect (healing, damage) activates and is applied.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

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.