Jump to content

Recommended Posts

Posted (edited)

Hey!

So for example, if I have to launch the player when they right click, I would launch them a certain amount, like so:

	@Override
    public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand)
    {
        //Just showing an example, I know this looks stupid...
        player.motionY = 0.5D;
        player.fallDistance = 0;
        
        return new ActionResult<>(EnumActionResult.SUCCESS, stack);
    }

But how do I edit the amount to satisfy all the levels of Jump Boost if the potion effect is active? (Level I, II, III, etc.)

Please help :/

Edited by Differentiation
Posted
1 hour ago, diesieben07 said:

EntityLivingBase::getActivePotionEffect will give you any active potion effect for that entity based on the potion. Then you can access the modifier using PotionEffect::getAmplifier.

What's the getter method for PotionEffect?

Sorry, I'm having a hard time to locate my IDE.

Posted

Thankfully I'm smart in math xD

if (player.getActivePotionEffect(MobEffects.JUMP_BOOST) != null)
{
	double amplifier = player.getActivePotionEffect(MobEffects.JUMP_BOOST).getAmplifier();
	player.motionY = ((amplifier + 0.45D) * 1.25D) - (amplifier * 1.1D);
}
else
{
	player.motionY = 0.45D;
}

Thanks again :D

Posted
8 minutes ago, diesieben07 said:

There is only one method that is being called twice inside the code snippet that you posted. It is not amplifier, there is no reference to such a method in that snippet anywhere (you do have a local variable named amplifier though).

else { player.motionY = 0.45D? }

xD

Posted (edited)

I don't see what you mean here.

You're either talking about 

player.getActivePotionEffect(MobEffects.JUMP_BOOST)

or

player.motionY

I don't see anything I called twice. Be more specific please?

Edited by Differentiation
Posted (edited)

No. I am telling you to not call getActivePotionEffect twice. Simple as that.

PotionEffect effect = player.getActivePotionEffect(MobEffects.JUMP_BOOST);
                    
if (effect != null)
{
	double amplifier = effect.getAmplifier();
                    	
	player.motionY = ((amplifier + 0.45D) * 1.25D) - (amplifier * 1.15D);
}
else
{
	player.motionY = 0.45D;
}

 

Edited by Differentiation

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.