1.15.2 How do I make potion effects level up during its effect?

Discussion in 'Spigot Plugin Development' started by kuai090, Mar 3, 2020.

  1. I am trying to make a player run as fast as they can without any limits by potion effect, and they got that by collecting XP. For instance, if a player gained XP by defeating a mob, the player's speed will increase permanently. How would I increase the level in its arguments? This is my code so far.

  2. drives_a_ford


    If you want to do this with potion effects (which doesn't really give you a lot of granularity), you'd first want to LivingEntity#getPotionEffect. If that's null, the player didn't have the effect before (i.e previous level is 0). If its not null, use PotionEffect#getAmplifier as the previous level.
    Now increment the previous level and add the new potion effect.

    However, you don't get much granularity doing it this way. I would suggest using Attribute.GENERIC_MOVEMENT_SPEED instead. Use Attributable#getAttribute and either AttributeInstance#addModifier or AttributeInstance#setBaseValue.
    • Agree Agree x 2
  3. Would it be something like this?

    Attached Files:

  4. drives_a_ford


    Why don't you just try it?
    But that should do the trick.
  5. I just tested it and it worked for a second then went back to its normal speed. Is it because I set the value too high?
  6. Well you can use player's walking speed and update it exponentially over each mob kill (but would obviously get limited at 10), or can use Potion Effect and just set it to last forever and update the speed's amplifier.
  7. I tried both of them and I didn't like it. Generic movement speed would work perfect, but it's not letting me work.