baileyholl / Ars-Nouveau

Repository for the Ars Nouveau minecraft mod. https://www.curseforge.com/minecraft/mc-mods/ars-nouveau
https://www.curseforge.com/minecraft/mc-mods/ars-nouveau
GNU Lesser General Public License v3.0
150 stars 92 forks source link

No way to tell Wixie's what Ingredients to use for potion crafting. #261

Closed tweakbsd closed 3 years ago

tweakbsd commented 3 years ago

I just found some unwanted Atum mod interactions. Atum adds brewing ingredients for all kinds of vanilla potions. e.g. you can brew Awkward Potion using "Anput's Finger Spores" which results that Wixie's can't use Nether Wart for autocrafting potions anymore. There's other potions affected as well.

I think the Dominion Wand would be a good option to "cycle" through which recipe / ingredient you want to use. Shift right clicking on the cauldron until the Wixie uses the recipe you want it to. Or as a fast fix, always prefer Vanilla over modded recipes for now which is probably preferable by most players.

I will also have a look at the code and see if can help with it but my time is super limited currently. :-(

tweakbsd commented 3 years ago

Here is a quick non-optimised implementation for WixieCauldron.java - WixieCauldronTile.setRecipes() method that checks the ingredients of potion recipes and prefers the ones using only vanilla items.

Code (Hopefully GitHub formats it somewhat readable) ` public void setRecipes(PlayerEntity playerEntity, ItemStack stack){ ItemStack craftingItem = stack; RecipeWrapper recipes = new RecipeWrapper(); if(craftingItem.getItem() == Items.POTION){

        RecipeWrapper recipesVanilla = new RecipeWrapper();
        RecipeWrapper recipesNotVanilla = new RecipeWrapper();
        boolean recipeNotVanillaFound = false;
        boolean recipeVanillaFound = false;

        for(BrewingRecipe r : ArsNouveauAPI.getInstance().getAllPotionRecipes()) {

            if(ItemStack.matches(stack, r.getOutput())) {
                isCraftingPotion = true;
                List<Ingredient> list = new ArrayList<>();

                list.add(new PotionIngredient(r.getInput().getItems()[0]));
                list.add(r.getIngredient());

                boolean ingredientsContainNonVanillaItems = false;
                for (ItemStack item: r.getIngredient().getItems()) {

                    ResourceLocation itemRegistryName = item.getItem().getRegistryName();
                    try {
                        if(!itemRegistryName.getNamespace().equals("minecraft")) {
                            ingredientsContainNonVanillaItems = true;
                            break;
                        }
                    } catch (NullPointerException e) {
                        // NOTE: Not much we can do if getNamespace() throws...
                    }
                }

                if(ingredientsContainNonVanillaItems) {
                    // NOTE: Alredy have a non vanilla recipe
                    if(recipeNotVanillaFound) {
                        continue;
                    }

                    recipesNotVanilla.addRecipe(list, r.getOutput(), null);
                    recipeNotVanillaFound = true;
                } else {
                    recipesVanilla.addRecipe(list, r.getOutput(), null);
                    recipeVanillaFound = true;
                    break;  // NOTE: Got a vanilla recipe. We're done.
                }

                // NOTE: Old code, just use first found recipe and done
                // recipes.addRecipe(list, r.getOutput(), null);
                // break
            }
        }

        if(recipeVanillaFound) {
            // NOTE: Always prefer Vanilla recipe
            recipes = recipesVanilla;
        } else {

            // NOTE: No vanilla recipe available, use what we got
            if(recipeNotVanillaFound) {
                recipes = recipesNotVanilla;
            }
        }

    }else {
        for (IRecipe r : level.getServer().getRecipeManager().getRecipes()) {
            if (r.getResultItem().getItem() != craftingItem.getItem())
                continue;

            if (r instanceof ShapedRecipe) {
                ShapedHelper helper = new ShapedHelper((ShapedRecipe) r);
                for (List<Ingredient> iList : helper.getPossibleRecipes()) {
                    recipes.addRecipe(iList, r.getResultItem(), r);
                }
            }

            if (r instanceof ShapelessRecipe)
                recipes.addRecipe(r.getIngredients(), r.getResultItem(), r);

        }
        if(!recipes.recipes.isEmpty())
            isCraftingPotion = false;
    }
    if(!recipes.recipes.isEmpty()) {
        this.recipeWrapper = recipes;
        this.craftingItem = stack.copy();
    }

    if((recipes.recipes.isEmpty() || recipeWrapper == null || recipeWrapper.recipes.isEmpty()) && playerEntity != null){
        PortUtil.sendMessage(playerEntity, new TranslationTextComponent("ars_nouveau.wixie.no_recipe"));
    }else if(playerEntity != null){
        PortUtil.sendMessage(playerEntity, new TranslationTextComponent("ars_nouveau.wixie.recipe_set"));
    }
}

`

If wanted I can make PR for it later this evening. But it's probably better to have a way to cycle through recipes anyway.

baileyholl commented 3 years ago

A way to cycle recipes would be fantastic, this is needed for normal crafting too. Looks like I forgot to add the checks for the actual inventory contents for potions, as that is how wixies determines what regular item they can craft as well, based on all recipes.

I would welcome a PR for cycling :)

baileyholl commented 3 years ago

Latest release addresses the issue with Atum, I think recipe swapping is a much bigger project that should encompass normal recipes as well.

I think this would be a pretty large undertaking however, it would need to be saved in NBT, a mechanism to rotate through recipes, and a way to display them clearly.

tweakbsd commented 3 years ago

Sorry that I opened a issue for the 2nd time without checking out the latest version. I was on 1.15.1 and thought that's pretty new. But I'll definitely update first next time before posting here.

Implementing recipe cycling would probably end up not good if I was going for it 'cause I'm super bad at things that involve user interaction. I can write code, but not design UIs unfortunately.

baileyholl commented 3 years ago

Going to close this for now as the original problem has been solved for modded potions.