From 574247ab30050f2b3cf6b32c7057b4106996bc12 Mon Sep 17 00:00:00 2001 From: Cow Date: Thu, 24 Sep 2020 18:50:48 +0200 Subject: Fix crash caused by another, outdated and buggy mod which sadly too many people still use - Switch to using reflections instead the vanilla's GuiContainer#getSlotUnderMouse method because a still frequently used but outdated version of another mod somehow deletes that method - also switched to Forge's ReflectionHelper --- src/main/java/de/cowtipper/cowlection/search/GuiSearch.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'src/main/java/de/cowtipper/cowlection/search') diff --git a/src/main/java/de/cowtipper/cowlection/search/GuiSearch.java b/src/main/java/de/cowtipper/cowlection/search/GuiSearch.java index f9b68a1..1dc48c3 100644 --- a/src/main/java/de/cowtipper/cowlection/search/GuiSearch.java +++ b/src/main/java/de/cowtipper/cowlection/search/GuiSearch.java @@ -21,9 +21,9 @@ import net.minecraftforge.fml.client.config.GuiButtonExt; import net.minecraftforge.fml.client.config.GuiCheckBox; import net.minecraftforge.fml.client.config.GuiConfig; import net.minecraftforge.fml.client.config.IConfigElement; +import net.minecraftforge.fml.relauncher.ReflectionHelper; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; -import org.apache.commons.lang3.reflect.FieldUtils; import org.apache.commons.lang3.tuple.ImmutableTriple; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; @@ -33,7 +33,6 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; -import java.lang.reflect.Field; import java.nio.file.Files; import java.nio.file.StandardCopyOption; import java.time.LocalDate; @@ -471,14 +470,9 @@ public class GuiSearch extends GuiScreen { } private float getScrollDistance() { - Field scrollDistanceField = FieldUtils.getField(GuiScrollingList.class, "scrollDistance", true); - if (scrollDistanceField == null) { - // scrollDistance field not found in class GuiScrollingList - return Float.MIN_VALUE; - } try { - return (float) scrollDistanceField.get(this); - } catch (IllegalAccessException e) { + return ReflectionHelper.getPrivateValue(GuiScrollingList.class, this, "scrollDistance"); + } catch (ReflectionHelper.UnableToAccessFieldException e) { e.printStackTrace(); return Float.MIN_VALUE; } -- cgit