Solved Problems with adding effects to potions

Discussion in 'Plugin Development' started by Bammerbom, Jul 21, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Bammerbom

    I have problems with adding a potion effect to a potion.
    I can do meta.setMainEffect(PotionEffectType.BLINDNESS); and meta.addCustomEffect(effect, true); but it is a bottle of the correct color, but with the name "Water Bottle", and no lore saying it has a potion effect, but when I drink it it adds blindness.

    Any idea what is going wrong here?
    Code (Simplified):
    Code:java
    1. ItemStack stack = p.getItemInHand(); //Yes I checked this stuff first
    2. PotionMeta meta = (PotionMeta) stack.getItemMeta();
    3. PotionEffectType ef = PotionEffectType.BLINDNESS;
    4. Integer dur = 120; //Some modifiers after this, but you get the idea
    5. Integer lev = 1; //Some modifiers after this, but you get the idea
    6. PotionEffect effect = new PotionEffect(ef, dur * 20, lev - 1);
    7. if(meta.getCustomEffects().isEmpty()){
    8. meta.addCustomEffect(effect, true);
    9. meta.setMainEffect(ef);
    10. }else{
    11. meta.addCustomEffect(effect, true);
    12. }
    13. stack.setItemMeta(meta);


    Another problem:
    When I set the potion to Splash, it still looks like a normal potion (With same problem as above), but when I try to drink it it throws the potion. When I throw the item away and then pick it up it is a drinkable potion (With again the same problem as above)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  2. Offline

    gvlfm78

    Well, you can possibly set the Display Name of the Potion yourself, and maybe add something fancy.

    Code:java
    1. ItemMeta itemMeta = stack.getItemMeta();
    2. itemMeta.setDisplayName("§bEpic Potion");


    But I have a suspect that it has something to do with you only setting the PotionMeta and not the ItemMeta. Do experiment with that.
     
  3. Offline

    DevilMental

    Bammerbom
    I'm not sure but I think the way you put the potion effect on the ItemStack is wrong.
    I use this code :
    Code:java
    1. ItemStack potion = new ItemStack(Material.POTION, 1);
    2. Potion night = new Potion(PotionType.NIGHT_VISION);
    3. night.setLevel(1);
    4. night.apply(potion);


    Tag me if you want more information or if it doesn't work.
    ~ DevilMental
     
  4. Offline

    Bammerbom

    gvlfm78
    I want it to have the normal name, and I am too lazy to do that for every possible potion name and lore.

    And about your PotionMeta thing, PotionMeta extends ItemMeta, so by setting the PotionMeta you automatticly set the itemmeta.

    WOW this is really weird.
    With blindness it didnt work, but it does with speed, I am trying some other effects now.

    It looks like the problem is only there with blindness, any other effect is working :(

    EDIT: I was trying and the problem is there with any potion that is not legit brewable.
    DevilMental gvlfm78

    I think I found the problem.
    There is no PotionType.BLINDNESS.

    Any idea how I could create a Potion of Blindness?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  5. Offline

    Garris0n

    Because the items you're trying to render don't actually exist. There is no blindness potion in the game, so it's not going to magically show up as such.
     
  6. Offline

    Bammerbom

    Garris0n I know they are not brewable, but I didnt know there was no item for it. Marked as solved.
     
Thread Status:
Not open for further replies.

Share This Page