MixinBrewingRecipeRegistry.java 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Roughly Enough Items by Danielshe.
  3. * Licensed under the MIT License.
  4. */
  5. package me.shedaniel.rei.mixin;
  6. import com.google.common.collect.Lists;
  7. import me.shedaniel.rei.plugin.DefaultPlugin;
  8. import me.shedaniel.rei.plugin.brewing.BrewingRecipe;
  9. import me.shedaniel.rei.plugin.brewing.DefaultBrewingDisplay;
  10. import net.minecraft.item.Item;
  11. import net.minecraft.item.ItemConvertible;
  12. import net.minecraft.item.ItemStack;
  13. import net.minecraft.item.PotionItem;
  14. import net.minecraft.potion.Potion;
  15. import net.minecraft.potion.PotionUtil;
  16. import net.minecraft.recipe.BrewingRecipeRegistry;
  17. import net.minecraft.recipe.Ingredient;
  18. import org.spongepowered.asm.mixin.Mixin;
  19. import org.spongepowered.asm.mixin.Unique;
  20. import org.spongepowered.asm.mixin.injection.At;
  21. import org.spongepowered.asm.mixin.injection.Inject;
  22. import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
  23. import java.util.List;
  24. @Mixin(BrewingRecipeRegistry.class)
  25. public class MixinBrewingRecipeRegistry {
  26. @Unique private static final List<BrewingRecipe> SELF_ITEM_RECIPES = Lists.newArrayList();
  27. @Unique private static final List<Potion> REGISTERED_POTION_TYPES = Lists.newArrayList();
  28. @Unique private static final List<Ingredient> SELF_POTION_TYPES = Lists.newArrayList();
  29. @Inject(method = "registerPotionType", at = @At("RETURN"))
  30. private static void method_8080(Item item_1, CallbackInfo ci) {
  31. if (item_1 instanceof PotionItem)
  32. SELF_POTION_TYPES.add(Ingredient.ofItems(new ItemConvertible[]{item_1}));
  33. }
  34. @Inject(method = "registerItemRecipe", at = @At("RETURN"))
  35. private static void method_8071(Item item_1, Item item_2, Item item_3, CallbackInfo ci) {
  36. if (item_1 instanceof PotionItem && item_3 instanceof PotionItem)
  37. SELF_ITEM_RECIPES.add(new BrewingRecipe(item_1, Ingredient.ofItems(new ItemConvertible[]{item_2}), item_3));
  38. }
  39. @Inject(method = "registerPotionRecipe", at = @At("RETURN"))
  40. private static void registerPotionRecipe(Potion potion_1, Item item_1, Potion potion_2, CallbackInfo ci) {
  41. if (!REGISTERED_POTION_TYPES.contains(potion_1))
  42. rei_registerPotionType(potion_1);
  43. if (!REGISTERED_POTION_TYPES.contains(potion_2))
  44. rei_registerPotionType(potion_2);
  45. for (Ingredient type : SELF_POTION_TYPES) {
  46. for (ItemStack stack : type.getMatchingStacksClient()) {
  47. DefaultPlugin.registerBrewingDisplay(new DefaultBrewingDisplay(PotionUtil.setPotion(stack.copy(), potion_1), Ingredient.ofItems(new ItemConvertible[]{item_1}), PotionUtil.setPotion(stack.copy(), potion_2)));
  48. }
  49. }
  50. }
  51. private static void rei_registerPotionType(Potion potion) {
  52. REGISTERED_POTION_TYPES.add(potion);
  53. for (BrewingRecipe recipe : SELF_ITEM_RECIPES) {
  54. DefaultPlugin.registerBrewingDisplay(new DefaultBrewingDisplay(PotionUtil.setPotion(recipe.input.getStackForRender(), potion), recipe.ingredient, PotionUtil.setPotion(recipe.output.getStackForRender(), potion)));
  55. }
  56. }
  57. }