Compare commits

...
Author SHA1 Message Date
Wilhelm Schuster 2c7207485d Ensure the NEI config is really only initialized once (#381)
bootNEI() is supposed to only be called once during the client's
lifetime. Turns out, if your pack has 800 mods, bootNEI() might be
called a second time before configLoaded is set to true at the end of
the plugin loading thread. This introduces a second variable that is
set at the end of the single threaded portion of bootNEI() so that it
truly can only be called once, but we can still retain the ability to
check if the plugin loading thread has finished.
2023-05-10 23:55:45 +02:00
Wilhelm Schuster e8094794c3 Allow scrolling through recipe handlers (#379)
In addition to scrolling through all recipes of a single handler, you
can now scroll through all the recipe handlers while hovering over the
handler tab bar (or anywhere in the recipe area while holding left
shift).
2023-05-09 21:57:27 +02:00
3 changed files with 41 additions and 6 deletions

No files matched your search

@@ -57,7 +57,8 @@ import codechicken.obfuscator.ObfuscationRun;
public class NEIClientConfig {
private static boolean configLoaded;
private static boolean mainNEIConfigLoaded;
private static boolean pluginNEIConfigLoaded;
private static boolean enabledOverride;
private static String worldPath;
@@ -463,8 +464,9 @@ public class NEIClientConfig {
}
public static void bootNEI(World world) {
if (configLoaded) return;
if (mainNEIConfigLoaded) return;
// main NEI config loading
ItemInfo.load(world);
GuiInfo.load();
RecipeInfo.load();
@@ -472,10 +474,13 @@ public class NEIClientConfig {
NEIController.load();
RecipeCatalysts.loadCatalystInfo();
mainNEIConfigLoaded = true;
new Thread("NEI Plugin Loader") {
@Override
public void run() {
logger.debug("Started NEI plugin loading");
ClassDiscoverer classDiscoverer = new ClassDiscoverer(
test -> test.startsWith("NEI") && test.endsWith("Config.class"),
IConfigureNEI.class);
@@ -493,8 +498,14 @@ public class NEIClientConfig {
}
}
// Set pluginNEIConfigLoaded here before posting the NEIConfigsLoadedEvent. This used to be the other
// way around, but apparently if your modpack includes 800 mods the event poster might not return in
// time and cause issues when loading a world for a second time as configLoaded is still false. This may
// cause issues in case one of the event handler calls the (non-thread-safe) NEI API. I don't expect any
// handler to do this, but who knows what modders have come up with...
pluginNEIConfigLoaded = true;
logger.debug("NEI plugin loading finished");
MinecraftForge.EVENT_BUS.post(new NEIConfigsLoadedEvent());
configLoaded = true;
}
}.start();
ItemSorter.loadConfig();
@@ -597,7 +608,7 @@ public class NEIClientConfig {
}
public static boolean isLoaded() {
return configLoaded;
return mainNEIConfigLoaded && pluginNEIConfigLoaded;
}
public static boolean loadHandlersFromJar() {
@@ -388,6 +388,8 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
// the value of the height field will be different from in other mouseover methods, which
// could be confusing...
if (recipeTabs.mouseScrolled(i)) return;
for (int recipe : getRecipeIndices()) if (handler.mouseScrolled(this, i, recipe)) return;
if (new Rectangle(guiLeft, guiTop, xSize, ySize).contains(GuiDraw.getMousePosition())) {
@@ -462,11 +464,11 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
if (page < 0) page = (handler.numRecipes() - 1) / getRecipesPerPage();
}
private void nextType() {
protected void nextType() {
setRecipePage(++recipetype);
}
private void prevType() {
protected void prevType() {
setRecipePage(--recipetype);
}
@@ -1,9 +1,13 @@
package codechicken.nei.recipe;
import static codechicken.lib.gui.GuiDraw.getMousePosition;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import org.lwjgl.input.Keyboard;
import codechicken.nei.Button;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIClientUtils;
@@ -192,4 +196,22 @@ public class GuiRecipeTabs {
}
return false;
}
protected boolean mouseScrolled(int i) {
Point mPos = getMousePosition();
// Switch recipe handler tabs if either left shift is held or the tab
// bar is enable and the mouse cursor is positioned over said tab bar.
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)
|| (NEIClientConfig.areJEIStyleTabsVisible() && (mPos.x >= area.x && mPos.x <= (area.x + area.width)
&& mPos.y >= area.y
&& mPos.y <= (area.y + area.height)))) {
if (i < 0) guiRecipe.nextType();
else guiRecipe.prevType();
return true;
}
return false;
}
}