Skip to content

Commit

Permalink
fix search module might use outdated mouse event buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Glease committed Nov 6, 2023
1 parent 53d04a8 commit 79b07ef
Showing 1 changed file with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class ThaumonomiconIndexSearcher {
public static ThaumonomiconIndexSearcher instance;
private static ByteBuffer mouseBuffer;
private static Field f_selectedCategory = null;
private static Field f_mouseBuffer;
private static GuiTextField thaumSearchField;
private static int listDisplayOffset = 0;
private static String searchCategory;
Expand All @@ -52,17 +53,11 @@ public static void init() {
MinecraftForge.EVENT_BUS.register(instance);
FMLCommonHandler.instance().bus().register(instance);

if (mouseBuffer == null)
try {
Field f_buf = Mouse.class.getDeclaredFields()[mouseBufferIdent];
if (!f_buf.getName().equalsIgnoreCase("readBuffer"))
f_buf = Mouse.class.getDeclaredField("readBuffer");
f_buf.setAccessible(true);
mouseBuffer = (ByteBuffer) f_buf.get(null);
} catch (Exception e) {
e.printStackTrace();
}
try {
f_mouseBuffer = Mouse.class.getDeclaredFields()[mouseBufferIdent];
if (!f_mouseBuffer.getName().equalsIgnoreCase("readBuffer"))
f_mouseBuffer = Mouse.class.getDeclaredField("readBuffer");
f_mouseBuffer.setAccessible(true);
f_selectedCategory = GuiResearchBrowser.class.getDeclaredFields()[selectedCategoryIdent];
if (!f_selectedCategory.getName().equalsIgnoreCase("selectedCategory"))
f_selectedCategory = GuiResearchBrowser.class.getDeclaredField("selectedCategory");
Expand All @@ -72,6 +67,14 @@ public static void init() {
}
}

private static void initMouseEventBuffer() {
try {
mouseBuffer = (ByteBuffer) f_mouseBuffer.get(null);
} catch (Exception e) {
e.printStackTrace();
}
}

static int getResultDisplayAreaWidth(GuiScreen gui) {
return Math.min(gui.width - getResultDisplayAreaX(gui), 224);
}
Expand Down Expand Up @@ -152,6 +155,7 @@ private static String getActiveCategory() {
public void onGuiInit(GuiScreenEvent.InitGuiEvent.Post event) {
searchResults.clear();
if (event.gui.getClass().getName().endsWith("GuiResearchBrowser")) {
initMouseEventBuffer();
int width = ConfigurationHandler.INSTANCE.getBrowserWidth();
int height = ConfigurationHandler.INSTANCE.getBrowserHeight();
thaumSearchField = new GuiTextField(event.gui.mc.fontRenderer, event.gui.width / 2, event.gui.height / 2 - height / 2 + 5, Math.min(width / 2 - 20, 120), 13);
Expand Down Expand Up @@ -243,6 +247,7 @@ public void onGuiPostDraw(GuiScreenEvent.DrawScreenEvent.Post event) {
public void onGuiOpen(GuiOpenEvent event) {
if (thaumSearchField != null) {
thaumSearchField = null;
mouseBuffer = null;
Keyboard.enableRepeatEvents(false);
}
}
Expand Down

0 comments on commit 79b07ef

Please sign in to comment.