REIBrewingRecipeRegistry.java 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package net.minecraft.recipe;
  2. import com.google.common.collect.Lists;
  3. import me.shedaniel.rei.api.RecipeHelper;
  4. import me.shedaniel.rei.plugin.BrewingRecipe;
  5. import me.shedaniel.rei.plugin.DefaultBrewingDisplay;
  6. import me.shedaniel.rei.plugin.DefaultPlugin;
  7. import net.minecraft.item.Item;
  8. import net.minecraft.potion.Potion;
  9. import net.minecraft.potion.PotionUtil;
  10. import java.util.Arrays;
  11. import java.util.List;
  12. public class REIBrewingRecipeRegistry {
  13. public static void registerDisplays(RecipeHelper recipeHelper) {
  14. List<Potion> registeredPotionTypes = Lists.newArrayList();
  15. List<BrewingRecipe> potionItemConversions = Lists.newArrayList();
  16. List<Ingredient> potionItems = REIPotionRecipeUtils.getPotionTypes();
  17. REIPotionRecipeUtils.getItemRecipes().forEach(o -> {
  18. try {
  19. Item input = (Item) REIPotionRecipeUtils.getInputFromRecipe(o);
  20. Item output = (Item) REIPotionRecipeUtils.getOutputFromRecipe(o);
  21. Ingredient reagent = REIPotionRecipeUtils.getIngredientFromRecipe(o);
  22. potionItemConversions.add(new BrewingRecipe(input, reagent, output));
  23. } catch (Throwable throwable) {
  24. throwable.printStackTrace();
  25. }
  26. });
  27. REIPotionRecipeUtils.getPotionRecipes().forEach(o -> {
  28. try {
  29. Potion input = (Potion) REIPotionRecipeUtils.getInputFromRecipe(o);
  30. Potion output = (Potion) REIPotionRecipeUtils.getOutputFromRecipe(o);
  31. Ingredient ingredient = REIPotionRecipeUtils.getIngredientFromRecipe(o);
  32. if (!registeredPotionTypes.contains(input))
  33. registerPotionType(recipeHelper, registeredPotionTypes, potionItemConversions, input);
  34. if (!registeredPotionTypes.contains(output))
  35. registerPotionType(recipeHelper, registeredPotionTypes, potionItemConversions, output);
  36. potionItems.stream().map(Ingredient::getStackArray).forEach(itemStacks -> Arrays.stream(itemStacks).forEach(stack -> {
  37. recipeHelper.registerDisplay(DefaultPlugin.BREWING, new DefaultBrewingDisplay(PotionUtil.setPotion(stack.copy(), input), ingredient, PotionUtil.setPotion(stack.copy(), output)));
  38. }));
  39. } catch (Throwable throwable) {
  40. throwable.printStackTrace();
  41. }
  42. });
  43. }
  44. private static void registerPotionType(RecipeHelper recipeHelper, List<Potion> list, List<BrewingRecipe> potionItemConversions, Potion potion) {
  45. list.add(potion);
  46. potionItemConversions.forEach(recipe -> {
  47. recipeHelper.registerDisplay(DefaultPlugin.BREWING, new DefaultBrewingDisplay(PotionUtil.setPotion(recipe.input.getDefaultStack(), potion), recipe.ingredient, PotionUtil.setPotion(recipe.output.getDefaultStack(), potion)));
  48. });
  49. }
  50. }