Potion in Merchant Menu

Discussion in 'Plugin Development' started by Xhork, Dec 30, 2018.

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

    Xhork

    Hey,

    I want to create a Villager custom trade for Potion of jump boost level 2 for 2 emeralds but when i'm creating the potion it has too many tags and is not ok with the "normal" jump boost potion level 2


    Code:
    ItemStack potion = new ItemStack(Material.POTION);
            PotionMeta meta = (PotionMeta) potion.getItemMeta();
            PotionEffect pe = new PotionEffect(PotionEffectType.JUMP, 1800, 1);
            meta.addCustomEffect(pe, true);
            meta.setColor(Color.LIME);
            meta.setDisplayName("§r§fPotion of Leaping");
            potion.setItemMeta(meta);
    the normal potion has 1 NBT tags and the one i create has 4 :(
     
  2. Online

    KarimAKL

    @Xhork What exactly is the problem? Does it not work?
     
  3. Offline

    Xhork

    no it's not working, i need to create an itemstack of jump boost potion level 2 but with only 1 tag

    (i think)
     
  4. Online

    KarimAKL

    @Xhork I'm pretty sure the amount of tags doesn't matter, as long as it has the tags you want.

    What is not working?
     
  5. Offline

    Xhork

  6. Online

    KarimAKL

    @Xhork If the two potions is not the same it won't work. (same NBT tags) What is your current code?
     
  7. Offline

    Xhork

    Here it is :

    Code:
    ItemStack potion = new ItemStack(Material.POTION);
            PotionMeta meta = (PotionMeta) potion.getItemMeta();
            PotionEffect pe = new PotionEffect(PotionEffectType.JUMP, 1800, 1);
            meta.addCustomEffect(pe, true);
            meta.setColor(Color.LIME);
            meta.setDisplayName("§r§fPotion of Leaping");
            potion.setItemMeta(meta);
     
  8. Online

    KarimAKL

    @Xhork I meant where you create the two potions and compare them.
     
  9. Offline

    Xhork

    I don't have to create 2 potions, I put this itemStack into a Merchant code, and try to sell a basic level 2 potion of jump boost into the villager but this is not working, the sell is not working
     
  10. Online

    KarimAKL

    @Xhork Are you creating a new ItemStack everytime? If so try saving the ItemStack in a variable and access it later.
     
  11. Offline

    Xhork

    @KarimAKL I'm creating this ItemStack everytime because i only do that one time, but not working
     
  12. Online

    KarimAKL

    @Xhork Are you doing something like this?
    Code:Java
    1. //Main class
    2. public class MainClass extends JavaPlugin {
    3. public void onEnable() {
    4. new PotionToTrade();
    5. }
    6. }
    7.  
    8. //Some class (this is an example, i don't know your code)
    9. public class PotionToTrade {
    10. private final ItemStack potion;
    11. public PotionToTrade() {
    12. potion = new ItemStack(Material.POTION);
    13. PotionMeta meta = (PotionMeta) potion.getItemMeta();
    14. PotionEffect pe = new PotionEffect(PotionEffectType.JUMP, 1800, 1);
    15. meta.addCustomEffect(pe, true);
    16. meta.setColor(Color.LIME);
    17. meta.setDisplayName("§r§fPotion of Leaping");
    18. potion.setItemMeta(meta);
    19. }
    20. public ItemStack getPotion() {return potion;}
    21. }
     
  13. Offline

    Xhork

    @KarimAKL
    Here is my full code for the trade system :
    Code:
    Merchant Potion = Bukkit.createMerchant("Potions");
            List<MerchantRecipe> merchantRecipes = new ArrayList<MerchantRecipe>();
         
            MerchantRecipe jump_boost = new MerchantRecipe(new ItemStack(Material.EMERALD, 2), 10000);
    
            ItemStack potion = new ItemStack(Material.POTION);
            PotionMeta meta = (PotionMeta) potion.getItemMeta();
            PotionEffect pe = new PotionEffect(PotionEffectType.JUMP, 1800, 1);
            meta.addCustomEffect(pe, true);
            meta.setColor(Color.LIME);
            meta.setDisplayName("§r§fPotion of Leaping");
            potion.setItemMeta(meta);
         
         
            jump_boost.setExperienceReward(false);
            jump_boost.addIngredient(potion);
            merchantRecipes.add(jump_boost);
            Potion.setRecipes(merchantRecipes);
         
            p.openMerchant(Potion, true);
     
  14. Online

    KarimAKL

    @Xhork I would guess that it's because of the line "ItemStack potion = new ItemStack(Material.POTION);"

    Try making a variable like i made in the post above that contains the ItemStack named 'potion' and then set the ingredient to that instead of the new potion you made. (give the player the ItemStack from the same variable)

    Remember to set the meta etc. for the variable before giving the potion to the player and before setting it as the ingredient.
     
  15. Offline

    Xhork

    @KarimAKL thank's but i don't give that potion to the player, i think you don't understand. I want to trade a simple level 2 potion of jump boost with a villager, but i need an itemstack JUST for the trade menu, not for the player, the player has to craft it ^^
     
  16. Online

    KarimAKL

    @Xhork I see, i thought you meant you wanted to be able to trade a custom potion. :7

    I'm sorry but i don't know if it's possible to do what you want. If it is i don't know how. :/
     
Thread Status:
Not open for further replies.

Share This Page