Can potions be used in recipes?

Discussion in 'Plugin Development' started by Ne0nx3r0, Jan 16, 2013.

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

    Ne0nx3r0

    So I've been playing around with using potions in recipes, and I can't seem to make it work.

    Is there something that prohibits using a specific potion in a recipe?

    Here's the itemstack I was trying to specify:
    Code:
    new ItemStack(Material.POTION,1,(short) 8196)
    The recipe works fine without it, but when I add it I can't seem to get it to show up.

    I just want to rule out an API limitation or something similar.
     
  2. Offline

    fireblast709

    apparently potions given by commands and creative potions have a different damage value (this is what Ive learned from another thread)
     
  3. Offline

    Miner_Fil

    They Do? I didnt know
     
  4. Offline

    Ne0nx3r0

    I just cant' seem to sort this out... Does anyone have a working recipe I could use to understand how potions can be used in recipes?
     
  5. Offline

    Ne0nx3r0

    Still haven't figured this out... I'm starting to think it's simply not supported by the API.
     
  6. Offline

    Cjreek

    I guess I would just add Material.POTION to the recipe and check any other properties of the potion in PrepareItemCraftEvent. There you can set the Result to AIR (invalid recipe) or set the result to anything you want.
     
  7. Offline

    fireblast709

    Ne0nx3r0 Where do you get your potions from? Creative or /give | brewing them yourself?
     
  8. Offline

    travja

    I would make the item stack, get the itemmeta and then check what it's name or lore is in comparison to the item you want.
     
  9. Offline

    fireblast709

    He wants to use Potions as ingredients
     
  10. Offline

    travja

    Exactly. In craftitemprepareevent check it's name or lore. Sorry i wasn't quite clear
     
  11. Offline

    Cjreek

    It might be better to directly look at the potion effect of the Potion.
     
  12. Offline

    Ne0nx3r0

    Well, I'd like to allow any potions to work, and any combination of creative/generated/brewed potions to work.

    That said, I can't even seem to make any specific potion method to work using something like:
    Code:
    recipe.setIngredient("P",Material.POTION,8196);//based on "normal" value
    Code:
    recipe.setIngredient("P",Material.POTION,4);//based on value given from getData
    Code:
    recipe.setIngredient("P",Material.POTION,42);//based on some random value from a thread
    Code:
    recipe.setIngredient("P",Material.POTION,-108);//based on value given from getData
    I was really hoping I could avoid essentially handling custom recipes myself after the default recipe system has already done it's job, but it seems there's not really another option.
     
  13. Offline

    travja

    If you want any potion make the damage value 0 I think
     
  14. Offline

    Cjreek

    As you (travja) said this I remembered that -1 actually is the value for "data value doesn't matter".
     
  15. Offline

    fireblast709

    The problem is, each potion exists twice in game. One value for brewed potions, and one for creative potions, differing in their bit strings, thus differing in datavalue.

    If you want to make a recipe for 1 specific potion, add it for both the creative and survival potion
     
  16. Offline

    Ne0nx3r0

    Yeah, but then the issue is that all the potions must come from the same source, or else you would need to create an exponentially grown number of recipes for each combination times the number of times a potion is used in a given recipe.

    In which case, I think it unfortunately is easier to just add a blank potion recipe then add an additional custom recipe filter... :/

    Is there a way to accurately identify a potion type regardless of where it came from?
     
  17. Offline

    Cjreek

    I suggested using -1 as data/durability value when adding the ingredient...
     
  18. Offline

    Ne0nx3r0

    Right, but I still want to catch a specific potion, so how would I for example identify a poison potion? (Assuming this excludes poison II, splash, etc.)
     
  19. Offline

    Cjreek

    In the PrepareItemCraftEvent get the potion, cast it to "Potion" and check what potion it actually is.
     
  20. Offline

    Ne0nx3r0

    Hrm. That could work, assuming the itemstack in the recipe will also end up returning the same value.

    I'll give it a shot, thanks!
     
  21. Offline

    Cjreek

    But don't check the items contained in event.getRecipe(). You have to get them directly from the event.getInventory().
     
  22. Offline

    Ne0nx3r0

    Cjreek Hrm. That's a problem, because I have a lot of recipes that could change in between resets.

    I guess I'll have to track them separately...

    Well, it's a bit funky, but it works.... You add the potion using -1 as the damage, then do your own checks against it.

    Code:
                    ItemStack[] storedComponents = this.componentRecipes.get(result);
                    //Admit it, people just like using the term "matrix"
                    ItemStack[] isMatrix = e.getInventory().getMatrix();
     
                    for(int i=0;i<storedComponents.length;i++)
                    {
                        if(storedComponents[i] != null)
                        {
                            if(storedComponents[i].getType() == Material.POTION)
                            {     
                                //Because water bottles don't have levels! -.-
                                byte componentsData = storedComponents[i].getData().getData();
                                byte matrixData = isMatrix[i].getData().getData();
     
                                if(componentsData == 0 && matrixData == 0)
                                {
                                    continue;
                                }
     
                                if(componentsData == 0 || matrixData == 0)
                                {
                                    return new ItemStack(Material.AIR);
                                }
     
                                if(!Potion.fromItemStack(storedComponents[i]).equals(Potion.fromItemStack(isMatrix[i])))
                                {
                                    return new ItemStack(Material.AIR);
                                }
                            }
                            else if(!storedComponents[i].isSimilar(isMatrix[i]))
                            {
                                return new ItemStack(Material.AIR);
                            }
                        }
                    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
Thread Status:
Not open for further replies.

Share This Page