aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/net
diff options
context:
space:
mode:
authorUnknown <shekwancheung0528@gmail.com>2019-03-14 19:22:18 +0800
committerUnknown <shekwancheung0528@gmail.com>2019-03-14 19:22:18 +0800
commitd0f4d495957d2454bdf43a64d31a21f06849e677 (patch)
treeb1ae87962790074f91e1ade3be8e7eb331a45b30 /src/main/java/net
parent72144a3911b69f25a2ab0e45acdd5d9edabeda80 (diff)
downloadRoughlyEnoughItems-d0f4d495957d2454bdf43a64d31a21f06849e677.tar.gz
RoughlyEnoughItems-d0f4d495957d2454bdf43a64d31a21f06849e677.tar.bz2
RoughlyEnoughItems-d0f4d495957d2454bdf43a64d31a21f06849e677.zip
Using Cloth as a hard dependency now
Diffstat (limited to 'src/main/java/net')
-rw-r--r--src/main/java/net/minecraft/recipe/REIBrewingRecipeRegistry.java56
-rw-r--r--src/main/java/net/minecraft/recipe/REIPotionRecipeUtils.java36
2 files changed, 92 insertions, 0 deletions
diff --git a/src/main/java/net/minecraft/recipe/REIBrewingRecipeRegistry.java b/src/main/java/net/minecraft/recipe/REIBrewingRecipeRegistry.java
new file mode 100644
index 000000000..0622afa6e
--- /dev/null
+++ b/src/main/java/net/minecraft/recipe/REIBrewingRecipeRegistry.java
@@ -0,0 +1,56 @@
+package net.minecraft.recipe;
+
+import com.google.common.collect.Lists;
+import me.shedaniel.rei.api.RecipeHelper;
+import me.shedaniel.rei.plugin.BrewingRecipe;
+import me.shedaniel.rei.plugin.DefaultBrewingDisplay;
+import me.shedaniel.rei.plugin.DefaultPlugin;
+import net.minecraft.item.Item;
+import net.minecraft.potion.Potion;
+import net.minecraft.potion.PotionUtil;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class REIBrewingRecipeRegistry {
+
+ public static void registerDisplays(RecipeHelper recipeHelper) {
+ List<Potion> registeredPotionTypes = Lists.newArrayList();
+ List<BrewingRecipe> potionItemConversions = Lists.newArrayList();
+ List<Ingredient> potionItems = REIPotionRecipeUtils.getPotionTypes();
+ REIPotionRecipeUtils.getItemRecipes().forEach(o -> {
+ try {
+ Item input = (Item) REIPotionRecipeUtils.getInputFromRecipe(o);
+ Item output = (Item) REIPotionRecipeUtils.getOutputFromRecipe(o);
+ Ingredient reagent = REIPotionRecipeUtils.getIngredientFromRecipe(o);
+ potionItemConversions.add(new BrewingRecipe(input, reagent, output));
+ } catch (Throwable throwable) {
+ throwable.printStackTrace();
+ }
+ });
+ REIPotionRecipeUtils.getPotionRecipes().forEach(o -> {
+ try {
+ Potion input = (Potion) REIPotionRecipeUtils.getInputFromRecipe(o);
+ Potion output = (Potion) REIPotionRecipeUtils.getOutputFromRecipe(o);
+ Ingredient ingredient = REIPotionRecipeUtils.getIngredientFromRecipe(o);
+ if (!registeredPotionTypes.contains(input))
+ registerPotionType(recipeHelper, registeredPotionTypes, potionItemConversions, input);
+ if (!registeredPotionTypes.contains(output))
+ registerPotionType(recipeHelper, registeredPotionTypes, potionItemConversions, output);
+ potionItems.stream().map(Ingredient::getStackArray).forEach(itemStacks -> Arrays.stream(itemStacks).forEach(stack -> {
+ recipeHelper.registerDisplay(DefaultPlugin.BREWING, new DefaultBrewingDisplay(PotionUtil.setPotion(stack.copy(), input), ingredient, PotionUtil.setPotion(stack.copy(), output)));
+ }));
+ } catch (Throwable throwable) {
+ throwable.printStackTrace();
+ }
+ });
+ }
+
+ private static void registerPotionType(RecipeHelper recipeHelper, List<Potion> list, List<BrewingRecipe> potionItemConversions, Potion potion) {
+ list.add(potion);
+ potionItemConversions.forEach(recipe -> {
+ recipeHelper.registerDisplay(DefaultPlugin.BREWING, new DefaultBrewingDisplay(PotionUtil.setPotion(recipe.input.getDefaultStack(), potion), recipe.ingredient, PotionUtil.setPotion(recipe.output.getDefaultStack(), potion)));
+ });
+ }
+
+}
diff --git a/src/main/java/net/minecraft/recipe/REIPotionRecipeUtils.java b/src/main/java/net/minecraft/recipe/REIPotionRecipeUtils.java
new file mode 100644
index 000000000..cc3bc6508
--- /dev/null
+++ b/src/main/java/net/minecraft/recipe/REIPotionRecipeUtils.java
@@ -0,0 +1,36 @@
+package net.minecraft.recipe;
+
+import com.google.common.collect.Lists;
+import me.shedaniel.cloth.api.ReflectionUtils;
+import net.minecraft.item.Item;
+import net.minecraft.potion.Potion;
+
+import java.util.List;
+
+public class REIPotionRecipeUtils {
+
+ public static Object getInputFromRecipe(BrewingRecipeRegistry.Recipe o) throws Throwable {
+ return ReflectionUtils.getField(o, Object.class, 0).orElseThrow(ReflectionUtils.ReflectionException::new);
+ }
+
+ public static Object getOutputFromRecipe(Object o) throws Throwable {
+ return ReflectionUtils.getField(o, Object.class, 2).orElseThrow(ReflectionUtils.ReflectionException::new);
+ }
+
+ public static Ingredient getIngredientFromRecipe(Object o) throws Throwable {
+ return ReflectionUtils.getField(o, Ingredient.class, 1).orElseThrow(ReflectionUtils.ReflectionException::new);
+ }
+
+ public static List<BrewingRecipeRegistry.Recipe<Item>> getItemRecipes() {
+ return ReflectionUtils.getStaticField(BrewingRecipeRegistry.class, List.class, 1).orElse(Lists.newArrayList());
+ }
+
+ public static List<BrewingRecipeRegistry.Recipe<Potion>> getPotionRecipes() {
+ return ReflectionUtils.getStaticField(BrewingRecipeRegistry.class, List.class, 0).orElse(Lists.newArrayList());
+ }
+
+ public static List<Ingredient> getPotionTypes() {
+ return ReflectionUtils.getStaticField(BrewingRecipeRegistry.class, List.class, 2).orElse(Lists.newArrayList());
+ }
+
+}