Posted October 14, 20178 yr 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 October 15, 20178 yr by Differentiation
October 14, 20178 yr 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.
October 14, 20178 yr Author 8 minutes ago, diesieben07 said: Which PotionEffect? Please clarify what you are looking for. PotionEffect::getAmplifier What is the getter for PotionEffect?
October 14, 20178 yr Author 9 minutes ago, diesieben07 said: Got it. Thanks! Edited October 14, 20178 yr by Differentiation
October 14, 20178 yr 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?
October 14, 20178 yr Author 2 minutes ago, diesieben07 said: Numerical IDs change, they are not constant. I see. I'll use MobEffects::JUMP_BOOST then. Thanks!
October 14, 20178 yr Author Thankfully I'm smart in math 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
October 14, 20178 yr Author 2 minutes ago, diesieben07 said: Why are you calling the method twice... What do you mean? amplifier?
October 14, 20178 yr 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? }
October 14, 20178 yr 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 October 14, 20178 yr by Differentiation
October 14, 20178 yr 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...
October 14, 20178 yr 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 October 14, 20178 yr by Differentiation
October 14, 20178 yr Author Just now, diesieben07 said: Good job. Thanks Edited October 14, 20178 yr 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.