Skip to content

Commit

Permalink
Add brewing step information for modded potions
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Sep 27, 2016
1 parent 1939894 commit e1e4440
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 6 deletions.
Expand Up @@ -4,11 +4,14 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.google.common.collect.ImmutableList;
import mezz.jei.Internal;
import mezz.jei.api.ingredients.IIngredientRegistry;
import mezz.jei.config.Config;
import mezz.jei.util.Java6Helper;
Expand All @@ -27,8 +30,12 @@

public class BrewingRecipeMaker {
private static final Set<Class> unhandledRecipeClasses = new HashSet<Class>();
private static final Map<String, Integer> brewingSteps = new HashMap<String, Integer>();

public static List<BrewingRecipeWrapper> getBrewingRecipes(IIngredientRegistry ingredientRegistry) {
unhandledRecipeClasses.clear();
brewingSteps.clear();

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

addVanillaBrewingRecipes(ingredientRegistry, recipes);
Expand Down Expand Up @@ -93,23 +100,67 @@ private static List<ItemStack> getNewPotions(final int brewingStep, List<ItemSta
if (!recipes.contains(recipe)) {
recipes.add(recipe);
newPotions.add(potionOutput);
String potionUid = Internal.getStackHelper().getUniqueIdentifierForStack(potionOutput);
brewingSteps.put(potionUid, brewingStep);
}
}
}
return newPotions;
}

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

while (unknownSteps.size() > 0) {
brewingRecipes = unknownSteps;
unknownSteps = addModdedBrewingRecipes(brewingRecipes, recipes);
if (unknownSteps.size() == brewingRecipes.size()) {
return;
}
}
}

private static Collection<IBrewingRecipe> addModdedBrewingRecipes(Collection<IBrewingRecipe> brewingRecipes, Collection<BrewingRecipeWrapper> recipes) {
Collection<IBrewingRecipe> unknownSteps = new ArrayList<IBrewingRecipe>();

for (IBrewingRecipe iBrewingRecipe : brewingRecipes) {
if (iBrewingRecipe instanceof BrewingRecipe) {
BrewingRecipe brewingRecipe = (BrewingRecipe) iBrewingRecipe;
BrewingRecipeWrapper recipe = new BrewingRecipeWrapper(brewingRecipe.getIngredient(), brewingRecipe.getInput(), brewingRecipe.getOutput(), 0);
recipes.add(recipe);

ItemStack input = brewingRecipe.getInput();
ItemStack output = brewingRecipe.getOutput();
String potionInputUid = Internal.getStackHelper().getUniqueIdentifierForStack(input);
String potionOutputUid = Internal.getStackHelper().getUniqueIdentifierForStack(output);

Integer steps = brewingSteps.get(potionInputUid);
if (steps == null) {
unknownSteps.add(brewingRecipe);
} else {
int outputBrewingStep = steps + 1;
brewingSteps.put(potionOutputUid, outputBrewingStep);

BrewingRecipeWrapper recipe = new BrewingRecipeWrapper(brewingRecipe.getIngredient(), input, output, outputBrewingStep);
recipes.add(recipe);
}
} else if (iBrewingRecipe instanceof BrewingOreRecipe) {
BrewingOreRecipe brewingRecipe = (BrewingOreRecipe) iBrewingRecipe;
BrewingRecipeWrapper recipe = new BrewingRecipeWrapper(brewingRecipe.getIngredient(), brewingRecipe.getInput(), brewingRecipe.getOutput(), 0);
recipes.add(recipe);

ItemStack input = brewingRecipe.getInput();
ItemStack output = brewingRecipe.getOutput();
String potionInputUid = Internal.getStackHelper().getUniqueIdentifierForStack(input);
String potionOutputUid = Internal.getStackHelper().getUniqueIdentifierForStack(output);

Integer steps = brewingSteps.get(potionInputUid);
if (steps == null) {
unknownSteps.add(brewingRecipe);
} else {
int outputBrewingStep = steps + 1;
brewingSteps.put(potionOutputUid, outputBrewingStep);

BrewingRecipeWrapper recipe = new BrewingRecipeWrapper(brewingRecipe.getIngredient(), input, output, outputBrewingStep);
recipes.add(recipe);
}
} else if (!(iBrewingRecipe instanceof VanillaBrewingRecipe)) {
Class recipeClass = iBrewingRecipe.getClass();
if (!unhandledRecipeClasses.contains(recipeClass)) {
Expand All @@ -120,5 +171,7 @@ private static void addModdedBrewingRecipes(Collection<BrewingRecipeWrapper> rec
}
}
}

return unknownSteps;
}
}
Expand Up @@ -2,8 +2,11 @@

import javax.annotation.Nullable;

import java.util.List;

import mezz.jei.api.ISubtypeRegistry;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.potion.PotionType;
import net.minecraft.potion.PotionUtils;

Expand All @@ -21,6 +24,13 @@ public String getSubtypeInfo(ItemStack itemStack) {
return null;
}
PotionType potionType = PotionUtils.getPotionFromItem(itemStack);
return potionType.getNamePrefixed("");
String potionTypeString = potionType.getNamePrefixed("");
StringBuilder stringBuilder = new StringBuilder(potionTypeString);
List<PotionEffect> effects = PotionUtils.getEffectsFromStack(itemStack);
for (PotionEffect effect : effects) {
stringBuilder.append(";").append(effect);
}

return stringBuilder.toString();
}
}

0 comments on commit e1e4440

Please sign in to comment.