Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mixin to OreIngredient to access its name #204

Merged
merged 2 commits into from
Jul 23, 2024

Conversation

juraj-hrivnak
Copy link
Contributor

@juraj-hrivnak juraj-hrivnak commented Jul 18, 2024

When using crafting.streamRecipes() and iterating through the recipes, it is impossible to get the name of an already existing oredict ingredient to be able to use it.

This PR adds an OreIngredient.getOreDict() method so you can access it in Groovy.
Example usage:

crafting.streamRecipes().each { recipe ->
    String result = null

    recipe.ingredients.each { ingredient ->
        if (ingredient instanceof OreIngredient) {
            result = IngredientHelper.asGroovyCode(ingredient.oreDict, false)
        }
    }

    log.info(result)
}

@juraj-hrivnak juraj-hrivnak changed the title Add mixin to OreIngredient to access it's name Add mixin to OreIngredient to access its name Jul 18, 2024
@Wizzerinus
Copy link
Contributor

also useful for mod compats tbh. I've had an issue recently where I had to make a custom wrapper around a mod's recipe because OreIngredient doesn't retain the ore dict key.

with this code though, I think OreIngredient has multiple constructors, and only one of them properly keeps the oredict name..?

@WaitingIdly
Copy link
Collaborator

your example usage indicates it is using OreDictIngredient, which is added by Groovyscript.

OreIngredient has a single constructor which does not save the oredict
image

@juraj-hrivnak
Copy link
Contributor Author

My bad, the example should use the OreIngredient. I edited it.

Yes, the OreIngredient constructor does not save the oredict, but it saves the oredict name, which is sufficient to convert it to the Groovy’s OreDictIngredient.

@brachy84 brachy84 added the enhancement New feature or request label Jul 22, 2024
@brachy84 brachy84 merged commit 6067df5 into CleanroomMC:master Jul 23, 2024
@juraj-hrivnak juraj-hrivnak deleted the oreingredient-mixin branch July 24, 2024 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants