瀏覽代碼

Using Cloth as a hard dependency now

Unknown 6 年之前
父節點
當前提交
62d0581fbc

+ 1 - 1
build.gradle

@@ -52,7 +52,7 @@ dependencies {
     modCompile "com.jamieswhiteshirt:developer-mode:${project.developermode_version}"
     modCompile "info.tehnut.pluginloader:plugin-loader:${project.pluginloader_version}"
     modCompile "net.fabricmc:fabric:${project.fabric_version}"
-    modCompile "cloth:Cloth:${cloth_version}"
+    modCompile "utils:Cloth:${cloth_version}"
 
     compile "blue.endless:jankson:${project.jankson_version}"
     contained "blue.endless:jankson:${project.jankson_version}"

+ 3 - 3
gradle.properties

@@ -1,9 +1,9 @@
-mod_version=2.4.0.63
+mod_version=2.4.1.64
 minecraft_version=19w09a
-yarn_version=19w09a.6
+yarn_version=19w09a.10
 fabric_version=0.2.3.108
 fabricloader_version=0.3.7.109
 pluginloader_version=1.14-1.0.6-8
 developermode_version=1.0.3
 jankson_version=1.1.0
-cloth_version=0.1.0.3
+cloth_version=0.1.0.4

+ 11 - 4
src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java

@@ -32,7 +32,7 @@ import java.util.Optional;
 
 public class RoughlyEnoughItemsCore implements ClientModInitializer, ModInitializer {
     
-    public static final Logger LOGGER = LogManager.getFormatterLogger("REI");
+    public static final Logger LOGGER;
     public static final Identifier DELETE_ITEMS_PACKET = new Identifier("roughlyenoughitems", "delete_item");
     public static final Identifier CREATE_ITEMS_PACKET = new Identifier("roughlyenoughitems", "create_item");
     private static final RecipeHelper RECIPE_HELPER = new RecipeHelperImpl();
@@ -41,6 +41,10 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer, ModInitiali
     private static final Map<Identifier, REIPlugin> plugins = Maps.newHashMap();
     private static ConfigManager configManager;
     
+    static {
+        LOGGER = LogManager.getFormatterLogger("REI");
+    }
+    
     public static RecipeHelper getRecipeHelper() {
         return RECIPE_HELPER;
     }
@@ -59,7 +63,7 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer, ModInitiali
     
     public static REIPlugin registerPlugin(Identifier identifier, REIPlugin plugin) {
         plugins.put(identifier, plugin);
-        RoughlyEnoughItemsCore.LOGGER.info("REI: Registered plugin %s from %s", identifier.toString(), plugin.getClass().getSimpleName());
+        RoughlyEnoughItemsCore.LOGGER.info("[REI] Registered plugin %s from %s", identifier.toString(), plugin.getClass().getSimpleName());
         plugin.onFirstLoad(getPluginDisabler());
         return plugin;
     }
@@ -81,16 +85,19 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer, ModInitiali
         
         // If pluginloader is not installed, base functionality should still remain
         if (!FabricLoader.getInstance().isModLoaded("pluginloader")) {
-            RoughlyEnoughItemsCore.LOGGER.warn("REI: Plugin Loader is not loaded! Please consider installing https://minecraft.curseforge.com/projects/pluginloader for REI plugin compatibility!");
+            RoughlyEnoughItemsCore.LOGGER.warn("[REI] Plugin Loader is not loaded! Please consider installing https://minecraft.curseforge.com/projects/pluginloader for REI plugin compatibility!");
             registerPlugin(new Identifier("roughlyenoughitems", "default_plugin"), new DefaultPlugin());
         }
         
         if (FabricLoader.getInstance().isModLoaded("cloth")) {
             try {
-                Class.forName("me.shedaniel.rei.cloth.ClothRegistry").getDeclaredMethod("register").invoke(null);
+                Class.forName("me.shedaniel.rei.utils.ClothRegistry").getDeclaredMethod("register").invoke(null);
             } catch (IllegalAccessException | InvocationTargetException | ClassNotFoundException | NoSuchMethodException e) {
                 e.printStackTrace();
             }
+        } else {
+            RoughlyEnoughItemsCore.LOGGER.fatal("[REI] Cloth NOT found! It is a dependency of REI: https://minecraft.curseforge.com/projects/utils");
+            System.exit(0);
         }
     }
     

+ 1 - 1
src/main/java/me/shedaniel/rei/RoughlyEnoughItemsPlugins.java

@@ -20,7 +20,7 @@ public class RoughlyEnoughItemsPlugins implements LoaderCreator {
                 REIPlugin plugin = (REIPlugin) container.getOwner().getAdapter().createInstance(aClass, instantiationOptions);
                 RoughlyEnoughItemsCore.registerPlugin(id, plugin);
             } catch (LanguageAdapterException e) {
-                RoughlyEnoughItemsCore.LOGGER.error("REI: Error loading plugin %s", id, e);
+                RoughlyEnoughItemsCore.LOGGER.error("[REI] Error loading plugin %s", id, e);
             }
         }).build();
     }

+ 21 - 11
src/main/java/me/shedaniel/rei/client/ConfigManager.java

@@ -17,17 +17,18 @@ public class ConfigManager implements me.shedaniel.rei.api.ConfigManager {
     
     private static final Gson GSON = new GsonBuilder().create();
     private static final Jankson JANKSON = Jankson.builder().build();
-    private final File configFile, oldConfigFile;
+    private final File configFile, veryOldConfigFile, oldConfigFile;
     private ConfigObject config;
     private boolean craftableOnly;
     
     public ConfigManager() {
-        this.oldConfigFile = new File(FabricLoader.getInstance().getConfigDirectory(), "rei.json");
-        this.configFile = new File(FabricLoader.getInstance().getConfigDirectory(), "roughlyenoughitems/config.json");
+        this.veryOldConfigFile = new File(FabricLoader.getInstance().getConfigDirectory(), "rei.json");
+        this.oldConfigFile = new File(FabricLoader.getInstance().getConfigDirectory(), "roughlyenoughitems/config.json");
+        this.configFile = new File(FabricLoader.getInstance().getConfigDirectory(), "roughlyenoughitems/config.json5");
         this.craftableOnly = false;
         try {
             loadConfig();
-            RoughlyEnoughItemsCore.LOGGER.info("REI: Config is loaded.");
+            RoughlyEnoughItemsCore.LOGGER.info("[REI] Config is loaded.");
         } catch (IOException e) {
             e.printStackTrace();
         }
@@ -37,7 +38,7 @@ public class ConfigManager implements me.shedaniel.rei.api.ConfigManager {
     public void saveConfig() throws IOException {
         configFile.getParentFile().mkdirs();
         if (!configFile.exists() && !configFile.createNewFile()) {
-            RoughlyEnoughItemsCore.LOGGER.error("REI: Failed to save config! Overwriting with default config.");
+            RoughlyEnoughItemsCore.LOGGER.error("[REI] Failed to save config! Overwriting with default config.");
             config = new ConfigObject();
             return;
         }
@@ -52,7 +53,7 @@ public class ConfigManager implements me.shedaniel.rei.api.ConfigManager {
             out.close();
         } catch (Exception e) {
             e.printStackTrace();
-            RoughlyEnoughItemsCore.LOGGER.error("REI: Failed to save config! Overwriting with default config.");
+            RoughlyEnoughItemsCore.LOGGER.error("[REI] Failed to save config! Overwriting with default config.");
             config = new ConfigObject();
             return;
         }
@@ -61,17 +62,26 @@ public class ConfigManager implements me.shedaniel.rei.api.ConfigManager {
     @Override
     public void loadConfig() throws IOException {
         configFile.getParentFile().mkdirs();
+        if (!configFile.exists() && veryOldConfigFile.exists()) {
+            RoughlyEnoughItemsCore.LOGGER.info("[REI] Detected old config file, trying to move it.");
+            try {
+                Files.move(veryOldConfigFile.toPath(), configFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
+            } catch (Exception e) {
+                e.printStackTrace();
+                RoughlyEnoughItemsCore.LOGGER.error("[REI] Failed to move config file.");
+            }
+        }
         if (!configFile.exists() && oldConfigFile.exists()) {
-            RoughlyEnoughItemsCore.LOGGER.info("REI: Detected old config file, trying to move it.");
+            RoughlyEnoughItemsCore.LOGGER.info("[REI] Detected old config file, trying to move it.");
             try {
                 Files.move(oldConfigFile.toPath(), configFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
             } catch (Exception e) {
                 e.printStackTrace();
-                RoughlyEnoughItemsCore.LOGGER.error("REI: Failed to move config file.");
+                RoughlyEnoughItemsCore.LOGGER.error("[REI] Failed to move config file.");
             }
         }
         if (!configFile.exists() || !configFile.canRead()) {
-            RoughlyEnoughItemsCore.LOGGER.warn("REI: Config not found! Creating one.");
+            RoughlyEnoughItemsCore.LOGGER.warn("[REI] Config not found! Creating one.");
             config = new ConfigObject();
             saveConfig();
             return;
@@ -80,14 +90,14 @@ public class ConfigManager implements me.shedaniel.rei.api.ConfigManager {
         try {
             JsonObject configJson = JANKSON.load(configFile);
             String regularized = configJson.toJson(false, false, 0);
-    
+            
             config = GSON.fromJson(regularized, ConfigObject.class);
         } catch (Exception e) {
             e.printStackTrace();
             failed = true;
         }
         if (failed || config == null) {
-            RoughlyEnoughItemsCore.LOGGER.error("REI: Failed to load config! Overwriting with default config.");
+            RoughlyEnoughItemsCore.LOGGER.error("[REI] Failed to load config! Overwriting with default config.");
             config = new ConfigObject();
         }
         saveConfig();

+ 0 - 21
src/main/java/me/shedaniel/rei/cloth/ClothRegistry.java

@@ -1,21 +0,0 @@
-package me.shedaniel.rei.cloth;
-
-import me.shedaniel.cloth.api.EventPriority;
-import me.shedaniel.cloth.hooks.ClothModMenuHooks;
-import me.shedaniel.rei.client.ClientHelper;
-import net.minecraft.client.MinecraftClient;
-
-public class ClothRegistry {
-    
-    public static void register() {
-        Runnable configRunnable = () -> ClientHelper.openConfigWindow(MinecraftClient.getInstance().currentScreen, false);
-        ClothModMenuHooks.CONFIG_BUTTON_EVENT.registerListener(event -> {
-            if (event.getModContainer() != null && event.getModContainer().getMetadata().getId().equalsIgnoreCase("roughlyenoughitems")) {
-                event.setEnabled(true);
-                event.setClickedRunnable(configRunnable);
-                event.setCancelled(true);
-            }
-        }, EventPriority.LOWEST);
-    }
-    
-}

+ 0 - 59
src/main/java/me/shedaniel/rei/mixin/MixinBrewingRecipeRegistry.java

@@ -1,59 +0,0 @@
-package me.shedaniel.rei.mixin;
-
-import com.google.common.collect.Lists;
-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.item.ItemProvider;
-import net.minecraft.item.PotionItem;
-import net.minecraft.potion.Potion;
-import net.minecraft.potion.PotionUtil;
-import net.minecraft.recipe.BrewingRecipeRegistry;
-import net.minecraft.recipe.Ingredient;
-import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.injection.At;
-import org.spongepowered.asm.mixin.injection.Inject;
-import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
-
-import java.util.Arrays;
-import java.util.List;
-
-@Mixin(BrewingRecipeRegistry.class)
-public class MixinBrewingRecipeRegistry {
-    
-    private static final List<BrewingRecipe> SELF_ITEM_RECIPES = Lists.newArrayList();
-    private static final List<Potion> REGISTERED_POTION_TYPES = Lists.newArrayList();
-    private static final List<Ingredient> SELF_POTION_TYPES = Lists.newArrayList();
-    
-    @Inject(method = "registerPotionType", at = @At("RETURN"))
-    private static void method_8080(Item item_1, CallbackInfo ci) {
-        if (item_1 instanceof PotionItem)
-            SELF_POTION_TYPES.add(Ingredient.ofItems(new ItemProvider[]{item_1}));
-    }
-    
-    @Inject(method = "registerItemRecipe", at = @At("RETURN"))
-    private static void method_8071(Item item_1, Item item_2, Item item_3, CallbackInfo ci) {
-        if (item_1 instanceof PotionItem && item_3 instanceof PotionItem)
-            SELF_ITEM_RECIPES.add(new BrewingRecipe(item_1, Ingredient.ofItems(new ItemProvider[]{item_2}), item_3));
-    }
-    
-    @Inject(method = "registerPotionRecipe", at = @At("RETURN"))
-    private static void registerPotionRecipe(Potion potion_1, Item item_1, Potion potion_2, CallbackInfo ci) {
-        if (!REGISTERED_POTION_TYPES.contains(potion_1))
-            rei_registerPotionType(potion_1);
-        if (!REGISTERED_POTION_TYPES.contains(potion_2))
-            rei_registerPotionType(potion_2);
-        SELF_POTION_TYPES.stream().map(Ingredient::getStackArray).forEach(itemStacks -> Arrays.stream(itemStacks).forEach(stack -> {
-            DefaultPlugin.registerBrewingDisplay(new DefaultBrewingDisplay(PotionUtil.setPotion(stack.copy(), potion_1), Ingredient.ofItems(new ItemProvider[]{item_1}), PotionUtil.setPotion(stack.copy(), potion_2)));
-        }));
-    }
-    
-    private static void rei_registerPotionType(Potion potion) {
-        REGISTERED_POTION_TYPES.add(potion);
-        SELF_ITEM_RECIPES.forEach(recipe -> {
-            DefaultPlugin.registerBrewingDisplay(new DefaultBrewingDisplay(PotionUtil.setPotion(recipe.input.getDefaultStack(), potion), recipe.ingredient, PotionUtil.setPotion(recipe.output.getDefaultStack(), potion)));
-        });
-    }
-    
-}

+ 0 - 20
src/main/java/me/shedaniel/rei/mixin/MixinClientPlayNetworkHandler.java

@@ -1,20 +0,0 @@
-package me.shedaniel.rei.mixin;
-
-import me.shedaniel.rei.RoughlyEnoughItemsCore;
-import me.shedaniel.rei.client.RecipeHelperImpl;
-import net.minecraft.client.network.ClientPlayNetworkHandler;
-import net.minecraft.client.network.packet.SynchronizeRecipesS2CPacket;
-import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.injection.At;
-import org.spongepowered.asm.mixin.injection.Inject;
-import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
-
-@Mixin(ClientPlayNetworkHandler.class)
-public class MixinClientPlayNetworkHandler {
-    
-    @Inject(method = "onSynchronizeRecipes", at = @At("RETURN"))
-    private void onUpdateRecipes(SynchronizeRecipesS2CPacket packetIn, CallbackInfo ci) {
-        ((RecipeHelperImpl) RoughlyEnoughItemsCore.getRecipeHelper()).recipesLoaded(((ClientPlayNetworkHandler) ((Object) this)).getRecipeManager());
-    }
-    
-}

+ 0 - 22
src/main/java/me/shedaniel/rei/mixin/MixinContainerScreen.java

@@ -15,7 +15,6 @@ import org.spongepowered.asm.mixin.Mixin;
 import org.spongepowered.asm.mixin.Shadow;
 import org.spongepowered.asm.mixin.injection.At;
 import org.spongepowered.asm.mixin.injection.Inject;
-import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
 import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
 
 @Mixin(ContainerScreen.class)
@@ -52,27 +51,6 @@ public class MixinContainerScreen extends Screen implements ContainerScreenHooks
         return height;
     }
     
-    @Inject(method = "onInitialized()V", at = @At("RETURN"))
-    protected void onInitialized(CallbackInfo info) {
-        if (MinecraftClient.getInstance().currentScreen instanceof CreativePlayerInventoryScreen) {
-            TabGetter tabGetter = (TabGetter) MinecraftClient.getInstance().currentScreen;
-            if (tabGetter.rei_getSelectedTab() != ItemGroup.INVENTORY.getIndex())
-                return;
-        }
-        ScreenHelper.setLastContainerScreen((ContainerScreen) (Object) this);
-        this.listeners.add(ScreenHelper.getLastOverlay(true));
-    }
-    
-    @Inject(method = "draw(IIF)V", at = @At("RETURN"))
-    public void draw(int int_1, int int_2, float float_1, CallbackInfo info) {
-        if (MinecraftClient.getInstance().currentScreen instanceof CreativePlayerInventoryScreen) {
-            TabGetter tabGetter = (TabGetter) MinecraftClient.getInstance().currentScreen;
-            if (tabGetter.rei_getSelectedTab() != ItemGroup.INVENTORY.getIndex())
-                return;
-        }
-        ScreenHelper.getLastOverlay().drawOverlay(int_1, int_2, float_1);
-    }
-    
     @Override
     public Slot rei_getHoveredSlot() {
         return focusedSlot;

+ 0 - 22
src/main/java/me/shedaniel/rei/mixin/MixinScreen.java

@@ -1,22 +0,0 @@
-package me.shedaniel.rei.mixin;
-
-import me.shedaniel.rei.RoughlyEnoughItemsCore;
-import net.minecraft.client.gui.ContainerScreen;
-import net.minecraft.client.gui.Screen;
-import net.minecraft.client.gui.widget.ButtonWidget;
-import net.minecraft.client.gui.widget.RecipeBookButtonWidget;
-import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.injection.At;
-import org.spongepowered.asm.mixin.injection.Inject;
-import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
-
-@Mixin(Screen.class)
-public class MixinScreen {
-    
-    @Inject(method = "addButton", at = @At("HEAD"), cancellable = true)
-    protected void addButton(ButtonWidget buttonWidget, CallbackInfoReturnable info) {
-        if (RoughlyEnoughItemsCore.getConfigManager().getConfig().disableRecipeBook && ((Screen) (Object) this) instanceof ContainerScreen && buttonWidget instanceof RecipeBookButtonWidget)
-            info.cancel();
-    }
-    
-}

+ 2 - 7
src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java

@@ -16,6 +16,7 @@ import net.minecraft.enchantment.EnchantmentHelper;
 import net.minecraft.item.ItemStack;
 import net.minecraft.item.Items;
 import net.minecraft.potion.PotionUtil;
+import net.minecraft.recipe.REIBrewingRecipeRegistry;
 import net.minecraft.recipe.Recipe;
 import net.minecraft.recipe.StonecuttingRecipe;
 import net.minecraft.recipe.cooking.BlastingRecipe;
@@ -40,12 +41,6 @@ public class DefaultPlugin implements REIPlugin {
     public static final Identifier BREWING = new Identifier("roughlyenoughitems", "plugins/brewing");
     public static final Identifier PLUGIN = new Identifier("roughlyenoughitems", "default_plugin");
     
-    private static final List<DefaultBrewingDisplay> BREWING_DISPLAYS = Lists.newArrayList();
-    
-    public static void registerBrewingDisplay(DefaultBrewingDisplay display) {
-        BREWING_DISPLAYS.add(display);
-    }
-    
     @Override
     public void onFirstLoad(PluginDisabler pluginDisabler) {
         if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().loadDefaultPlugin) {
@@ -104,7 +99,7 @@ public class DefaultPlugin implements REIPlugin {
                 recipeHelper.registerDisplay(CAMPFIRE, new DefaultCampfireDisplay((CampfireCookingRecipe) recipe));
             else if (recipe instanceof StonecuttingRecipe)
                 recipeHelper.registerDisplay(STONE_CUTTING, new DefaultStoneCuttingDisplay((StonecuttingRecipe) recipe));
-        BREWING_DISPLAYS.stream().forEachOrdered(display -> recipeHelper.registerDisplay(BREWING, display));
+        REIBrewingRecipeRegistry.registerDisplays(recipeHelper);
         List<ItemStack> arrowStack = Arrays.asList(Items.ARROW.getDefaultStack());
         RoughlyEnoughItemsCore.getItemRegisterer().getItemList().stream().filter(stack -> stack.getItem().equals(Items.LINGERING_POTION)).forEach(stack -> {
             List<List<ItemStack>> input = new ArrayList<>();

+ 58 - 0
src/main/java/me/shedaniel/rei/utils/ClothRegistry.java

@@ -0,0 +1,58 @@
+package me.shedaniel.rei.utils;
+
+import me.shedaniel.cloth.api.EventPriority;
+import me.shedaniel.cloth.hooks.ClothHooks;
+import me.shedaniel.cloth.hooks.ClothModMenuHooks;
+import me.shedaniel.rei.RoughlyEnoughItemsCore;
+import me.shedaniel.rei.api.TabGetter;
+import me.shedaniel.rei.client.ClientHelper;
+import me.shedaniel.rei.client.RecipeHelperImpl;
+import me.shedaniel.rei.client.ScreenHelper;
+import net.minecraft.client.MinecraftClient;
+import net.minecraft.client.gui.ContainerScreen;
+import net.minecraft.client.gui.ingame.CreativePlayerInventoryScreen;
+import net.minecraft.client.gui.widget.RecipeBookButtonWidget;
+import net.minecraft.item.ItemGroup;
+
+public class ClothRegistry {
+    
+    public static void register() {
+        Runnable configRunnable = () -> ClientHelper.openConfigWindow(MinecraftClient.getInstance().currentScreen, false);
+        ClothModMenuHooks.CONFIG_BUTTON_EVENT.registerListener(event -> {
+            if (event.getModContainer() != null && event.getModContainer().getMetadata().getId().equalsIgnoreCase("roughlyenoughitems")) {
+                event.setEnabled(true);
+                event.setClickedRunnable(configRunnable);
+                event.setCancelled(true);
+            }
+        }, EventPriority.LOWEST);
+        ClothHooks.CLIENT_SYNC_RECIPES.registerListener(event -> {
+            ((RecipeHelperImpl) RoughlyEnoughItemsCore.getRecipeHelper()).recipesLoaded(event.getManager());
+        });
+        ClothHooks.CLIENT_SCREEN_ADD_BUTTON.registerListener(event -> {
+            if (RoughlyEnoughItemsCore.getConfigManager().getConfig().disableRecipeBook && event.getScreen() instanceof ContainerScreen && event.getButtonWidget() instanceof RecipeBookButtonWidget)
+                event.setCancelled(true);
+        }, EventPriority.LOWEST);
+        ClothHooks.CLIENT_POST_INIT_SCREEN.registerListener(post -> {
+            if (post.getScreen() instanceof ContainerScreen) {
+                if (post.getScreen() instanceof CreativePlayerInventoryScreen) {
+                    TabGetter tabGetter = (TabGetter) post.getScreen();
+                    if (tabGetter.rei_getSelectedTab() != ItemGroup.INVENTORY.getIndex())
+                        return;
+                }
+                ScreenHelper.setLastContainerScreen((ContainerScreen) post.getScreen());
+                post.getInputListeners().add(ScreenHelper.getLastOverlay(true));
+            }
+        }, EventPriority.LOWEST);
+        ClothHooks.CLIENT_POST_DRAW_SCREEN.registerListener(post -> {
+            if (post.getScreen() instanceof ContainerScreen) {
+                if (post.getScreen() instanceof CreativePlayerInventoryScreen) {
+                    TabGetter tabGetter = (TabGetter) post.getScreen();
+                    if (tabGetter.rei_getSelectedTab() != ItemGroup.INVENTORY.getIndex())
+                        return;
+                }
+                ScreenHelper.getLastOverlay().drawOverlay(post.getMouseX(), post.getMouseY(), post.getDelta());
+            }
+        }, EventPriority.LOWEST);
+    }
+    
+}

+ 56 - 0
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)));
+        });
+    }
+    
+}

+ 36 - 0
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());
+    }
+    
+}

+ 0 - 3
src/main/resources/roughlyenoughitems.client.json

@@ -4,13 +4,10 @@
   "minVersion": "0.7.11",
   "compatibilityLevel": "JAVA_8",
   "mixins": [
-    "MixinScreen",
     "MixinContainerScreen",
-    "MixinClientPlayNetworkHandler",
     "MixinPlayerInventoryScreen",
     "MixinCraftingTableScreen",
     "MixinCreativePlayerInventoryScreen",
-    "MixinBrewingRecipeRegistry",
     "MixinTabGetter",
     "GhostSlotsHook"
   ],