aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java15
-rw-r--r--src/main/java/me/shedaniel/rei/RoughlyEnoughItemsPlugins.java2
-rw-r--r--src/main/java/me/shedaniel/rei/client/ConfigManager.java32
-rw-r--r--src/main/java/me/shedaniel/rei/cloth/ClothRegistry.java21
-rw-r--r--src/main/java/me/shedaniel/rei/mixin/MixinBrewingRecipeRegistry.java59
-rw-r--r--src/main/java/me/shedaniel/rei/mixin/MixinClientPlayNetworkHandler.java20
-rw-r--r--src/main/java/me/shedaniel/rei/mixin/MixinContainerScreen.java22
-rw-r--r--src/main/java/me/shedaniel/rei/mixin/MixinScreen.java22
-rw-r--r--src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java9
-rw-r--r--src/main/java/me/shedaniel/rei/utils/ClothRegistry.java58
-rw-r--r--src/main/java/net/minecraft/recipe/REIBrewingRecipeRegistry.java56
-rw-r--r--src/main/java/net/minecraft/recipe/REIPotionRecipeUtils.java36
12 files changed, 185 insertions, 167 deletions
diff --git a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java
index 652c2cb29..2eef84bf1 100644
--- a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java
+++ b/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);
}
}
diff --git a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsPlugins.java b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsPlugins.java
index 0dabfcda9..452e97eea 100644
--- a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsPlugins.java
+++ b/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();
}
diff --git a/src/main/java/me/shedaniel/rei/client/ConfigManager.java b/src/main/java/me/shedaniel/rei/client/ConfigManager.java
index c05442b41..8973e5865 100644
--- a/src/main/java/me/shedaniel/rei/client/ConfigManager.java
+++ b/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();
diff --git a/src/main/java/me/shedaniel/rei/cloth/ClothRegistry.java b/src/main/java/me/shedaniel/rei/cloth/ClothRegistry.java
deleted file mode 100644
index a644046b0..000000000
--- a/src/main/java/me/shedaniel/rei/cloth/ClothRegistry.java
+++ /dev/null
@@ -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);
- }
-
-}
diff --git a/src/main/java/me/shedaniel/rei/mixin/MixinBrewingRecipeRegistry.java b/src/main/java/me/shedaniel/rei/mixin/MixinBrewingRecipeRegistry.java
deleted file mode 100644
index 5c3e10461..000000000
--- a/src/main/java/me/shedaniel/rei/mixin/MixinBrewingRecipeRegistry.java
+++ /dev/null
@@ -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)));
- });
- }
-
-}
diff --git a/src/main/java/me/shedaniel/rei/mixin/MixinClientPlayNetworkHandler.java b/src/main/java/me/shedaniel/rei/mixin/MixinClientPlayNetworkHandler.java
deleted file mode 100644
index 2d2b86554..000000000
--- a/src/main/java/me/shedaniel/rei/mixin/MixinClientPlayNetworkHandler.java
+++ /dev/null
@@ -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());
- }
-
-}
diff --git a/src/main/java/me/shedaniel/rei/mixin/MixinContainerScreen.java b/src/main/java/me/shedaniel/rei/mixin/MixinContainerScreen.java
index 2147f0f09..5371ca545 100644
--- a/src/main/java/me/shedaniel/rei/mixin/MixinContainerScreen.java
+++ b/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;
diff --git a/src/main/java/me/shedaniel/rei/mixin/MixinScreen.java b/src/main/java/me/shedaniel/rei/mixin/MixinScreen.java
deleted file mode 100644
index df034a967..000000000
--- a/src/main/java/me/shedaniel/rei/mixin/MixinScreen.java
+++ /dev/null
@@ -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();
- }
-
-}
diff --git a/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java b/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java
index b74f97911..6e54c55e5 100644
--- a/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java
+++ b/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<>();
diff --git a/src/main/java/me/shedaniel/rei/utils/ClothRegistry.java b/src/main/java/me/shedaniel/rei/utils/ClothRegistry.java
new file mode 100644
index 000000000..3879feded
--- /dev/null
+++ b/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);
+ }
+
+}
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());
+ }
+
+}