Jump to content

[1.7.10] Can't add potion effect to player


Ms_Raven

Recommended Posts

I'm trying to cause the Nausea effect on the player when their Sanity (custom variable) has run out.

The console spams "Sanity = 0" when it runs out, but the effect is never added.

 

Why not?

 

@SubscribeEvent
	public void onLivingUpdate(LivingUpdateEvent event)
{
		if (event.entity instanceof EntityPlayer)
		{
			EntityPlayer player = (EntityPlayer) event.entity;
			ExtendedPlayer props = ExtendedPlayer.get(player);

			if (player.isPlayerFullyAsleep())
			{
				props.replenishSanity();        //This works fine
			}


			//Problem starts here
			if(props.getCurrentSanity() == 0)
			{
				Tools.printcon("Sanity = " + props.getCurrentSanity());                           //This DOES happen.
				player.addPotionEffect(new PotionEffect(Potion.confusion.getId(), 1, 5));       //This does NOT happen.
			}
		}
	}

 

 

Link to comment
Share on other sites

1st of all - you need to addPotion effect on !world.isRemote (server side).

Second problem - in adding potion method you are feeding it time parameter == 1. There is this "bad design" thing there which causes potion to be automatically removed just after adding it if the time was == 1. To make effect actually happen you need to set time to 2 or more ticks.

 

Setting it to 2+ should remove problems (also visual ones), but still - I personally don't like potion updating code. It should be feeded in for-next-tick-queue, not just randomly put there (effect might be added in different places in tick "lifespan" therefore it can be treated differently in different situations).

1.7.10 is no longer supported by forge, you are on your own.

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.