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 multiple matching Stacks #27

Merged
merged 1 commit into from
Oct 27, 2024
Merged

Conversation

forester302
Copy link
Contributor

@forester302 forester302 commented Oct 15, 2024

Make RecipeDataGenerator for 1.20.5 add multiple recipes to an item when there are multiple matching stacks for a slot

Minecraft uses a tag system to do this as if there are 9 slots with 5 options each that becomes 1953125 recipes

I have compromised on this and in cases where there are options i have only done 1 recipe for each option
(for example crafting tables, it does 10 recipes - 1 for each wood type - instead of the 10000 possible ways to craft a crafting table)

this should be enough to fix the issue in PrismarineJS/minecraft-data#917, but not every way you can make an item is represented, and wont be unless a tag system can be implemented into this also.

#23

Copy link
Contributor

@SuperGamerTron SuperGamerTron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only accounts for multiple stacks in shaped recipes. We can use this method for shapeless recipes:

private void generateShapelessRecipe(DynamicRegistryManager registryManager, JsonObject finalObj, ShapelessRecipe sl, int n) {
    boolean hasIncremented = false;
    List<Ingredient> ingredients = sl.getIngredients();
    List<Integer> ingr = new ArrayList<>();

    for (Ingredient ingredient : ingredients) {
        var matching = ingredient.getMatchingStacks();

        if (matching.length > n) {
            ingr.add(getRawIdFor(matching[n].getItem()));
        } else {
            ingr.add(getRawIdFor(matching[0].getItem()));
        }

        if (matching.length - 1 > n && !hasIncremented) {
            generateShapelessRecipe(registryManager, finalObj, sl, n + 1);
            hasIncremented = true;
        }
    }

    JsonArray ingredientsArray = new JsonArray();
    for (Integer id : ingr) {
        ingredientsArray.add(id);
    }

    JsonObject finalRecipe = new JsonObject();
    finalRecipe.add("ingredients", ingredientsArray);

    JsonObject resultObject = new JsonObject();
    resultObject.addProperty("id", getRawIdFor(sl.getResult(registryManager).getItem()));
    resultObject.addProperty("count", sl.getResult(registryManager).getCount());
    finalRecipe.add("result", resultObject);

    String id = ((Integer) getRawIdFor(sl.getResult(registryManager).getItem())).toString();

    if (!finalObj.has(id)) {
        finalObj.add(id, new JsonArray());
    }
    finalObj.get(id).getAsJsonArray().add(finalRecipe);
}

Then in generateDataJson():

...
} else if (recipe instanceof ShapelessRecipe sl) {
    generateShapelessRecipe(registryManager, finalObj, sl, 0);
}
...

@rom1504 rom1504 merged commit f8368f9 into PrismarineJS:main Oct 27, 2024
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants