Skip to content

Commit

Permalink
Fix #1518 Add support for Crafttweaker removing brewing recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Apr 7, 2019
1 parent 4cc026a commit eb473f4
Showing 1 changed file with 12 additions and 13 deletions.
Expand Up @@ -16,7 +16,6 @@
import net.minecraftforge.common.brewing.VanillaBrewingRecipe;
import net.minecraft.init.PotionTypes;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionHelper;
import net.minecraft.potion.PotionType;
import net.minecraft.potion.PotionUtils;
import net.minecraft.util.NonNullList;
Expand Down Expand Up @@ -47,35 +46,40 @@ private List<BrewingRecipeWrapper> getBrewingRecipes() {

Set<BrewingRecipeWrapper> recipes = new HashSet<>();

addVanillaBrewingRecipes(recipes);
addModdedBrewingRecipes(recipes);
Collection<IBrewingRecipe> brewingRecipes = BrewingRecipeRegistry.getRecipes();
brewingRecipes.stream()
.filter(r -> r instanceof VanillaBrewingRecipe)
.map(r -> (VanillaBrewingRecipe) r)
.findFirst()
.ifPresent(vanillaBrewingRecipe -> addVanillaBrewingRecipes(recipes, vanillaBrewingRecipe));
addModdedBrewingRecipes(brewingRecipes, recipes);

List<BrewingRecipeWrapper> recipeList = new ArrayList<>(recipes);
recipeList.sort(Comparator.comparingInt(BrewingRecipeWrapper::getBrewingSteps));

return recipeList;
}

private void addVanillaBrewingRecipes(Collection<BrewingRecipeWrapper> recipes) {
private void addVanillaBrewingRecipes(Collection<BrewingRecipeWrapper> recipes, VanillaBrewingRecipe vanillaBrewingRecipe) {
List<ItemStack> potionIngredients = ingredientRegistry.getPotionIngredients();
List<ItemStack> knownPotions = new ArrayList<>();

knownPotions.add(BrewingRecipeUtil.WATER_BOTTLE);

boolean foundNewPotions;
do {
List<ItemStack> newPotions = getNewPotions(knownPotions, potionIngredients, recipes);
List<ItemStack> newPotions = getNewPotions(knownPotions, potionIngredients, recipes, vanillaBrewingRecipe);
foundNewPotions = !newPotions.isEmpty();
knownPotions.addAll(newPotions);
} while (foundNewPotions);
}

private List<ItemStack> getNewPotions(List<ItemStack> knownPotions, List<ItemStack> potionIngredients, Collection<BrewingRecipeWrapper> recipes) {
private List<ItemStack> getNewPotions(List<ItemStack> knownPotions, List<ItemStack> potionIngredients, Collection<BrewingRecipeWrapper> recipes, VanillaBrewingRecipe vanillaBrewingRecipe) {
List<ItemStack> newPotions = new ArrayList<>();
for (ItemStack potionInput : knownPotions) {
for (ItemStack potionIngredient : potionIngredients) {
ItemStack potionOutput = PotionHelper.doReaction(potionIngredient, potionInput.copy());
if (potionOutput.equals(potionInput)) {
ItemStack potionOutput = vanillaBrewingRecipe.getOutput(potionInput.copy(), potionIngredient);
if (potionOutput.isEmpty()) {
continue;
}

Expand Down Expand Up @@ -107,11 +111,6 @@ private List<ItemStack> getNewPotions(List<ItemStack> knownPotions, List<ItemSta
return newPotions;
}

private void addModdedBrewingRecipes(Collection<BrewingRecipeWrapper> recipes) {
Collection<IBrewingRecipe> brewingRecipes = BrewingRecipeRegistry.getRecipes();
addModdedBrewingRecipes(brewingRecipes, recipes);
}

private void addModdedBrewingRecipes(Collection<IBrewingRecipe> brewingRecipes, Collection<BrewingRecipeWrapper> recipes) {
for (IBrewingRecipe iBrewingRecipe : brewingRecipes) {
if (iBrewingRecipe instanceof AbstractBrewingRecipe) {
Expand Down

0 comments on commit eb473f4

Please sign in to comment.