use of net.minecraft.world.item.crafting.CustomRecipe in project Polymorph by TheIllusiveC4.
the class PolymorphCommands method scanRecipes.
private static <C extends Container, T extends Recipe<C>> int scanRecipes(RecipeType<T> pType, List<String> pOutput, RecipeManager pRecipeManager, Function<Recipe<?>, RecipeWrapper> pFactory) {
Collection<RecipeWrapper> recipes = pRecipeManager.getAllRecipesFor(pType).stream().map(pFactory).collect(Collectors.toList());
List<Set<ResourceLocation>> conflicts = new ArrayList<>();
Set<ResourceLocation> skipped = new TreeSet<>();
Set<ResourceLocation> processed = new HashSet<>();
for (RecipeWrapper recipe : recipes) {
ResourceLocation id = recipe.getId();
if (processed.contains(id)) {
continue;
}
processed.add(id);
if (recipe.getRecipe() instanceof CustomRecipe) {
skipped.add(id);
continue;
}
Set<ResourceLocation> currentGroup = new TreeSet<>();
for (RecipeWrapper otherRecipe : recipes) {
if (processed.contains(otherRecipe.getId())) {
continue;
}
if (otherRecipe.conflicts(recipe)) {
currentGroup.add(id);
currentGroup.add(otherRecipe.getId());
processed.add(otherRecipe.getId());
}
}
if (!currentGroup.isEmpty()) {
conflicts.add(currentGroup);
}
}
pOutput.add("===================================================================");
pOutput.add(Registry.RECIPE_TYPE.getKey(pType) + " recipe conflicts (" + conflicts.size() + ")");
pOutput.add("===================================================================");
pOutput.add("");
int count = 1;
for (Set<ResourceLocation> conflict : conflicts) {
StringJoiner joiner = new StringJoiner(", ");
conflict.stream().map(ResourceLocation::toString).forEach(joiner::add);
pOutput.add(count + ": " + joiner);
pOutput.add("");
count++;
}
if (skipped.size() > 0) {
pOutput.add("Skipped special recipes: ");
for (ResourceLocation resourceLocation : skipped) {
pOutput.add(resourceLocation.toString());
}
pOutput.add("");
}
return conflicts.size();
}
Aggregations