Solved Creating an inventory with a list of potions

Discussion in 'Plugin Development' started by JRL1004, Oct 28, 2015.

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

    JRL1004

    I am trying to fill a plugin request
    (Viewable here: http://bukkit.org/threads/magic.390532/)

    and I am having an issue with this part of the request:
    - potioncraft: left click to get a GUI of all potions that you can get.

    I understand how to create inventories and such as well as how to work with them for click event and all that. My issue is that I can't think of a way to like all of the potions that are in the default potions creative tab automatically and I really do not want to have to hard-code every item into the class.

    TL;DR > How do I add all 63 potions from the creative menu into a custom inventory without hardcoding them?
     
  2. Offline

    HenkDeKipGaming

    Well I would say you can't... You just have to put every single potion in the GUI...
    Maybe you can try making a method that generates all the item ID's of all the potions and puts them in the correct order, but that might even be more work than just putting all the potions in there...
    If there is an other way, sorry for posting this. But I think there isn't.
     
  3. Offline

    JRL1004

    I have this so far:

    Code:
        @SuppressWarnings("deprecation")
        private void updateInventory() {
            int newValue = toNextMod9(4 * (PotionType.values().length - 1));
            if (potionInventory != null) potionInventory.clear();
            potionInventory = Bukkit.createInventory(null, newValue, ChatColor.AQUA + "PotionCrafting");
            for (PotionType pt : PotionType.values()) {
                if (pt == PotionType.WATER) continue;
                for (int b = 0; b < 2; b++)
                    for (int i = 0; i < 2; i++) {
                        Potion potion = new Potion(pt, i + 1, b == 1, true);
                        potionInventory.addItem(potion.toItemStack(1));
                    }
            }
        }
    
        private int toNextMod9(int input) {
            while (input % 9 != 0)
                input++;
            return input;
        }
    
    Any ideas on how I could improve on this?

    EDIT: Here is what the previous code creates:
    [​IMG]
     
  4. Offline

    DoggyCode™

    That looks good? Why would you want to change it?
     
  5. Offline

    JRL1004

    @DoggyCode™ I was asking for improvisation ideas on the second part. I know it works but I don't not want to call it done if there is a way to improve the quality.

    I do like how you saw it looks good, though. Thanks :D
     
  6. Offline

    DoggyCode™

    Well, what I can say is that a chest can only contain 54 different ItemStacks, and you want
    different ItemStacks, meaning that your only solution would be making a Next button, creating a separate inventory once it's clicked, and you continue the adding from there.
     
  7. Offline

    HenkDeKipGaming

    I don't see anything that could be changed!
    Looks great! :)
     
Thread Status:
Not open for further replies.

Share This Page