Potions API

Discussion in 'Bukkit Preview' started by fullwall, Feb 10, 2012.

  1. Offline

    fullwall

    This feature provides API for two things - potion effects and potions themselves.
    To this end, it introduces two main classes - Potion and PotionEffect.

    A potion effect has a duration (measured in ticks) an amplifier, and a PotionEffectType, and can be applied to LivingEntities, causing effects such as blindness, faster moving speed, and more. Amplifiers increase the strength of an effect and are effect-dependent, such as how much health will be given by the heal effect. Various methods exist in LivingEntity to give effects, such as
    Code:
    LivingEntity.addPotionEffect(PotionEffect) and
    LivingEntity.getActivePotionEffects()
    Note that only one potion effect of a given type can be present at any one time, and that the potion effects NIGHT_VISION and INVISIBILITY are unusable due to not being implemented by Minecraft.

    The Potion class acts as a representation of an ingame potion, and can be created using
    Code:
    new Potion(PotionType);
    where PotionType is an enum of the usable subset of potion effects. Potions have a tier (accessible using the Potion.Tier enum) which alters the amplifier of the resulting effect, an 'extended duration' flag, which increases duration by a set amount (roughly 8/3 * base duration), and a splash flag, which allows the potion to be thrown and affect an area.

    Potions can be created from a raw damage value using the static methods
    Code:
    Potion.fromDamage(int) and
    Potion.fromItemStack(ItemStack)
    and applied to both LivingEntities (by adding the effects of the potion) and ItemStacks (by setting the raw damage value).

    Finally, the Potion class also contains a PotionBrewer (Potion.getPotionBrewer()), which contains two small helper methods, used to convert from raw potion damage values to PotionEffects, and to create PotionEffects with modifiers from PotionEffectType applied.
     
    MrWaffleman, AlexMl, McSebi96 and 4 others like this.

Share This Page