diff options
author | Cow <cow@volloeko.de> | 2020-09-24 18:50:48 +0200 |
---|---|---|
committer | Cow <cow@volloeko.de> | 2020-09-24 18:50:48 +0200 |
commit | 574247ab30050f2b3cf6b32c7057b4106996bc12 (patch) | |
tree | ff04b5c90e3c97e4c60558493b5ab38eff7e75b9 /src/main/java | |
parent | f6d584431f878b931bf9f745a02b43dd8035cb44 (diff) | |
download | Cowlection-574247ab30050f2b3cf6b32c7057b4106996bc12.tar.gz Cowlection-574247ab30050f2b3cf6b32c7057b4106996bc12.tar.bz2 Cowlection-574247ab30050f2b3cf6b32c7057b4106996bc12.zip |
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
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/de/cowtipper/cowlection/listener/skyblock/DungeonsListener.java | 15 | ||||
-rw-r--r-- | src/main/java/de/cowtipper/cowlection/search/GuiSearch.java | 12 |
2 files changed, 16 insertions, 11 deletions
diff --git a/src/main/java/de/cowtipper/cowlection/listener/skyblock/DungeonsListener.java b/src/main/java/de/cowtipper/cowlection/listener/skyblock/DungeonsListener.java index 1098f1e..edbadb0 100644 --- a/src/main/java/de/cowtipper/cowlection/listener/skyblock/DungeonsListener.java +++ b/src/main/java/de/cowtipper/cowlection/listener/skyblock/DungeonsListener.java @@ -10,6 +10,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.audio.SoundCategory; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.inventory.GuiChest; +import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.init.Blocks; @@ -36,6 +37,7 @@ import net.minecraftforge.event.entity.player.PlayerSetSpawnEvent; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; +import net.minecraftforge.fml.relauncher.ReflectionHelper; import net.minecraftforge.fml.relauncher.Side; import org.apache.commons.lang3.StringUtils; import org.lwjgl.input.Mouse; @@ -492,7 +494,7 @@ public class DungeonsListener { IInventory inventory = guiChest.inventorySlots.getSlot(0).inventory; if (inventory.getName().equals("Party Finder")) { // get dungeon floor nr when joining a dungeon party via party finder - Slot hoveredSlot = guiChest.getSlotUnderMouse(); + Slot hoveredSlot = getSlotUnderMouse(guiChest); if (hoveredSlot != null && hoveredSlot.getHasStack()) { // clicked on an item List<String> itemToolTip = hoveredSlot.getStack().getTooltip(Minecraft.getMinecraft().thePlayer, false); @@ -515,7 +517,7 @@ public class DungeonsListener { } } else if (inventory.getName().equals("Group Builder")) { // get dungeon floor nr when creating a dungeon party for party finder - Slot hoveredSlot = guiChest.getSlotUnderMouse(); + Slot hoveredSlot = getSlotUnderMouse(guiChest); if (hoveredSlot != null && hoveredSlot.getHasStack() && hoveredSlot.getStack().hasDisplayName()) { // clicked on an item String clickedItemName = EnumChatFormatting.getTextWithoutFormattingCodes(hoveredSlot.getStack().getDisplayName()); @@ -547,6 +549,15 @@ public class DungeonsListener { } } + private Slot getSlotUnderMouse(GuiChest guiChest) { + try { + return ReflectionHelper.getPrivateValue(GuiContainer.class, guiChest, "theSlot", "field_147006_u"); + } catch (ReflectionHelper.UnableToAccessFieldException e) { + e.printStackTrace(); + return null; + } + } + @SubscribeEvent public void onPlayerTick(TickEvent.PlayerTickEvent e) { if (e.phase != TickEvent.Phase.END && e.side != Side.CLIENT && e.type != TickEvent.Type.PLAYER) { 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; } |