Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (โ‹ฎ) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

  • Author
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.

  • Author
8 minutes ago, diesieben07 said:

Which PotionEffect? Please clarify what you are looking for.

PotionEffect::getAmplifier

What is the getter for PotionEffect? :/

  • Author
1 minute ago, diesieben07 said:

Do not use getPotionById. Use the constants defined in theย MobEffects class.

ย 

Why not though? Does it give errors or something?

  • Author

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

  • Author
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

  • Author

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

  • Author

ย 

Just now, diesieben07 said:

Which is being called - let's count together - once, that's right. So it's not what I am talking about.

So you're basically telling me to remove the null check...

  • Author

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions โ†’ Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.