diff --git a/src/main/java/codechicken/nei/ClientHandler.java b/src/main/java/codechicken/nei/ClientHandler.java index a8d9cda8..9cfa5140 100644 --- a/src/main/java/codechicken/nei/ClientHandler.java +++ b/src/main/java/codechicken/nei/ClientHandler.java @@ -46,18 +46,24 @@ import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.regex.Pattern; +import java.util.stream.Collectors; public class ClientHandler { private static String[] defaultSerialHandlers = { "WayofTime.alchemicalWizardry.client.nei.NEIAlchemyRecipeHandler" }; - private static String[] defaultHeightHackHandlers = { - "ic2.neiIntegration.core.recipehandler.FluidCannerRecipeHandler", - "tconstruct.plugins.nei.RecipeHandlerAlloying", - "tconstruct.plugins.nei.RecipeHandlerCastingBasin", - "tconstruct.plugins.nei.RecipeHandlerCastingTable", - "tconstruct.plugins.nei.RecipeHandlerMelting", + private static String[] defaultHeightHackHandlerRegex = { + "buildcraft.compat.nei.*", + "cofh.thermalexpansion.plugins.nei.handlers.*", + "crazypants.enderio.nei.*", + "forestry.factory.recipes.nei.*", + "ic2.neiIntegration.core.recipehandler.*", + "mariculture.plugins.nei.*", + "redgear.brewcraft.plugins.nei.*", + "tconstruct.plugins.nei.*", + "WayofTime.alchemicalWizardry.client.nei.*", }; private static String[] defaultHandlerOrdering = { "# Each line in this file should either be a comment (starts with '#') or an ordering.", @@ -180,7 +186,7 @@ public class ClientHandler if (!file.exists()) { try (FileWriter writer = new FileWriter(file)) { NEIClientConfig.logger.info("Creating default height hack handlers list {}", file); - Collection toSave = Loader.isModLoaded("dreamcraft") ? Collections.singletonList("") : Arrays.asList(defaultHeightHackHandlers); + Collection toSave = Arrays.asList(defaultHeightHackHandlerRegex); IOUtils.writeLines(toSave, "\n", writer); } catch (IOException e) { NEIClientConfig.logger.error("Failed to save default height hack handlers list to file {}", file, e); @@ -189,7 +195,10 @@ public class ClientHandler try (FileReader reader = new FileReader(file)) { NEIClientConfig.logger.info("Loading height hack handlers from file {}", file); - NEIClientConfig.heightHackHandlers = new HashSet<>(IOUtils.readLines(reader)); + NEIClientConfig.heightHackHandlerRegex = + IOUtils.readLines(reader).stream() + .map(Pattern::compile) + .collect(Collectors.toCollection(HashSet::new)); } catch (IOException e) { NEIClientConfig.logger.error("Failed to load height hack handlers from file {}", file, e); } diff --git a/src/main/java/codechicken/nei/NEIClientConfig.java b/src/main/java/codechicken/nei/NEIClientConfig.java index 87c3e3eb..7ba15986 100644 --- a/src/main/java/codechicken/nei/NEIClientConfig.java +++ b/src/main/java/codechicken/nei/NEIClientConfig.java @@ -48,6 +48,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.function.Function; +import java.util.regex.Pattern; public class NEIClientConfig { private static boolean configLoaded; @@ -68,8 +69,9 @@ public class NEIClientConfig { // Set of handlers that need to be run in serial public static HashSet serialHandlers = new HashSet<>(); - // Set of handler ID of handlers that need the hack in GuiRecipe.startHeightHack(). - public static HashSet heightHackHandlers = new HashSet<>(); + // Set of regexes matching handler ID of handlers that need the hack in GuiRecipe.startHeightHack(). + // We use regex here so that we can apply the height hack to entire mods with one entry. + public static HashSet heightHackHandlerRegex = new HashSet<>(); // Map of handler ID to sort order. // Handlers will be sorted in ascending order, so smaller numbers show up earlier. diff --git a/src/main/java/codechicken/nei/recipe/GuiRecipe.java b/src/main/java/codechicken/nei/recipe/GuiRecipe.java index f6f562a7..34d345ef 100644 --- a/src/main/java/codechicken/nei/recipe/GuiRecipe.java +++ b/src/main/java/codechicken/nei/recipe/GuiRecipe.java @@ -18,16 +18,13 @@ import codechicken.nei.guihook.GuiContainerManager; import codechicken.nei.guihook.IContainerTooltipHandler; import codechicken.nei.guihook.IGuiClientSide; import codechicken.nei.guihook.IGuiHandleMouseWheel; -import codechicken.nei.recipe.StackInfo; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; -import net.minecraft.nbt.NBTTagCompound; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -import net.minecraft.item.Item; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; @@ -38,6 +35,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; +import java.util.regex.Matcher; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -112,7 +110,11 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve private HeightHack() { trueHeight = height; - if (NEIClientConfig.heightHackHandlers.contains(handler.getHandlerId())) { + boolean applyHeightHack = + NEIClientConfig.heightHackHandlerRegex.stream() + .map(pattern -> pattern.matcher(handler.getHandlerId())) + .anyMatch(Matcher::matches); + if (applyHeightHack) { // The old mods use the calculation ((height - 166) / 2) to compute the y-value of // the top edge of the NEI window. // guiTop is exactly that: the y-value of the top edge of the NEI window.