aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/pers/gwyog/gtneioreplugin/GTNEIOrePlugin.java2
-rw-r--r--src/main/java/pers/gwyog/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java8
-rw-r--r--src/main/java/pers/gwyog/gtneioreplugin/util/GuiRecipeHelper.java96
-rw-r--r--src/main/resources/META-INF/gtneioreplugin_at.cfg5
4 files changed, 104 insertions, 7 deletions
diff --git a/src/main/java/pers/gwyog/gtneioreplugin/GTNEIOrePlugin.java b/src/main/java/pers/gwyog/gtneioreplugin/GTNEIOrePlugin.java
index 7b52bd44c6..8adcc41c10 100644
--- a/src/main/java/pers/gwyog/gtneioreplugin/GTNEIOrePlugin.java
+++ b/src/main/java/pers/gwyog/gtneioreplugin/GTNEIOrePlugin.java
@@ -9,6 +9,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import pers.gwyog.gtneioreplugin.util.GT5OreLayerHelper;
import pers.gwyog.gtneioreplugin.util.GT5OreSmallHelper;
+import pers.gwyog.gtneioreplugin.util.GuiRecipeHelper;
@Mod(modid = GTNEIOrePlugin.MODID, name = GTNEIOrePlugin.NAME, version = GTNEIOrePlugin.VERSION, dependencies = "required-after:gregtech;required-after:NotEnoughItems")
public class GTNEIOrePlugin {
@@ -41,6 +42,7 @@ public class GTNEIOrePlugin {
if (event.getSide() == Side.CLIENT) {
new GT5OreLayerHelper();
new GT5OreSmallHelper();
+ new GuiRecipeHelper();
if (csv) {
new pers.gwyog.gtneioreplugin.util.CSVMaker().run();
}
diff --git a/src/main/java/pers/gwyog/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java b/src/main/java/pers/gwyog/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java
index 6bc9db3e2c..f5bb8a618b 100644
--- a/src/main/java/pers/gwyog/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java
+++ b/src/main/java/pers/gwyog/gtneioreplugin/plugin/gregtech5/PluginGT5Base.java
@@ -10,6 +10,7 @@ import net.minecraft.client.resources.I18n;
import net.minecraft.util.EnumChatFormatting;
import pers.gwyog.gtneioreplugin.plugin.PluginBase;
import pers.gwyog.gtneioreplugin.util.DimensionHelper;
+import pers.gwyog.gtneioreplugin.util.GuiRecipeHelper;
import java.awt.Point;
import java.awt.Rectangle;
@@ -87,9 +88,12 @@ public abstract class PluginGT5Base extends PluginBase {
* @return Rectangle area of dimension names
*/
protected Rectangle getDimensionNamesRect(GuiRecipe gui, int recipe, String dimNames) {
- int height = dimNames.length() > 70 ? 30 : (dimNames.length() > 36 ? 20 : 10);
+ int dimNamesHeight = dimNames.length() > 70 ? 30 : (dimNames.length() > 36 ? 20 : 10);
Point offset = gui.getRecipePosition(recipe);
- return new Rectangle(gui.guiLeft + offset.x + 2, gui.guiTop + offset.y + 110, gui.xSize - 9, height );
+ return new Rectangle(GuiRecipeHelper.getGuiLeft(gui) + offset.x + 2,
+ GuiRecipeHelper.getGuiTop(gui) + offset.y + 110,
+ GuiRecipeHelper.getXSize(gui) - 9,
+ dimNamesHeight );
}
protected int getMaximumMaterialIndex(short meta, boolean smallOre) {
diff --git a/src/main/java/pers/gwyog/gtneioreplugin/util/GuiRecipeHelper.java b/src/main/java/pers/gwyog/gtneioreplugin/util/GuiRecipeHelper.java
new file mode 100644
index 0000000000..78d43f1bdd
--- /dev/null
+++ b/src/main/java/pers/gwyog/gtneioreplugin/util/GuiRecipeHelper.java
@@ -0,0 +1,96 @@
+package pers.gwyog.gtneioreplugin.util;
+
+import java.lang.reflect.Field;
+
+import org.apache.logging.log4j.Level;
+
+import codechicken.nei.recipe.GuiRecipe;
+import cpw.mods.fml.common.FMLLog;
+import net.minecraft.client.Minecraft;
+
+public class GuiRecipeHelper {
+ private static final String INIT_ERROR = "pers.gwyog.gtneioreplugin.util.GuiRecipeHelper failed setting up reflection : ";
+ private static final int DEFAULT_XSIZE = 176;
+
+ private static Class<GuiRecipe> guiRecipeClass;
+ public static Field xSizeField;
+ public static Field guiLeftField;
+ public static Field guiTopField;
+
+ /**
+ * Access the xSize field of a GuiRecipe instance, or use a fallback hardcoded value if that fails
+ *
+ * @param gui GuiRecipe object
+ * @return Integer value of the xSize field of that object
+ */
+ public static int getXSize(GuiRecipe gui) {
+ if (xSizeField != null) {
+ try {
+ return (int) xSizeField.get(gui);
+ } catch (IllegalAccessException e) {
+ // Fail silently, hoping that it it fails it will be during initialization
+ }
+ }
+
+ // Fallback should work unless codechicken.nei.recipe.GuiRecipe implementation changes
+ return DEFAULT_XSIZE;
+ }
+
+
+ /**
+ * Access the guiLeft field of a GuiRecipe instance, or use a fallback hardcoded value if that fails
+ *
+ * @param gui GuiRecipe object
+ * @return Integer value of the guiLeft field of that object
+ */
+ public static int getGuiLeft(GuiRecipe gui) {
+ if (guiLeftField != null) {
+ try {
+ return (int) guiLeftField.get(gui);
+ } catch (IllegalAccessException e) {
+ // Fail silently, hoping that it it fails it will be during initialization
+ }
+ }
+
+ // Fallback should work unless codechicken.nei.recipe.GuiRecipe implementation changes
+ return (Minecraft.getMinecraft().currentScreen.width - DEFAULT_XSIZE) / 2;
+ }
+
+ /**
+ * Access the guiTop field of a GuiRecipe instance, or use a fallback hardcoded value if that fails
+ *
+ * @param gui GuiRecipe object
+ * @return Integer value of the guiTop field of that object
+ */
+ public static int getGuiTop(GuiRecipe gui) {
+ if (guiTopField != null) {
+ try {
+ return (int) guiTopField.get(gui);
+ } catch (IllegalAccessException e) {
+ // Fail silently, hoping that it it fails it will be during initialization
+ }
+ }
+
+ // Fallback should work unless codechicken.nei.recipe.GuiRecipe implementation changes
+ int height = Minecraft.getMinecraft().currentScreen.height;
+ int ySize = Math.min(Math.max(height - 68, 166), 370);
+ return (height - ySize) / 2 + 10;
+ }
+
+ /**
+ * Initialize the GuiRecipe Field accessors through reflection
+ */
+ public GuiRecipeHelper() {
+ guiRecipeClass = GuiRecipe.class;
+ try {
+ guiLeftField = guiRecipeClass.getField("guiLeft");
+ guiLeftField.setAccessible(true);
+ guiTopField = guiRecipeClass.getField("guiTop");
+ guiTopField.setAccessible(true);
+ xSizeField = guiRecipeClass.getField("xSize");
+ xSizeField.setAccessible(true);
+ } catch(NoSuchFieldException|SecurityException e) {
+ FMLLog.log(Level.ERROR, INIT_ERROR + e.getMessage());
+ }
+ }
+}
diff --git a/src/main/resources/META-INF/gtneioreplugin_at.cfg b/src/main/resources/META-INF/gtneioreplugin_at.cfg
deleted file mode 100644
index efa5067287..0000000000
--- a/src/main/resources/META-INF/gtneioreplugin_at.cfg
+++ /dev/null
@@ -1,5 +0,0 @@
-# GT NEI Ore Plugin Access Transformer configuration file
-public net.minecraft.client.gui.inventory.GuiContainer field_146999_f #xSize
-public net.minecraft.client.gui.inventory.GuiContainer field_147000_g #ySize
-public net.minecraft.client.gui.inventory.GuiContainer field_147003_i #guiLeft
-public net.minecraft.client.gui.inventory.GuiContainer field_147009_r #guiTop \ No newline at end of file