How to make a saturation potion?

Discussion in 'Plugin Development' started by MakerofRobots, Aug 1, 2013.

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

    MakerofRobots

    I want to make and give to a player a potion that has the saturation effect on it (id 23 on the minecraft wiki). Buuuuut when you make a new potion object, the only thing you can do as far as effects is change the PotionType, and the options for that are only the potions you can brew in vanilla minecraft. I am considering using a listener to tell when you drink a certain potion (PlayerConsumeItemEvent) to apply the effect I want. I would much prefer to add the effect to the potion if someone knows how.

    I tried to do
    Code:java
    1. new PotionEffect();
    but even with that, all you can do is vanilla stuff...
     
  2. Offline

    xTrollxDudex

    MakerofRobots
    Create a new potion with specific properties and when the player consumes it check if it is a potion and it has the properties of the potion you defined earlier. Then give them a saturation effect

    MakerofRobots

    Have you attempted to perhaps have a custom name for the item.. then when they consume it, check for the name, is it's the correct name apply this?

    Code:
    player.addPotionEffect(new PotionEffect(PotionEffectType.SATURATION, 1200, 1));
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Nov 25, 2021
  3. Offline

    MakerofRobots

    valon750
    xTrollxDudex
    Thanks guys, but is there no way to just add the saturation effect to the potion? I already kinda had the listener way of doing it figured out.
     
  4. Offline

    tommycake50

    Yeah, if you want to edit some NBT tags im sure you could.
    but you won't get much help for nms code here.
     
  5. Offline

    MakerofRobots

    where can i find this elusive "help" you speak of?
     
  6. Offline

    tommycake50

    Idk, i have never even used NMS.
    i don't think a lot of people have.
     
  7. Offline

    xTrollxDudex

    tommycake50 and MakerofRobots like this.
  8. Offline

    macguy8

    Code:
    ItemStack itemStack = (new Potion(PotionType.WATER, 2)).toItemStack(1);
    
    Essentially, you'd be creating a Potion object (http://jd.bukkit.org/rb/apidocs/org/bukkit/potion/Potion.html) with the tier of 2 (second argument) and then be creating an ItemStack from it. The 1st parameter of .toItemStack is the amount to be in the ItemStack. Note, this requires a PotionType value, NOT a PotionEffectType. PotionType only provides a value for every potion that can be actually made, not all effect types that are in the game. It wouldn't provide what you need, but it'd be a start.

    Wait, I think I just had a deep moment. I think you can just use...
    new ItemStack(Material.POTION, 1, <Potion Data Value>); You should be able to get that id from the wiki.

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

    xTrollxDudex

    macguy8
    Potion data can be recived by creating a new Potion() and all the parameters and potion.getData().getData()
     
  10. Offline

    macguy8

    Potion accepts a PotionType enum, which are all potions that can be made in game. It however doesn't accept the PotionEffectType enum, and only PotionEffectType contains SATURATION, so therefor that would not work.
     
    xTrollxDudex likes this.
  11. Offline

    foodyling

  12. Offline

    tommycake50

  13. Offline

    foodyling

    MakerofRobots tommycake50 Yet it is possible by using PotionMeta, confirmed to work for me:
    Code:
            ItemStack potion = new ItemStack(Material.POTION);
            PotionMeta meta = (PotionMeta) potion.getItemMeta();
            meta.addCustomEffect(new PotionEffect(PotionEffectType.SATURATION, 200, 0), true);
            potion.setItemMeta(meta);
            player.getInventory().addItem(potion);
            
     
    Shortninja66 and tommycake50 like this.
  14. Offline

    valon750

    foodyling

    Huh.. now that's one awesome idea....
     
Thread Status:
Not open for further replies.

Share This Page