Solved How to code a Potion of Bad Luck? [Lock Please]

Discussion in 'Plugin Development' started by Mr. Sandwich, May 14, 2016.

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

    Mr. Sandwich

    I tried to code a potion of bad luck but I dont know what to do..
    Code:
                        ItemStack badLuck = new ItemStack(Material.POTION, 1, (short) 27);
                        ItemMeta badLuckMeta = badLuck.getItemMeta();
                        badLuckMeta.setDisplayName(ChatColor.GREEN + "Potion of Bad Luck");
                           badLuck.setItemMeta(badLuckMeta);
    
    Help?
     
  2. I would make a listener which checks if a player drinks the Bad Luck potion then display some kind of notification that the player now has bad luck because I don't think you can display custom potion effects and if the player fishes something, kills mob or things like that, you modify the dropped items.
    Maybe even mess with the loot table system in 1.9 if possible..
     
  3. Offline

    Mr. Sandwich

    I need to create a potion of bad luck to not check for one, I want to code a command that gives the player this potion
     
  4. something like
    Code:
    player.getInventory().addItem(badLuckPotion) 
    ..?
     
  5. Offline

    Mr. Sandwich

    ... I asked how you create this specific itemstack not how to give it to a player...
     
  6. ..But didn't you already create the itemstack with
    Code:
    ItemStack badLuck = new ItemStack(Material.POTION, 1, (short) 27);
    ItemMeta badLuckMeta = badLuck.getItemMeta();
    badLuckMeta.setDisplayName(ChatColor.GREEN + "Potion of Bad Luck");
    badLuck.setItemMeta(badLuckMeta);
    Use the Minecraft Wiki page to get the item metadata if you want a specific color.
     
  7. Offline

    Mr. Sandwich

    This item metadata doesnt work, it gives the wrong potion and I asked for a way to fix it to give the right potion
     
  8. Then click on the link I gave you and search for the item metadata value for the corrent potion.
    Oh and take a look at this ^^
     
  9. Offline

    Mr. Sandwich

    I am sorry for being rude but can you stop linking me to pages where you dont even check if they have my solution?
    the whole point of this is that there's no potion of bad luck, you need to create one, it doesnt have an id or a damage value for a potion so this http://minecraft.gamepedia.com/Potion is useless for me
     
  10. "I am sorry for being rude but" I am just posting these links to help you make yourself a custom potion. You first need to choose from the Potions on http://minecraft.gamepedia.com/Potion because you can't create an own texture, you need to choose an existing potion. Then you create your itemstack with the data value of the existing potion which you want the texture from, give it to the player and then check for the right events and modify them.
    Oh and I think you need to work with NBT instead of item metadata in 1.9 and I linked the other page because it looks like there may be a way to create custom potion effects but I didn't really look into it.
     
  11. Offline

    Mr. Sandwich

    http://minecraft.gamepedia.com/Potion doesnt help because there's no potion of bad luck, but I do know its possible to create one using a plugin. I need a way to set a potion effect to a potion like in complete vanilla minecraft you use
    /give @p minecraft:potion 1 0 {CustomPotionEffects:[{Id:27,Amplifier:0,Duration:20000}]}
    but I want to know how to do it in a plugin

    EDIT: The website edits minecraft: Potion to a smiley face in case you were wondering why its there
     
  12. Of course there is no bad luck potion, it just helps choosing a potion on which this new potion should be based on.
    By the way, for how long have you been learning Java and working with Bukkit?
     
  13. Offline

    I Al Istannen

    @Kage0x3B
    In (I think) 1.9 a "Bad luck" potion was added, decreasing the weights for the Loot tables. Similar there is a "Luck" one, increasing it.
    The way to get new potions has changed in 1.9, which is probably why he asks.


    @Mr. Sandwich
    I don't actually know, but this might help you.
     
    DoggyCode™ likes this.
  14. Offline

    DoggyCode™

    You don't use new ItemStack to create a new lotion. You use:

    Potion pot = new Potion(PotionType.pottype, int level, boolean splash);

    Then you can use

    ItemStack potItem = pot.toItemStack(int amount);

    Then add that to somewhere

    You don't have to work with ItemMeta, if anything you'd have to work with PotionMeta.

    You can find everhthing about it here: https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/browse/src/main/java/org/bukkit/potion

    Just go into the Potion.java to see all the stuff you can do with your Potion object.

    Sent from my SM-N9005 using Tapatalk
     
  15. Offline

    Mr. Sandwich

    @DoggyCode There's no PotionType.Unluck so I cant do that and I tried
    Code:
                         Potion pot = new Potion(PotionType.UNCRAFTABLE, 1, false);
                         ItemStack potItem = pot.toItemStack(1);
                         PotionMeta pMeta = (PotionMeta) potItem.getItemMeta();
                         pMeta.setBasePotionData(new PotionData(PotionType.getByEffect(PotionEffectType.UNLUCK)));
                         pMeta.setDisplayName(ChatColor.GREEN + "Potion of Bad Luck");
                         potItem.setItemMeta(pMeta);
    
    but it doesnt work(it doesnt work because there's no potion of unluck, when I changed UNLUCK to REGENERATION it worked)
    it doesn't work because it wants to spawn a potion of bad luck(which doesnt exist) but it doesnt find it so it cant do it but I want to do is to take like a potion of leaping(jump boost) and then set the UNLUCK potion effect on it, like in essentials you have a /potion command(I think thats how its named) where you can take potions and add them more potions effect, remove them and switch them but the texture and the id of the original potion stays so you will be able to create potions like potion of bad luck. (Its kind of hard to explain if you didnt understand tell me and I will try to re-explain)
    "pMeta.setBasePotionData(new..." sets the base of the potion, I need to set the base to Junp Boost, add Unluck aka Bad Luck and then remove jump boost(or keep it if theres no other choice)

    EDIT: I dont know if it helps but when you spawn it in normal minecraft with
    /give @p minecraft:potion 1 0 {CustomPotionEffects:[{Id:27,Amplifier:0,Duration:20}]}
    Then its called Uncraftable Potion and after some research and stuff I was able to do this
    Code:
                            Potion pot = new Potion(PotionType.JUMP, 1, false);
                            ItemStack potItem = pot.toItemStack(1);
                            PotionMeta pMeta = (PotionMeta) potItem.getItemMeta();
                            pMeta.addCustomEffect(new PotionEffect(PotionEffectType.UNLUCK,100,1), false);
                            pMeta.removeCustomEffect(PotionEffectType.JUMP);
                            pMeta.setDisplayName(ChatColor.GREEN + "Potion of Bad Luck");
                            potItem.setItemMeta(pMeta);
    
    But it still has jump boost so does anyone have an idea for how to remove it?
    Second Edit: Ok I finally did it!
    Code:
                         Potion pot = new Potion(PotionType.UNCRAFTABLE, 1, false);
                         ItemStack potItem = pot.toItemStack(1);
                         PotionMeta pMeta = (PotionMeta) potItem.getItemMeta();
                         pMeta.addCustomEffect(new PotionEffect(PotionEffectType.UNLUCK,10800,0), false);
                            pMeta.setDisplayName(ChatColor.GREEN + "Potion of Bad Luck");
                            potItem.setItemMeta(pMeta);
    
     
    Last edited: May 15, 2016
  16. Offline

    I Al Istannen

    @Mr. Sandwich
    This worked for me:
    Code:java
    1. ItemStack potion = new ItemStack(Material.POTION);
    2. PotionMeta meta2 = (PotionMeta) potion.getItemMeta();
    3. meta2.addCustomEffect(new PotionEffect(PotionEffectType.UNLUCK, 20*10, 2), true);
    4. potion.setItemMeta(meta2);

    Yes, this is code, and yes, maybe it can be considered spoonfeeding, but it differs just in one bold thing, so hey.

    EDIT: Didn't see your edit :p
     
  17. Offline

    Mr. Sandwich

    Lol it's fine and your version of this code works too so maybe it will help someone else by the way can a moderator lock this thread?
     
  18. Offline

    timtower Administrator Administrator Moderator

Thread Status:
Not open for further replies.

Share This Page