From d09d2b50e7cff97eec3a213c731c8a16cdeb7b7a Mon Sep 17 00:00:00 2001 From: Michael Carver <4365312+shortcarver@users.noreply.github.com> Date: Tue, 1 Oct 2024 21:39:10 -0500 Subject: [PATCH 1/8] trying to do the bookmark overlay --- .gitignore | 3 + Makefile | 9 + src/main/java/mezz/jei/GuiEventHandler.java | 277 ++++++----- .../java/mezz/jei/IngredientBookmarks.java | 35 ++ src/main/java/mezz/jei/JeiHelpers.java | 1 + src/main/java/mezz/jei/JeiRuntime.java | 114 +++-- src/main/java/mezz/jei/JeiStarter.java | 5 +- .../java/mezz/jei/api/IBookmarksOverlay.java | 15 + src/main/java/mezz/jei/api/IJeiHelpers.java | 1 + src/main/java/mezz/jei/api/IJeiRuntime.java | 2 + .../api/ingredients/IIngredientBookmarks.java | 18 + .../java/mezz/jei/config/KeyBindings.java | 2 + .../java/mezz/jei/gui/BookmarksOverlay.java | 76 +++ .../jei/gui/BookmarksOverlayInternal.java | 295 +++++++++++ .../mezz/jei/gui/ItemListOverlayInternal.java | 3 + .../java/mezz/jei/input/InputHandler.java | 469 +++++++++--------- 16 files changed, 921 insertions(+), 404 deletions(-) create mode 100644 Makefile create mode 100644 src/main/java/mezz/jei/IngredientBookmarks.java create mode 100644 src/main/java/mezz/jei/api/IBookmarksOverlay.java create mode 100644 src/main/java/mezz/jei/api/ingredients/IIngredientBookmarks.java create mode 100644 src/main/java/mezz/jei/gui/BookmarksOverlay.java create mode 100644 src/main/java/mezz/jei/gui/BookmarksOverlayInternal.java diff --git a/.gitignore b/.gitignore index b40db0506..d27c08be3 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,6 @@ out/ build/* /bin/ changelog.html + +.DS_Store +.vscode/ \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..03357e2a6 --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +switch_java: + export JAVA_HOME=`/usr/libexec/java_home -v 1.8.0_362` +bd: + JAVA_HOME=`/usr/libexec/java_home -v 1.8.0_362` + ./gradlew build + make deploy +deploy: + rm /Users/mcarver/Documents/curseforge/minecraft/Instances/TestJEI/mods/jei_1.10.2-3.14.8.jar + cp build/libs/jei_1.10.2-3.14.8.jar /Users/mcarver/Documents/curseforge/minecraft/Instances/TestJEI/mods/ diff --git a/src/main/java/mezz/jei/GuiEventHandler.java b/src/main/java/mezz/jei/GuiEventHandler.java index 78a2d92b7..e0cb35dbd 100644 --- a/src/main/java/mezz/jei/GuiEventHandler.java +++ b/src/main/java/mezz/jei/GuiEventHandler.java @@ -4,6 +4,8 @@ import mezz.jei.config.Config; import mezz.jei.config.OverlayToggleEvent; +import mezz.jei.gui.BookmarksOverlay; +import mezz.jei.gui.BookmarksOverlayInternal; import mezz.jei.gui.ItemListOverlay; import mezz.jei.gui.ItemListOverlayInternal; import mezz.jei.gui.TooltipRenderer; @@ -20,133 +22,150 @@ import org.lwjgl.input.Mouse; public class GuiEventHandler { - private static final String showRecipesText = Translator.translateToLocal("jei.tooltip.show.recipes"); - private final JeiRuntime runtime; - @Nullable - private InputHandler inputHandler; - @Nullable - private GuiContainer previousGui = null; - - public GuiEventHandler(JeiRuntime runtime) { - this.runtime = runtime; - } - - @SubscribeEvent - public void onOverlayToggle(OverlayToggleEvent event) { - GuiScreen currentScreen = Minecraft.getMinecraft().currentScreen; - onNewScreen(currentScreen); - } - - @SubscribeEvent - public void onGuiInit(GuiScreenEvent.InitGuiEvent.Post event) { - GuiScreen gui = event.getGui(); - onNewScreen(gui); - } - - private void onNewScreen(@Nullable GuiScreen screen) { - if (screen instanceof GuiContainer || screen instanceof RecipesGui) { - ItemListOverlay itemListOverlay = runtime.getItemListOverlay(); - ItemListOverlayInternal itemListOverlayInternal = itemListOverlay.create(screen); - inputHandler = new InputHandler(runtime, itemListOverlayInternal); - } else { - inputHandler = null; - } - } - - @SubscribeEvent - public void onGuiOpen(GuiOpenEvent event) { - ItemListOverlay itemListOverlay = runtime.getItemListOverlay(); - - GuiScreen gui = event.getGui(); - if (gui instanceof GuiContainer) { - GuiContainer guiContainer = (GuiContainer) gui; - if (previousGui != guiContainer) { - previousGui = guiContainer; - if (itemListOverlay.isOpen()) { - itemListOverlay.close(); - } - } - } else if (!(gui instanceof RecipesGui)) { - if (itemListOverlay.isOpen()) { - itemListOverlay.close(); - inputHandler = null; - } - } - } - - @SubscribeEvent - public void onDrawBackgroundEventPost(GuiScreenEvent.BackgroundDrawnEvent event) { - ItemListOverlay itemListOverlay = runtime.getItemListOverlay(); - ItemListOverlayInternal itemListOverlayInternal = itemListOverlay.getInternal(); - if (itemListOverlayInternal != null) { - GuiScreen gui = event.getGui(); - if (itemListOverlayInternal.hasScreenChanged(gui)) { - itemListOverlayInternal = itemListOverlay.create(gui); - inputHandler = new InputHandler(runtime, itemListOverlayInternal); - } - - if (itemListOverlayInternal != null) { - itemListOverlayInternal.drawScreen(gui.mc, event.getMouseX(), event.getMouseY()); - } - } - } - - @SubscribeEvent - public void onDrawScreenEventPost(GuiScreenEvent.DrawScreenEvent.Post event) { - GuiScreen gui = event.getGui(); - if (gui instanceof GuiContainer) { - GuiContainer guiContainer = (GuiContainer) gui; - RecipeRegistry recipeRegistry = runtime.getRecipeRegistry(); - if (recipeRegistry.getRecipeClickableArea(guiContainer, event.getMouseX() - guiContainer.guiLeft, event.getMouseY() - guiContainer.guiTop) != null) { - TooltipRenderer.drawHoveringText(guiContainer.mc, showRecipesText, event.getMouseX(), event.getMouseY()); - } - } - - ItemListOverlay itemListOverlay = runtime.getItemListOverlay(); - ItemListOverlayInternal itemListOverlayInternal = itemListOverlay.getInternal(); - if (itemListOverlayInternal != null) { - itemListOverlayInternal.drawTooltips(gui.mc, event.getMouseX(), event.getMouseY()); - } - } - - @SubscribeEvent - public void onClientTick(TickEvent.ClientTickEvent event) { - if (event.phase == TickEvent.Phase.END) { - return; - } - - ItemListOverlay itemListOverlay = runtime.getItemListOverlay(); - ItemListOverlayInternal itemListOverlayInternal = itemListOverlay.getInternal(); - if (itemListOverlayInternal != null) { - itemListOverlayInternal.handleTick(); - } - } - - @SubscribeEvent - public void onGuiKeyboardEvent(GuiScreenEvent.KeyboardInputEvent.Pre event) { - if (inputHandler != null) { - if (inputHandler.handleKeyEvent()) { - event.setCanceled(true); - } - } - } - - @SubscribeEvent - public void onGuiMouseEvent(GuiScreenEvent.MouseInputEvent.Pre event) { - GuiScreen guiScreen = event.getGui(); - if (inputHandler != null) { - int x = Mouse.getEventX() * guiScreen.width / guiScreen.mc.displayWidth; - int y = guiScreen.height - Mouse.getEventY() * guiScreen.height / guiScreen.mc.displayHeight - 1; - if (inputHandler.handleMouseEvent(guiScreen, x, y)) { - event.setCanceled(true); - } - } - } - - @SubscribeEvent - public void onPotionShiftEvent(GuiScreenEvent.PotionShiftEvent event) { - if (Config.isOverlayEnabled()) { - event.setCanceled(true); - } - } + private static final String showRecipesText = Translator.translateToLocal("jei.tooltip.show.recipes"); + private final JeiRuntime runtime; + @Nullable + private InputHandler inputHandler; + @Nullable + private GuiContainer previousGui = null; + + public GuiEventHandler(JeiRuntime runtime) { + this.runtime = runtime; + } + + @SubscribeEvent + public void onOverlayToggle(OverlayToggleEvent event) { + GuiScreen currentScreen = Minecraft.getMinecraft().currentScreen; + onNewScreen(currentScreen); + } + + @SubscribeEvent + public void onGuiInit(GuiScreenEvent.InitGuiEvent.Post event) { + GuiScreen gui = event.getGui(); + onNewScreen(gui); + } + + private void onNewScreen(@Nullable GuiScreen screen) { + if (screen instanceof GuiContainer || screen instanceof RecipesGui) { + ItemListOverlay itemListOverlay = runtime.getItemListOverlay(); + ItemListOverlayInternal itemListOverlayInternal = itemListOverlay.create(screen); + BookmarksOverlay bookmarksOverlay = runtime.getBookmarksOverlay(); + BookmarksOverlayInternal bookmarksOverlayInternal = bookmarksOverlay.create(screen); + inputHandler = new InputHandler(runtime, itemListOverlayInternal); + } else { + inputHandler = null; + } + } + + @SubscribeEvent + public void onGuiOpen(GuiOpenEvent event) { + ItemListOverlay itemListOverlay = runtime.getItemListOverlay(); + + GuiScreen gui = event.getGui(); + if (gui instanceof GuiContainer) { + GuiContainer guiContainer = (GuiContainer) gui; + if (previousGui != guiContainer) { + previousGui = guiContainer; + if (itemListOverlay.isOpen()) { + itemListOverlay.close(); + } + } + } else if (!(gui instanceof RecipesGui)) { + if (itemListOverlay.isOpen()) { + itemListOverlay.close(); + inputHandler = null; + } + } + } + + @SubscribeEvent + public void onDrawBackgroundEventPost(GuiScreenEvent.BackgroundDrawnEvent event) { + ItemListOverlay itemListOverlay = runtime.getItemListOverlay(); + ItemListOverlayInternal itemListOverlayInternal = itemListOverlay.getInternal(); + if (itemListOverlayInternal != null) { + GuiScreen gui = event.getGui(); + if (itemListOverlayInternal.hasScreenChanged(gui)) { + itemListOverlayInternal = itemListOverlay.create(gui); + inputHandler = new InputHandler(runtime, itemListOverlayInternal); + } + + if (itemListOverlayInternal != null) { + itemListOverlayInternal.drawScreen(gui.mc, event.getMouseX(), event.getMouseY()); + } + } + BookmarksOverlay bookmarksOverlay = runtime.getBookmarksOverlay(); + BookmarksOverlayInternal bookmarksOverlayInternal = bookmarksOverlay.getInternal(); + if (bookmarksOverlayInternal != null) { + GuiScreen gui = event.getGui(); + if (bookmarksOverlayInternal.hasScreenChanged(gui)) { + bookmarksOverlayInternal = bookmarksOverlay.create(gui); + // TODO: inputHandler = new InputHandler(runtime, bookmarksOverlayInternal); + } + + if (bookmarksOverlayInternal != null) { + bookmarksOverlayInternal.drawScreen(gui.mc, event.getMouseX(), event.getMouseY()); + } + } + + } + + @SubscribeEvent + public void onDrawScreenEventPost(GuiScreenEvent.DrawScreenEvent.Post event) { + GuiScreen gui = event.getGui(); + if (gui instanceof GuiContainer) { + GuiContainer guiContainer = (GuiContainer) gui; + RecipeRegistry recipeRegistry = runtime.getRecipeRegistry(); + if (recipeRegistry.getRecipeClickableArea(guiContainer, event.getMouseX() - guiContainer.guiLeft, + event.getMouseY() - guiContainer.guiTop) != null) { + TooltipRenderer.drawHoveringText(guiContainer.mc, showRecipesText, event.getMouseX(), event.getMouseY()); + } + } + + ItemListOverlay itemListOverlay = runtime.getItemListOverlay(); + ItemListOverlayInternal itemListOverlayInternal = itemListOverlay.getInternal(); + if (itemListOverlayInternal != null) { + itemListOverlayInternal.drawTooltips(gui.mc, event.getMouseX(), event.getMouseY()); + } + } + + @SubscribeEvent + public void onClientTick(TickEvent.ClientTickEvent event) { + if (event.phase == TickEvent.Phase.END) { + return; + } + + ItemListOverlay itemListOverlay = runtime.getItemListOverlay(); + ItemListOverlayInternal itemListOverlayInternal = itemListOverlay.getInternal(); + if (itemListOverlayInternal != null) { + itemListOverlayInternal.handleTick(); + } + } + + @SubscribeEvent + public void onGuiKeyboardEvent(GuiScreenEvent.KeyboardInputEvent.Pre event) { + if (inputHandler != null) { + if (inputHandler.handleKeyEvent()) { + event.setCanceled(true); + } + } + } + + @SubscribeEvent + public void onGuiMouseEvent(GuiScreenEvent.MouseInputEvent.Pre event) { + GuiScreen guiScreen = event.getGui(); + if (inputHandler != null) { + int x = Mouse.getEventX() * guiScreen.width / guiScreen.mc.displayWidth; + int y = guiScreen.height - Mouse.getEventY() * guiScreen.height / guiScreen.mc.displayHeight - 1; + if (inputHandler.handleMouseEvent(guiScreen, x, y)) { + event.setCanceled(true); + } + } + } + + @SubscribeEvent + public void onPotionShiftEvent(GuiScreenEvent.PotionShiftEvent event) { + if (Config.isOverlayEnabled()) { + event.setCanceled(true); + } + } } diff --git a/src/main/java/mezz/jei/IngredientBookmarks.java b/src/main/java/mezz/jei/IngredientBookmarks.java new file mode 100644 index 000000000..78072166e --- /dev/null +++ b/src/main/java/mezz/jei/IngredientBookmarks.java @@ -0,0 +1,35 @@ +package mezz.jei; + +import java.util.HashSet; +import java.util.Iterator; + +import mezz.jei.api.ingredients.IIngredientBookmarks; +import mezz.jei.api.ingredients.IIngredientHelper; +import mezz.jei.api.ingredients.IIngredientRegistry; + +public class IngredientBookmarks implements IIngredientBookmarks { + private final IIngredientRegistry ingredientRegistry; + private HashSet bookmarkList = new HashSet(); + + public IngredientBookmarks(IIngredientRegistry ingredientRegistry) { + this.ingredientRegistry = ingredientRegistry; + } + + @Override + public void toggleIngredientBookmark(Object ingredient) { + IIngredientHelper ingredientHelper = ingredientRegistry.getIngredientHelper(ingredient); + String uniqueId = ingredientHelper.getUniqueId(ingredient); + // System.out.println(ingredientHelper.getUniqueId(ingredient)); + if (bookmarkList.contains(uniqueId)) { + bookmarkList.remove(uniqueId); + } else { + bookmarkList.add(uniqueId); + } + + Iterator iterator = bookmarkList.iterator(); + System.out.println("Dumping bookmarks"); + while(iterator.hasNext()) { + System.out.println(iterator.next()); + } + } +} diff --git a/src/main/java/mezz/jei/JeiHelpers.java b/src/main/java/mezz/jei/JeiHelpers.java index a29d7dec7..ac297c594 100644 --- a/src/main/java/mezz/jei/JeiHelpers.java +++ b/src/main/java/mezz/jei/JeiHelpers.java @@ -4,6 +4,7 @@ import mezz.jei.api.IJeiHelpers; import mezz.jei.api.INbtRegistry; +import mezz.jei.api.INbtRegistry.INbtInterpreter; import mezz.jei.api.ISubtypeRegistry; import mezz.jei.api.ingredients.IIngredientRegistry; import mezz.jei.gui.GuiHelper; diff --git a/src/main/java/mezz/jei/JeiRuntime.java b/src/main/java/mezz/jei/JeiRuntime.java index c0767a755..d266399f4 100644 --- a/src/main/java/mezz/jei/JeiRuntime.java +++ b/src/main/java/mezz/jei/JeiRuntime.java @@ -5,6 +5,8 @@ import mezz.jei.api.IJeiRuntime; import mezz.jei.api.gui.IAdvancedGuiHandler; +import mezz.jei.api.ingredients.IIngredientBookmarks; +import mezz.jei.gui.BookmarksOverlay; import mezz.jei.gui.ItemListOverlay; import mezz.jei.gui.recipes.RecipesGui; import net.minecraft.client.gui.GuiScreen; @@ -12,58 +14,76 @@ public class JeiRuntime implements IJeiRuntime { - private final RecipeRegistry recipeRegistry; - private final ItemListOverlay itemListOverlay; - private final RecipesGui recipesGui; - private final IngredientRegistry ingredientRegistry; - private final List> advancedGuiHandlers; + private final RecipeRegistry recipeRegistry; + private final ItemListOverlay itemListOverlay; + private final BookmarksOverlay bookmarksOverlay; + private final RecipesGui recipesGui; + private final IngredientRegistry ingredientRegistry; + private final List> advancedGuiHandlers; + private final IngredientBookmarks ingredientBookmarks; - public JeiRuntime(RecipeRegistry recipeRegistry, ItemListOverlay itemListOverlay, RecipesGui recipesGui, IngredientRegistry ingredientRegistry, List> advancedGuiHandlers) { - this.recipeRegistry = recipeRegistry; - this.itemListOverlay = itemListOverlay; - this.recipesGui = recipesGui; - this.ingredientRegistry = ingredientRegistry; - this.advancedGuiHandlers = advancedGuiHandlers; - } + public JeiRuntime(RecipeRegistry recipeRegistry, ItemListOverlay itemListOverlay, RecipesGui recipesGui, + IngredientRegistry ingredientRegistry, List> advancedGuiHandlers, + IngredientBookmarks ingredientBookmarks, BookmarksOverlay bookmarksOverlay) { + this.recipeRegistry = recipeRegistry; + this.itemListOverlay = itemListOverlay; + this.recipesGui = recipesGui; + this.ingredientRegistry = ingredientRegistry; + this.advancedGuiHandlers = advancedGuiHandlers; + this.ingredientBookmarks = ingredientBookmarks; + this.bookmarksOverlay = bookmarksOverlay; + } - public void close() { - if (itemListOverlay.isOpen()) { - itemListOverlay.close(); - } - if (recipesGui.isOpen()) { - recipesGui.close(); - } - } + public void close() { + if (itemListOverlay.isOpen()) { + itemListOverlay.close(); + } + if (bookmarksOverlay.isOpen()) { + bookmarksOverlay.close(); + } + if (recipesGui.isOpen()) { + recipesGui.close(); + } + } - @Override - public RecipeRegistry getRecipeRegistry() { - return recipeRegistry; - } + @Override + public RecipeRegistry getRecipeRegistry() { + return recipeRegistry; + } - @Override - public ItemListOverlay getItemListOverlay() { - return itemListOverlay; - } + @Override + public ItemListOverlay getItemListOverlay() { + return itemListOverlay; + } - @Override - public RecipesGui getRecipesGui() { - return recipesGui; - } + @Override + public BookmarksOverlay getBookmarksOverlay() { + return bookmarksOverlay; + } - public IngredientRegistry getIngredientRegistry() { - return ingredientRegistry; - } + @Override + public RecipesGui getRecipesGui() { + return recipesGui; + } - public List> getActiveAdvancedGuiHandlers(GuiScreen guiScreen) { - List> activeAdvancedGuiHandler = new ArrayList>(); - if (guiScreen instanceof GuiContainer) { - for (IAdvancedGuiHandler advancedGuiHandler : advancedGuiHandlers) { - Class guiContainerClass = advancedGuiHandler.getGuiContainerClass(); - if (guiContainerClass.isInstance(guiScreen)) { - activeAdvancedGuiHandler.add(advancedGuiHandler); - } - } - } - return activeAdvancedGuiHandler; - } + public IngredientRegistry getIngredientRegistry() { + return ingredientRegistry; + } + + public IIngredientBookmarks getIngredientBookmarks() { + return ingredientBookmarks; + } + + public List> getActiveAdvancedGuiHandlers(GuiScreen guiScreen) { + List> activeAdvancedGuiHandler = new ArrayList>(); + if (guiScreen instanceof GuiContainer) { + for (IAdvancedGuiHandler advancedGuiHandler : advancedGuiHandlers) { + Class guiContainerClass = advancedGuiHandler.getGuiContainerClass(); + if (guiContainerClass.isInstance(guiScreen)) { + activeAdvancedGuiHandler.add(advancedGuiHandler); + } + } + } + return activeAdvancedGuiHandler; + } } diff --git a/src/main/java/mezz/jei/JeiStarter.java b/src/main/java/mezz/jei/JeiStarter.java index 71d39fbf9..a8ca0c262 100644 --- a/src/main/java/mezz/jei/JeiStarter.java +++ b/src/main/java/mezz/jei/JeiStarter.java @@ -7,6 +7,7 @@ import mezz.jei.api.IJeiRuntime; import mezz.jei.api.IModPlugin; import mezz.jei.api.gui.IAdvancedGuiHandler; +import mezz.jei.gui.BookmarksOverlay; import mezz.jei.gui.ItemListOverlay; import mezz.jei.gui.recipes.RecipesGui; import mezz.jei.plugins.vanilla.VanillaPlugin; @@ -60,8 +61,10 @@ public void start(List plugins, boolean resourceReload) { start_time = System.currentTimeMillis(); List> advancedGuiHandlers = modRegistry.getAdvancedGuiHandlers(); ItemListOverlay itemListOverlay = new ItemListOverlay(itemFilter, advancedGuiHandlers, ingredientRegistry); + BookmarksOverlay bookmarksOverlay = new BookmarksOverlay(advancedGuiHandlers, ingredientRegistry); RecipesGui recipesGui = new RecipesGui(recipeRegistry); - JeiRuntime jeiRuntime = new JeiRuntime(recipeRegistry, itemListOverlay, recipesGui, ingredientRegistry, advancedGuiHandlers); + IngredientBookmarks ingredientBookmarks = new IngredientBookmarks(ingredientRegistry); + JeiRuntime jeiRuntime = new JeiRuntime(recipeRegistry, itemListOverlay, recipesGui, ingredientRegistry, advancedGuiHandlers, ingredientBookmarks, bookmarksOverlay); Internal.setRuntime(jeiRuntime); Log.info("Built runtime in {} ms", System.currentTimeMillis() - start_time); diff --git a/src/main/java/mezz/jei/api/IBookmarksOverlay.java b/src/main/java/mezz/jei/api/IBookmarksOverlay.java new file mode 100644 index 000000000..189ba30d5 --- /dev/null +++ b/src/main/java/mezz/jei/api/IBookmarksOverlay.java @@ -0,0 +1,15 @@ +package mezz.jei.api; + +import javax.annotation.Nullable; +import java.util.Collection; + +import com.google.common.collect.ImmutableList; +import net.minecraft.item.ItemStack; + +public interface IBookmarksOverlay { + /** + * @return the stack that's currently under the mouse, or null if there is none + */ + @Nullable + ItemStack getStackUnderMouse(); +} diff --git a/src/main/java/mezz/jei/api/IJeiHelpers.java b/src/main/java/mezz/jei/api/IJeiHelpers.java index 3c415ae70..0f1a6a374 100644 --- a/src/main/java/mezz/jei/api/IJeiHelpers.java +++ b/src/main/java/mezz/jei/api/IJeiHelpers.java @@ -1,6 +1,7 @@ package mezz.jei.api; import mezz.jei.api.ingredients.IIngredientBlacklist; +import mezz.jei.api.ingredients.IIngredientBookmarks; import mezz.jei.api.recipe.IStackHelper; import mezz.jei.api.recipe.transfer.IRecipeTransferHandlerHelper; diff --git a/src/main/java/mezz/jei/api/IJeiRuntime.java b/src/main/java/mezz/jei/api/IJeiRuntime.java index 9d876b453..c7999048b 100644 --- a/src/main/java/mezz/jei/api/IJeiRuntime.java +++ b/src/main/java/mezz/jei/api/IJeiRuntime.java @@ -9,6 +9,8 @@ public interface IJeiRuntime { IItemListOverlay getItemListOverlay(); + IBookmarksOverlay getBookmarksOverlay(); + /** * @since JEI 3.2.12 */ diff --git a/src/main/java/mezz/jei/api/ingredients/IIngredientBookmarks.java b/src/main/java/mezz/jei/api/ingredients/IIngredientBookmarks.java new file mode 100644 index 000000000..5de94e90a --- /dev/null +++ b/src/main/java/mezz/jei/api/ingredients/IIngredientBookmarks.java @@ -0,0 +1,18 @@ +package mezz.jei.api.ingredients; + +import mezz.jei.api.IJeiHelpers; + +/** + * The Ingredient bookmaks allows mods add and remove ingredients from JEI's + * bookmark list + * Get the instance from {@link IJeiHelpers#getIngredientBookmarks()}. + * + * @Since JEI 3.14.9 + */ +public interface IIngredientBookmarks { + /** + * Toggles visibility of ingredient in the bookmark list. + */ + void toggleIngredientBookmark(Object ingredient); + +} diff --git a/src/main/java/mezz/jei/config/KeyBindings.java b/src/main/java/mezz/jei/config/KeyBindings.java index a3de57ec5..ede6b23ef 100644 --- a/src/main/java/mezz/jei/config/KeyBindings.java +++ b/src/main/java/mezz/jei/config/KeyBindings.java @@ -15,6 +15,7 @@ public class KeyBindings { public static final KeyBinding showUses = new KeyBinding("key.jei.showUses", KeyConflictContext.GUI, Keyboard.KEY_U, categoryName); public static final KeyBinding recipeBack = new KeyBinding("key.jei.recipeBack", KeyConflictContext.GUI, Keyboard.KEY_BACK, categoryName); public static final KeyBinding toggleCheatMode = new KeyBinding("key.jei.toggleCheatMode", KeyConflictContext.GUI, Keyboard.KEY_NONE, categoryName); + public static final KeyBinding toggleBookmark = new KeyBinding("key.jei.toggleBookmark", KeyConflictContext.GUI, Keyboard.KEY_A, categoryName); public static void init() { ClientRegistry.registerKeyBinding(toggleOverlay); @@ -23,5 +24,6 @@ public static void init() { ClientRegistry.registerKeyBinding(showUses); ClientRegistry.registerKeyBinding(recipeBack); ClientRegistry.registerKeyBinding(toggleCheatMode); + ClientRegistry.registerKeyBinding(toggleBookmark); } } diff --git a/src/main/java/mezz/jei/gui/BookmarksOverlay.java b/src/main/java/mezz/jei/gui/BookmarksOverlay.java new file mode 100644 index 000000000..740566665 --- /dev/null +++ b/src/main/java/mezz/jei/gui/BookmarksOverlay.java @@ -0,0 +1,76 @@ +package mezz.jei.gui; + +import javax.annotation.Nullable; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import com.google.common.collect.ImmutableList; +import mezz.jei.ItemFilter; +import mezz.jei.api.IBookmarksOverlay; +import mezz.jei.api.IItemListOverlay; +import mezz.jei.api.gui.IAdvancedGuiHandler; +import mezz.jei.api.ingredients.IIngredientRegistry; +import mezz.jei.config.Config; +import mezz.jei.util.Log; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.item.ItemStack; + +public class BookmarksOverlay implements IBookmarksOverlay { + private final List> advancedGuiHandlers; + @Nullable + private BookmarksOverlayInternal internal; + private final IIngredientRegistry ingredientRegistry; + + public BookmarksOverlay(List> advancedGuiHandlers, IIngredientRegistry ingredientRegistry) { + this.advancedGuiHandlers = advancedGuiHandlers; + this.ingredientRegistry = ingredientRegistry; + } + + @Nullable + @Override + public ItemStack getStackUnderMouse() { + if (internal != null) { + return internal.getStackUnderMouse(); + } + return null; + } + + public List> getAdvancedGuiHandlers() { + return advancedGuiHandlers; + } + + public boolean isOpen() { + return internal != null; + } + + public void close() { + if (internal != null) { + internal.close(); + } + internal = null; + } + + public BookmarksOverlayInternal getInternal() { + return internal; + } + + + public BookmarksOverlayInternal create(GuiScreen guiScreen) { + close(); + + if (Config.isOverlayEnabled()) { + GuiProperties guiProperties = GuiProperties.create(guiScreen); + if (guiProperties != null) { + final int columns = BookmarksOverlayInternal.getColumns(guiProperties); + if (columns >= 4) { + internal = new BookmarksOverlayInternal(this, ingredientRegistry, guiScreen, guiProperties); + return internal; + } + } + } + + return null; + } +} diff --git a/src/main/java/mezz/jei/gui/BookmarksOverlayInternal.java b/src/main/java/mezz/jei/gui/BookmarksOverlayInternal.java new file mode 100644 index 000000000..739633808 --- /dev/null +++ b/src/main/java/mezz/jei/gui/BookmarksOverlayInternal.java @@ -0,0 +1,295 @@ +package mezz.jei.gui; + +import java.awt.Rectangle; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import mezz.jei.Internal; +import mezz.jei.api.gui.IAdvancedGuiHandler; +import mezz.jei.api.gui.IDrawable; +import mezz.jei.api.ingredients.IIngredientRegistry; +import mezz.jei.config.Config; +import mezz.jei.gui.ingredients.GuiIngredientFast; +import mezz.jei.gui.ingredients.GuiIngredientFastList; +import mezz.jei.gui.ingredients.GuiItemStackGroup; +import mezz.jei.input.ClickedIngredient; +import mezz.jei.input.IClickedIngredient; +import mezz.jei.input.IKeyable; +import mezz.jei.input.IMouseHandler; +import mezz.jei.input.IShowsRecipeFocuses; +import mezz.jei.util.Java6Helper; +import mezz.jei.util.StackHelper; +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ChatAllowedCharacters; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.text.TextFormatting; + +public class BookmarksOverlayInternal implements IShowsRecipeFocuses, IMouseHandler, IKeyable { + + private static final int borderPadding = 2; + private static final int searchHeight = 16; + private static final int buttonSize = 20; + private static final String nextLabel = ">"; + private static final String backLabel = "<"; + + private static final int itemStackPadding = 1; + private static final int itemStackWidth = GuiItemStackGroup.getWidth(itemStackPadding); + private static final int itemStackHeight = GuiItemStackGroup.getHeight(itemStackPadding); + private static int firstItemIndex = 0; + + private static final String clearLabel = "Clr"; + + private final GuiIngredientFastList guiIngredientList; + private final GuiProperties guiProperties; + private final List guiAreas; + private final BookmarksOverlay parent; + + private GuiIngredientFast hovered = null; + + private final GuiButton clearButton; + + private List> activeAdvancedGuiHandlers = Collections.emptyList(); + + public BookmarksOverlayInternal(BookmarksOverlay parent, IIngredientRegistry ingredientRegistry, GuiScreen guiScreen, + GuiProperties guiProperties) { + + this.parent = parent; + this.guiProperties = guiProperties; + this.guiIngredientList = new GuiIngredientFastList(ingredientRegistry); + + this.activeAdvancedGuiHandlers = getActiveAdvancedGuiHandlers(guiScreen); + if (!activeAdvancedGuiHandlers.isEmpty() && guiScreen instanceof GuiContainer) { + GuiContainer guiContainer = (GuiContainer) guiScreen; + guiAreas = getGuiAreas(guiContainer); + } else { + guiAreas = Collections.emptyList(); + } + + final int columns = getColumns(guiProperties); + final int rows = getRows(guiProperties); + final int xSize = columns * itemStackWidth; + final int xEmptySpace = guiProperties.getScreenWidth() - guiProperties.getGuiLeft() - guiProperties.getGuiXSize() + - xSize; + + final int leftEdge = guiProperties.getGuiLeft() + guiProperties.getGuiXSize() + (xEmptySpace / 2); + final int rightEdge = leftEdge + xSize; + + final int yItemButtonSpace = getItemButtonYSpace(guiProperties); + final int itemButtonsHeight = rows * itemStackHeight; + + final int buttonStartY = buttonSize + (2 * borderPadding) + (yItemButtonSpace - itemButtonsHeight) / 2; + createItemButtons(guiIngredientList, guiAreas, leftEdge, buttonStartY, columns, rows); + + clearButton = new GuiButton(0, rightEdge - buttonSize, borderPadding, buttonSize, buttonSize, nextLabel); + } + + public void drawScreen(Minecraft minecraft, int mouseX, int mouseY) { + GlStateManager.disableLighting(); + + clearButton.drawButton(minecraft, mouseX, mouseY); + + GlStateManager.disableBlend(); + + if (shouldShowDeleteItemTooltip(minecraft)) { + hovered = guiIngredientList.render(minecraft, false, mouseX, mouseY); + } else { + boolean mouseOver = isMouseOver(mouseX, mouseY); + hovered = guiIngredientList.render(minecraft, mouseOver, mouseX, mouseY); + } + + if (hovered != null) { + hovered.drawHovered(minecraft); + } + + GlStateManager.enableAlpha(); + } + + private List getGuiAreas(GuiContainer guiContainer) { + List guiAreas = new ArrayList(); + for (IAdvancedGuiHandler advancedGuiHandler : activeAdvancedGuiHandlers) { + List guiExtraAreas = getGuiAreas(guiContainer, advancedGuiHandler); + if (guiExtraAreas != null) { + guiAreas.addAll(guiExtraAreas); + } + } + return guiAreas; + } + + private List getGuiAreas(GuiContainer gui, + IAdvancedGuiHandler advancedGuiHandler) { + Class guiClass = advancedGuiHandler.getGuiContainerClass(); + if (guiClass.isInstance(gui)) { + T guiT = guiClass.cast(gui); + return advancedGuiHandler.getGuiExtraAreas(guiT); + } + return null; + } + + private boolean shouldShowDeleteItemTooltip(Minecraft minecraft) { + if (Config.isDeleteItemsInCheatModeActive()) { + EntityPlayer player = minecraft.thePlayer; + if (player.inventory.getItemStack() != null) { + return true; + } + } + return false; + } + + private List> getActiveAdvancedGuiHandlers(GuiScreen guiScreen) { + List> activeAdvancedGuiHandler = new ArrayList>(); + if (guiScreen instanceof GuiContainer) { + for (IAdvancedGuiHandler advancedGuiHandler : parent.getAdvancedGuiHandlers()) { + Class guiContainerClass = advancedGuiHandler.getGuiContainerClass(); + if (guiContainerClass.isInstance(guiScreen)) { + activeAdvancedGuiHandler.add(advancedGuiHandler); + } + } + } + return activeAdvancedGuiHandler; + } + + @Override + public IClickedIngredient getIngredientUnderMouse(int mouseX, int mouseY) { + if (!isMouseOver(mouseX, mouseY)) { + return null; + } + + ClickedIngredient clicked = guiIngredientList.getIngredientUnderMouse(mouseX, mouseY); + if (clicked != null) { + setKeyboardFocus(false); + clicked.setAllowsCheating(); + } + return clicked; + } + + @Override + public boolean canSetFocusWithMouse() { + return true; + } + + @Override + public boolean handleMouseScrolled(int mouseX, int mouseY, int scrollDelta) { + return false; + } + + @Override + public boolean isMouseOver(int mouseX, int mouseY) { + + for (Rectangle guiArea : guiAreas) { + if (guiArea.contains(mouseX, mouseY)) { + return false; + } + } + + return true; + } + + @Override + public boolean hasKeyboardFocus() { + return false; + } + + @Override + public void setKeyboardFocus(boolean focus) { + } + + @Override + public boolean onKeyPressed(char typedChar, int keyCode) { + return false; + } + + @Override + public boolean handleMouseClicked(int mouseX, int mouseY, int mouseButton) { + return false; + } + + public ItemStack getStackUnderMouse() { + if (hovered != null) { + Object ingredient = hovered.getIngredient(); + if (ingredient instanceof ItemStack) { + return (ItemStack) ingredient; + } + } + return null; + } + + public static int getColumns(GuiProperties guiProperties) { + return getItemButtonXSpace(guiProperties) / itemStackWidth; + } + + private static int getItemButtonXSpace(GuiProperties guiProperties) { + return guiProperties.getScreenWidth() + - (guiProperties.getGuiLeft() + guiProperties.getGuiXSize() + (2 * borderPadding)); + } + + public static int getRows(GuiProperties guiProperties) { + return getItemButtonYSpace(guiProperties) / itemStackHeight; + } + + private static int getItemButtonYSpace(GuiProperties guiProperties) { + return guiProperties.getScreenHeight() - (buttonSize + searchHeight + 2 + (4 * borderPadding)); + } + + private static void createItemButtons(GuiIngredientFastList guiItemStacks, List guiAreas, + final int xStart, final int yStart, final int columnCount, final int rowCount) { + guiItemStacks.clear(); + + for (int row = 0; row < rowCount; row++) { + int y = yStart + (row * itemStackHeight); + for (int column = 0; column < columnCount; column++) { + int x = xStart + (column * itemStackWidth); + GuiIngredientFast guiIngredientFast = new GuiIngredientFast(x, y, itemStackPadding); + if (guiAreas != null) { + Rectangle stackArea = guiIngredientFast.getArea(); + if (intersects(guiAreas, stackArea)) { + continue; + } + } + guiItemStacks.add(guiIngredientFast); + } + } + } + + private static boolean intersects(List areas, Rectangle comparisonArea) { + for (Rectangle area : areas) { + if (area.intersects(comparisonArea)) { + return true; + } + } + return false; + } + + public void close() { + setKeyboardFocus(false); + Config.saveFilterText(); + } + public boolean hasScreenChanged(GuiScreen guiScreen) { + if (!Config.isOverlayEnabled()) { + return true; + } + GuiProperties guiProperties = GuiProperties.create(guiScreen); + if (guiProperties == null) { + return true; + } + if (!this.guiProperties.equals(guiProperties)) { + return true; + } else if (!activeAdvancedGuiHandlers.isEmpty() && guiScreen instanceof GuiContainer) { + GuiContainer guiContainer = (GuiContainer) guiScreen; + List guiAreas = getGuiAreas(guiContainer); + if (!Java6Helper.equals(this.guiAreas, guiAreas)) { + return true; + } + } + + return false; + } +} diff --git a/src/main/java/mezz/jei/gui/ItemListOverlayInternal.java b/src/main/java/mezz/jei/gui/ItemListOverlayInternal.java index 13c6bc61f..f8bc31968 100644 --- a/src/main/java/mezz/jei/gui/ItemListOverlayInternal.java +++ b/src/main/java/mezz/jei/gui/ItemListOverlayInternal.java @@ -67,6 +67,7 @@ public class ItemListOverlayInternal implements IShowsRecipeFocuses, IMouseHandl private final GuiButton nextButton; private final GuiButton backButton; private final GuiButton configButton; + private final GuiButton clearButton; private final IDrawable configButtonIcon; private final IDrawable configButtonCheatIcon; private final HoverChecker configButtonHoverChecker; @@ -115,6 +116,7 @@ public ItemListOverlayInternal(ItemListOverlay parent, IIngredientRegistry ingre nextButton = new GuiButton(0, rightEdge - buttonSize, borderPadding, buttonSize, buttonSize, nextLabel); backButton = new GuiButton(1, leftEdge, borderPadding, buttonSize, buttonSize, backLabel); + clearButton = new GuiButton(3, 0, borderPadding, buttonSize, buttonSize, "CLR"); final int searchFieldX; final int searchFieldY = guiProperties.getScreenHeight() - searchHeight - borderPadding - 2; @@ -292,6 +294,7 @@ public void drawScreen(Minecraft minecraft, int mouseX, int mouseY) { nextButton.drawButton(minecraft, mouseX, mouseY); backButton.drawButton(minecraft, mouseX, mouseY); configButton.drawButton(minecraft, mouseX, mouseY); + clearButton.drawButton(minecraft, mouseX, mouseY); IDrawable icon = Config.isCheatItemsEnabled() ? configButtonCheatIcon : configButtonIcon; icon.draw(minecraft, configButton.xPosition + 2, configButton.yPosition + 2); diff --git a/src/main/java/mezz/jei/input/InputHandler.java b/src/main/java/mezz/jei/input/InputHandler.java index 19d7d249b..93d1137ca 100644 --- a/src/main/java/mezz/jei/input/InputHandler.java +++ b/src/main/java/mezz/jei/input/InputHandler.java @@ -6,6 +6,7 @@ import mezz.jei.JeiRuntime; import mezz.jei.RecipeRegistry; +import mezz.jei.api.ingredients.IIngredientBookmarks; import mezz.jei.api.ingredients.IIngredientHelper; import mezz.jei.api.ingredients.IIngredientRegistry; import mezz.jei.api.recipe.IFocus; @@ -25,233 +26,247 @@ import net.minecraft.item.ItemStack; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; +import net.minecraftforge.fluids.FluidStack; public class InputHandler { - private final RecipeRegistry recipeRegistry; - private final IIngredientRegistry ingredientRegistry; - private final RecipesGui recipesGui; - @Nullable - private final ItemListOverlayInternal itemListOverlayInternal; - private final MouseHelper mouseHelper; - private final List showsRecipeFocuses = new ArrayList(); - - private boolean clickHandled = false; - - public InputHandler(JeiRuntime runtime, @Nullable ItemListOverlayInternal itemListOverlayInternal) { - this.recipeRegistry = runtime.getRecipeRegistry(); - this.ingredientRegistry = runtime.getIngredientRegistry(); - this.recipesGui = runtime.getRecipesGui(); - this.itemListOverlayInternal = itemListOverlayInternal; - - this.mouseHelper = new MouseHelper(); - - showsRecipeFocuses.add(recipesGui); - if (itemListOverlayInternal != null) { - showsRecipeFocuses.add(itemListOverlayInternal); - } - showsRecipeFocuses.add(new GuiContainerWrapper()); - } - - public boolean handleMouseEvent(GuiScreen guiScreen, int mouseX, int mouseY) { - boolean cancelEvent = false; - if (Mouse.getEventButton() > -1) { - if (Mouse.getEventButtonState()) { - if (!clickHandled) { - cancelEvent = handleMouseClick(guiScreen, Mouse.getEventButton(), mouseX, mouseY); - clickHandled = cancelEvent; - } - } else if (clickHandled) { - clickHandled = false; - cancelEvent = true; - } - } else if (Mouse.getEventDWheel() != 0) { - cancelEvent = handleMouseScroll(Mouse.getEventDWheel(), mouseX, mouseY); - } - return cancelEvent; - } - - private boolean handleMouseScroll(int dWheel, int mouseX, int mouseY) { - return itemListOverlayInternal != null && itemListOverlayInternal.handleMouseScrolled(mouseX, mouseY, dWheel); - } - - private boolean handleMouseClick(GuiScreen guiScreen, int mouseButton, int mouseX, int mouseY) { - if (itemListOverlayInternal != null && itemListOverlayInternal.handleMouseClicked(mouseX, mouseY, mouseButton)) { - return true; - } - - IClickedIngredient clicked = getFocusUnderMouseForClick(mouseX, mouseY); - if (clicked != null && handleMouseClickedFocus(mouseButton, clicked)) { - return true; - } - - if (guiScreen instanceof GuiContainer) { - GuiContainer guiContainer = (GuiContainer) guiScreen; - RecipeClickableArea clickableArea = recipeRegistry.getRecipeClickableArea(guiContainer, mouseX - guiContainer.guiLeft, mouseY - guiContainer.guiTop); - if (clickableArea != null) { - List recipeCategoryUids = clickableArea.getRecipeCategoryUids(); - recipesGui.showCategories(recipeCategoryUids); - } - } - - return false; - } - - @Nullable - private IClickedIngredient getFocusUnderMouseForClick(int mouseX, int mouseY) { - for (IShowsRecipeFocuses gui : showsRecipeFocuses) { - if (gui.canSetFocusWithMouse()) { - IClickedIngredient clicked = gui.getIngredientUnderMouse(mouseX, mouseY); - if (clicked != null) { - return clicked; - } - } - } - return null; - } - - @Nullable - private IClickedIngredient getIngredientUnderMouseForKey(int mouseX, int mouseY) { - for (IShowsRecipeFocuses gui : showsRecipeFocuses) { - IClickedIngredient clicked = gui.getIngredientUnderMouse(mouseX, mouseY); - if (clicked != null) { - return clicked; - } - } - return null; - } - - private boolean handleMouseClickedFocus(int mouseButton, IClickedIngredient clicked) { - if (Config.isEditModeEnabled()) { - if (handleClickEdit(mouseButton, clicked.getValue())) { - return true; - } - } - - if (Config.isCheatItemsEnabled() && clicked.allowsCheating() && !recipesGui.isOpen()) { - Object focusValue = clicked.getValue(); - if (focusValue instanceof ItemStack) { - ItemStack itemStack = (ItemStack) focusValue; - CommandUtil.giveStack(itemStack, mouseButton); - return true; - } - } - - if (mouseButton == 0) { - IFocus focus = new Focus(IFocus.Mode.OUTPUT, clicked.getValue()); - recipesGui.show(focus); - return true; - } else if (mouseButton == 1) { - IFocus focus = new Focus(IFocus.Mode.INPUT, clicked.getValue()); - recipesGui.show(focus); - return true; - } - - return false; - } - - private boolean handleClickEdit(int mouseButton, V ingredient) { - Config.IngredientBlacklistType blacklistType = null; - if (GuiScreen.isCtrlKeyDown()) { - if (GuiScreen.isShiftKeyDown()) { - if (mouseButton == 0) { - blacklistType = Config.IngredientBlacklistType.MOD_ID; - } - } else { - if (mouseButton == 0) { - blacklistType = Config.IngredientBlacklistType.ITEM; - } else if (mouseButton == 1) { - blacklistType = Config.IngredientBlacklistType.WILDCARD; - } - } - } - - if (blacklistType == null) { - return false; - } - - IIngredientHelper ingredientHelper = ingredientRegistry.getIngredientHelper(ingredient); - - if (Config.isIngredientOnConfigBlacklist(ingredient, blacklistType, ingredientHelper)) { - Config.removeIngredientFromConfigBlacklist(ingredient, blacklistType, ingredientHelper); - } else { - Config.addIngredientToConfigBlacklist(ingredient, blacklistType, ingredientHelper); - } - return true; - } - - public boolean handleKeyEvent() { - char typedChar = Keyboard.getEventCharacter(); - int eventKey = Keyboard.getEventKey(); - - return ((eventKey == 0 && typedChar >= 32) || Keyboard.getEventKeyState()) && - handleKeyDown(typedChar, eventKey); - } - - private boolean handleKeyDown(char typedChar, int eventKey) { - if (itemListOverlayInternal != null && itemListOverlayInternal.hasKeyboardFocus()) { - if (isInventoryCloseKey(eventKey) || isEnterKey(eventKey)) { - itemListOverlayInternal.setKeyboardFocus(false); - return true; - } else if (itemListOverlayInternal.onKeyPressed(typedChar, eventKey)) { - return true; - } - } - - if (KeyBindings.toggleOverlay.isActiveAndMatches(eventKey)) { - Config.toggleOverlayEnabled(); - return false; - } - - if (itemListOverlayInternal != null) { - if (KeyBindings.toggleCheatMode.isActiveAndMatches(eventKey)) { - Config.toggleCheatItemsEnabled(); - return true; - } - - if (KeyBindings.focusSearch.isActiveAndMatches(eventKey)) { - itemListOverlayInternal.setKeyboardFocus(true); - return true; - } - } - - if (!isContainerTextFieldFocused()) { - final boolean showRecipe = KeyBindings.showRecipe.isActiveAndMatches(eventKey); - final boolean showUses = KeyBindings.showUses.isActiveAndMatches(eventKey); - if (showRecipe || showUses) { - IClickedIngredient clicked = getIngredientUnderMouseForKey(mouseHelper.getX(), mouseHelper.getY()); - if (clicked != null) { - IFocus.Mode mode = showRecipe ? IFocus.Mode.OUTPUT : IFocus.Mode.INPUT; - recipesGui.show(new Focus(mode, clicked.getValue())); - return true; - } - } - - if (itemListOverlayInternal != null && itemListOverlayInternal.onKeyPressed(typedChar, eventKey)) { - return true; - } - } - - return false; - } - - private boolean isContainerTextFieldFocused() { - GuiScreen gui = Minecraft.getMinecraft().currentScreen; - if (gui == null) { - return false; - } - GuiTextField textField = ReflectionUtil.getFieldWithClass(gui, GuiTextField.class); - return textField != null && textField.getVisible() && textField.isEnabled && textField.isFocused(); - } - - public static boolean isInventoryToggleKey(int keyCode) { - return Minecraft.getMinecraft().gameSettings.keyBindInventory.isActiveAndMatches(keyCode); - } - - public static boolean isInventoryCloseKey(int keyCode) { - return keyCode == Keyboard.KEY_ESCAPE; - } - - public static boolean isEnterKey(int keyCode) { - return keyCode == Keyboard.KEY_RETURN; - } + private final RecipeRegistry recipeRegistry; + private final IIngredientRegistry ingredientRegistry; + private final RecipesGui recipesGui; + @Nullable + private final ItemListOverlayInternal itemListOverlayInternal; + private final MouseHelper mouseHelper; + private final List showsRecipeFocuses = new ArrayList(); + private final IIngredientBookmarks ingredientBookmarks; + + private boolean clickHandled = false; + + public InputHandler(JeiRuntime runtime, @Nullable ItemListOverlayInternal itemListOverlayInternal) { + this.recipeRegistry = runtime.getRecipeRegistry(); + this.ingredientRegistry = runtime.getIngredientRegistry(); + this.recipesGui = runtime.getRecipesGui(); + this.itemListOverlayInternal = itemListOverlayInternal; + this.ingredientBookmarks = runtime.getIngredientBookmarks(); + + this.mouseHelper = new MouseHelper(); + + showsRecipeFocuses.add(recipesGui); + if (itemListOverlayInternal != null) { + showsRecipeFocuses.add(itemListOverlayInternal); + } + showsRecipeFocuses.add(new GuiContainerWrapper()); + } + + public boolean handleMouseEvent(GuiScreen guiScreen, int mouseX, int mouseY) { + boolean cancelEvent = false; + if (Mouse.getEventButton() > -1) { + if (Mouse.getEventButtonState()) { + if (!clickHandled) { + cancelEvent = handleMouseClick(guiScreen, Mouse.getEventButton(), mouseX, mouseY); + clickHandled = cancelEvent; + } + } else if (clickHandled) { + clickHandled = false; + cancelEvent = true; + } + } else if (Mouse.getEventDWheel() != 0) { + cancelEvent = handleMouseScroll(Mouse.getEventDWheel(), mouseX, mouseY); + } + return cancelEvent; + } + + private boolean handleMouseScroll(int dWheel, int mouseX, int mouseY) { + return itemListOverlayInternal != null && itemListOverlayInternal.handleMouseScrolled(mouseX, mouseY, dWheel); + } + + private boolean handleMouseClick(GuiScreen guiScreen, int mouseButton, int mouseX, int mouseY) { + if (itemListOverlayInternal != null && itemListOverlayInternal.handleMouseClicked(mouseX, mouseY, mouseButton)) { + return true; + } + + IClickedIngredient clicked = getFocusUnderMouseForClick(mouseX, mouseY); + if (clicked != null && handleMouseClickedFocus(mouseButton, clicked)) { + return true; + } + + if (guiScreen instanceof GuiContainer) { + GuiContainer guiContainer = (GuiContainer) guiScreen; + RecipeClickableArea clickableArea = recipeRegistry.getRecipeClickableArea(guiContainer, + mouseX - guiContainer.guiLeft, mouseY - guiContainer.guiTop); + if (clickableArea != null) { + List recipeCategoryUids = clickableArea.getRecipeCategoryUids(); + recipesGui.showCategories(recipeCategoryUids); + } + } + + return false; + } + + @Nullable + private IClickedIngredient getFocusUnderMouseForClick(int mouseX, int mouseY) { + for (IShowsRecipeFocuses gui : showsRecipeFocuses) { + if (gui.canSetFocusWithMouse()) { + IClickedIngredient clicked = gui.getIngredientUnderMouse(mouseX, mouseY); + if (clicked != null) { + return clicked; + } + } + } + return null; + } + + @Nullable + private IClickedIngredient getIngredientUnderMouseForKey(int mouseX, int mouseY) { + for (IShowsRecipeFocuses gui : showsRecipeFocuses) { + IClickedIngredient clicked = gui.getIngredientUnderMouse(mouseX, mouseY); + if (clicked != null) { + return clicked; + } + } + return null; + } + + private boolean handleMouseClickedFocus(int mouseButton, IClickedIngredient clicked) { + if (Config.isEditModeEnabled()) { + if (handleClickEdit(mouseButton, clicked.getValue())) { + return true; + } + } + + if (Config.isCheatItemsEnabled() && clicked.allowsCheating() && !recipesGui.isOpen()) { + Object focusValue = clicked.getValue(); + if (focusValue instanceof ItemStack) { + ItemStack itemStack = (ItemStack) focusValue; + CommandUtil.giveStack(itemStack, mouseButton); + return true; + } + } + + if (mouseButton == 0) { + IFocus focus = new Focus(IFocus.Mode.OUTPUT, clicked.getValue()); + recipesGui.show(focus); + return true; + } else if (mouseButton == 1) { + IFocus focus = new Focus(IFocus.Mode.INPUT, clicked.getValue()); + recipesGui.show(focus); + return true; + } + + return false; + } + + private boolean handleClickEdit(int mouseButton, V ingredient) { + Config.IngredientBlacklistType blacklistType = null; + if (GuiScreen.isCtrlKeyDown()) { + if (GuiScreen.isShiftKeyDown()) { + if (mouseButton == 0) { + blacklistType = Config.IngredientBlacklistType.MOD_ID; + } + } else { + if (mouseButton == 0) { + blacklistType = Config.IngredientBlacklistType.ITEM; + } else if (mouseButton == 1) { + blacklistType = Config.IngredientBlacklistType.WILDCARD; + } + } + } + + if (blacklistType == null) { + return false; + } + + IIngredientHelper ingredientHelper = ingredientRegistry.getIngredientHelper(ingredient); + + if (Config.isIngredientOnConfigBlacklist(ingredient, blacklistType, ingredientHelper)) { + Config.removeIngredientFromConfigBlacklist(ingredient, blacklistType, ingredientHelper); + } else { + Config.addIngredientToConfigBlacklist(ingredient, blacklistType, ingredientHelper); + } + return true; + } + + public boolean handleKeyEvent() { + char typedChar = Keyboard.getEventCharacter(); + int eventKey = Keyboard.getEventKey(); + + return ((eventKey == 0 && typedChar >= 32) || Keyboard.getEventKeyState()) && + handleKeyDown(typedChar, eventKey); + } + + private boolean handleKeyDown(char typedChar, int eventKey) { + if (itemListOverlayInternal != null && itemListOverlayInternal.hasKeyboardFocus()) { + if (isInventoryCloseKey(eventKey) || isEnterKey(eventKey)) { + itemListOverlayInternal.setKeyboardFocus(false); + return true; + } else if (itemListOverlayInternal.onKeyPressed(typedChar, eventKey)) { + return true; + } + } + + if (KeyBindings.toggleOverlay.isActiveAndMatches(eventKey)) { + Config.toggleOverlayEnabled(); + return false; + } + + if (itemListOverlayInternal != null) { + if (KeyBindings.toggleCheatMode.isActiveAndMatches(eventKey)) { + Config.toggleCheatItemsEnabled(); + return true; + } + + if (KeyBindings.focusSearch.isActiveAndMatches(eventKey)) { + itemListOverlayInternal.setKeyboardFocus(true); + return true; + } + } + + if (!isContainerTextFieldFocused()) { + final boolean showRecipe = KeyBindings.showRecipe.isActiveAndMatches(eventKey); + final boolean showUses = KeyBindings.showUses.isActiveAndMatches(eventKey); + final boolean toggleBookmark = KeyBindings.toggleBookmark.isActiveAndMatches(eventKey); + if (showRecipe || showUses) { + IClickedIngredient clicked = getIngredientUnderMouseForKey(mouseHelper.getX(), mouseHelper.getY()); + if (clicked != null) { + IFocus.Mode mode = showRecipe ? IFocus.Mode.OUTPUT : IFocus.Mode.INPUT; + recipesGui.show(new Focus(mode, clicked.getValue())); + return true; + } + } + + if (toggleBookmark) { + // get the bookmarks list and add or remove the clicked ingredient + IClickedIngredient clicked = getIngredientUnderMouseForKey(mouseHelper.getX(), mouseHelper.getY()); + if (clicked != null) { + ingredientBookmarks.toggleIngredientBookmark(clicked.getValue()); + } + return true; + } + + if (itemListOverlayInternal != null && itemListOverlayInternal.onKeyPressed(typedChar, eventKey)) { + return true; + } + } + + return false; + } + + private boolean isContainerTextFieldFocused() { + GuiScreen gui = Minecraft.getMinecraft().currentScreen; + if (gui == null) { + return false; + } + GuiTextField textField = ReflectionUtil.getFieldWithClass(gui, GuiTextField.class); + return textField != null && textField.getVisible() && textField.isEnabled && textField.isFocused(); + } + + public static boolean isInventoryToggleKey(int keyCode) { + return Minecraft.getMinecraft().gameSettings.keyBindInventory.isActiveAndMatches(keyCode); + } + + public static boolean isInventoryCloseKey(int keyCode) { + return keyCode == Keyboard.KEY_ESCAPE; + } + + public static boolean isEnterKey(int keyCode) { + return keyCode == Keyboard.KEY_RETURN; + } } From 81365d8574320f6069632b4f2abbf1d3c8235430 Mon Sep 17 00:00:00 2001 From: Michael Carver <4365312+shortcarver@users.noreply.github.com> Date: Wed, 2 Oct 2024 18:41:03 -0500 Subject: [PATCH 2/8] got it working --- src/main/java/mezz/jei/GuiEventHandler.java | 18 - .../mezz/jei/IngredientBaseListFactory.java | 248 ++-- .../java/mezz/jei/IngredientBookmarks.java | 64 +- src/main/java/mezz/jei/JeiRuntime.java | 13 +- src/main/java/mezz/jei/JeiStarter.java | 296 ++--- .../java/mezz/jei/api/IBookmarksOverlay.java | 15 - src/main/java/mezz/jei/api/IJeiRuntime.java | 2 - .../api/ingredients/IIngredientBookmarks.java | 8 +- .../java/mezz/jei/gui/BookmarksOverlay.java | 76 -- .../jei/gui/BookmarksOverlayInternal.java | 295 ----- .../java/mezz/jei/gui/ItemListOverlay.java | 238 ++-- .../mezz/jei/gui/ItemListOverlayInternal.java | 1111 +++++++++-------- .../ingredients/GuiIngredientFastList.java | 6 + .../java/mezz/jei/input/InputHandler.java | 3 +- 14 files changed, 1049 insertions(+), 1344 deletions(-) delete mode 100644 src/main/java/mezz/jei/api/IBookmarksOverlay.java delete mode 100644 src/main/java/mezz/jei/gui/BookmarksOverlay.java delete mode 100644 src/main/java/mezz/jei/gui/BookmarksOverlayInternal.java diff --git a/src/main/java/mezz/jei/GuiEventHandler.java b/src/main/java/mezz/jei/GuiEventHandler.java index e0cb35dbd..8fa6e0889 100644 --- a/src/main/java/mezz/jei/GuiEventHandler.java +++ b/src/main/java/mezz/jei/GuiEventHandler.java @@ -4,8 +4,6 @@ import mezz.jei.config.Config; import mezz.jei.config.OverlayToggleEvent; -import mezz.jei.gui.BookmarksOverlay; -import mezz.jei.gui.BookmarksOverlayInternal; import mezz.jei.gui.ItemListOverlay; import mezz.jei.gui.ItemListOverlayInternal; import mezz.jei.gui.TooltipRenderer; @@ -49,8 +47,6 @@ private void onNewScreen(@Nullable GuiScreen screen) { if (screen instanceof GuiContainer || screen instanceof RecipesGui) { ItemListOverlay itemListOverlay = runtime.getItemListOverlay(); ItemListOverlayInternal itemListOverlayInternal = itemListOverlay.create(screen); - BookmarksOverlay bookmarksOverlay = runtime.getBookmarksOverlay(); - BookmarksOverlayInternal bookmarksOverlayInternal = bookmarksOverlay.create(screen); inputHandler = new InputHandler(runtime, itemListOverlayInternal); } else { inputHandler = null; @@ -93,20 +89,6 @@ public void onDrawBackgroundEventPost(GuiScreenEvent.BackgroundDrawnEvent event) itemListOverlayInternal.drawScreen(gui.mc, event.getMouseX(), event.getMouseY()); } } - BookmarksOverlay bookmarksOverlay = runtime.getBookmarksOverlay(); - BookmarksOverlayInternal bookmarksOverlayInternal = bookmarksOverlay.getInternal(); - if (bookmarksOverlayInternal != null) { - GuiScreen gui = event.getGui(); - if (bookmarksOverlayInternal.hasScreenChanged(gui)) { - bookmarksOverlayInternal = bookmarksOverlay.create(gui); - // TODO: inputHandler = new InputHandler(runtime, bookmarksOverlayInternal); - } - - if (bookmarksOverlayInternal != null) { - bookmarksOverlayInternal.drawScreen(gui.mc, event.getMouseX(), event.getMouseY()); - } - } - } @SubscribeEvent diff --git a/src/main/java/mezz/jei/IngredientBaseListFactory.java b/src/main/java/mezz/jei/IngredientBaseListFactory.java index 2ee8eddf1..3ae6a2e9f 100644 --- a/src/main/java/mezz/jei/IngredientBaseListFactory.java +++ b/src/main/java/mezz/jei/IngredientBaseListFactory.java @@ -20,127 +20,129 @@ import net.minecraft.item.ItemStack; public class IngredientBaseListFactory { - private IngredientBaseListFactory() { - - } - - public static ImmutableList create() { - Log.info("Building item filter..."); - long start_time = System.currentTimeMillis(); - - IIngredientRegistry ingredientRegistry = Internal.getIngredientRegistry(); - JeiHelpers jeiHelpers = Internal.getHelpers(); - IngredientChecker ingredientChecker = new IngredientChecker(jeiHelpers); - - List ingredientListElements = new LinkedList(); - - for (Class ingredientClass : ingredientRegistry.getRegisteredIngredientClasses()) { - addToBaseList(ingredientListElements, ingredientRegistry, ingredientChecker, ingredientClass); - } - - sortIngredientListElements(ingredientListElements); - ImmutableList immutableElements = ImmutableList.copyOf(ingredientListElements); - - Log.info("Built item filter in {} ms", System.currentTimeMillis() - start_time); - return immutableElements; - } - - private static void addToBaseList(List baseList, IIngredientRegistry ingredientRegistry, IngredientChecker ingredientChecker, Class ingredientClass) { - IIngredientHelper ingredientHelper = ingredientRegistry.getIngredientHelper(ingredientClass); - IIngredientRenderer ingredientRenderer = ingredientRegistry.getIngredientRenderer(ingredientClass); - - ImmutableList ingredients = ingredientRegistry.getIngredients(ingredientClass); - for (V ingredient : ingredients) { - if (ingredient != null) { - if (!ingredientChecker.isIngredientHidden(ingredient, ingredientHelper)) { - IngredientListElement ingredientListElement = IngredientListElement.create(ingredient, ingredientHelper, ingredientRenderer); - if (ingredientListElement != null) { - baseList.add(ingredientListElement); - } - } - } - } - } - - private static void sortIngredientListElements(List ingredientListElements) { - int index = 0; - final Map itemAddedOrder = new HashMap(); - for (IIngredientListElement ingredientListElement : ingredientListElements) { - String uid = getWildcardUid(ingredientListElement); - if (!itemAddedOrder.containsKey(uid)) { - itemAddedOrder.put(uid, index); - index++; - } - } - - Collections.sort(ingredientListElements, new Comparator() { - @Override - public int compare(IIngredientListElement o1, IIngredientListElement o2) { - final String modName1 = getModName(o1); - final String modName2 = getModName(o2); - - if (modName1.equals(modName2)) { - boolean isItemStack1 = (o1.getIngredient() instanceof ItemStack); - boolean isItemStack2 = (o2.getIngredient() instanceof ItemStack); - if (isItemStack1 && !isItemStack2) { - return -1; - } else if (!isItemStack1 && isItemStack2) { - return 1; - } - - final String uid1 = getWildcardUid(o1); - final String uid2 = getWildcardUid(o2); - - final int orderIndex1 = itemAddedOrder.get(uid1); - final int orderIndex2 = itemAddedOrder.get(uid2); - return Java6Helper.compare(orderIndex1, orderIndex2); - } else if (modName1.equals(Constants.minecraftModName)) { - return -1; - } else if (modName2.equals(Constants.minecraftModName)) { - return 1; - } else { - return modName1.compareTo(modName2); - } - } - }); - } - - private static String getModName(IIngredientListElement ingredientListElement) { - V ingredient = ingredientListElement.getIngredient(); - IIngredientHelper ingredientHelper = ingredientListElement.getIngredientHelper(); - String modId = ingredientHelper.getModId(ingredient); - return Internal.getModIdUtil().getModNameForModId(modId); - } - - private static String getWildcardUid(IIngredientListElement ingredientListElement) { - V ingredient = ingredientListElement.getIngredient(); - IIngredientHelper ingredientHelper = ingredientListElement.getIngredientHelper(); - return ingredientHelper.getWildcardId(ingredient); - } - - private static class IngredientChecker { - private final IngredientBlacklist ingredientBlacklist; - - public IngredientChecker(JeiHelpers jeiHelpers) { - ingredientBlacklist = jeiHelpers.getIngredientBlacklist(); - } - - public boolean isIngredientHidden(V ingredient, IIngredientHelper ingredientHelper) { - try { - if (ingredientBlacklist.isIngredientBlacklistedByApi(ingredient)) { - return true; - } - - if (!Config.isEditModeEnabled() && Config.isIngredientOnConfigBlacklist(ingredient, ingredientHelper)) { - return true; - } - } catch (RuntimeException e) { - String ingredientInfo = ingredientHelper.getErrorInfo(ingredient); - Log.error("Could not check blacklist for ingredient {}", ingredientInfo, e); - return true; - } - - return false; - } - } + private IngredientBaseListFactory() { + + } + + public static ImmutableList create() { + Log.info("Building item filter..."); + long start_time = System.currentTimeMillis(); + + IIngredientRegistry ingredientRegistry = Internal.getIngredientRegistry(); + JeiHelpers jeiHelpers = Internal.getHelpers(); + IngredientChecker ingredientChecker = new IngredientChecker(jeiHelpers); + + List ingredientListElements = new LinkedList(); + + for (Class ingredientClass : ingredientRegistry.getRegisteredIngredientClasses()) { + addToBaseList(ingredientListElements, ingredientRegistry, ingredientChecker, ingredientClass); + } + + sortIngredientListElements(ingredientListElements); + ImmutableList immutableElements = ImmutableList.copyOf(ingredientListElements); + + Log.info("Built item filter in {} ms", System.currentTimeMillis() - start_time); + return immutableElements; + } + + private static void addToBaseList(List baseList, IIngredientRegistry ingredientRegistry, + IngredientChecker ingredientChecker, Class ingredientClass) { + IIngredientHelper ingredientHelper = ingredientRegistry.getIngredientHelper(ingredientClass); + IIngredientRenderer ingredientRenderer = ingredientRegistry.getIngredientRenderer(ingredientClass); + + ImmutableList ingredients = ingredientRegistry.getIngredients(ingredientClass); + for (V ingredient : ingredients) { + if (ingredient != null) { + if (!ingredientChecker.isIngredientHidden(ingredient, ingredientHelper)) { + IngredientListElement ingredientListElement = IngredientListElement.create(ingredient, ingredientHelper, + ingredientRenderer); + if (ingredientListElement != null) { + baseList.add(ingredientListElement); + } + } + } + } + } + + private static void sortIngredientListElements(List ingredientListElements) { + int index = 0; + final Map itemAddedOrder = new HashMap(); + for (IIngredientListElement ingredientListElement : ingredientListElements) { + String uid = getWildcardUid(ingredientListElement); + if (!itemAddedOrder.containsKey(uid)) { + itemAddedOrder.put(uid, index); + index++; + } + } + + Collections.sort(ingredientListElements, new Comparator() { + @Override + public int compare(IIngredientListElement o1, IIngredientListElement o2) { + final String modName1 = getModName(o1); + final String modName2 = getModName(o2); + + if (modName1.equals(modName2)) { + boolean isItemStack1 = (o1.getIngredient() instanceof ItemStack); + boolean isItemStack2 = (o2.getIngredient() instanceof ItemStack); + if (isItemStack1 && !isItemStack2) { + return -1; + } else if (!isItemStack1 && isItemStack2) { + return 1; + } + + final String uid1 = getWildcardUid(o1); + final String uid2 = getWildcardUid(o2); + + final int orderIndex1 = itemAddedOrder.get(uid1); + final int orderIndex2 = itemAddedOrder.get(uid2); + return Java6Helper.compare(orderIndex1, orderIndex2); + } else if (modName1.equals(Constants.minecraftModName)) { + return -1; + } else if (modName2.equals(Constants.minecraftModName)) { + return 1; + } else { + return modName1.compareTo(modName2); + } + } + }); + } + + private static String getModName(IIngredientListElement ingredientListElement) { + V ingredient = ingredientListElement.getIngredient(); + IIngredientHelper ingredientHelper = ingredientListElement.getIngredientHelper(); + String modId = ingredientHelper.getModId(ingredient); + return Internal.getModIdUtil().getModNameForModId(modId); + } + + private static String getWildcardUid(IIngredientListElement ingredientListElement) { + V ingredient = ingredientListElement.getIngredient(); + IIngredientHelper ingredientHelper = ingredientListElement.getIngredientHelper(); + return ingredientHelper.getWildcardId(ingredient); + } + + private static class IngredientChecker { + private final IngredientBlacklist ingredientBlacklist; + + public IngredientChecker(JeiHelpers jeiHelpers) { + ingredientBlacklist = jeiHelpers.getIngredientBlacklist(); + } + + public boolean isIngredientHidden(V ingredient, IIngredientHelper ingredientHelper) { + try { + if (ingredientBlacklist.isIngredientBlacklistedByApi(ingredient)) { + return true; + } + + if (!Config.isEditModeEnabled() && Config.isIngredientOnConfigBlacklist(ingredient, ingredientHelper)) { + return true; + } + } catch (RuntimeException e) { + String ingredientInfo = ingredientHelper.getErrorInfo(ingredient); + Log.error("Could not check blacklist for ingredient {}", ingredientInfo, e); + return true; + } + + return false; + } + } } diff --git a/src/main/java/mezz/jei/IngredientBookmarks.java b/src/main/java/mezz/jei/IngredientBookmarks.java index 78072166e..592bbc984 100644 --- a/src/main/java/mezz/jei/IngredientBookmarks.java +++ b/src/main/java/mezz/jei/IngredientBookmarks.java @@ -1,35 +1,79 @@ package mezz.jei; +import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; import mezz.jei.api.ingredients.IIngredientBookmarks; import mezz.jei.api.ingredients.IIngredientHelper; import mezz.jei.api.ingredients.IIngredientRegistry; +import mezz.jei.api.ingredients.IIngredientRenderer; +import mezz.jei.gui.ingredients.IIngredientListElement; +import mezz.jei.util.IngredientListElement; +import com.google.common.collect.ImmutableCollection; +import com.google.common.collect.ImmutableList; public class IngredientBookmarks implements IIngredientBookmarks { private final IIngredientRegistry ingredientRegistry; - private HashSet bookmarkList = new HashSet(); + private List bookmarkIds = new LinkedList(); + private HashMap bookmarkList = new HashMap(); public IngredientBookmarks(IIngredientRegistry ingredientRegistry) { this.ingredientRegistry = ingredientRegistry; } @Override - public void toggleIngredientBookmark(Object ingredient) { - IIngredientHelper ingredientHelper = ingredientRegistry.getIngredientHelper(ingredient); + public void toggleIngredientBookmark(V ingredient) { + IIngredientHelper ingredientHelper = ingredientRegistry.getIngredientHelper(ingredient); String uniqueId = ingredientHelper.getUniqueId(ingredient); - // System.out.println(ingredientHelper.getUniqueId(ingredient)); - if (bookmarkList.contains(uniqueId)) { + + // find ingredient in registry + ImmutableCollection clazzes = ingredientRegistry.getRegisteredIngredientClasses(); + for (Class clazz: clazzes) { + ImmutableList iList = ingredientRegistry.getIngredients(clazz); + IIngredientHelper iHelper = ingredientRegistry.getIngredientHelper(clazz); + for (V i: iList) { + if (iHelper.getUniqueId(i).equals(uniqueId)) { + ingredient = i; + break; + } + } + } + + // System.out.println(ingredientHelper.getUniqueId(ingredient)); + if (bookmarkIds.contains(uniqueId)){ + bookmarkIds.remove(uniqueId); bookmarkList.remove(uniqueId); } else { - bookmarkList.add(uniqueId); + bookmarkIds.add(uniqueId); + bookmarkList.put(uniqueId, ingredient); } + } + + @Override + public List getIngredientList() { + List ingredientListElements = new LinkedList(); + + for (String uniqueId : bookmarkIds) { + Object ingredient = bookmarkList.get(uniqueId); - Iterator iterator = bookmarkList.iterator(); - System.out.println("Dumping bookmarks"); - while(iterator.hasNext()) { - System.out.println(iterator.next()); + IIngredientHelper ingredientHelper = ingredientRegistry.getIngredientHelper(ingredient); + IIngredientRenderer ingredientRenderer = ingredientRegistry.getIngredientRenderer(ingredient); + IngredientListElement ingredientListElement = IngredientListElement.create(ingredient, ingredientHelper, + ingredientRenderer); + if (ingredientListElement != null) { + ingredientListElements.add(ingredientListElement); + } } + return ingredientListElements; + } + + @Override + public void clear(){ + bookmarkIds.clear(); + bookmarkList.clear(); } } diff --git a/src/main/java/mezz/jei/JeiRuntime.java b/src/main/java/mezz/jei/JeiRuntime.java index d266399f4..61c040a1a 100644 --- a/src/main/java/mezz/jei/JeiRuntime.java +++ b/src/main/java/mezz/jei/JeiRuntime.java @@ -6,7 +6,6 @@ import mezz.jei.api.IJeiRuntime; import mezz.jei.api.gui.IAdvancedGuiHandler; import mezz.jei.api.ingredients.IIngredientBookmarks; -import mezz.jei.gui.BookmarksOverlay; import mezz.jei.gui.ItemListOverlay; import mezz.jei.gui.recipes.RecipesGui; import net.minecraft.client.gui.GuiScreen; @@ -16,7 +15,6 @@ public class JeiRuntime implements IJeiRuntime { private final RecipeRegistry recipeRegistry; private final ItemListOverlay itemListOverlay; - private final BookmarksOverlay bookmarksOverlay; private final RecipesGui recipesGui; private final IngredientRegistry ingredientRegistry; private final List> advancedGuiHandlers; @@ -24,23 +22,19 @@ public class JeiRuntime implements IJeiRuntime { public JeiRuntime(RecipeRegistry recipeRegistry, ItemListOverlay itemListOverlay, RecipesGui recipesGui, IngredientRegistry ingredientRegistry, List> advancedGuiHandlers, - IngredientBookmarks ingredientBookmarks, BookmarksOverlay bookmarksOverlay) { + IngredientBookmarks ingredientBookmarks) { this.recipeRegistry = recipeRegistry; this.itemListOverlay = itemListOverlay; this.recipesGui = recipesGui; this.ingredientRegistry = ingredientRegistry; this.advancedGuiHandlers = advancedGuiHandlers; this.ingredientBookmarks = ingredientBookmarks; - this.bookmarksOverlay = bookmarksOverlay; } public void close() { if (itemListOverlay.isOpen()) { itemListOverlay.close(); } - if (bookmarksOverlay.isOpen()) { - bookmarksOverlay.close(); - } if (recipesGui.isOpen()) { recipesGui.close(); } @@ -56,11 +50,6 @@ public ItemListOverlay getItemListOverlay() { return itemListOverlay; } - @Override - public BookmarksOverlay getBookmarksOverlay() { - return bookmarksOverlay; - } - @Override public RecipesGui getRecipesGui() { return recipesGui; diff --git a/src/main/java/mezz/jei/JeiStarter.java b/src/main/java/mezz/jei/JeiStarter.java index a8ca0c262..1bf589606 100644 --- a/src/main/java/mezz/jei/JeiStarter.java +++ b/src/main/java/mezz/jei/JeiStarter.java @@ -7,7 +7,6 @@ import mezz.jei.api.IJeiRuntime; import mezz.jei.api.IModPlugin; import mezz.jei.api.gui.IAdvancedGuiHandler; -import mezz.jei.gui.BookmarksOverlay; import mezz.jei.gui.ItemListOverlay; import mezz.jei.gui.recipes.RecipesGui; import mezz.jei.plugins.vanilla.VanillaPlugin; @@ -19,165 +18,166 @@ import net.minecraftforge.fml.common.ProgressManager; public class JeiStarter { - private boolean started; - @Nullable - private GuiEventHandler guiEventHandler; + private boolean started; + @Nullable + private GuiEventHandler guiEventHandler; - public void start(List plugins, boolean resourceReload) { - long jeiStartTime = System.currentTimeMillis(); + public void start(List plugins, boolean resourceReload) { + long jeiStartTime = System.currentTimeMillis(); - Log.info("Starting JEI..."); - SubtypeRegistry subtypeRegistry = new SubtypeRegistry(); + Log.info("Starting JEI..."); + SubtypeRegistry subtypeRegistry = new SubtypeRegistry(); - registerItemSubtypes(plugins, subtypeRegistry); + registerItemSubtypes(plugins, subtypeRegistry); - StackHelper stackHelper = new StackHelper(subtypeRegistry); - stackHelper.enableUidCache(); - Internal.setStackHelper(stackHelper); + StackHelper stackHelper = new StackHelper(subtypeRegistry); + stackHelper.enableUidCache(); + Internal.setStackHelper(stackHelper); - IngredientRegistry ingredientRegistry = registerIngredients(plugins); - Internal.setIngredientRegistry(ingredientRegistry); + IngredientRegistry ingredientRegistry = registerIngredients(plugins); + Internal.setIngredientRegistry(ingredientRegistry); - JeiHelpers jeiHelpers = new JeiHelpers(ingredientRegistry, stackHelper, subtypeRegistry); - Internal.setHelpers(jeiHelpers); + JeiHelpers jeiHelpers = new JeiHelpers(ingredientRegistry, stackHelper, subtypeRegistry); + Internal.setHelpers(jeiHelpers); - ModIdUtil modIdUtil = Internal.getModIdUtil(); - ItemRegistry itemRegistry = new ItemRegistry(ingredientRegistry, modIdUtil); + ModIdUtil modIdUtil = Internal.getModIdUtil(); + ItemRegistry itemRegistry = new ItemRegistry(ingredientRegistry, modIdUtil); - ModRegistry modRegistry = new ModRegistry(jeiHelpers, itemRegistry, ingredientRegistry); + ModRegistry modRegistry = new ModRegistry(jeiHelpers, itemRegistry, ingredientRegistry); - registerPlugins(plugins, modRegistry); + registerPlugins(plugins, modRegistry); - Log.info("Building recipe registry..."); - long start_time = System.currentTimeMillis(); - RecipeRegistry recipeRegistry = modRegistry.createRecipeRegistry(stackHelper, ingredientRegistry); - Log.info("Built recipe registry in {} ms", System.currentTimeMillis() - start_time); + Log.info("Building recipe registry..."); + long start_time = System.currentTimeMillis(); + RecipeRegistry recipeRegistry = modRegistry.createRecipeRegistry(stackHelper, ingredientRegistry); + Log.info("Built recipe registry in {} ms", System.currentTimeMillis() - start_time); - IngredientInformation.onStart(resourceReload); + IngredientInformation.onStart(resourceReload); - ItemFilter itemFilter = new ItemFilter(); + ItemFilter itemFilter = new ItemFilter(); - Log.info("Building runtime..."); - start_time = System.currentTimeMillis(); - List> advancedGuiHandlers = modRegistry.getAdvancedGuiHandlers(); - ItemListOverlay itemListOverlay = new ItemListOverlay(itemFilter, advancedGuiHandlers, ingredientRegistry); - BookmarksOverlay bookmarksOverlay = new BookmarksOverlay(advancedGuiHandlers, ingredientRegistry); - RecipesGui recipesGui = new RecipesGui(recipeRegistry); + Log.info("Building runtime..."); + start_time = System.currentTimeMillis(); IngredientBookmarks ingredientBookmarks = new IngredientBookmarks(ingredientRegistry); - JeiRuntime jeiRuntime = new JeiRuntime(recipeRegistry, itemListOverlay, recipesGui, ingredientRegistry, advancedGuiHandlers, ingredientBookmarks, bookmarksOverlay); - Internal.setRuntime(jeiRuntime); - Log.info("Built runtime in {} ms", System.currentTimeMillis() - start_time); - - stackHelper.disableUidCache(); - - sendRuntime(plugins, jeiRuntime); - - if (guiEventHandler != null) { - MinecraftForge.EVENT_BUS.unregister(guiEventHandler); - } - guiEventHandler = new GuiEventHandler(jeiRuntime); - MinecraftForge.EVENT_BUS.register(guiEventHandler); - - started = true; - Log.info("Finished Starting JEI in {} ms", System.currentTimeMillis() - jeiStartTime); - } - - public boolean hasStarted() { - return started; - } - - private static void registerItemSubtypes(List plugins, SubtypeRegistry subtypeRegistry) { - ProgressManager.ProgressBar progressBar = ProgressManager.push("Registering item subtypes", plugins.size()); - Iterator iterator = plugins.iterator(); - while (iterator.hasNext()) { - IModPlugin plugin = iterator.next(); - try { - progressBar.step(plugin.getClass().getName()); - plugin.registerItemSubtypes(subtypeRegistry); - } catch (RuntimeException e) { - Log.error("Failed to register item subtypes for mod plugin: {}", plugin.getClass(), e); - iterator.remove(); - } catch (AbstractMethodError ignored) { - // legacy mod plugins do not have registerItemSubtypes - } - } - ProgressManager.pop(progressBar); - } - - private static IngredientRegistry registerIngredients(List plugins) { - ProgressManager.ProgressBar progressBar = ProgressManager.push("Registering ingredients", plugins.size()); - ModIngredientRegistration modIngredientRegistry = new ModIngredientRegistration(); - - Iterator iterator = plugins.iterator(); - while (iterator.hasNext()) { - IModPlugin plugin = iterator.next(); - try { - progressBar.step(plugin.getClass().getName()); - plugin.registerIngredients(modIngredientRegistry); - } catch (RuntimeException e) { - if (VanillaPlugin.class.isInstance(plugin)) { - throw e; - } else { - Log.error("Failed to register Ingredients for mod plugin: {}", plugin.getClass(), e); - iterator.remove(); - } - } catch (AbstractMethodError ignored) { - if (VanillaPlugin.class.isInstance(plugin)) { - throw ignored; - } - // legacy mod plugins do not have registerIngredients - } - } - ProgressManager.pop(progressBar); - - return modIngredientRegistry.createIngredientRegistry(); - } - - private static void registerPlugins(List plugins, ModRegistry modRegistry) { - ProgressManager.ProgressBar progressBar = ProgressManager.push("Registering plugins", plugins.size()); - Iterator iterator = plugins.iterator(); - while (iterator.hasNext()) { - IModPlugin plugin = iterator.next(); - try { - progressBar.step(plugin.getClass().getName()); - long start_time = System.currentTimeMillis(); - Log.info("Registering plugin: {} ...", plugin.getClass().getName()); - plugin.register(modRegistry); - long timeElapsedMs = System.currentTimeMillis() - start_time; - Log.info("Registered plugin: {} in {} ms", plugin.getClass().getName(), timeElapsedMs); - } catch (RuntimeException e) { - Log.error("Failed to register mod plugin: {}", plugin.getClass(), e); - iterator.remove(); - } catch (LinkageError e) { - Log.error("Failed to register mod plugin: {}", plugin.getClass(), e); - iterator.remove(); - } - } - ProgressManager.pop(progressBar); - } - - private static void sendRuntime(List plugins, IJeiRuntime jeiRuntime) { - ProgressManager.ProgressBar progressBar = ProgressManager.push("Sending Runtime", plugins.size()); - Iterator iterator = plugins.iterator(); - while (iterator.hasNext()) { - IModPlugin plugin = iterator.next(); - try { - progressBar.step(plugin.getClass().getName()); - long start_time = System.currentTimeMillis(); - Log.info("Sending runtime to plugin: {} ...", plugin.getClass().getName()); - plugin.onRuntimeAvailable(jeiRuntime); - long timeElapsedMs = System.currentTimeMillis() - start_time; - if (timeElapsedMs > 100) { - Log.warning("Sending runtime to plugin: {} took {} ms", plugin.getClass().getName(), timeElapsedMs); - } - } catch (RuntimeException e) { - Log.error("Sending runtime to plugin failed: {}", plugin.getClass(), e); - iterator.remove(); - } catch (LinkageError e) { - Log.error("Sending runtime to plugin failed: {}", plugin.getClass(), e); - iterator.remove(); - } - } - ProgressManager.pop(progressBar); - } + List> advancedGuiHandlers = modRegistry.getAdvancedGuiHandlers(); + ItemListOverlay itemListOverlay = new ItemListOverlay(itemFilter, advancedGuiHandlers, ingredientRegistry, + ingredientBookmarks); + RecipesGui recipesGui = new RecipesGui(recipeRegistry); + JeiRuntime jeiRuntime = new JeiRuntime(recipeRegistry, itemListOverlay, recipesGui, ingredientRegistry, + advancedGuiHandlers, ingredientBookmarks); + Internal.setRuntime(jeiRuntime); + Log.info("Built runtime in {} ms", System.currentTimeMillis() - start_time); + + stackHelper.disableUidCache(); + + sendRuntime(plugins, jeiRuntime); + + if (guiEventHandler != null) { + MinecraftForge.EVENT_BUS.unregister(guiEventHandler); + } + guiEventHandler = new GuiEventHandler(jeiRuntime); + MinecraftForge.EVENT_BUS.register(guiEventHandler); + + started = true; + Log.info("Finished Starting JEI in {} ms", System.currentTimeMillis() - jeiStartTime); + } + + public boolean hasStarted() { + return started; + } + + private static void registerItemSubtypes(List plugins, SubtypeRegistry subtypeRegistry) { + ProgressManager.ProgressBar progressBar = ProgressManager.push("Registering item subtypes", plugins.size()); + Iterator iterator = plugins.iterator(); + while (iterator.hasNext()) { + IModPlugin plugin = iterator.next(); + try { + progressBar.step(plugin.getClass().getName()); + plugin.registerItemSubtypes(subtypeRegistry); + } catch (RuntimeException e) { + Log.error("Failed to register item subtypes for mod plugin: {}", plugin.getClass(), e); + iterator.remove(); + } catch (AbstractMethodError ignored) { + // legacy mod plugins do not have registerItemSubtypes + } + } + ProgressManager.pop(progressBar); + } + + private static IngredientRegistry registerIngredients(List plugins) { + ProgressManager.ProgressBar progressBar = ProgressManager.push("Registering ingredients", plugins.size()); + ModIngredientRegistration modIngredientRegistry = new ModIngredientRegistration(); + + Iterator iterator = plugins.iterator(); + while (iterator.hasNext()) { + IModPlugin plugin = iterator.next(); + try { + progressBar.step(plugin.getClass().getName()); + plugin.registerIngredients(modIngredientRegistry); + } catch (RuntimeException e) { + if (VanillaPlugin.class.isInstance(plugin)) { + throw e; + } else { + Log.error("Failed to register Ingredients for mod plugin: {}", plugin.getClass(), e); + iterator.remove(); + } + } catch (AbstractMethodError ignored) { + if (VanillaPlugin.class.isInstance(plugin)) { + throw ignored; + } + // legacy mod plugins do not have registerIngredients + } + } + ProgressManager.pop(progressBar); + + return modIngredientRegistry.createIngredientRegistry(); + } + + private static void registerPlugins(List plugins, ModRegistry modRegistry) { + ProgressManager.ProgressBar progressBar = ProgressManager.push("Registering plugins", plugins.size()); + Iterator iterator = plugins.iterator(); + while (iterator.hasNext()) { + IModPlugin plugin = iterator.next(); + try { + progressBar.step(plugin.getClass().getName()); + long start_time = System.currentTimeMillis(); + Log.info("Registering plugin: {} ...", plugin.getClass().getName()); + plugin.register(modRegistry); + long timeElapsedMs = System.currentTimeMillis() - start_time; + Log.info("Registered plugin: {} in {} ms", plugin.getClass().getName(), timeElapsedMs); + } catch (RuntimeException e) { + Log.error("Failed to register mod plugin: {}", plugin.getClass(), e); + iterator.remove(); + } catch (LinkageError e) { + Log.error("Failed to register mod plugin: {}", plugin.getClass(), e); + iterator.remove(); + } + } + ProgressManager.pop(progressBar); + } + + private static void sendRuntime(List plugins, IJeiRuntime jeiRuntime) { + ProgressManager.ProgressBar progressBar = ProgressManager.push("Sending Runtime", plugins.size()); + Iterator iterator = plugins.iterator(); + while (iterator.hasNext()) { + IModPlugin plugin = iterator.next(); + try { + progressBar.step(plugin.getClass().getName()); + long start_time = System.currentTimeMillis(); + Log.info("Sending runtime to plugin: {} ...", plugin.getClass().getName()); + plugin.onRuntimeAvailable(jeiRuntime); + long timeElapsedMs = System.currentTimeMillis() - start_time; + if (timeElapsedMs > 100) { + Log.warning("Sending runtime to plugin: {} took {} ms", plugin.getClass().getName(), timeElapsedMs); + } + } catch (RuntimeException e) { + Log.error("Sending runtime to plugin failed: {}", plugin.getClass(), e); + iterator.remove(); + } catch (LinkageError e) { + Log.error("Sending runtime to plugin failed: {}", plugin.getClass(), e); + iterator.remove(); + } + } + ProgressManager.pop(progressBar); + } } diff --git a/src/main/java/mezz/jei/api/IBookmarksOverlay.java b/src/main/java/mezz/jei/api/IBookmarksOverlay.java deleted file mode 100644 index 189ba30d5..000000000 --- a/src/main/java/mezz/jei/api/IBookmarksOverlay.java +++ /dev/null @@ -1,15 +0,0 @@ -package mezz.jei.api; - -import javax.annotation.Nullable; -import java.util.Collection; - -import com.google.common.collect.ImmutableList; -import net.minecraft.item.ItemStack; - -public interface IBookmarksOverlay { - /** - * @return the stack that's currently under the mouse, or null if there is none - */ - @Nullable - ItemStack getStackUnderMouse(); -} diff --git a/src/main/java/mezz/jei/api/IJeiRuntime.java b/src/main/java/mezz/jei/api/IJeiRuntime.java index c7999048b..9d876b453 100644 --- a/src/main/java/mezz/jei/api/IJeiRuntime.java +++ b/src/main/java/mezz/jei/api/IJeiRuntime.java @@ -9,8 +9,6 @@ public interface IJeiRuntime { IItemListOverlay getItemListOverlay(); - IBookmarksOverlay getBookmarksOverlay(); - /** * @since JEI 3.2.12 */ diff --git a/src/main/java/mezz/jei/api/ingredients/IIngredientBookmarks.java b/src/main/java/mezz/jei/api/ingredients/IIngredientBookmarks.java index 5de94e90a..5fd54521a 100644 --- a/src/main/java/mezz/jei/api/ingredients/IIngredientBookmarks.java +++ b/src/main/java/mezz/jei/api/ingredients/IIngredientBookmarks.java @@ -1,6 +1,9 @@ package mezz.jei.api.ingredients; +import java.util.List; + import mezz.jei.api.IJeiHelpers; +import mezz.jei.gui.ingredients.IIngredientListElement; /** * The Ingredient bookmaks allows mods add and remove ingredients from JEI's @@ -13,6 +16,9 @@ public interface IIngredientBookmarks { /** * Toggles visibility of ingredient in the bookmark list. */ - void toggleIngredientBookmark(Object ingredient); + void toggleIngredientBookmark(V ingredient); + + List getIngredientList(); + void clear(); } diff --git a/src/main/java/mezz/jei/gui/BookmarksOverlay.java b/src/main/java/mezz/jei/gui/BookmarksOverlay.java deleted file mode 100644 index 740566665..000000000 --- a/src/main/java/mezz/jei/gui/BookmarksOverlay.java +++ /dev/null @@ -1,76 +0,0 @@ -package mezz.jei.gui; - -import javax.annotation.Nullable; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import com.google.common.collect.ImmutableList; -import mezz.jei.ItemFilter; -import mezz.jei.api.IBookmarksOverlay; -import mezz.jei.api.IItemListOverlay; -import mezz.jei.api.gui.IAdvancedGuiHandler; -import mezz.jei.api.ingredients.IIngredientRegistry; -import mezz.jei.config.Config; -import mezz.jei.util.Log; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.item.ItemStack; - -public class BookmarksOverlay implements IBookmarksOverlay { - private final List> advancedGuiHandlers; - @Nullable - private BookmarksOverlayInternal internal; - private final IIngredientRegistry ingredientRegistry; - - public BookmarksOverlay(List> advancedGuiHandlers, IIngredientRegistry ingredientRegistry) { - this.advancedGuiHandlers = advancedGuiHandlers; - this.ingredientRegistry = ingredientRegistry; - } - - @Nullable - @Override - public ItemStack getStackUnderMouse() { - if (internal != null) { - return internal.getStackUnderMouse(); - } - return null; - } - - public List> getAdvancedGuiHandlers() { - return advancedGuiHandlers; - } - - public boolean isOpen() { - return internal != null; - } - - public void close() { - if (internal != null) { - internal.close(); - } - internal = null; - } - - public BookmarksOverlayInternal getInternal() { - return internal; - } - - - public BookmarksOverlayInternal create(GuiScreen guiScreen) { - close(); - - if (Config.isOverlayEnabled()) { - GuiProperties guiProperties = GuiProperties.create(guiScreen); - if (guiProperties != null) { - final int columns = BookmarksOverlayInternal.getColumns(guiProperties); - if (columns >= 4) { - internal = new BookmarksOverlayInternal(this, ingredientRegistry, guiScreen, guiProperties); - return internal; - } - } - } - - return null; - } -} diff --git a/src/main/java/mezz/jei/gui/BookmarksOverlayInternal.java b/src/main/java/mezz/jei/gui/BookmarksOverlayInternal.java deleted file mode 100644 index 739633808..000000000 --- a/src/main/java/mezz/jei/gui/BookmarksOverlayInternal.java +++ /dev/null @@ -1,295 +0,0 @@ -package mezz.jei.gui; - -import java.awt.Rectangle; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import mezz.jei.Internal; -import mezz.jei.api.gui.IAdvancedGuiHandler; -import mezz.jei.api.gui.IDrawable; -import mezz.jei.api.ingredients.IIngredientRegistry; -import mezz.jei.config.Config; -import mezz.jei.gui.ingredients.GuiIngredientFast; -import mezz.jei.gui.ingredients.GuiIngredientFastList; -import mezz.jei.gui.ingredients.GuiItemStackGroup; -import mezz.jei.input.ClickedIngredient; -import mezz.jei.input.IClickedIngredient; -import mezz.jei.input.IKeyable; -import mezz.jei.input.IMouseHandler; -import mezz.jei.input.IShowsRecipeFocuses; -import mezz.jei.util.Java6Helper; -import mezz.jei.util.StackHelper; -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ChatAllowedCharacters; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.text.TextFormatting; - -public class BookmarksOverlayInternal implements IShowsRecipeFocuses, IMouseHandler, IKeyable { - - private static final int borderPadding = 2; - private static final int searchHeight = 16; - private static final int buttonSize = 20; - private static final String nextLabel = ">"; - private static final String backLabel = "<"; - - private static final int itemStackPadding = 1; - private static final int itemStackWidth = GuiItemStackGroup.getWidth(itemStackPadding); - private static final int itemStackHeight = GuiItemStackGroup.getHeight(itemStackPadding); - private static int firstItemIndex = 0; - - private static final String clearLabel = "Clr"; - - private final GuiIngredientFastList guiIngredientList; - private final GuiProperties guiProperties; - private final List guiAreas; - private final BookmarksOverlay parent; - - private GuiIngredientFast hovered = null; - - private final GuiButton clearButton; - - private List> activeAdvancedGuiHandlers = Collections.emptyList(); - - public BookmarksOverlayInternal(BookmarksOverlay parent, IIngredientRegistry ingredientRegistry, GuiScreen guiScreen, - GuiProperties guiProperties) { - - this.parent = parent; - this.guiProperties = guiProperties; - this.guiIngredientList = new GuiIngredientFastList(ingredientRegistry); - - this.activeAdvancedGuiHandlers = getActiveAdvancedGuiHandlers(guiScreen); - if (!activeAdvancedGuiHandlers.isEmpty() && guiScreen instanceof GuiContainer) { - GuiContainer guiContainer = (GuiContainer) guiScreen; - guiAreas = getGuiAreas(guiContainer); - } else { - guiAreas = Collections.emptyList(); - } - - final int columns = getColumns(guiProperties); - final int rows = getRows(guiProperties); - final int xSize = columns * itemStackWidth; - final int xEmptySpace = guiProperties.getScreenWidth() - guiProperties.getGuiLeft() - guiProperties.getGuiXSize() - - xSize; - - final int leftEdge = guiProperties.getGuiLeft() + guiProperties.getGuiXSize() + (xEmptySpace / 2); - final int rightEdge = leftEdge + xSize; - - final int yItemButtonSpace = getItemButtonYSpace(guiProperties); - final int itemButtonsHeight = rows * itemStackHeight; - - final int buttonStartY = buttonSize + (2 * borderPadding) + (yItemButtonSpace - itemButtonsHeight) / 2; - createItemButtons(guiIngredientList, guiAreas, leftEdge, buttonStartY, columns, rows); - - clearButton = new GuiButton(0, rightEdge - buttonSize, borderPadding, buttonSize, buttonSize, nextLabel); - } - - public void drawScreen(Minecraft minecraft, int mouseX, int mouseY) { - GlStateManager.disableLighting(); - - clearButton.drawButton(minecraft, mouseX, mouseY); - - GlStateManager.disableBlend(); - - if (shouldShowDeleteItemTooltip(minecraft)) { - hovered = guiIngredientList.render(minecraft, false, mouseX, mouseY); - } else { - boolean mouseOver = isMouseOver(mouseX, mouseY); - hovered = guiIngredientList.render(minecraft, mouseOver, mouseX, mouseY); - } - - if (hovered != null) { - hovered.drawHovered(minecraft); - } - - GlStateManager.enableAlpha(); - } - - private List getGuiAreas(GuiContainer guiContainer) { - List guiAreas = new ArrayList(); - for (IAdvancedGuiHandler advancedGuiHandler : activeAdvancedGuiHandlers) { - List guiExtraAreas = getGuiAreas(guiContainer, advancedGuiHandler); - if (guiExtraAreas != null) { - guiAreas.addAll(guiExtraAreas); - } - } - return guiAreas; - } - - private List getGuiAreas(GuiContainer gui, - IAdvancedGuiHandler advancedGuiHandler) { - Class guiClass = advancedGuiHandler.getGuiContainerClass(); - if (guiClass.isInstance(gui)) { - T guiT = guiClass.cast(gui); - return advancedGuiHandler.getGuiExtraAreas(guiT); - } - return null; - } - - private boolean shouldShowDeleteItemTooltip(Minecraft minecraft) { - if (Config.isDeleteItemsInCheatModeActive()) { - EntityPlayer player = minecraft.thePlayer; - if (player.inventory.getItemStack() != null) { - return true; - } - } - return false; - } - - private List> getActiveAdvancedGuiHandlers(GuiScreen guiScreen) { - List> activeAdvancedGuiHandler = new ArrayList>(); - if (guiScreen instanceof GuiContainer) { - for (IAdvancedGuiHandler advancedGuiHandler : parent.getAdvancedGuiHandlers()) { - Class guiContainerClass = advancedGuiHandler.getGuiContainerClass(); - if (guiContainerClass.isInstance(guiScreen)) { - activeAdvancedGuiHandler.add(advancedGuiHandler); - } - } - } - return activeAdvancedGuiHandler; - } - - @Override - public IClickedIngredient getIngredientUnderMouse(int mouseX, int mouseY) { - if (!isMouseOver(mouseX, mouseY)) { - return null; - } - - ClickedIngredient clicked = guiIngredientList.getIngredientUnderMouse(mouseX, mouseY); - if (clicked != null) { - setKeyboardFocus(false); - clicked.setAllowsCheating(); - } - return clicked; - } - - @Override - public boolean canSetFocusWithMouse() { - return true; - } - - @Override - public boolean handleMouseScrolled(int mouseX, int mouseY, int scrollDelta) { - return false; - } - - @Override - public boolean isMouseOver(int mouseX, int mouseY) { - - for (Rectangle guiArea : guiAreas) { - if (guiArea.contains(mouseX, mouseY)) { - return false; - } - } - - return true; - } - - @Override - public boolean hasKeyboardFocus() { - return false; - } - - @Override - public void setKeyboardFocus(boolean focus) { - } - - @Override - public boolean onKeyPressed(char typedChar, int keyCode) { - return false; - } - - @Override - public boolean handleMouseClicked(int mouseX, int mouseY, int mouseButton) { - return false; - } - - public ItemStack getStackUnderMouse() { - if (hovered != null) { - Object ingredient = hovered.getIngredient(); - if (ingredient instanceof ItemStack) { - return (ItemStack) ingredient; - } - } - return null; - } - - public static int getColumns(GuiProperties guiProperties) { - return getItemButtonXSpace(guiProperties) / itemStackWidth; - } - - private static int getItemButtonXSpace(GuiProperties guiProperties) { - return guiProperties.getScreenWidth() - - (guiProperties.getGuiLeft() + guiProperties.getGuiXSize() + (2 * borderPadding)); - } - - public static int getRows(GuiProperties guiProperties) { - return getItemButtonYSpace(guiProperties) / itemStackHeight; - } - - private static int getItemButtonYSpace(GuiProperties guiProperties) { - return guiProperties.getScreenHeight() - (buttonSize + searchHeight + 2 + (4 * borderPadding)); - } - - private static void createItemButtons(GuiIngredientFastList guiItemStacks, List guiAreas, - final int xStart, final int yStart, final int columnCount, final int rowCount) { - guiItemStacks.clear(); - - for (int row = 0; row < rowCount; row++) { - int y = yStart + (row * itemStackHeight); - for (int column = 0; column < columnCount; column++) { - int x = xStart + (column * itemStackWidth); - GuiIngredientFast guiIngredientFast = new GuiIngredientFast(x, y, itemStackPadding); - if (guiAreas != null) { - Rectangle stackArea = guiIngredientFast.getArea(); - if (intersects(guiAreas, stackArea)) { - continue; - } - } - guiItemStacks.add(guiIngredientFast); - } - } - } - - private static boolean intersects(List areas, Rectangle comparisonArea) { - for (Rectangle area : areas) { - if (area.intersects(comparisonArea)) { - return true; - } - } - return false; - } - - public void close() { - setKeyboardFocus(false); - Config.saveFilterText(); - } - public boolean hasScreenChanged(GuiScreen guiScreen) { - if (!Config.isOverlayEnabled()) { - return true; - } - GuiProperties guiProperties = GuiProperties.create(guiScreen); - if (guiProperties == null) { - return true; - } - if (!this.guiProperties.equals(guiProperties)) { - return true; - } else if (!activeAdvancedGuiHandlers.isEmpty() && guiScreen instanceof GuiContainer) { - GuiContainer guiContainer = (GuiContainer) guiScreen; - List guiAreas = getGuiAreas(guiContainer); - if (!Java6Helper.equals(this.guiAreas, guiAreas)) { - return true; - } - } - - return false; - } -} diff --git a/src/main/java/mezz/jei/gui/ItemListOverlay.java b/src/main/java/mezz/jei/gui/ItemListOverlay.java index b12f7fee6..0083a4499 100644 --- a/src/main/java/mezz/jei/gui/ItemListOverlay.java +++ b/src/main/java/mezz/jei/gui/ItemListOverlay.java @@ -10,6 +10,7 @@ import mezz.jei.ItemFilter; import mezz.jei.api.IItemListOverlay; import mezz.jei.api.gui.IAdvancedGuiHandler; +import mezz.jei.api.ingredients.IIngredientBookmarks; import mezz.jei.api.ingredients.IIngredientRegistry; import mezz.jei.config.Config; import mezz.jei.util.Log; @@ -17,119 +18,126 @@ import net.minecraft.item.ItemStack; public class ItemListOverlay implements IItemListOverlay { - private final ItemFilter itemFilter; - private final List> advancedGuiHandlers; - private final IIngredientRegistry ingredientRegistry; - private final Set highlightedStacks = new HashSet(); - - @Nullable - private ItemListOverlayInternal internal; - - public ItemListOverlay(ItemFilter itemFilter, List> advancedGuiHandlers, IIngredientRegistry ingredientRegistry) { - this.itemFilter = itemFilter; - this.advancedGuiHandlers = advancedGuiHandlers; - this.ingredientRegistry = ingredientRegistry; - } - - @Nullable - public ItemListOverlayInternal create(GuiScreen guiScreen) { - close(); - - if (Config.isOverlayEnabled()) { - GuiProperties guiProperties = GuiProperties.create(guiScreen); - if (guiProperties != null) { - final int columns = ItemListOverlayInternal.getColumns(guiProperties); - if (columns >= 4) { - internal = new ItemListOverlayInternal(this, ingredientRegistry, guiScreen, guiProperties); - return internal; - } - } - } - - return null; - } - - @Nullable - public ItemListOverlayInternal getInternal() { - return internal; - } - - @Nullable - @Override - public ItemStack getStackUnderMouse() { - if (internal != null) { - return internal.getStackUnderMouse(); - } - return null; - } - - @Override - public void setFilterText(@Nullable String filterText) { - if (filterText == null) { - Log.error("null filterText", new NullPointerException()); - return; - } - - Config.setFilterText(filterText); - - if (internal != null) { - internal.setFilterText(filterText); - } - } - - public void rebuildItemFilter() { - ItemFilter itemFilter = getItemFilter(); - itemFilter.rebuild(); - ItemListOverlayInternal.setToFirstPage(); - if (internal != null) { - internal.updateLayout(); - } - } - - @Override - public String getFilterText() { - return Config.getFilterText(); - } - - @Override - public ImmutableList getVisibleStacks() { - if (internal == null) { - return ImmutableList.of(); - } - return internal.getVisibleStacks(); - } - - @Override - public ImmutableList getFilteredStacks() { - return itemFilter.getItemStacks(); - } - - @Override - public void highlightStacks(Collection stacks) { - highlightedStacks.clear(); - highlightedStacks.addAll(stacks); - } - - public Set getHighlightedStacks() { - return highlightedStacks; - } - - public ItemFilter getItemFilter() { - return itemFilter; - } - - public List> getAdvancedGuiHandlers() { - return advancedGuiHandlers; - } - - public boolean isOpen() { - return internal != null; - } - - public void close() { - if (internal != null) { - internal.close(); - } - internal = null; - } + private final ItemFilter itemFilter; + private final List> advancedGuiHandlers; + private final IIngredientRegistry ingredientRegistry; + private final Set highlightedStacks = new HashSet(); + private final IIngredientBookmarks ingredientBookmarks; + + @Nullable + private ItemListOverlayInternal internal; + + public ItemListOverlay(ItemFilter itemFilter, List> advancedGuiHandlers, + IIngredientRegistry ingredientRegistry, IIngredientBookmarks ingredientBookmarks) { + this.itemFilter = itemFilter; + this.advancedGuiHandlers = advancedGuiHandlers; + this.ingredientRegistry = ingredientRegistry; + this.ingredientBookmarks = ingredientBookmarks; + } + + @Nullable + public ItemListOverlayInternal create(GuiScreen guiScreen) { + close(); + + if (Config.isOverlayEnabled()) { + GuiProperties guiProperties = GuiProperties.create(guiScreen); + if (guiProperties != null) { + final int columns = ItemListOverlayInternal.getColumns(guiProperties); + if (columns >= 4) { + internal = new ItemListOverlayInternal(this, ingredientRegistry, guiScreen, guiProperties); + return internal; + } + } + } + + return null; + } + + @Nullable + public ItemListOverlayInternal getInternal() { + return internal; + } + + @Nullable + @Override + public ItemStack getStackUnderMouse() { + if (internal != null) { + return internal.getStackUnderMouse(); + } + return null; + } + + @Override + public void setFilterText(@Nullable String filterText) { + if (filterText == null) { + Log.error("null filterText", new NullPointerException()); + return; + } + + Config.setFilterText(filterText); + + if (internal != null) { + internal.setFilterText(filterText); + } + } + + public void rebuildItemFilter() { + ItemFilter itemFilter = getItemFilter(); + itemFilter.rebuild(); + ItemListOverlayInternal.setToFirstPage(); + if (internal != null) { + internal.updateLayout(); + } + } + + @Override + public String getFilterText() { + return Config.getFilterText(); + } + + @Override + public ImmutableList getVisibleStacks() { + if (internal == null) { + return ImmutableList.of(); + } + return internal.getVisibleStacks(); + } + + @Override + public ImmutableList getFilteredStacks() { + return itemFilter.getItemStacks(); + } + + @Override + public void highlightStacks(Collection stacks) { + highlightedStacks.clear(); + highlightedStacks.addAll(stacks); + } + + public Set getHighlightedStacks() { + return highlightedStacks; + } + + public ItemFilter getItemFilter() { + return itemFilter; + } + + public List> getAdvancedGuiHandlers() { + return advancedGuiHandlers; + } + + public boolean isOpen() { + return internal != null; + } + + public void close() { + if (internal != null) { + internal.close(); + } + internal = null; + } + + public IIngredientBookmarks getIngredientBookmarks() { + return ingredientBookmarks; + } } diff --git a/src/main/java/mezz/jei/gui/ItemListOverlayInternal.java b/src/main/java/mezz/jei/gui/ItemListOverlayInternal.java index f8bc31968..56928f249 100644 --- a/src/main/java/mezz/jei/gui/ItemListOverlayInternal.java +++ b/src/main/java/mezz/jei/gui/ItemListOverlayInternal.java @@ -51,536 +51,591 @@ public class ItemListOverlayInternal implements IShowsRecipeFocuses, IMouseHandler, IKeyable { - private static final int borderPadding = 2; - private static final int searchHeight = 16; - private static final int buttonSize = 20; - private static final String nextLabel = ">"; - private static final String backLabel = "<"; - - private static final int itemStackPadding = 1; - private static final int itemStackWidth = GuiItemStackGroup.getWidth(itemStackPadding); - private static final int itemStackHeight = GuiItemStackGroup.getHeight(itemStackPadding); - private static int firstItemIndex = 0; - - private final ItemListOverlay parent; - - private final GuiButton nextButton; - private final GuiButton backButton; - private final GuiButton configButton; + private static final int borderPadding = 2; + private static final int searchHeight = 16; + private static final int buttonSize = 20; + private static final String nextLabel = ">"; + private static final String backLabel = "<"; + + private static final int itemStackPadding = 1; + private static final int itemStackWidth = GuiItemStackGroup.getWidth(itemStackPadding); + private static final int itemStackHeight = GuiItemStackGroup.getHeight(itemStackPadding); + private static int firstItemIndex = 0; + + private final ItemListOverlay parent; + + private final GuiButton nextButton; + private final GuiButton backButton; + private final GuiButton configButton; private final GuiButton clearButton; - private final IDrawable configButtonIcon; - private final IDrawable configButtonCheatIcon; - private final HoverChecker configButtonHoverChecker; - private final GuiTextFieldFilter searchField; - - private String pageNumDisplayString = "1/1"; - private int pageNumDisplayX; - private int pageNumDisplayY; - - private final GuiIngredientFastList guiIngredientList; - @Nullable - private GuiIngredientFast hovered = null; - - // properties of the gui we're beside - private final GuiProperties guiProperties; - private final List guiAreas; - private List> activeAdvancedGuiHandlers = Collections.emptyList(); - - public ItemListOverlayInternal(ItemListOverlay parent, IIngredientRegistry ingredientRegistry, GuiScreen guiScreen, GuiProperties guiProperties) { - this.parent = parent; - - this.guiIngredientList = new GuiIngredientFastList(ingredientRegistry); - - this.guiProperties = guiProperties; - this.activeAdvancedGuiHandlers = getActiveAdvancedGuiHandlers(guiScreen); - if (!activeAdvancedGuiHandlers.isEmpty() && guiScreen instanceof GuiContainer) { - GuiContainer guiContainer = (GuiContainer) guiScreen; - guiAreas = getGuiAreas(guiContainer); - } else { - guiAreas = Collections.emptyList(); - } - - final int columns = getColumns(guiProperties); - final int rows = getRows(guiProperties); - final int xSize = columns * itemStackWidth; - final int xEmptySpace = guiProperties.getScreenWidth() - guiProperties.getGuiLeft() - guiProperties.getGuiXSize() - xSize; - - final int leftEdge = guiProperties.getGuiLeft() + guiProperties.getGuiXSize() + (xEmptySpace / 2); - final int rightEdge = leftEdge + xSize; - - final int yItemButtonSpace = getItemButtonYSpace(guiProperties); - final int itemButtonsHeight = rows * itemStackHeight; - - final int buttonStartY = buttonSize + (2 * borderPadding) + (yItemButtonSpace - itemButtonsHeight) / 2; - createItemButtons(guiIngredientList, guiAreas, leftEdge, buttonStartY, columns, rows); - - nextButton = new GuiButton(0, rightEdge - buttonSize, borderPadding, buttonSize, buttonSize, nextLabel); - backButton = new GuiButton(1, leftEdge, borderPadding, buttonSize, buttonSize, backLabel); - clearButton = new GuiButton(3, 0, borderPadding, buttonSize, buttonSize, "CLR"); - - final int searchFieldX; - final int searchFieldY = guiProperties.getScreenHeight() - searchHeight - borderPadding - 2; - final int searchFieldWidth; - - if (isSearchBarCentered(guiProperties)) { - searchFieldX = guiProperties.getGuiLeft(); - searchFieldWidth = guiProperties.getGuiXSize() - buttonSize - 1; - } else { - searchFieldX = leftEdge; - searchFieldWidth = rightEdge - leftEdge - buttonSize - 1; - } - - FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; - searchField = new GuiTextFieldFilter(0, fontRenderer, searchFieldX, searchFieldY, searchFieldWidth, searchHeight, parent.getItemFilter()); - setKeyboardFocus(false); - - int configButtonX = searchFieldX + searchFieldWidth + 1; - int configButtonY = guiProperties.getScreenHeight() - buttonSize - borderPadding; - configButton = new GuiButton(2, configButtonX, configButtonY, buttonSize, buttonSize, ""); - ResourceLocation configButtonIconLocation = new ResourceLocation(Constants.RESOURCE_DOMAIN, Constants.TEXTURE_RECIPE_BACKGROUND_PATH); - GuiHelper guiHelper = Internal.getHelpers().getGuiHelper(); - configButtonIcon = guiHelper.createDrawable(configButtonIconLocation, 0, 166, 16, 16); - configButtonCheatIcon = guiHelper.createDrawable(configButtonIconLocation, 16, 166, 16, 16); - configButtonHoverChecker = new HoverChecker(configButton, 0); - - updateLayout(); - } - - private static boolean isSearchBarCentered(GuiProperties guiProperties) { - return Config.isCenterSearchBarEnabled() && - guiProperties.getGuiTop() + guiProperties.getGuiYSize() + searchHeight < guiProperties.getScreenHeight(); - } - - private List> getActiveAdvancedGuiHandlers(GuiScreen guiScreen) { - List> activeAdvancedGuiHandler = new ArrayList>(); - if (guiScreen instanceof GuiContainer) { - for (IAdvancedGuiHandler advancedGuiHandler : parent.getAdvancedGuiHandlers()) { - Class guiContainerClass = advancedGuiHandler.getGuiContainerClass(); - if (guiContainerClass.isInstance(guiScreen)) { - activeAdvancedGuiHandler.add(advancedGuiHandler); - } - } - } - return activeAdvancedGuiHandler; - } - - private List getGuiAreas(GuiContainer guiContainer) { - List guiAreas = new ArrayList(); - for (IAdvancedGuiHandler advancedGuiHandler : activeAdvancedGuiHandlers) { - List guiExtraAreas = getGuiAreas(guiContainer, advancedGuiHandler); - if (guiExtraAreas != null) { - guiAreas.addAll(guiExtraAreas); - } - } - return guiAreas; - } - - @Nullable - private List getGuiAreas(GuiContainer gui, IAdvancedGuiHandler advancedGuiHandler) { - Class guiClass = advancedGuiHandler.getGuiContainerClass(); - if (guiClass.isInstance(gui)) { - T guiT = guiClass.cast(gui); - return advancedGuiHandler.getGuiExtraAreas(guiT); - } - return null; - } - - public boolean hasScreenChanged(GuiScreen guiScreen) { - if (!Config.isOverlayEnabled()) { - return true; - } - GuiProperties guiProperties = GuiProperties.create(guiScreen); - if (guiProperties == null) { - return true; - } - if (!this.guiProperties.equals(guiProperties)) { - return true; - } else if (!activeAdvancedGuiHandlers.isEmpty() && guiScreen instanceof GuiContainer) { - GuiContainer guiContainer = (GuiContainer) guiScreen; - List guiAreas = getGuiAreas(guiContainer); - if (!Java6Helper.equals(this.guiAreas, guiAreas)) { - return true; - } - } - - return false; - } - - private static void createItemButtons(GuiIngredientFastList guiItemStacks, @Nullable List guiAreas, final int xStart, final int yStart, final int columnCount, final int rowCount) { - guiItemStacks.clear(); - - for (int row = 0; row < rowCount; row++) { - int y = yStart + (row * itemStackHeight); - for (int column = 0; column < columnCount; column++) { - int x = xStart + (column * itemStackWidth); - GuiIngredientFast guiIngredientFast = new GuiIngredientFast(x, y, itemStackPadding); - if (guiAreas != null) { - Rectangle stackArea = guiIngredientFast.getArea(); - if (intersects(guiAreas, stackArea)) { - continue; - } - } - guiItemStacks.add(guiIngredientFast); - } - } - } - - private static boolean intersects(List areas, Rectangle comparisonArea) { - for (Rectangle area : areas) { - if (area.intersects(comparisonArea)) { - return true; - } - } - return false; - } - - public void updateLayout() { - ImmutableList ingredientList = parent.getItemFilter().getIngredientList(); - guiIngredientList.set(firstItemIndex, ingredientList); - - FontRenderer fontRendererObj = Minecraft.getMinecraft().fontRendererObj; - - pageNumDisplayString = (getPageNum() + 1) + "/" + getPageCount(); - int pageDisplayWidth = fontRendererObj.getStringWidth(pageNumDisplayString); - pageNumDisplayX = ((backButton.xPosition + backButton.width) + nextButton.xPosition) / 2 - (pageDisplayWidth / 2); - pageNumDisplayY = backButton.yPosition + Math.round((backButton.height - fontRendererObj.FONT_HEIGHT) / 2.0f); - - searchField.update(); - } - - private void nextPage() { - final int itemsCount = parent.getItemFilter().size(); - if (itemsCount == 0) { - firstItemIndex = 0; - return; - } - - firstItemIndex += guiIngredientList.size(); - if (firstItemIndex >= itemsCount) { - firstItemIndex = 0; - } - updateLayout(); - } - - private void previousPage() { - final int itemsPerPage = guiIngredientList.size(); - if (itemsPerPage == 0) { - firstItemIndex = 0; - return; - } - final int itemsCount = parent.getItemFilter().size(); - - int pageNum = firstItemIndex / itemsPerPage; - if (pageNum == 0) { - pageNum = itemsCount / itemsPerPage; - } else { - pageNum--; - } - - firstItemIndex = itemsPerPage * pageNum; - if (firstItemIndex > 0 && firstItemIndex == itemsCount) { - pageNum--; - firstItemIndex = itemsPerPage * pageNum; - } - updateLayout(); - } - - public void drawScreen(Minecraft minecraft, int mouseX, int mouseY) { - GlStateManager.disableLighting(); - - minecraft.fontRendererObj.drawString(pageNumDisplayString, pageNumDisplayX, pageNumDisplayY, Color.white.getRGB(), true); - searchField.drawTextBox(); - - nextButton.drawButton(minecraft, mouseX, mouseY); - backButton.drawButton(minecraft, mouseX, mouseY); - configButton.drawButton(minecraft, mouseX, mouseY); + private final IDrawable configButtonIcon; + private final IDrawable configButtonCheatIcon; + private final HoverChecker configButtonHoverChecker; + private final GuiTextFieldFilter searchField; + + private String pageNumDisplayString = "1/1"; + private int pageNumDisplayX; + private int pageNumDisplayY; + + private final GuiIngredientFastList guiIngredientList; + private final GuiIngredientFastList guiBookmarks; + @Nullable + private GuiIngredientFast hovered = null; + + // properties of the gui we're beside + private final GuiProperties guiProperties; + private final List guiAreas; + private List> activeAdvancedGuiHandlers = Collections.emptyList(); + + public ItemListOverlayInternal(ItemListOverlay parent, IIngredientRegistry ingredientRegistry, GuiScreen guiScreen, + GuiProperties guiProperties) { + this.parent = parent; + + this.guiBookmarks = new GuiIngredientFastList(ingredientRegistry); + this.guiIngredientList = new GuiIngredientFastList(ingredientRegistry); + + this.guiProperties = guiProperties; + this.activeAdvancedGuiHandlers = getActiveAdvancedGuiHandlers(guiScreen); + if (!activeAdvancedGuiHandlers.isEmpty() && guiScreen instanceof GuiContainer) { + GuiContainer guiContainer = (GuiContainer) guiScreen; + guiAreas = getGuiAreas(guiContainer); + } else { + guiAreas = Collections.emptyList(); + } + + final int columns = getColumns(guiProperties); + final int rows = getRows(guiProperties); + final int xSize = columns * itemStackWidth; + final int xEmptySpace = guiProperties.getScreenWidth() - guiProperties.getGuiLeft() - guiProperties.getGuiXSize() + - xSize; + + final int leftEdge = guiProperties.getGuiLeft() + guiProperties.getGuiXSize() + (xEmptySpace / 2); + final int rightEdge = leftEdge + xSize; + + final int yItemButtonSpace = getItemButtonYSpace(guiProperties); + final int itemButtonsHeight = rows * itemStackHeight; + + final int buttonStartY = buttonSize + (2 * borderPadding) + (yItemButtonSpace - itemButtonsHeight) / 2; + // this renders the items gui + createItemButtons(guiIngredientList, guiAreas, leftEdge, buttonStartY, columns, rows); + createItemButtons(guiBookmarks, guiAreas, 0, guiProperties.getGuiTop() + buttonSize, columns, rows); + + nextButton = new GuiButton(0, rightEdge - buttonSize, borderPadding, buttonSize, buttonSize, nextLabel); + backButton = new GuiButton(1, leftEdge, borderPadding, buttonSize, buttonSize, backLabel); + clearButton = new GuiButton(3, 0, guiProperties.getGuiTop(), buttonSize * 3, buttonSize, "CLEAR"); + + final int searchFieldX; + final int searchFieldY = guiProperties.getScreenHeight() - searchHeight - borderPadding - 2; + final int searchFieldWidth; + + if (isSearchBarCentered(guiProperties)) { + searchFieldX = guiProperties.getGuiLeft(); + searchFieldWidth = guiProperties.getGuiXSize() - buttonSize - 1; + } else { + searchFieldX = leftEdge; + searchFieldWidth = rightEdge - leftEdge - buttonSize - 1; + } + + FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; + searchField = new GuiTextFieldFilter(0, fontRenderer, searchFieldX, searchFieldY, searchFieldWidth, searchHeight, + parent.getItemFilter()); + setKeyboardFocus(false); + + int configButtonX = searchFieldX + searchFieldWidth + 1; + int configButtonY = guiProperties.getScreenHeight() - buttonSize - borderPadding; + configButton = new GuiButton(2, configButtonX, configButtonY, buttonSize, buttonSize, ""); + ResourceLocation configButtonIconLocation = new ResourceLocation(Constants.RESOURCE_DOMAIN, + Constants.TEXTURE_RECIPE_BACKGROUND_PATH); + GuiHelper guiHelper = Internal.getHelpers().getGuiHelper(); + configButtonIcon = guiHelper.createDrawable(configButtonIconLocation, 0, 166, 16, 16); + configButtonCheatIcon = guiHelper.createDrawable(configButtonIconLocation, 16, 166, 16, 16); + configButtonHoverChecker = new HoverChecker(configButton, 0); + + updateLayout(); + } + + private static boolean isSearchBarCentered(GuiProperties guiProperties) { + return Config.isCenterSearchBarEnabled() && + guiProperties.getGuiTop() + guiProperties.getGuiYSize() + searchHeight < guiProperties.getScreenHeight(); + } + + private List> getActiveAdvancedGuiHandlers(GuiScreen guiScreen) { + List> activeAdvancedGuiHandler = new ArrayList>(); + if (guiScreen instanceof GuiContainer) { + for (IAdvancedGuiHandler advancedGuiHandler : parent.getAdvancedGuiHandlers()) { + Class guiContainerClass = advancedGuiHandler.getGuiContainerClass(); + if (guiContainerClass.isInstance(guiScreen)) { + activeAdvancedGuiHandler.add(advancedGuiHandler); + } + } + } + return activeAdvancedGuiHandler; + } + + private List getGuiAreas(GuiContainer guiContainer) { + List guiAreas = new ArrayList(); + for (IAdvancedGuiHandler advancedGuiHandler : activeAdvancedGuiHandlers) { + List guiExtraAreas = getGuiAreas(guiContainer, advancedGuiHandler); + if (guiExtraAreas != null) { + guiAreas.addAll(guiExtraAreas); + } + } + return guiAreas; + } + + @Nullable + private List getGuiAreas(GuiContainer gui, + IAdvancedGuiHandler advancedGuiHandler) { + Class guiClass = advancedGuiHandler.getGuiContainerClass(); + if (guiClass.isInstance(gui)) { + T guiT = guiClass.cast(gui); + return advancedGuiHandler.getGuiExtraAreas(guiT); + } + return null; + } + + public boolean hasScreenChanged(GuiScreen guiScreen) { + if (!Config.isOverlayEnabled()) { + return true; + } + GuiProperties guiProperties = GuiProperties.create(guiScreen); + if (guiProperties == null) { + return true; + } + if (!this.guiProperties.equals(guiProperties)) { + return true; + } else if (!activeAdvancedGuiHandlers.isEmpty() && guiScreen instanceof GuiContainer) { + GuiContainer guiContainer = (GuiContainer) guiScreen; + List guiAreas = getGuiAreas(guiContainer); + if (!Java6Helper.equals(this.guiAreas, guiAreas)) { + return true; + } + } + + return false; + } + + private static void createItemButtons(GuiIngredientFastList guiItemStacks, @Nullable List guiAreas, + final int xStart, final int yStart, final int columnCount, final int rowCount) { + guiItemStacks.clear(); + + for (int row = 0; row < rowCount; row++) { + int y = yStart + (row * itemStackHeight); + for (int column = 0; column < columnCount; column++) { + int x = xStart + (column * itemStackWidth); + GuiIngredientFast guiIngredientFast = new GuiIngredientFast(x, y, itemStackPadding); + if (guiAreas != null) { + Rectangle stackArea = guiIngredientFast.getArea(); + if (intersects(guiAreas, stackArea)) { + continue; + } + } + guiItemStacks.add(guiIngredientFast); + } + } + } + + private static boolean intersects(List areas, Rectangle comparisonArea) { + for (Rectangle area : areas) { + if (area.intersects(comparisonArea)) { + return true; + } + } + return false; + } + + public void updateLayout() { + ImmutableList ingredientList = parent.getItemFilter().getIngredientList(); + guiIngredientList.set(firstItemIndex, ingredientList); + + List bookmarkList = parent.getIngredientBookmarks().getIngredientList(); + guiBookmarks.set(0, bookmarkList); + + FontRenderer fontRendererObj = Minecraft.getMinecraft().fontRendererObj; + + pageNumDisplayString = (getPageNum() + 1) + "/" + getPageCount(); + int pageDisplayWidth = fontRendererObj.getStringWidth(pageNumDisplayString); + pageNumDisplayX = ((backButton.xPosition + backButton.width) + nextButton.xPosition) / 2 - (pageDisplayWidth / 2); + pageNumDisplayY = backButton.yPosition + Math.round((backButton.height - fontRendererObj.FONT_HEIGHT) / 2.0f); + + searchField.update(); + } + + private void nextPage() { + final int itemsCount = parent.getItemFilter().size(); + if (itemsCount == 0) { + firstItemIndex = 0; + return; + } + + firstItemIndex += guiIngredientList.size(); + if (firstItemIndex >= itemsCount) { + firstItemIndex = 0; + } + updateLayout(); + } + + private void previousPage() { + final int itemsPerPage = guiIngredientList.size(); + if (itemsPerPage == 0) { + firstItemIndex = 0; + return; + } + final int itemsCount = parent.getItemFilter().size(); + + int pageNum = firstItemIndex / itemsPerPage; + if (pageNum == 0) { + pageNum = itemsCount / itemsPerPage; + } else { + pageNum--; + } + + firstItemIndex = itemsPerPage * pageNum; + if (firstItemIndex > 0 && firstItemIndex == itemsCount) { + pageNum--; + firstItemIndex = itemsPerPage * pageNum; + } + updateLayout(); + } + + public void drawScreen(Minecraft minecraft, int mouseX, int mouseY) { + GlStateManager.disableLighting(); + + minecraft.fontRendererObj.drawString(pageNumDisplayString, pageNumDisplayX, pageNumDisplayY, Color.white.getRGB(), + true); + searchField.drawTextBox(); + + nextButton.drawButton(minecraft, mouseX, mouseY); + backButton.drawButton(minecraft, mouseX, mouseY); + configButton.drawButton(minecraft, mouseX, mouseY); clearButton.drawButton(minecraft, mouseX, mouseY); - IDrawable icon = Config.isCheatItemsEnabled() ? configButtonCheatIcon : configButtonIcon; - icon.draw(minecraft, configButton.xPosition + 2, configButton.yPosition + 2); - - GlStateManager.disableBlend(); - - if (shouldShowDeleteItemTooltip(minecraft)) { - hovered = guiIngredientList.render(minecraft, false, mouseX, mouseY); - } else { - boolean mouseOver = isMouseOver(mouseX, mouseY); - hovered = guiIngredientList.render(minecraft, mouseOver, mouseX, mouseY); - } - - Set highlightedStacks = parent.getHighlightedStacks(); - if (!highlightedStacks.isEmpty()) { - StackHelper helper = Internal.getHelpers().getStackHelper(); - for (GuiIngredientFast guiItemStack : guiIngredientList.getAllGuiIngredients()) { - Object ingredient = guiItemStack.getIngredient(); - if (ingredient instanceof ItemStack) { - if (helper.containsStack(highlightedStacks, (ItemStack) ingredient) != null) { - guiItemStack.drawHighlight(); - } - } - } - } - - if (hovered != null) { - hovered.drawHovered(minecraft); - } - - GlStateManager.enableAlpha(); - } - - private boolean shouldShowDeleteItemTooltip(Minecraft minecraft) { - if (Config.isDeleteItemsInCheatModeActive()) { - EntityPlayer player = minecraft.thePlayer; - if (player.inventory.getItemStack() != null) { - return true; - } - } - return false; - } - - public void drawTooltips(Minecraft minecraft, int mouseX, int mouseY) { - boolean mouseOver = isMouseOver(mouseX, mouseY); - if (mouseOver && shouldShowDeleteItemTooltip(minecraft)) { - String deleteItem = Translator.translateToLocal("jei.tooltip.delete.item"); - TooltipRenderer.drawHoveringText(minecraft, deleteItem, mouseX, mouseY); - } - - if (hovered != null) { - hovered.drawTooltip(minecraft, mouseX, mouseY); - } - - if (configButtonHoverChecker.checkHover(mouseX, mouseY)) { - String configString = Translator.translateToLocal("jei.tooltip.config"); - if (Config.isCheatItemsEnabled()) { - List tooltip = Arrays.asList( - configString, - TextFormatting.RED + Translator.translateToLocal("jei.tooltip.cheat.mode") - ); - TooltipRenderer.drawHoveringText(minecraft, tooltip, mouseX, mouseY); - } else { - TooltipRenderer.drawHoveringText(minecraft, configString, mouseX, mouseY); - } - } - } - - public void handleTick() { - searchField.updateCursorCounter(); - } - - @Override - public boolean isMouseOver(int mouseX, int mouseY) { - if (mouseX < guiProperties.getGuiLeft() + guiProperties.getGuiXSize()) { - return isSearchBarCentered(guiProperties) && - (searchField.isMouseOver(mouseX, mouseY) || configButtonHoverChecker.checkHover(mouseX, mouseY)); - } - - for (Rectangle guiArea : guiAreas) { - if (guiArea.contains(mouseX, mouseY)) { - return false; - } - } - - return true; - } - - @Override - @Nullable - public IClickedIngredient getIngredientUnderMouse(int mouseX, int mouseY) { - if (!isMouseOver(mouseX, mouseY)) { - return null; - } - - ClickedIngredient clicked = guiIngredientList.getIngredientUnderMouse(mouseX, mouseY); - if (clicked != null) { - setKeyboardFocus(false); - clicked.setAllowsCheating(); - } - return clicked; - } - - @Override - public boolean canSetFocusWithMouse() { - return true; - } - - @Override - public boolean handleMouseClicked(int mouseX, int mouseY, int mouseButton) { - if (!isMouseOver(mouseX, mouseY)) { - setKeyboardFocus(false); - return false; - } - - if (Config.isDeleteItemsInCheatModeActive()) { - Minecraft minecraft = Minecraft.getMinecraft(); - EntityPlayerSP player = minecraft.thePlayer; - ItemStack itemStack = player.inventory.getItemStack(); - if (itemStack != null) { - player.inventory.setItemStack(null); - PacketJei packet = new PacketDeletePlayerItem(itemStack); - JustEnoughItems.getProxy().sendPacketToServer(packet); - return true; - } - } - - boolean buttonClicked = handleMouseClickedButtons(mouseX, mouseY); - if (buttonClicked) { - setKeyboardFocus(false); - return true; - } - - return handleMouseClickedSearch(mouseX, mouseY, mouseButton); - } - - @Override - public boolean handleMouseScrolled(int mouseX, int mouseY, int scrollDelta) { - if (!isMouseOver(mouseX, mouseY)) { - return false; - } - if (scrollDelta < 0) { - nextPage(); - return true; - } else if (scrollDelta > 0) { - previousPage(); - return true; - } - return false; - } - - private boolean handleMouseClickedButtons(int mouseX, int mouseY) { - Minecraft minecraft = Minecraft.getMinecraft(); - if (nextButton.mousePressed(minecraft, mouseX, mouseY)) { - nextPage(); - nextButton.playPressSound(minecraft.getSoundHandler()); - return true; - } else if (backButton.mousePressed(minecraft, mouseX, mouseY)) { - previousPage(); - backButton.playPressSound(minecraft.getSoundHandler()); - return true; - } else if (configButton.mousePressed(minecraft, mouseX, mouseY)) { - configButton.playPressSound(minecraft.getSoundHandler()); - if (Keyboard.getEventKeyState() && (Keyboard.getEventKey() == Keyboard.KEY_LCONTROL || Keyboard.getEventKey() == Keyboard.KEY_RCONTROL)) { - Config.toggleCheatItemsEnabled(); - } else { - if (minecraft.currentScreen != null) { - parent.close(); - GuiScreen configScreen = new JEIModConfigGui(minecraft.currentScreen); - minecraft.displayGuiScreen(configScreen); - } - } - return true; - } - return false; - } - - private boolean handleMouseClickedSearch(int mouseX, int mouseY, int mouseButton) { - boolean searchClicked = searchField.isMouseOver(mouseX, mouseY); - setKeyboardFocus(searchClicked); - if (searchClicked && searchField.handleMouseClicked(mouseX, mouseY, mouseButton)) { - updateLayout(); - } - return searchClicked; - } - - @Override - public boolean hasKeyboardFocus() { - return searchField.isFocused(); - } - - @Override - public void setKeyboardFocus(boolean keyboardFocus) { - searchField.setFocused(keyboardFocus); - } - - @Override - public boolean onKeyPressed(char typedChar, int keyCode) { - if (hasKeyboardFocus()) { - boolean handled = searchField.textboxKeyTyped(typedChar, keyCode); - if (handled) { - boolean changed = Config.setFilterText(searchField.getText()); - if (changed) { - firstItemIndex = 0; - updateLayout(); - } - } - return handled; - } - return false; - } - - private static int getItemButtonXSpace(GuiProperties guiProperties) { - return guiProperties.getScreenWidth() - (guiProperties.getGuiLeft() + guiProperties.getGuiXSize() + (2 * borderPadding)); - } - - private static int getItemButtonYSpace(GuiProperties guiProperties) { - if (isSearchBarCentered(guiProperties)) { - return guiProperties.getScreenHeight() - (buttonSize + (3 * borderPadding)); - } - return guiProperties.getScreenHeight() - (buttonSize + searchHeight + 2 + (4 * borderPadding)); - } - - public static int getColumns(GuiProperties guiProperties) { - return getItemButtonXSpace(guiProperties) / itemStackWidth; - } - - public static int getRows(GuiProperties guiProperties) { - return getItemButtonYSpace(guiProperties) / itemStackHeight; - } - - private int getPageCount() { - final int itemCount = parent.getItemFilter().size(); - final int stacksPerPage = guiIngredientList.size(); - if (stacksPerPage == 0) { - return 1; - } - int pageCount = MathUtil.divideCeil(itemCount, stacksPerPage); - pageCount = Math.max(1, pageCount); - return pageCount; - } - - private int getPageNum() { - final int stacksPerPage = guiIngredientList.size(); - if (stacksPerPage == 0) { - return 1; - } - return firstItemIndex / stacksPerPage; - } - - public void close() { - setKeyboardFocus(false); - Config.saveFilterText(); - } - - @Nullable - public ItemStack getStackUnderMouse() { - if (hovered != null) { - Object ingredient = hovered.getIngredient(); - if (ingredient instanceof ItemStack) { - return (ItemStack) ingredient; - } - } - return null; - } - - public void setFilterText(String filterText) { - searchField.setText(filterText); - setToFirstPage(); - updateLayout(); - } - - public static void setToFirstPage() { - firstItemIndex = 0; - } - - public ImmutableList getVisibleStacks() { - ImmutableList.Builder visibleStacks = ImmutableList.builder(); - for (GuiIngredientFast guiItemStack : guiIngredientList.getAllGuiIngredients()) { - Object ingredient = guiItemStack.getIngredient(); - if (ingredient instanceof ItemStack) { - ItemStack itemStack = (ItemStack) ingredient; - visibleStacks.add(itemStack); - } - } - return visibleStacks.build(); - } + IDrawable icon = Config.isCheatItemsEnabled() ? configButtonCheatIcon : configButtonIcon; + icon.draw(minecraft, configButton.xPosition + 2, configButton.yPosition + 2); + + GlStateManager.disableBlend(); + + if (shouldShowDeleteItemTooltip(minecraft)) { + hovered = guiIngredientList.render(minecraft, false, mouseX, mouseY); + } else { + boolean mouseOver = isMouseOver(mouseX, mouseY); + hovered = guiIngredientList.render(minecraft, mouseOver, mouseX, mouseY); + } + + if (hovered == null) { + hovered = guiBookmarks.render(minecraft, isMouseOver(mouseX, mouseY), mouseX, mouseY); + } else { + guiBookmarks.render(minecraft, isMouseOver(mouseX, mouseY), mouseX, mouseY); + } + + Set highlightedStacks = parent.getHighlightedStacks(); + if (!highlightedStacks.isEmpty()) { + StackHelper helper = Internal.getHelpers().getStackHelper(); + for (GuiIngredientFast guiItemStack : guiIngredientList.getAllGuiIngredients()) { + Object ingredient = guiItemStack.getIngredient(); + if (ingredient instanceof ItemStack) { + if (helper.containsStack(highlightedStacks, (ItemStack) ingredient) != null) { + guiItemStack.drawHighlight(); + } + } + } + for (GuiIngredientFast guiItemStack : guiBookmarks.getAllGuiIngredients()) { + Object ingredient = guiItemStack.getIngredient(); + if (ingredient instanceof ItemStack) { + if (helper.containsStack(highlightedStacks, (ItemStack) ingredient) != null) { + guiItemStack.drawHighlight(); + } + } + } + } + + if (hovered != null) { + hovered.drawHovered(minecraft); + } + + GlStateManager.enableAlpha(); + } + + private boolean shouldShowDeleteItemTooltip(Minecraft minecraft) { + if (Config.isDeleteItemsInCheatModeActive()) { + EntityPlayer player = minecraft.thePlayer; + if (player.inventory.getItemStack() != null) { + return true; + } + } + return false; + } + + public void drawTooltips(Minecraft minecraft, int mouseX, int mouseY) { + boolean mouseOver = isMouseOver(mouseX, mouseY); + if (mouseOver && shouldShowDeleteItemTooltip(minecraft)) { + String deleteItem = Translator.translateToLocal("jei.tooltip.delete.item"); + TooltipRenderer.drawHoveringText(minecraft, deleteItem, mouseX, mouseY); + } + + if (hovered != null) { + hovered.drawTooltip(minecraft, mouseX, mouseY); + } + + if (configButtonHoverChecker.checkHover(mouseX, mouseY)) { + String configString = Translator.translateToLocal("jei.tooltip.config"); + if (Config.isCheatItemsEnabled()) { + List tooltip = Arrays.asList( + configString, + TextFormatting.RED + Translator.translateToLocal("jei.tooltip.cheat.mode")); + TooltipRenderer.drawHoveringText(minecraft, tooltip, mouseX, mouseY); + } else { + TooltipRenderer.drawHoveringText(minecraft, configString, mouseX, mouseY); + } + } + } + + public void handleTick() { + searchField.updateCursorCounter(); + } + + @Override + public boolean isMouseOver(int mouseX, int mouseY) { + if (mouseX > guiProperties.getGuiLeft() && mouseX < guiProperties.getGuiLeft() + guiProperties.getGuiXSize() + && mouseY > guiProperties.getGuiTop() && mouseY < guiProperties.getGuiTop() + guiProperties.getGuiYSize()) { + return false; + } + // if (mouseX < guiProperties.getGuiLeft() + guiProperties.getGuiXSize()) { + // return isSearchBarCentered(guiProperties) && + // (searchField.isMouseOver(mouseX, mouseY) || + // configButtonHoverChecker.checkHover(mouseX, mouseY)); + // } + + // for (Rectangle guiArea : guiAreas) { + // if (guiArea.contains(mouseX, mouseY)) { + // return false; + // } + // } + + return true; + } + + @Override + @Nullable + public IClickedIngredient getIngredientUnderMouse(int mouseX, int mouseY) { + if (!isMouseOver(mouseX, mouseY)) { + return null; + } + + ClickedIngredient clicked = guiIngredientList.getIngredientUnderMouse(mouseX, mouseY); + if (clicked != null) { + setKeyboardFocus(false); + clicked.setAllowsCheating(); + return clicked; + } + clicked = guiBookmarks.getIngredientUnderMouse(mouseX, mouseY); + if (clicked != null) { + setKeyboardFocus(false); + clicked.setAllowsCheating(); + return clicked; + } + return null; + } + + @Override + public boolean canSetFocusWithMouse() { + return true; + } + + @Override + public boolean handleMouseClicked(int mouseX, int mouseY, int mouseButton) { + if (!isMouseOver(mouseX, mouseY)) { + setKeyboardFocus(false); + return false; + } + + if (Config.isDeleteItemsInCheatModeActive()) { + Minecraft minecraft = Minecraft.getMinecraft(); + EntityPlayerSP player = minecraft.thePlayer; + ItemStack itemStack = player.inventory.getItemStack(); + if (itemStack != null) { + player.inventory.setItemStack(null); + PacketJei packet = new PacketDeletePlayerItem(itemStack); + JustEnoughItems.getProxy().sendPacketToServer(packet); + return true; + } + } + + boolean buttonClicked = handleMouseClickedButtons(mouseX, mouseY); + if (buttonClicked) { + setKeyboardFocus(false); + return true; + } + + return handleMouseClickedSearch(mouseX, mouseY, mouseButton); + } + + @Override + public boolean handleMouseScrolled(int mouseX, int mouseY, int scrollDelta) { + if (!isMouseOver(mouseX, mouseY)) { + return false; + } + if (scrollDelta < 0) { + nextPage(); + return true; + } else if (scrollDelta > 0) { + previousPage(); + return true; + } + return false; + } + + private boolean handleMouseClickedButtons(int mouseX, int mouseY) { + Minecraft minecraft = Minecraft.getMinecraft(); + if (nextButton.mousePressed(minecraft, mouseX, mouseY)) { + nextPage(); + nextButton.playPressSound(minecraft.getSoundHandler()); + return true; + } else if (backButton.mousePressed(minecraft, mouseX, mouseY)) { + previousPage(); + backButton.playPressSound(minecraft.getSoundHandler()); + return true; + } else if (configButton.mousePressed(minecraft, mouseX, mouseY)) { + configButton.playPressSound(minecraft.getSoundHandler()); + if (Keyboard.getEventKeyState() + && (Keyboard.getEventKey() == Keyboard.KEY_LCONTROL || Keyboard.getEventKey() == Keyboard.KEY_RCONTROL)) { + Config.toggleCheatItemsEnabled(); + } else { + if (minecraft.currentScreen != null) { + parent.close(); + GuiScreen configScreen = new JEIModConfigGui(minecraft.currentScreen); + minecraft.displayGuiScreen(configScreen); + } + } + return true; + } else if (clearButton.mousePressed(minecraft, mouseX, mouseY)) { + clearButton.playPressSound(minecraft.getSoundHandler()); + parent.getIngredientBookmarks().clear(); + updateLayout(); + return true; + } + return false; + } + + private boolean handleMouseClickedSearch(int mouseX, int mouseY, int mouseButton) { + boolean searchClicked = searchField.isMouseOver(mouseX, mouseY); + setKeyboardFocus(searchClicked); + if (searchClicked && searchField.handleMouseClicked(mouseX, mouseY, mouseButton)) { + updateLayout(); + } + return searchClicked; + } + + @Override + public boolean hasKeyboardFocus() { + return searchField.isFocused(); + } + + @Override + public void setKeyboardFocus(boolean keyboardFocus) { + searchField.setFocused(keyboardFocus); + } + + @Override + public boolean onKeyPressed(char typedChar, int keyCode) { + if (hasKeyboardFocus()) { + boolean handled = searchField.textboxKeyTyped(typedChar, keyCode); + if (handled) { + boolean changed = Config.setFilterText(searchField.getText()); + if (changed) { + firstItemIndex = 0; + updateLayout(); + } + } + return handled; + } + return false; + } + + // Finds the right edge of the inventory screen + private static int getItemButtonXSpace(GuiProperties guiProperties) { + return guiProperties.getScreenWidth() + - (guiProperties.getGuiLeft() + guiProperties.getGuiXSize() + (2 * borderPadding)); + } + + private static int getItemButtonYSpace(GuiProperties guiProperties) { + if (isSearchBarCentered(guiProperties)) { + return guiProperties.getScreenHeight() - (buttonSize + (3 * borderPadding)); + } + // finds the height of the list screen area minus the search and the buttons + return guiProperties.getScreenHeight() - (buttonSize + searchHeight + 2 + (4 * borderPadding)); + } + + public static int getColumns(GuiProperties guiProperties) { + return getItemButtonXSpace(guiProperties) / itemStackWidth; + } + + public static int getRows(GuiProperties guiProperties) { + return getItemButtonYSpace(guiProperties) / itemStackHeight; + } + + private int getPageCount() { + final int itemCount = parent.getItemFilter().size(); + final int stacksPerPage = guiIngredientList.size(); + if (stacksPerPage == 0) { + return 1; + } + int pageCount = MathUtil.divideCeil(itemCount, stacksPerPage); + pageCount = Math.max(1, pageCount); + return pageCount; + } + + private int getPageNum() { + final int stacksPerPage = guiIngredientList.size(); + if (stacksPerPage == 0) { + return 1; + } + return firstItemIndex / stacksPerPage; + } + + public void close() { + setKeyboardFocus(false); + Config.saveFilterText(); + } + + @Nullable + public ItemStack getStackUnderMouse() { + if (hovered != null) { + Object ingredient = hovered.getIngredient(); + if (ingredient instanceof ItemStack) { + return (ItemStack) ingredient; + } + } + return null; + } + + public void setFilterText(String filterText) { + searchField.setText(filterText); + setToFirstPage(); + updateLayout(); + } + + public static void setToFirstPage() { + firstItemIndex = 0; + } + + public ImmutableList getVisibleStacks() { + ImmutableList.Builder visibleStacks = ImmutableList.builder(); + for (GuiIngredientFast guiItemStack : guiIngredientList.getAllGuiIngredients()) { + Object ingredient = guiItemStack.getIngredient(); + if (ingredient instanceof ItemStack) { + ItemStack itemStack = (ItemStack) ingredient; + visibleStacks.add(itemStack); + } + } + for (GuiIngredientFast guiItemStack : guiBookmarks.getAllGuiIngredients()) { + Object ingredient = guiItemStack.getIngredient(); + if (ingredient instanceof ItemStack) { + ItemStack itemStack = (ItemStack) ingredient; + visibleStacks.add(itemStack); + } + } + return visibleStacks.build(); + } } diff --git a/src/main/java/mezz/jei/gui/ingredients/GuiIngredientFastList.java b/src/main/java/mezz/jei/gui/ingredients/GuiIngredientFastList.java index 786c8ddab..e21c22424 100644 --- a/src/main/java/mezz/jei/gui/ingredients/GuiIngredientFastList.java +++ b/src/main/java/mezz/jei/gui/ingredients/GuiIngredientFastList.java @@ -27,10 +27,16 @@ public class GuiIngredientFastList { private final IIngredientRegistry ingredientRegistry; + private boolean sortDisabled = false; + public GuiIngredientFastList(IIngredientRegistry ingredientRegistry) { this.ingredientRegistry = ingredientRegistry; } + public void setSortDisabled(boolean sortDisabled) { + this.sortDisabled = sortDisabled; + } + public void clear() { renderAll.clear(); diff --git a/src/main/java/mezz/jei/input/InputHandler.java b/src/main/java/mezz/jei/input/InputHandler.java index 93d1137ca..80e1a3c28 100644 --- a/src/main/java/mezz/jei/input/InputHandler.java +++ b/src/main/java/mezz/jei/input/InputHandler.java @@ -237,8 +237,9 @@ private boolean handleKeyDown(char typedChar, int eventKey) { IClickedIngredient clicked = getIngredientUnderMouseForKey(mouseHelper.getX(), mouseHelper.getY()); if (clicked != null) { ingredientBookmarks.toggleIngredientBookmark(clicked.getValue()); + itemListOverlayInternal.updateLayout(); + return true; } - return true; } if (itemListOverlayInternal != null && itemListOverlayInternal.onKeyPressed(typedChar, eventKey)) { From db51780cc4d189b26871fb7ec2d73be371291b10 Mon Sep 17 00:00:00 2001 From: Michael Carver <4365312+shortcarver@users.noreply.github.com> Date: Wed, 2 Oct 2024 18:52:40 -0500 Subject: [PATCH 3/8] did some cleanup --- src/main/java/mezz/jei/GuiEventHandler.java | 259 +++++----- .../mezz/jei/IngredientBaseListFactory.java | 248 +++++---- .../java/mezz/jei/IngredientBookmarks.java | 107 ++-- src/main/java/mezz/jei/JeiHelpers.java | 1 - src/main/java/mezz/jei/JeiRuntime.java | 108 ++-- src/main/java/mezz/jei/JeiStarter.java | 322 ++++++------ src/main/java/mezz/jei/api/IJeiHelpers.java | 1 - .../java/mezz/jei/gui/ItemListOverlay.java | 244 ++++----- .../mezz/jei/gui/ItemListOverlayInternal.java | 7 +- .../ingredients/GuiIngredientFastList.java | 6 - .../java/mezz/jei/input/InputHandler.java | 482 +++++++++--------- 11 files changed, 888 insertions(+), 897 deletions(-) diff --git a/src/main/java/mezz/jei/GuiEventHandler.java b/src/main/java/mezz/jei/GuiEventHandler.java index 8fa6e0889..78a2d92b7 100644 --- a/src/main/java/mezz/jei/GuiEventHandler.java +++ b/src/main/java/mezz/jei/GuiEventHandler.java @@ -20,134 +20,133 @@ import org.lwjgl.input.Mouse; public class GuiEventHandler { - private static final String showRecipesText = Translator.translateToLocal("jei.tooltip.show.recipes"); - private final JeiRuntime runtime; - @Nullable - private InputHandler inputHandler; - @Nullable - private GuiContainer previousGui = null; - - public GuiEventHandler(JeiRuntime runtime) { - this.runtime = runtime; - } - - @SubscribeEvent - public void onOverlayToggle(OverlayToggleEvent event) { - GuiScreen currentScreen = Minecraft.getMinecraft().currentScreen; - onNewScreen(currentScreen); - } - - @SubscribeEvent - public void onGuiInit(GuiScreenEvent.InitGuiEvent.Post event) { - GuiScreen gui = event.getGui(); - onNewScreen(gui); - } - - private void onNewScreen(@Nullable GuiScreen screen) { - if (screen instanceof GuiContainer || screen instanceof RecipesGui) { - ItemListOverlay itemListOverlay = runtime.getItemListOverlay(); - ItemListOverlayInternal itemListOverlayInternal = itemListOverlay.create(screen); - inputHandler = new InputHandler(runtime, itemListOverlayInternal); - } else { - inputHandler = null; - } - } - - @SubscribeEvent - public void onGuiOpen(GuiOpenEvent event) { - ItemListOverlay itemListOverlay = runtime.getItemListOverlay(); - - GuiScreen gui = event.getGui(); - if (gui instanceof GuiContainer) { - GuiContainer guiContainer = (GuiContainer) gui; - if (previousGui != guiContainer) { - previousGui = guiContainer; - if (itemListOverlay.isOpen()) { - itemListOverlay.close(); - } - } - } else if (!(gui instanceof RecipesGui)) { - if (itemListOverlay.isOpen()) { - itemListOverlay.close(); - inputHandler = null; - } - } - } - - @SubscribeEvent - public void onDrawBackgroundEventPost(GuiScreenEvent.BackgroundDrawnEvent event) { - ItemListOverlay itemListOverlay = runtime.getItemListOverlay(); - ItemListOverlayInternal itemListOverlayInternal = itemListOverlay.getInternal(); - if (itemListOverlayInternal != null) { - GuiScreen gui = event.getGui(); - if (itemListOverlayInternal.hasScreenChanged(gui)) { - itemListOverlayInternal = itemListOverlay.create(gui); - inputHandler = new InputHandler(runtime, itemListOverlayInternal); - } - - if (itemListOverlayInternal != null) { - itemListOverlayInternal.drawScreen(gui.mc, event.getMouseX(), event.getMouseY()); - } - } - } - - @SubscribeEvent - public void onDrawScreenEventPost(GuiScreenEvent.DrawScreenEvent.Post event) { - GuiScreen gui = event.getGui(); - if (gui instanceof GuiContainer) { - GuiContainer guiContainer = (GuiContainer) gui; - RecipeRegistry recipeRegistry = runtime.getRecipeRegistry(); - if (recipeRegistry.getRecipeClickableArea(guiContainer, event.getMouseX() - guiContainer.guiLeft, - event.getMouseY() - guiContainer.guiTop) != null) { - TooltipRenderer.drawHoveringText(guiContainer.mc, showRecipesText, event.getMouseX(), event.getMouseY()); - } - } - - ItemListOverlay itemListOverlay = runtime.getItemListOverlay(); - ItemListOverlayInternal itemListOverlayInternal = itemListOverlay.getInternal(); - if (itemListOverlayInternal != null) { - itemListOverlayInternal.drawTooltips(gui.mc, event.getMouseX(), event.getMouseY()); - } - } - - @SubscribeEvent - public void onClientTick(TickEvent.ClientTickEvent event) { - if (event.phase == TickEvent.Phase.END) { - return; - } - - ItemListOverlay itemListOverlay = runtime.getItemListOverlay(); - ItemListOverlayInternal itemListOverlayInternal = itemListOverlay.getInternal(); - if (itemListOverlayInternal != null) { - itemListOverlayInternal.handleTick(); - } - } - - @SubscribeEvent - public void onGuiKeyboardEvent(GuiScreenEvent.KeyboardInputEvent.Pre event) { - if (inputHandler != null) { - if (inputHandler.handleKeyEvent()) { - event.setCanceled(true); - } - } - } - - @SubscribeEvent - public void onGuiMouseEvent(GuiScreenEvent.MouseInputEvent.Pre event) { - GuiScreen guiScreen = event.getGui(); - if (inputHandler != null) { - int x = Mouse.getEventX() * guiScreen.width / guiScreen.mc.displayWidth; - int y = guiScreen.height - Mouse.getEventY() * guiScreen.height / guiScreen.mc.displayHeight - 1; - if (inputHandler.handleMouseEvent(guiScreen, x, y)) { - event.setCanceled(true); - } - } - } - - @SubscribeEvent - public void onPotionShiftEvent(GuiScreenEvent.PotionShiftEvent event) { - if (Config.isOverlayEnabled()) { - event.setCanceled(true); - } - } + private static final String showRecipesText = Translator.translateToLocal("jei.tooltip.show.recipes"); + private final JeiRuntime runtime; + @Nullable + private InputHandler inputHandler; + @Nullable + private GuiContainer previousGui = null; + + public GuiEventHandler(JeiRuntime runtime) { + this.runtime = runtime; + } + + @SubscribeEvent + public void onOverlayToggle(OverlayToggleEvent event) { + GuiScreen currentScreen = Minecraft.getMinecraft().currentScreen; + onNewScreen(currentScreen); + } + + @SubscribeEvent + public void onGuiInit(GuiScreenEvent.InitGuiEvent.Post event) { + GuiScreen gui = event.getGui(); + onNewScreen(gui); + } + + private void onNewScreen(@Nullable GuiScreen screen) { + if (screen instanceof GuiContainer || screen instanceof RecipesGui) { + ItemListOverlay itemListOverlay = runtime.getItemListOverlay(); + ItemListOverlayInternal itemListOverlayInternal = itemListOverlay.create(screen); + inputHandler = new InputHandler(runtime, itemListOverlayInternal); + } else { + inputHandler = null; + } + } + + @SubscribeEvent + public void onGuiOpen(GuiOpenEvent event) { + ItemListOverlay itemListOverlay = runtime.getItemListOverlay(); + + GuiScreen gui = event.getGui(); + if (gui instanceof GuiContainer) { + GuiContainer guiContainer = (GuiContainer) gui; + if (previousGui != guiContainer) { + previousGui = guiContainer; + if (itemListOverlay.isOpen()) { + itemListOverlay.close(); + } + } + } else if (!(gui instanceof RecipesGui)) { + if (itemListOverlay.isOpen()) { + itemListOverlay.close(); + inputHandler = null; + } + } + } + + @SubscribeEvent + public void onDrawBackgroundEventPost(GuiScreenEvent.BackgroundDrawnEvent event) { + ItemListOverlay itemListOverlay = runtime.getItemListOverlay(); + ItemListOverlayInternal itemListOverlayInternal = itemListOverlay.getInternal(); + if (itemListOverlayInternal != null) { + GuiScreen gui = event.getGui(); + if (itemListOverlayInternal.hasScreenChanged(gui)) { + itemListOverlayInternal = itemListOverlay.create(gui); + inputHandler = new InputHandler(runtime, itemListOverlayInternal); + } + + if (itemListOverlayInternal != null) { + itemListOverlayInternal.drawScreen(gui.mc, event.getMouseX(), event.getMouseY()); + } + } + } + + @SubscribeEvent + public void onDrawScreenEventPost(GuiScreenEvent.DrawScreenEvent.Post event) { + GuiScreen gui = event.getGui(); + if (gui instanceof GuiContainer) { + GuiContainer guiContainer = (GuiContainer) gui; + RecipeRegistry recipeRegistry = runtime.getRecipeRegistry(); + if (recipeRegistry.getRecipeClickableArea(guiContainer, event.getMouseX() - guiContainer.guiLeft, event.getMouseY() - guiContainer.guiTop) != null) { + TooltipRenderer.drawHoveringText(guiContainer.mc, showRecipesText, event.getMouseX(), event.getMouseY()); + } + } + + ItemListOverlay itemListOverlay = runtime.getItemListOverlay(); + ItemListOverlayInternal itemListOverlayInternal = itemListOverlay.getInternal(); + if (itemListOverlayInternal != null) { + itemListOverlayInternal.drawTooltips(gui.mc, event.getMouseX(), event.getMouseY()); + } + } + + @SubscribeEvent + public void onClientTick(TickEvent.ClientTickEvent event) { + if (event.phase == TickEvent.Phase.END) { + return; + } + + ItemListOverlay itemListOverlay = runtime.getItemListOverlay(); + ItemListOverlayInternal itemListOverlayInternal = itemListOverlay.getInternal(); + if (itemListOverlayInternal != null) { + itemListOverlayInternal.handleTick(); + } + } + + @SubscribeEvent + public void onGuiKeyboardEvent(GuiScreenEvent.KeyboardInputEvent.Pre event) { + if (inputHandler != null) { + if (inputHandler.handleKeyEvent()) { + event.setCanceled(true); + } + } + } + + @SubscribeEvent + public void onGuiMouseEvent(GuiScreenEvent.MouseInputEvent.Pre event) { + GuiScreen guiScreen = event.getGui(); + if (inputHandler != null) { + int x = Mouse.getEventX() * guiScreen.width / guiScreen.mc.displayWidth; + int y = guiScreen.height - Mouse.getEventY() * guiScreen.height / guiScreen.mc.displayHeight - 1; + if (inputHandler.handleMouseEvent(guiScreen, x, y)) { + event.setCanceled(true); + } + } + } + + @SubscribeEvent + public void onPotionShiftEvent(GuiScreenEvent.PotionShiftEvent event) { + if (Config.isOverlayEnabled()) { + event.setCanceled(true); + } + } } diff --git a/src/main/java/mezz/jei/IngredientBaseListFactory.java b/src/main/java/mezz/jei/IngredientBaseListFactory.java index 3ae6a2e9f..2ee8eddf1 100644 --- a/src/main/java/mezz/jei/IngredientBaseListFactory.java +++ b/src/main/java/mezz/jei/IngredientBaseListFactory.java @@ -20,129 +20,127 @@ import net.minecraft.item.ItemStack; public class IngredientBaseListFactory { - private IngredientBaseListFactory() { - - } - - public static ImmutableList create() { - Log.info("Building item filter..."); - long start_time = System.currentTimeMillis(); - - IIngredientRegistry ingredientRegistry = Internal.getIngredientRegistry(); - JeiHelpers jeiHelpers = Internal.getHelpers(); - IngredientChecker ingredientChecker = new IngredientChecker(jeiHelpers); - - List ingredientListElements = new LinkedList(); - - for (Class ingredientClass : ingredientRegistry.getRegisteredIngredientClasses()) { - addToBaseList(ingredientListElements, ingredientRegistry, ingredientChecker, ingredientClass); - } - - sortIngredientListElements(ingredientListElements); - ImmutableList immutableElements = ImmutableList.copyOf(ingredientListElements); - - Log.info("Built item filter in {} ms", System.currentTimeMillis() - start_time); - return immutableElements; - } - - private static void addToBaseList(List baseList, IIngredientRegistry ingredientRegistry, - IngredientChecker ingredientChecker, Class ingredientClass) { - IIngredientHelper ingredientHelper = ingredientRegistry.getIngredientHelper(ingredientClass); - IIngredientRenderer ingredientRenderer = ingredientRegistry.getIngredientRenderer(ingredientClass); - - ImmutableList ingredients = ingredientRegistry.getIngredients(ingredientClass); - for (V ingredient : ingredients) { - if (ingredient != null) { - if (!ingredientChecker.isIngredientHidden(ingredient, ingredientHelper)) { - IngredientListElement ingredientListElement = IngredientListElement.create(ingredient, ingredientHelper, - ingredientRenderer); - if (ingredientListElement != null) { - baseList.add(ingredientListElement); - } - } - } - } - } - - private static void sortIngredientListElements(List ingredientListElements) { - int index = 0; - final Map itemAddedOrder = new HashMap(); - for (IIngredientListElement ingredientListElement : ingredientListElements) { - String uid = getWildcardUid(ingredientListElement); - if (!itemAddedOrder.containsKey(uid)) { - itemAddedOrder.put(uid, index); - index++; - } - } - - Collections.sort(ingredientListElements, new Comparator() { - @Override - public int compare(IIngredientListElement o1, IIngredientListElement o2) { - final String modName1 = getModName(o1); - final String modName2 = getModName(o2); - - if (modName1.equals(modName2)) { - boolean isItemStack1 = (o1.getIngredient() instanceof ItemStack); - boolean isItemStack2 = (o2.getIngredient() instanceof ItemStack); - if (isItemStack1 && !isItemStack2) { - return -1; - } else if (!isItemStack1 && isItemStack2) { - return 1; - } - - final String uid1 = getWildcardUid(o1); - final String uid2 = getWildcardUid(o2); - - final int orderIndex1 = itemAddedOrder.get(uid1); - final int orderIndex2 = itemAddedOrder.get(uid2); - return Java6Helper.compare(orderIndex1, orderIndex2); - } else if (modName1.equals(Constants.minecraftModName)) { - return -1; - } else if (modName2.equals(Constants.minecraftModName)) { - return 1; - } else { - return modName1.compareTo(modName2); - } - } - }); - } - - private static String getModName(IIngredientListElement ingredientListElement) { - V ingredient = ingredientListElement.getIngredient(); - IIngredientHelper ingredientHelper = ingredientListElement.getIngredientHelper(); - String modId = ingredientHelper.getModId(ingredient); - return Internal.getModIdUtil().getModNameForModId(modId); - } - - private static String getWildcardUid(IIngredientListElement ingredientListElement) { - V ingredient = ingredientListElement.getIngredient(); - IIngredientHelper ingredientHelper = ingredientListElement.getIngredientHelper(); - return ingredientHelper.getWildcardId(ingredient); - } - - private static class IngredientChecker { - private final IngredientBlacklist ingredientBlacklist; - - public IngredientChecker(JeiHelpers jeiHelpers) { - ingredientBlacklist = jeiHelpers.getIngredientBlacklist(); - } - - public boolean isIngredientHidden(V ingredient, IIngredientHelper ingredientHelper) { - try { - if (ingredientBlacklist.isIngredientBlacklistedByApi(ingredient)) { - return true; - } - - if (!Config.isEditModeEnabled() && Config.isIngredientOnConfigBlacklist(ingredient, ingredientHelper)) { - return true; - } - } catch (RuntimeException e) { - String ingredientInfo = ingredientHelper.getErrorInfo(ingredient); - Log.error("Could not check blacklist for ingredient {}", ingredientInfo, e); - return true; - } - - return false; - } - } + private IngredientBaseListFactory() { + + } + + public static ImmutableList create() { + Log.info("Building item filter..."); + long start_time = System.currentTimeMillis(); + + IIngredientRegistry ingredientRegistry = Internal.getIngredientRegistry(); + JeiHelpers jeiHelpers = Internal.getHelpers(); + IngredientChecker ingredientChecker = new IngredientChecker(jeiHelpers); + + List ingredientListElements = new LinkedList(); + + for (Class ingredientClass : ingredientRegistry.getRegisteredIngredientClasses()) { + addToBaseList(ingredientListElements, ingredientRegistry, ingredientChecker, ingredientClass); + } + + sortIngredientListElements(ingredientListElements); + ImmutableList immutableElements = ImmutableList.copyOf(ingredientListElements); + + Log.info("Built item filter in {} ms", System.currentTimeMillis() - start_time); + return immutableElements; + } + + private static void addToBaseList(List baseList, IIngredientRegistry ingredientRegistry, IngredientChecker ingredientChecker, Class ingredientClass) { + IIngredientHelper ingredientHelper = ingredientRegistry.getIngredientHelper(ingredientClass); + IIngredientRenderer ingredientRenderer = ingredientRegistry.getIngredientRenderer(ingredientClass); + + ImmutableList ingredients = ingredientRegistry.getIngredients(ingredientClass); + for (V ingredient : ingredients) { + if (ingredient != null) { + if (!ingredientChecker.isIngredientHidden(ingredient, ingredientHelper)) { + IngredientListElement ingredientListElement = IngredientListElement.create(ingredient, ingredientHelper, ingredientRenderer); + if (ingredientListElement != null) { + baseList.add(ingredientListElement); + } + } + } + } + } + + private static void sortIngredientListElements(List ingredientListElements) { + int index = 0; + final Map itemAddedOrder = new HashMap(); + for (IIngredientListElement ingredientListElement : ingredientListElements) { + String uid = getWildcardUid(ingredientListElement); + if (!itemAddedOrder.containsKey(uid)) { + itemAddedOrder.put(uid, index); + index++; + } + } + + Collections.sort(ingredientListElements, new Comparator() { + @Override + public int compare(IIngredientListElement o1, IIngredientListElement o2) { + final String modName1 = getModName(o1); + final String modName2 = getModName(o2); + + if (modName1.equals(modName2)) { + boolean isItemStack1 = (o1.getIngredient() instanceof ItemStack); + boolean isItemStack2 = (o2.getIngredient() instanceof ItemStack); + if (isItemStack1 && !isItemStack2) { + return -1; + } else if (!isItemStack1 && isItemStack2) { + return 1; + } + + final String uid1 = getWildcardUid(o1); + final String uid2 = getWildcardUid(o2); + + final int orderIndex1 = itemAddedOrder.get(uid1); + final int orderIndex2 = itemAddedOrder.get(uid2); + return Java6Helper.compare(orderIndex1, orderIndex2); + } else if (modName1.equals(Constants.minecraftModName)) { + return -1; + } else if (modName2.equals(Constants.minecraftModName)) { + return 1; + } else { + return modName1.compareTo(modName2); + } + } + }); + } + + private static String getModName(IIngredientListElement ingredientListElement) { + V ingredient = ingredientListElement.getIngredient(); + IIngredientHelper ingredientHelper = ingredientListElement.getIngredientHelper(); + String modId = ingredientHelper.getModId(ingredient); + return Internal.getModIdUtil().getModNameForModId(modId); + } + + private static String getWildcardUid(IIngredientListElement ingredientListElement) { + V ingredient = ingredientListElement.getIngredient(); + IIngredientHelper ingredientHelper = ingredientListElement.getIngredientHelper(); + return ingredientHelper.getWildcardId(ingredient); + } + + private static class IngredientChecker { + private final IngredientBlacklist ingredientBlacklist; + + public IngredientChecker(JeiHelpers jeiHelpers) { + ingredientBlacklist = jeiHelpers.getIngredientBlacklist(); + } + + public boolean isIngredientHidden(V ingredient, IIngredientHelper ingredientHelper) { + try { + if (ingredientBlacklist.isIngredientBlacklistedByApi(ingredient)) { + return true; + } + + if (!Config.isEditModeEnabled() && Config.isIngredientOnConfigBlacklist(ingredient, ingredientHelper)) { + return true; + } + } catch (RuntimeException e) { + String ingredientInfo = ingredientHelper.getErrorInfo(ingredient); + Log.error("Could not check blacklist for ingredient {}", ingredientInfo, e); + return true; + } + + return false; + } + } } diff --git a/src/main/java/mezz/jei/IngredientBookmarks.java b/src/main/java/mezz/jei/IngredientBookmarks.java index 592bbc984..9f55e5f4e 100644 --- a/src/main/java/mezz/jei/IngredientBookmarks.java +++ b/src/main/java/mezz/jei/IngredientBookmarks.java @@ -1,9 +1,6 @@ package mezz.jei; -import java.util.ArrayList; import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -17,63 +14,65 @@ import com.google.common.collect.ImmutableList; public class IngredientBookmarks implements IIngredientBookmarks { - private final IIngredientRegistry ingredientRegistry; - private List bookmarkIds = new LinkedList(); - private HashMap bookmarkList = new HashMap(); + private final IIngredientRegistry ingredientRegistry; - public IngredientBookmarks(IIngredientRegistry ingredientRegistry) { - this.ingredientRegistry = ingredientRegistry; - } + // Using both so cause linked list will retain order of insertion + private List bookmarkIds = new LinkedList(); + private HashMap bookmarkList = new HashMap(); - @Override - public void toggleIngredientBookmark(V ingredient) { - IIngredientHelper ingredientHelper = ingredientRegistry.getIngredientHelper(ingredient); - String uniqueId = ingredientHelper.getUniqueId(ingredient); + public IngredientBookmarks(IIngredientRegistry ingredientRegistry) { + this.ingredientRegistry = ingredientRegistry; + } - // find ingredient in registry - ImmutableCollection clazzes = ingredientRegistry.getRegisteredIngredientClasses(); - for (Class clazz: clazzes) { - ImmutableList iList = ingredientRegistry.getIngredients(clazz); - IIngredientHelper iHelper = ingredientRegistry.getIngredientHelper(clazz); - for (V i: iList) { - if (iHelper.getUniqueId(i).equals(uniqueId)) { - ingredient = i; - break; - } - } - } + @Override + public void toggleIngredientBookmark(V ingredient) { + IIngredientHelper ingredientHelper = ingredientRegistry.getIngredientHelper(ingredient); + String uniqueId = ingredientHelper.getUniqueId(ingredient); - // System.out.println(ingredientHelper.getUniqueId(ingredient)); - if (bookmarkIds.contains(uniqueId)){ - bookmarkIds.remove(uniqueId); - bookmarkList.remove(uniqueId); - } else { - bookmarkIds.add(uniqueId); - bookmarkList.put(uniqueId, ingredient); - } - } + // find ingredient in registry + ImmutableCollection clazzes = ingredientRegistry.getRegisteredIngredientClasses(); + for (Class clazz : clazzes) { + ImmutableList iList = ingredientRegistry.getIngredients(clazz); + IIngredientHelper iHelper = ingredientRegistry.getIngredientHelper(clazz); + for (V i : iList) { + if (iHelper.getUniqueId(i).equals(uniqueId)) { + ingredient = i; + break; + } + } + } - @Override - public List getIngredientList() { - List ingredientListElements = new LinkedList(); + // System.out.println(ingredientHelper.getUniqueId(ingredient)); + if (bookmarkIds.contains(uniqueId)) { + bookmarkIds.remove(uniqueId); + bookmarkList.remove(uniqueId); + } else { + bookmarkIds.add(uniqueId); + bookmarkList.put(uniqueId, ingredient); + } + } - for (String uniqueId : bookmarkIds) { - Object ingredient = bookmarkList.get(uniqueId); + @Override + public List getIngredientList() { + List ingredientListElements = new LinkedList(); - IIngredientHelper ingredientHelper = ingredientRegistry.getIngredientHelper(ingredient); - IIngredientRenderer ingredientRenderer = ingredientRegistry.getIngredientRenderer(ingredient); - IngredientListElement ingredientListElement = IngredientListElement.create(ingredient, ingredientHelper, - ingredientRenderer); - if (ingredientListElement != null) { - ingredientListElements.add(ingredientListElement); - } - } - return ingredientListElements; - } + for (String uniqueId : bookmarkIds) { + Object ingredient = bookmarkList.get(uniqueId); - @Override - public void clear(){ - bookmarkIds.clear(); - bookmarkList.clear(); - } + IIngredientHelper ingredientHelper = ingredientRegistry.getIngredientHelper(ingredient); + IIngredientRenderer ingredientRenderer = ingredientRegistry.getIngredientRenderer(ingredient); + IngredientListElement ingredientListElement = IngredientListElement.create(ingredient, ingredientHelper, + ingredientRenderer); + if (ingredientListElement != null) { + ingredientListElements.add(ingredientListElement); + } + } + return ingredientListElements; + } + + @Override + public void clear() { + bookmarkIds.clear(); + bookmarkList.clear(); + } } diff --git a/src/main/java/mezz/jei/JeiHelpers.java b/src/main/java/mezz/jei/JeiHelpers.java index ac297c594..a29d7dec7 100644 --- a/src/main/java/mezz/jei/JeiHelpers.java +++ b/src/main/java/mezz/jei/JeiHelpers.java @@ -4,7 +4,6 @@ import mezz.jei.api.IJeiHelpers; import mezz.jei.api.INbtRegistry; -import mezz.jei.api.INbtRegistry.INbtInterpreter; import mezz.jei.api.ISubtypeRegistry; import mezz.jei.api.ingredients.IIngredientRegistry; import mezz.jei.gui.GuiHelper; diff --git a/src/main/java/mezz/jei/JeiRuntime.java b/src/main/java/mezz/jei/JeiRuntime.java index 61c040a1a..69323c76b 100644 --- a/src/main/java/mezz/jei/JeiRuntime.java +++ b/src/main/java/mezz/jei/JeiRuntime.java @@ -13,66 +13,66 @@ public class JeiRuntime implements IJeiRuntime { - private final RecipeRegistry recipeRegistry; - private final ItemListOverlay itemListOverlay; - private final RecipesGui recipesGui; - private final IngredientRegistry ingredientRegistry; - private final List> advancedGuiHandlers; - private final IngredientBookmarks ingredientBookmarks; + private final RecipeRegistry recipeRegistry; + private final ItemListOverlay itemListOverlay; + private final RecipesGui recipesGui; + private final IngredientRegistry ingredientRegistry; + private final List> advancedGuiHandlers; + private final IngredientBookmarks ingredientBookmarks; - public JeiRuntime(RecipeRegistry recipeRegistry, ItemListOverlay itemListOverlay, RecipesGui recipesGui, - IngredientRegistry ingredientRegistry, List> advancedGuiHandlers, - IngredientBookmarks ingredientBookmarks) { - this.recipeRegistry = recipeRegistry; - this.itemListOverlay = itemListOverlay; - this.recipesGui = recipesGui; - this.ingredientRegistry = ingredientRegistry; - this.advancedGuiHandlers = advancedGuiHandlers; - this.ingredientBookmarks = ingredientBookmarks; - } + public JeiRuntime(RecipeRegistry recipeRegistry, ItemListOverlay itemListOverlay, RecipesGui recipesGui, + IngredientRegistry ingredientRegistry, List> advancedGuiHandlers, + IngredientBookmarks ingredientBookmarks) { + this.recipeRegistry = recipeRegistry; + this.itemListOverlay = itemListOverlay; + this.recipesGui = recipesGui; + this.ingredientRegistry = ingredientRegistry; + this.advancedGuiHandlers = advancedGuiHandlers; + this.ingredientBookmarks = ingredientBookmarks; + } - public void close() { - if (itemListOverlay.isOpen()) { - itemListOverlay.close(); - } - if (recipesGui.isOpen()) { - recipesGui.close(); - } - } + public void close() { + if (itemListOverlay.isOpen()) { + itemListOverlay.close(); + } + if (recipesGui.isOpen()) { + recipesGui.close(); + } + } - @Override - public RecipeRegistry getRecipeRegistry() { - return recipeRegistry; - } + @Override + public RecipeRegistry getRecipeRegistry() { + return recipeRegistry; + } - @Override - public ItemListOverlay getItemListOverlay() { - return itemListOverlay; - } + @Override + public ItemListOverlay getItemListOverlay() { + return itemListOverlay; + } - @Override - public RecipesGui getRecipesGui() { - return recipesGui; - } + @Override + public RecipesGui getRecipesGui() { + return recipesGui; + } - public IngredientRegistry getIngredientRegistry() { - return ingredientRegistry; - } + public IngredientRegistry getIngredientRegistry() { + return ingredientRegistry; + } - public IIngredientBookmarks getIngredientBookmarks() { - return ingredientBookmarks; - } + public IIngredientBookmarks getIngredientBookmarks() { + return ingredientBookmarks; + } - public List> getActiveAdvancedGuiHandlers(GuiScreen guiScreen) { - List> activeAdvancedGuiHandler = new ArrayList>(); - if (guiScreen instanceof GuiContainer) { - for (IAdvancedGuiHandler advancedGuiHandler : advancedGuiHandlers) { - Class guiContainerClass = advancedGuiHandler.getGuiContainerClass(); - if (guiContainerClass.isInstance(guiScreen)) { - activeAdvancedGuiHandler.add(advancedGuiHandler); - } - } - } - return activeAdvancedGuiHandler; - } + public List> getActiveAdvancedGuiHandlers(GuiScreen guiScreen) { + List> activeAdvancedGuiHandler = new ArrayList>(); + if (guiScreen instanceof GuiContainer) { + for (IAdvancedGuiHandler advancedGuiHandler : advancedGuiHandlers) { + Class guiContainerClass = advancedGuiHandler.getGuiContainerClass(); + if (guiContainerClass.isInstance(guiScreen)) { + activeAdvancedGuiHandler.add(advancedGuiHandler); + } + } + } + return activeAdvancedGuiHandler; + } } diff --git a/src/main/java/mezz/jei/JeiStarter.java b/src/main/java/mezz/jei/JeiStarter.java index 1bf589606..ce84fd786 100644 --- a/src/main/java/mezz/jei/JeiStarter.java +++ b/src/main/java/mezz/jei/JeiStarter.java @@ -18,166 +18,164 @@ import net.minecraftforge.fml.common.ProgressManager; public class JeiStarter { - private boolean started; - @Nullable - private GuiEventHandler guiEventHandler; - - public void start(List plugins, boolean resourceReload) { - long jeiStartTime = System.currentTimeMillis(); - - Log.info("Starting JEI..."); - SubtypeRegistry subtypeRegistry = new SubtypeRegistry(); - - registerItemSubtypes(plugins, subtypeRegistry); - - StackHelper stackHelper = new StackHelper(subtypeRegistry); - stackHelper.enableUidCache(); - Internal.setStackHelper(stackHelper); - - IngredientRegistry ingredientRegistry = registerIngredients(plugins); - Internal.setIngredientRegistry(ingredientRegistry); - - JeiHelpers jeiHelpers = new JeiHelpers(ingredientRegistry, stackHelper, subtypeRegistry); - Internal.setHelpers(jeiHelpers); - - ModIdUtil modIdUtil = Internal.getModIdUtil(); - ItemRegistry itemRegistry = new ItemRegistry(ingredientRegistry, modIdUtil); - - ModRegistry modRegistry = new ModRegistry(jeiHelpers, itemRegistry, ingredientRegistry); - - registerPlugins(plugins, modRegistry); - - Log.info("Building recipe registry..."); - long start_time = System.currentTimeMillis(); - RecipeRegistry recipeRegistry = modRegistry.createRecipeRegistry(stackHelper, ingredientRegistry); - Log.info("Built recipe registry in {} ms", System.currentTimeMillis() - start_time); - - IngredientInformation.onStart(resourceReload); - - ItemFilter itemFilter = new ItemFilter(); - - Log.info("Building runtime..."); - start_time = System.currentTimeMillis(); - IngredientBookmarks ingredientBookmarks = new IngredientBookmarks(ingredientRegistry); - List> advancedGuiHandlers = modRegistry.getAdvancedGuiHandlers(); - ItemListOverlay itemListOverlay = new ItemListOverlay(itemFilter, advancedGuiHandlers, ingredientRegistry, - ingredientBookmarks); - RecipesGui recipesGui = new RecipesGui(recipeRegistry); - JeiRuntime jeiRuntime = new JeiRuntime(recipeRegistry, itemListOverlay, recipesGui, ingredientRegistry, - advancedGuiHandlers, ingredientBookmarks); - Internal.setRuntime(jeiRuntime); - Log.info("Built runtime in {} ms", System.currentTimeMillis() - start_time); - - stackHelper.disableUidCache(); - - sendRuntime(plugins, jeiRuntime); - - if (guiEventHandler != null) { - MinecraftForge.EVENT_BUS.unregister(guiEventHandler); - } - guiEventHandler = new GuiEventHandler(jeiRuntime); - MinecraftForge.EVENT_BUS.register(guiEventHandler); - - started = true; - Log.info("Finished Starting JEI in {} ms", System.currentTimeMillis() - jeiStartTime); - } - - public boolean hasStarted() { - return started; - } - - private static void registerItemSubtypes(List plugins, SubtypeRegistry subtypeRegistry) { - ProgressManager.ProgressBar progressBar = ProgressManager.push("Registering item subtypes", plugins.size()); - Iterator iterator = plugins.iterator(); - while (iterator.hasNext()) { - IModPlugin plugin = iterator.next(); - try { - progressBar.step(plugin.getClass().getName()); - plugin.registerItemSubtypes(subtypeRegistry); - } catch (RuntimeException e) { - Log.error("Failed to register item subtypes for mod plugin: {}", plugin.getClass(), e); - iterator.remove(); - } catch (AbstractMethodError ignored) { - // legacy mod plugins do not have registerItemSubtypes - } - } - ProgressManager.pop(progressBar); - } - - private static IngredientRegistry registerIngredients(List plugins) { - ProgressManager.ProgressBar progressBar = ProgressManager.push("Registering ingredients", plugins.size()); - ModIngredientRegistration modIngredientRegistry = new ModIngredientRegistration(); - - Iterator iterator = plugins.iterator(); - while (iterator.hasNext()) { - IModPlugin plugin = iterator.next(); - try { - progressBar.step(plugin.getClass().getName()); - plugin.registerIngredients(modIngredientRegistry); - } catch (RuntimeException e) { - if (VanillaPlugin.class.isInstance(plugin)) { - throw e; - } else { - Log.error("Failed to register Ingredients for mod plugin: {}", plugin.getClass(), e); - iterator.remove(); - } - } catch (AbstractMethodError ignored) { - if (VanillaPlugin.class.isInstance(plugin)) { - throw ignored; - } - // legacy mod plugins do not have registerIngredients - } - } - ProgressManager.pop(progressBar); - - return modIngredientRegistry.createIngredientRegistry(); - } - - private static void registerPlugins(List plugins, ModRegistry modRegistry) { - ProgressManager.ProgressBar progressBar = ProgressManager.push("Registering plugins", plugins.size()); - Iterator iterator = plugins.iterator(); - while (iterator.hasNext()) { - IModPlugin plugin = iterator.next(); - try { - progressBar.step(plugin.getClass().getName()); - long start_time = System.currentTimeMillis(); - Log.info("Registering plugin: {} ...", plugin.getClass().getName()); - plugin.register(modRegistry); - long timeElapsedMs = System.currentTimeMillis() - start_time; - Log.info("Registered plugin: {} in {} ms", plugin.getClass().getName(), timeElapsedMs); - } catch (RuntimeException e) { - Log.error("Failed to register mod plugin: {}", plugin.getClass(), e); - iterator.remove(); - } catch (LinkageError e) { - Log.error("Failed to register mod plugin: {}", plugin.getClass(), e); - iterator.remove(); - } - } - ProgressManager.pop(progressBar); - } - - private static void sendRuntime(List plugins, IJeiRuntime jeiRuntime) { - ProgressManager.ProgressBar progressBar = ProgressManager.push("Sending Runtime", plugins.size()); - Iterator iterator = plugins.iterator(); - while (iterator.hasNext()) { - IModPlugin plugin = iterator.next(); - try { - progressBar.step(plugin.getClass().getName()); - long start_time = System.currentTimeMillis(); - Log.info("Sending runtime to plugin: {} ...", plugin.getClass().getName()); - plugin.onRuntimeAvailable(jeiRuntime); - long timeElapsedMs = System.currentTimeMillis() - start_time; - if (timeElapsedMs > 100) { - Log.warning("Sending runtime to plugin: {} took {} ms", plugin.getClass().getName(), timeElapsedMs); - } - } catch (RuntimeException e) { - Log.error("Sending runtime to plugin failed: {}", plugin.getClass(), e); - iterator.remove(); - } catch (LinkageError e) { - Log.error("Sending runtime to plugin failed: {}", plugin.getClass(), e); - iterator.remove(); - } - } - ProgressManager.pop(progressBar); - } + private boolean started; + @Nullable + private GuiEventHandler guiEventHandler; + + public void start(List plugins, boolean resourceReload) { + long jeiStartTime = System.currentTimeMillis(); + + Log.info("Starting JEI..."); + SubtypeRegistry subtypeRegistry = new SubtypeRegistry(); + + registerItemSubtypes(plugins, subtypeRegistry); + + StackHelper stackHelper = new StackHelper(subtypeRegistry); + stackHelper.enableUidCache(); + Internal.setStackHelper(stackHelper); + + IngredientRegistry ingredientRegistry = registerIngredients(plugins); + Internal.setIngredientRegistry(ingredientRegistry); + + JeiHelpers jeiHelpers = new JeiHelpers(ingredientRegistry, stackHelper, subtypeRegistry); + Internal.setHelpers(jeiHelpers); + + ModIdUtil modIdUtil = Internal.getModIdUtil(); + ItemRegistry itemRegistry = new ItemRegistry(ingredientRegistry, modIdUtil); + + ModRegistry modRegistry = new ModRegistry(jeiHelpers, itemRegistry, ingredientRegistry); + + registerPlugins(plugins, modRegistry); + + Log.info("Building recipe registry..."); + long start_time = System.currentTimeMillis(); + RecipeRegistry recipeRegistry = modRegistry.createRecipeRegistry(stackHelper, ingredientRegistry); + Log.info("Built recipe registry in {} ms", System.currentTimeMillis() - start_time); + + IngredientInformation.onStart(resourceReload); + + ItemFilter itemFilter = new ItemFilter(); + + Log.info("Building runtime..."); + start_time = System.currentTimeMillis(); + IngredientBookmarks ingredientBookmarks = new IngredientBookmarks(ingredientRegistry); + List> advancedGuiHandlers = modRegistry.getAdvancedGuiHandlers(); + ItemListOverlay itemListOverlay = new ItemListOverlay(itemFilter, advancedGuiHandlers, ingredientRegistry, ingredientBookmarks); + RecipesGui recipesGui = new RecipesGui(recipeRegistry); + JeiRuntime jeiRuntime = new JeiRuntime(recipeRegistry, itemListOverlay, recipesGui, ingredientRegistry, advancedGuiHandlers, ingredientBookmarks); + Internal.setRuntime(jeiRuntime); + Log.info("Built runtime in {} ms", System.currentTimeMillis() - start_time); + + stackHelper.disableUidCache(); + + sendRuntime(plugins, jeiRuntime); + + if (guiEventHandler != null) { + MinecraftForge.EVENT_BUS.unregister(guiEventHandler); + } + guiEventHandler = new GuiEventHandler(jeiRuntime); + MinecraftForge.EVENT_BUS.register(guiEventHandler); + + started = true; + Log.info("Finished Starting JEI in {} ms", System.currentTimeMillis() - jeiStartTime); + } + + public boolean hasStarted() { + return started; + } + + private static void registerItemSubtypes(List plugins, SubtypeRegistry subtypeRegistry) { + ProgressManager.ProgressBar progressBar = ProgressManager.push("Registering item subtypes", plugins.size()); + Iterator iterator = plugins.iterator(); + while (iterator.hasNext()) { + IModPlugin plugin = iterator.next(); + try { + progressBar.step(plugin.getClass().getName()); + plugin.registerItemSubtypes(subtypeRegistry); + } catch (RuntimeException e) { + Log.error("Failed to register item subtypes for mod plugin: {}", plugin.getClass(), e); + iterator.remove(); + } catch (AbstractMethodError ignored) { + // legacy mod plugins do not have registerItemSubtypes + } + } + ProgressManager.pop(progressBar); + } + + private static IngredientRegistry registerIngredients(List plugins) { + ProgressManager.ProgressBar progressBar = ProgressManager.push("Registering ingredients", plugins.size()); + ModIngredientRegistration modIngredientRegistry = new ModIngredientRegistration(); + + Iterator iterator = plugins.iterator(); + while (iterator.hasNext()) { + IModPlugin plugin = iterator.next(); + try { + progressBar.step(plugin.getClass().getName()); + plugin.registerIngredients(modIngredientRegistry); + } catch (RuntimeException e) { + if (VanillaPlugin.class.isInstance(plugin)) { + throw e; + } else { + Log.error("Failed to register Ingredients for mod plugin: {}", plugin.getClass(), e); + iterator.remove(); + } + } catch (AbstractMethodError ignored) { + if (VanillaPlugin.class.isInstance(plugin)) { + throw ignored; + } + // legacy mod plugins do not have registerIngredients + } + } + ProgressManager.pop(progressBar); + + return modIngredientRegistry.createIngredientRegistry(); + } + + private static void registerPlugins(List plugins, ModRegistry modRegistry) { + ProgressManager.ProgressBar progressBar = ProgressManager.push("Registering plugins", plugins.size()); + Iterator iterator = plugins.iterator(); + while (iterator.hasNext()) { + IModPlugin plugin = iterator.next(); + try { + progressBar.step(plugin.getClass().getName()); + long start_time = System.currentTimeMillis(); + Log.info("Registering plugin: {} ...", plugin.getClass().getName()); + plugin.register(modRegistry); + long timeElapsedMs = System.currentTimeMillis() - start_time; + Log.info("Registered plugin: {} in {} ms", plugin.getClass().getName(), timeElapsedMs); + } catch (RuntimeException e) { + Log.error("Failed to register mod plugin: {}", plugin.getClass(), e); + iterator.remove(); + } catch (LinkageError e) { + Log.error("Failed to register mod plugin: {}", plugin.getClass(), e); + iterator.remove(); + } + } + ProgressManager.pop(progressBar); + } + + private static void sendRuntime(List plugins, IJeiRuntime jeiRuntime) { + ProgressManager.ProgressBar progressBar = ProgressManager.push("Sending Runtime", plugins.size()); + Iterator iterator = plugins.iterator(); + while (iterator.hasNext()) { + IModPlugin plugin = iterator.next(); + try { + progressBar.step(plugin.getClass().getName()); + long start_time = System.currentTimeMillis(); + Log.info("Sending runtime to plugin: {} ...", plugin.getClass().getName()); + plugin.onRuntimeAvailable(jeiRuntime); + long timeElapsedMs = System.currentTimeMillis() - start_time; + if (timeElapsedMs > 100) { + Log.warning("Sending runtime to plugin: {} took {} ms", plugin.getClass().getName(), timeElapsedMs); + } + } catch (RuntimeException e) { + Log.error("Sending runtime to plugin failed: {}", plugin.getClass(), e); + iterator.remove(); + } catch (LinkageError e) { + Log.error("Sending runtime to plugin failed: {}", plugin.getClass(), e); + iterator.remove(); + } + } + ProgressManager.pop(progressBar); + } } diff --git a/src/main/java/mezz/jei/api/IJeiHelpers.java b/src/main/java/mezz/jei/api/IJeiHelpers.java index 0f1a6a374..3c415ae70 100644 --- a/src/main/java/mezz/jei/api/IJeiHelpers.java +++ b/src/main/java/mezz/jei/api/IJeiHelpers.java @@ -1,7 +1,6 @@ package mezz.jei.api; import mezz.jei.api.ingredients.IIngredientBlacklist; -import mezz.jei.api.ingredients.IIngredientBookmarks; import mezz.jei.api.recipe.IStackHelper; import mezz.jei.api.recipe.transfer.IRecipeTransferHandlerHelper; diff --git a/src/main/java/mezz/jei/gui/ItemListOverlay.java b/src/main/java/mezz/jei/gui/ItemListOverlay.java index 0083a4499..3b4824c22 100644 --- a/src/main/java/mezz/jei/gui/ItemListOverlay.java +++ b/src/main/java/mezz/jei/gui/ItemListOverlay.java @@ -18,126 +18,126 @@ import net.minecraft.item.ItemStack; public class ItemListOverlay implements IItemListOverlay { - private final ItemFilter itemFilter; - private final List> advancedGuiHandlers; - private final IIngredientRegistry ingredientRegistry; - private final Set highlightedStacks = new HashSet(); - private final IIngredientBookmarks ingredientBookmarks; - - @Nullable - private ItemListOverlayInternal internal; - - public ItemListOverlay(ItemFilter itemFilter, List> advancedGuiHandlers, - IIngredientRegistry ingredientRegistry, IIngredientBookmarks ingredientBookmarks) { - this.itemFilter = itemFilter; - this.advancedGuiHandlers = advancedGuiHandlers; - this.ingredientRegistry = ingredientRegistry; - this.ingredientBookmarks = ingredientBookmarks; - } - - @Nullable - public ItemListOverlayInternal create(GuiScreen guiScreen) { - close(); - - if (Config.isOverlayEnabled()) { - GuiProperties guiProperties = GuiProperties.create(guiScreen); - if (guiProperties != null) { - final int columns = ItemListOverlayInternal.getColumns(guiProperties); - if (columns >= 4) { - internal = new ItemListOverlayInternal(this, ingredientRegistry, guiScreen, guiProperties); - return internal; - } - } - } - - return null; - } - - @Nullable - public ItemListOverlayInternal getInternal() { - return internal; - } - - @Nullable - @Override - public ItemStack getStackUnderMouse() { - if (internal != null) { - return internal.getStackUnderMouse(); - } - return null; - } - - @Override - public void setFilterText(@Nullable String filterText) { - if (filterText == null) { - Log.error("null filterText", new NullPointerException()); - return; - } - - Config.setFilterText(filterText); - - if (internal != null) { - internal.setFilterText(filterText); - } - } - - public void rebuildItemFilter() { - ItemFilter itemFilter = getItemFilter(); - itemFilter.rebuild(); - ItemListOverlayInternal.setToFirstPage(); - if (internal != null) { - internal.updateLayout(); - } - } - - @Override - public String getFilterText() { - return Config.getFilterText(); - } - - @Override - public ImmutableList getVisibleStacks() { - if (internal == null) { - return ImmutableList.of(); - } - return internal.getVisibleStacks(); - } - - @Override - public ImmutableList getFilteredStacks() { - return itemFilter.getItemStacks(); - } - - @Override - public void highlightStacks(Collection stacks) { - highlightedStacks.clear(); - highlightedStacks.addAll(stacks); - } - - public Set getHighlightedStacks() { - return highlightedStacks; - } - - public ItemFilter getItemFilter() { - return itemFilter; - } - - public List> getAdvancedGuiHandlers() { - return advancedGuiHandlers; - } - - public boolean isOpen() { - return internal != null; - } - - public void close() { - if (internal != null) { - internal.close(); - } - internal = null; - } - - public IIngredientBookmarks getIngredientBookmarks() { - return ingredientBookmarks; - } + private final ItemFilter itemFilter; + private final List> advancedGuiHandlers; + private final IIngredientRegistry ingredientRegistry; + private final Set highlightedStacks = new HashSet(); + private final IIngredientBookmarks ingredientBookmarks; + + @Nullable + private ItemListOverlayInternal internal; + + public ItemListOverlay(ItemFilter itemFilter, List> advancedGuiHandlers, + IIngredientRegistry ingredientRegistry, IIngredientBookmarks ingredientBookmarks) { + this.itemFilter = itemFilter; + this.advancedGuiHandlers = advancedGuiHandlers; + this.ingredientRegistry = ingredientRegistry; + this.ingredientBookmarks = ingredientBookmarks; + } + + @Nullable + public ItemListOverlayInternal create(GuiScreen guiScreen) { + close(); + + if (Config.isOverlayEnabled()) { + GuiProperties guiProperties = GuiProperties.create(guiScreen); + if (guiProperties != null) { + final int columns = ItemListOverlayInternal.getColumns(guiProperties); + if (columns >= 4) { + internal = new ItemListOverlayInternal(this, ingredientRegistry, guiScreen, guiProperties); + return internal; + } + } + } + + return null; + } + + @Nullable + public ItemListOverlayInternal getInternal() { + return internal; + } + + @Nullable + @Override + public ItemStack getStackUnderMouse() { + if (internal != null) { + return internal.getStackUnderMouse(); + } + return null; + } + + @Override + public void setFilterText(@Nullable String filterText) { + if (filterText == null) { + Log.error("null filterText", new NullPointerException()); + return; + } + + Config.setFilterText(filterText); + + if (internal != null) { + internal.setFilterText(filterText); + } + } + + public void rebuildItemFilter() { + ItemFilter itemFilter = getItemFilter(); + itemFilter.rebuild(); + ItemListOverlayInternal.setToFirstPage(); + if (internal != null) { + internal.updateLayout(); + } + } + + @Override + public String getFilterText() { + return Config.getFilterText(); + } + + @Override + public ImmutableList getVisibleStacks() { + if (internal == null) { + return ImmutableList.of(); + } + return internal.getVisibleStacks(); + } + + @Override + public ImmutableList getFilteredStacks() { + return itemFilter.getItemStacks(); + } + + @Override + public void highlightStacks(Collection stacks) { + highlightedStacks.clear(); + highlightedStacks.addAll(stacks); + } + + public Set getHighlightedStacks() { + return highlightedStacks; + } + + public ItemFilter getItemFilter() { + return itemFilter; + } + + public List> getAdvancedGuiHandlers() { + return advancedGuiHandlers; + } + + public boolean isOpen() { + return internal != null; + } + + public void close() { + if (internal != null) { + internal.close(); + } + internal = null; + } + + public IIngredientBookmarks getIngredientBookmarks() { + return ingredientBookmarks; + } } diff --git a/src/main/java/mezz/jei/gui/ItemListOverlayInternal.java b/src/main/java/mezz/jei/gui/ItemListOverlayInternal.java index 56928f249..64c36e1b6 100644 --- a/src/main/java/mezz/jei/gui/ItemListOverlayInternal.java +++ b/src/main/java/mezz/jei/gui/ItemListOverlayInternal.java @@ -118,10 +118,12 @@ public ItemListOverlayInternal(ItemListOverlay parent, IIngredientRegistry ingre final int buttonStartY = buttonSize + (2 * borderPadding) + (yItemButtonSpace - itemButtonsHeight) / 2; // this renders the items gui createItemButtons(guiIngredientList, guiAreas, leftEdge, buttonStartY, columns, rows); + // Alight with bottom of clear button createItemButtons(guiBookmarks, guiAreas, 0, guiProperties.getGuiTop() + buttonSize, columns, rows); nextButton = new GuiButton(0, rightEdge - buttonSize, borderPadding, buttonSize, buttonSize, nextLabel); backButton = new GuiButton(1, leftEdge, borderPadding, buttonSize, buttonSize, backLabel); + // align with the top of inventory gui clearButton = new GuiButton(3, 0, guiProperties.getGuiTop(), buttonSize * 3, buttonSize, "CLEAR"); final int searchFieldX; @@ -396,8 +398,11 @@ public void handleTick() { @Override public boolean isMouseOver(int mouseX, int mouseY) { + // Clickable area is anywhere outside of the inventory screen. Should probably + // narrow this down, but I don't know how do detect other mods that might be + // using the screen. if (mouseX > guiProperties.getGuiLeft() && mouseX < guiProperties.getGuiLeft() + guiProperties.getGuiXSize() - && mouseY > guiProperties.getGuiTop() && mouseY < guiProperties.getGuiTop() + guiProperties.getGuiYSize()) { + && mouseY > guiProperties.getGuiTop() && mouseY < guiProperties.getGuiTop() + guiProperties.getGuiYSize()) { return false; } // if (mouseX < guiProperties.getGuiLeft() + guiProperties.getGuiXSize()) { diff --git a/src/main/java/mezz/jei/gui/ingredients/GuiIngredientFastList.java b/src/main/java/mezz/jei/gui/ingredients/GuiIngredientFastList.java index e21c22424..786c8ddab 100644 --- a/src/main/java/mezz/jei/gui/ingredients/GuiIngredientFastList.java +++ b/src/main/java/mezz/jei/gui/ingredients/GuiIngredientFastList.java @@ -27,16 +27,10 @@ public class GuiIngredientFastList { private final IIngredientRegistry ingredientRegistry; - private boolean sortDisabled = false; - public GuiIngredientFastList(IIngredientRegistry ingredientRegistry) { this.ingredientRegistry = ingredientRegistry; } - public void setSortDisabled(boolean sortDisabled) { - this.sortDisabled = sortDisabled; - } - public void clear() { renderAll.clear(); diff --git a/src/main/java/mezz/jei/input/InputHandler.java b/src/main/java/mezz/jei/input/InputHandler.java index 80e1a3c28..09d96768e 100644 --- a/src/main/java/mezz/jei/input/InputHandler.java +++ b/src/main/java/mezz/jei/input/InputHandler.java @@ -29,245 +29,245 @@ import net.minecraftforge.fluids.FluidStack; public class InputHandler { - private final RecipeRegistry recipeRegistry; - private final IIngredientRegistry ingredientRegistry; - private final RecipesGui recipesGui; - @Nullable - private final ItemListOverlayInternal itemListOverlayInternal; - private final MouseHelper mouseHelper; - private final List showsRecipeFocuses = new ArrayList(); - private final IIngredientBookmarks ingredientBookmarks; - - private boolean clickHandled = false; - - public InputHandler(JeiRuntime runtime, @Nullable ItemListOverlayInternal itemListOverlayInternal) { - this.recipeRegistry = runtime.getRecipeRegistry(); - this.ingredientRegistry = runtime.getIngredientRegistry(); - this.recipesGui = runtime.getRecipesGui(); - this.itemListOverlayInternal = itemListOverlayInternal; - this.ingredientBookmarks = runtime.getIngredientBookmarks(); - - this.mouseHelper = new MouseHelper(); - - showsRecipeFocuses.add(recipesGui); - if (itemListOverlayInternal != null) { - showsRecipeFocuses.add(itemListOverlayInternal); - } - showsRecipeFocuses.add(new GuiContainerWrapper()); - } - - public boolean handleMouseEvent(GuiScreen guiScreen, int mouseX, int mouseY) { - boolean cancelEvent = false; - if (Mouse.getEventButton() > -1) { - if (Mouse.getEventButtonState()) { - if (!clickHandled) { - cancelEvent = handleMouseClick(guiScreen, Mouse.getEventButton(), mouseX, mouseY); - clickHandled = cancelEvent; - } - } else if (clickHandled) { - clickHandled = false; - cancelEvent = true; - } - } else if (Mouse.getEventDWheel() != 0) { - cancelEvent = handleMouseScroll(Mouse.getEventDWheel(), mouseX, mouseY); - } - return cancelEvent; - } - - private boolean handleMouseScroll(int dWheel, int mouseX, int mouseY) { - return itemListOverlayInternal != null && itemListOverlayInternal.handleMouseScrolled(mouseX, mouseY, dWheel); - } - - private boolean handleMouseClick(GuiScreen guiScreen, int mouseButton, int mouseX, int mouseY) { - if (itemListOverlayInternal != null && itemListOverlayInternal.handleMouseClicked(mouseX, mouseY, mouseButton)) { - return true; - } - - IClickedIngredient clicked = getFocusUnderMouseForClick(mouseX, mouseY); - if (clicked != null && handleMouseClickedFocus(mouseButton, clicked)) { - return true; - } - - if (guiScreen instanceof GuiContainer) { - GuiContainer guiContainer = (GuiContainer) guiScreen; - RecipeClickableArea clickableArea = recipeRegistry.getRecipeClickableArea(guiContainer, - mouseX - guiContainer.guiLeft, mouseY - guiContainer.guiTop); - if (clickableArea != null) { - List recipeCategoryUids = clickableArea.getRecipeCategoryUids(); - recipesGui.showCategories(recipeCategoryUids); - } - } - - return false; - } - - @Nullable - private IClickedIngredient getFocusUnderMouseForClick(int mouseX, int mouseY) { - for (IShowsRecipeFocuses gui : showsRecipeFocuses) { - if (gui.canSetFocusWithMouse()) { - IClickedIngredient clicked = gui.getIngredientUnderMouse(mouseX, mouseY); - if (clicked != null) { - return clicked; - } - } - } - return null; - } - - @Nullable - private IClickedIngredient getIngredientUnderMouseForKey(int mouseX, int mouseY) { - for (IShowsRecipeFocuses gui : showsRecipeFocuses) { - IClickedIngredient clicked = gui.getIngredientUnderMouse(mouseX, mouseY); - if (clicked != null) { - return clicked; - } - } - return null; - } - - private boolean handleMouseClickedFocus(int mouseButton, IClickedIngredient clicked) { - if (Config.isEditModeEnabled()) { - if (handleClickEdit(mouseButton, clicked.getValue())) { - return true; - } - } - - if (Config.isCheatItemsEnabled() && clicked.allowsCheating() && !recipesGui.isOpen()) { - Object focusValue = clicked.getValue(); - if (focusValue instanceof ItemStack) { - ItemStack itemStack = (ItemStack) focusValue; - CommandUtil.giveStack(itemStack, mouseButton); - return true; - } - } - - if (mouseButton == 0) { - IFocus focus = new Focus(IFocus.Mode.OUTPUT, clicked.getValue()); - recipesGui.show(focus); - return true; - } else if (mouseButton == 1) { - IFocus focus = new Focus(IFocus.Mode.INPUT, clicked.getValue()); - recipesGui.show(focus); - return true; - } - - return false; - } - - private boolean handleClickEdit(int mouseButton, V ingredient) { - Config.IngredientBlacklistType blacklistType = null; - if (GuiScreen.isCtrlKeyDown()) { - if (GuiScreen.isShiftKeyDown()) { - if (mouseButton == 0) { - blacklistType = Config.IngredientBlacklistType.MOD_ID; - } - } else { - if (mouseButton == 0) { - blacklistType = Config.IngredientBlacklistType.ITEM; - } else if (mouseButton == 1) { - blacklistType = Config.IngredientBlacklistType.WILDCARD; - } - } - } - - if (blacklistType == null) { - return false; - } - - IIngredientHelper ingredientHelper = ingredientRegistry.getIngredientHelper(ingredient); - - if (Config.isIngredientOnConfigBlacklist(ingredient, blacklistType, ingredientHelper)) { - Config.removeIngredientFromConfigBlacklist(ingredient, blacklistType, ingredientHelper); - } else { - Config.addIngredientToConfigBlacklist(ingredient, blacklistType, ingredientHelper); - } - return true; - } - - public boolean handleKeyEvent() { - char typedChar = Keyboard.getEventCharacter(); - int eventKey = Keyboard.getEventKey(); - - return ((eventKey == 0 && typedChar >= 32) || Keyboard.getEventKeyState()) && - handleKeyDown(typedChar, eventKey); - } - - private boolean handleKeyDown(char typedChar, int eventKey) { - if (itemListOverlayInternal != null && itemListOverlayInternal.hasKeyboardFocus()) { - if (isInventoryCloseKey(eventKey) || isEnterKey(eventKey)) { - itemListOverlayInternal.setKeyboardFocus(false); - return true; - } else if (itemListOverlayInternal.onKeyPressed(typedChar, eventKey)) { - return true; - } - } - - if (KeyBindings.toggleOverlay.isActiveAndMatches(eventKey)) { - Config.toggleOverlayEnabled(); - return false; - } - - if (itemListOverlayInternal != null) { - if (KeyBindings.toggleCheatMode.isActiveAndMatches(eventKey)) { - Config.toggleCheatItemsEnabled(); - return true; - } - - if (KeyBindings.focusSearch.isActiveAndMatches(eventKey)) { - itemListOverlayInternal.setKeyboardFocus(true); - return true; - } - } - - if (!isContainerTextFieldFocused()) { - final boolean showRecipe = KeyBindings.showRecipe.isActiveAndMatches(eventKey); - final boolean showUses = KeyBindings.showUses.isActiveAndMatches(eventKey); - final boolean toggleBookmark = KeyBindings.toggleBookmark.isActiveAndMatches(eventKey); - if (showRecipe || showUses) { - IClickedIngredient clicked = getIngredientUnderMouseForKey(mouseHelper.getX(), mouseHelper.getY()); - if (clicked != null) { - IFocus.Mode mode = showRecipe ? IFocus.Mode.OUTPUT : IFocus.Mode.INPUT; - recipesGui.show(new Focus(mode, clicked.getValue())); - return true; - } - } - - if (toggleBookmark) { - // get the bookmarks list and add or remove the clicked ingredient - IClickedIngredient clicked = getIngredientUnderMouseForKey(mouseHelper.getX(), mouseHelper.getY()); - if (clicked != null) { - ingredientBookmarks.toggleIngredientBookmark(clicked.getValue()); - itemListOverlayInternal.updateLayout(); - return true; - } - } - - if (itemListOverlayInternal != null && itemListOverlayInternal.onKeyPressed(typedChar, eventKey)) { - return true; - } - } - - return false; - } - - private boolean isContainerTextFieldFocused() { - GuiScreen gui = Minecraft.getMinecraft().currentScreen; - if (gui == null) { - return false; - } - GuiTextField textField = ReflectionUtil.getFieldWithClass(gui, GuiTextField.class); - return textField != null && textField.getVisible() && textField.isEnabled && textField.isFocused(); - } - - public static boolean isInventoryToggleKey(int keyCode) { - return Minecraft.getMinecraft().gameSettings.keyBindInventory.isActiveAndMatches(keyCode); - } - - public static boolean isInventoryCloseKey(int keyCode) { - return keyCode == Keyboard.KEY_ESCAPE; - } - - public static boolean isEnterKey(int keyCode) { - return keyCode == Keyboard.KEY_RETURN; - } + private final RecipeRegistry recipeRegistry; + private final IIngredientRegistry ingredientRegistry; + private final RecipesGui recipesGui; + @Nullable + private final ItemListOverlayInternal itemListOverlayInternal; + private final MouseHelper mouseHelper; + private final List showsRecipeFocuses = new ArrayList(); + private final IIngredientBookmarks ingredientBookmarks; + + private boolean clickHandled = false; + + public InputHandler(JeiRuntime runtime, @Nullable ItemListOverlayInternal itemListOverlayInternal) { + this.recipeRegistry = runtime.getRecipeRegistry(); + this.ingredientRegistry = runtime.getIngredientRegistry(); + this.recipesGui = runtime.getRecipesGui(); + this.itemListOverlayInternal = itemListOverlayInternal; + this.ingredientBookmarks = runtime.getIngredientBookmarks(); + + this.mouseHelper = new MouseHelper(); + + showsRecipeFocuses.add(recipesGui); + if (itemListOverlayInternal != null) { + showsRecipeFocuses.add(itemListOverlayInternal); + } + showsRecipeFocuses.add(new GuiContainerWrapper()); + } + + public boolean handleMouseEvent(GuiScreen guiScreen, int mouseX, int mouseY) { + boolean cancelEvent = false; + if (Mouse.getEventButton() > -1) { + if (Mouse.getEventButtonState()) { + if (!clickHandled) { + cancelEvent = handleMouseClick(guiScreen, Mouse.getEventButton(), mouseX, mouseY); + clickHandled = cancelEvent; + } + } else if (clickHandled) { + clickHandled = false; + cancelEvent = true; + } + } else if (Mouse.getEventDWheel() != 0) { + cancelEvent = handleMouseScroll(Mouse.getEventDWheel(), mouseX, mouseY); + } + return cancelEvent; + } + + private boolean handleMouseScroll(int dWheel, int mouseX, int mouseY) { + return itemListOverlayInternal != null && itemListOverlayInternal.handleMouseScrolled(mouseX, mouseY, dWheel); + } + + private boolean handleMouseClick(GuiScreen guiScreen, int mouseButton, int mouseX, int mouseY) { + if (itemListOverlayInternal != null && itemListOverlayInternal.handleMouseClicked(mouseX, mouseY, mouseButton)) { + return true; + } + + IClickedIngredient clicked = getFocusUnderMouseForClick(mouseX, mouseY); + if (clicked != null && handleMouseClickedFocus(mouseButton, clicked)) { + return true; + } + + if (guiScreen instanceof GuiContainer) { + GuiContainer guiContainer = (GuiContainer) guiScreen; + RecipeClickableArea clickableArea = recipeRegistry.getRecipeClickableArea(guiContainer, + mouseX - guiContainer.guiLeft, mouseY - guiContainer.guiTop); + if (clickableArea != null) { + List recipeCategoryUids = clickableArea.getRecipeCategoryUids(); + recipesGui.showCategories(recipeCategoryUids); + } + } + + return false; + } + + @Nullable + private IClickedIngredient getFocusUnderMouseForClick(int mouseX, int mouseY) { + for (IShowsRecipeFocuses gui : showsRecipeFocuses) { + if (gui.canSetFocusWithMouse()) { + IClickedIngredient clicked = gui.getIngredientUnderMouse(mouseX, mouseY); + if (clicked != null) { + return clicked; + } + } + } + return null; + } + + @Nullable + private IClickedIngredient getIngredientUnderMouseForKey(int mouseX, int mouseY) { + for (IShowsRecipeFocuses gui : showsRecipeFocuses) { + IClickedIngredient clicked = gui.getIngredientUnderMouse(mouseX, mouseY); + if (clicked != null) { + return clicked; + } + } + return null; + } + + private boolean handleMouseClickedFocus(int mouseButton, IClickedIngredient clicked) { + if (Config.isEditModeEnabled()) { + if (handleClickEdit(mouseButton, clicked.getValue())) { + return true; + } + } + + if (Config.isCheatItemsEnabled() && clicked.allowsCheating() && !recipesGui.isOpen()) { + Object focusValue = clicked.getValue(); + if (focusValue instanceof ItemStack) { + ItemStack itemStack = (ItemStack) focusValue; + CommandUtil.giveStack(itemStack, mouseButton); + return true; + } + } + + if (mouseButton == 0) { + IFocus focus = new Focus(IFocus.Mode.OUTPUT, clicked.getValue()); + recipesGui.show(focus); + return true; + } else if (mouseButton == 1) { + IFocus focus = new Focus(IFocus.Mode.INPUT, clicked.getValue()); + recipesGui.show(focus); + return true; + } + + return false; + } + + private boolean handleClickEdit(int mouseButton, V ingredient) { + Config.IngredientBlacklistType blacklistType = null; + if (GuiScreen.isCtrlKeyDown()) { + if (GuiScreen.isShiftKeyDown()) { + if (mouseButton == 0) { + blacklistType = Config.IngredientBlacklistType.MOD_ID; + } + } else { + if (mouseButton == 0) { + blacklistType = Config.IngredientBlacklistType.ITEM; + } else if (mouseButton == 1) { + blacklistType = Config.IngredientBlacklistType.WILDCARD; + } + } + } + + if (blacklistType == null) { + return false; + } + + IIngredientHelper ingredientHelper = ingredientRegistry.getIngredientHelper(ingredient); + + if (Config.isIngredientOnConfigBlacklist(ingredient, blacklistType, ingredientHelper)) { + Config.removeIngredientFromConfigBlacklist(ingredient, blacklistType, ingredientHelper); + } else { + Config.addIngredientToConfigBlacklist(ingredient, blacklistType, ingredientHelper); + } + return true; + } + + public boolean handleKeyEvent() { + char typedChar = Keyboard.getEventCharacter(); + int eventKey = Keyboard.getEventKey(); + + return ((eventKey == 0 && typedChar >= 32) || Keyboard.getEventKeyState()) && + handleKeyDown(typedChar, eventKey); + } + + private boolean handleKeyDown(char typedChar, int eventKey) { + if (itemListOverlayInternal != null && itemListOverlayInternal.hasKeyboardFocus()) { + if (isInventoryCloseKey(eventKey) || isEnterKey(eventKey)) { + itemListOverlayInternal.setKeyboardFocus(false); + return true; + } else if (itemListOverlayInternal.onKeyPressed(typedChar, eventKey)) { + return true; + } + } + + if (KeyBindings.toggleOverlay.isActiveAndMatches(eventKey)) { + Config.toggleOverlayEnabled(); + return false; + } + + if (itemListOverlayInternal != null) { + if (KeyBindings.toggleCheatMode.isActiveAndMatches(eventKey)) { + Config.toggleCheatItemsEnabled(); + return true; + } + + if (KeyBindings.focusSearch.isActiveAndMatches(eventKey)) { + itemListOverlayInternal.setKeyboardFocus(true); + return true; + } + } + + if (!isContainerTextFieldFocused()) { + final boolean showRecipe = KeyBindings.showRecipe.isActiveAndMatches(eventKey); + final boolean showUses = KeyBindings.showUses.isActiveAndMatches(eventKey); + final boolean toggleBookmark = KeyBindings.toggleBookmark.isActiveAndMatches(eventKey); + if (showRecipe || showUses) { + IClickedIngredient clicked = getIngredientUnderMouseForKey(mouseHelper.getX(), mouseHelper.getY()); + if (clicked != null) { + IFocus.Mode mode = showRecipe ? IFocus.Mode.OUTPUT : IFocus.Mode.INPUT; + recipesGui.show(new Focus(mode, clicked.getValue())); + return true; + } + } + + if (toggleBookmark) { + // get the bookmarks list and add or remove the clicked ingredient + IClickedIngredient clicked = getIngredientUnderMouseForKey(mouseHelper.getX(), mouseHelper.getY()); + if (clicked != null) { + ingredientBookmarks.toggleIngredientBookmark(clicked.getValue()); + itemListOverlayInternal.updateLayout(); + return true; + } + } + + if (itemListOverlayInternal != null && itemListOverlayInternal.onKeyPressed(typedChar, eventKey)) { + return true; + } + } + + return false; + } + + private boolean isContainerTextFieldFocused() { + GuiScreen gui = Minecraft.getMinecraft().currentScreen; + if (gui == null) { + return false; + } + GuiTextField textField = ReflectionUtil.getFieldWithClass(gui, GuiTextField.class); + return textField != null && textField.getVisible() && textField.isEnabled && textField.isFocused(); + } + + public static boolean isInventoryToggleKey(int keyCode) { + return Minecraft.getMinecraft().gameSettings.keyBindInventory.isActiveAndMatches(keyCode); + } + + public static boolean isInventoryCloseKey(int keyCode) { + return keyCode == Keyboard.KEY_ESCAPE; + } + + public static boolean isEnterKey(int keyCode) { + return keyCode == Keyboard.KEY_RETURN; + } } From 6a77e432a7af979b37fe69e90ec7ac2cb419c684 Mon Sep 17 00:00:00 2001 From: Michael Carver <4365312+shortcarver@users.noreply.github.com> Date: Wed, 2 Oct 2024 19:00:53 -0500 Subject: [PATCH 4/8] added translations for key binding --- .../jei/api/ingredients/IIngredientBookmarks.java | 12 ++++++------ src/main/resources/assets/jei/lang/ar_SA.lang | 1 + src/main/resources/assets/jei/lang/cs_CZ.lang | 1 + src/main/resources/assets/jei/lang/de_DE.lang | 1 + src/main/resources/assets/jei/lang/el_GR.lang | 1 + src/main/resources/assets/jei/lang/en_US.lang | 1 + src/main/resources/assets/jei/lang/he_IL.lang | 1 + src/main/resources/assets/jei/lang/it_IT.lang | 1 + src/main/resources/assets/jei/lang/ja_JP.lang | 1 + src/main/resources/assets/jei/lang/ko_KR.lang | 1 + src/main/resources/assets/jei/lang/pl_PL.lang | 1 + src/main/resources/assets/jei/lang/pt_BR.lang | 1 + src/main/resources/assets/jei/lang/ru_RU.lang | 1 + src/main/resources/assets/jei/lang/sv_SE.lang | 1 + src/main/resources/assets/jei/lang/uk_UA.lang | 1 + src/main/resources/assets/jei/lang/zh_CN.lang | 1 + src/main/resources/assets/jei/lang/zh_TW.lang | 1 + 17 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/main/java/mezz/jei/api/ingredients/IIngredientBookmarks.java b/src/main/java/mezz/jei/api/ingredients/IIngredientBookmarks.java index 5fd54521a..579ab19cb 100644 --- a/src/main/java/mezz/jei/api/ingredients/IIngredientBookmarks.java +++ b/src/main/java/mezz/jei/api/ingredients/IIngredientBookmarks.java @@ -13,12 +13,12 @@ * @Since JEI 3.14.9 */ public interface IIngredientBookmarks { - /** - * Toggles visibility of ingredient in the bookmark list. - */ - void toggleIngredientBookmark(V ingredient); + /** + * Toggles visibility of ingredient in the bookmark list. + */ + void toggleIngredientBookmark(V ingredient); - List getIngredientList(); + List getIngredientList(); - void clear(); + void clear(); } diff --git a/src/main/resources/assets/jei/lang/ar_SA.lang b/src/main/resources/assets/jei/lang/ar_SA.lang index c4efdfc67..be8e81e16 100644 --- a/src/main/resources/assets/jei/lang/ar_SA.lang +++ b/src/main/resources/assets/jei/lang/ar_SA.lang @@ -27,6 +27,7 @@ key.jei.showRecipe=أظهر وصفات العناصر key.jei.showUses=أظهر فوائد العناصر key.jei.recipeBack=أظهر صفحة العناصر السابقة key.jei.toggleCheatMode=تبديل وضع غش العناصر +key.jei.toggleBookmark=تبديل الإشارة المرجعية # Config config.jei.default=الأصلي diff --git a/src/main/resources/assets/jei/lang/cs_CZ.lang b/src/main/resources/assets/jei/lang/cs_CZ.lang index 99f9e148c..076facad9 100644 --- a/src/main/resources/assets/jei/lang/cs_CZ.lang +++ b/src/main/resources/assets/jei/lang/cs_CZ.lang @@ -27,6 +27,7 @@ key.jei.showRecipe=Zobrazit recept key.jei.showUses=Zobrazit použití key.jei.recipeBack=Zobrazit předchozí stránku key.jei.toggleCheatMode=Ovládat s Cheat Módem +key.jei.toggleBookmark=Přepnout záložku # Config config.jei.default=Výchozí diff --git a/src/main/resources/assets/jei/lang/de_DE.lang b/src/main/resources/assets/jei/lang/de_DE.lang index 1608342d5..59708c1b7 100644 --- a/src/main/resources/assets/jei/lang/de_DE.lang +++ b/src/main/resources/assets/jei/lang/de_DE.lang @@ -31,6 +31,7 @@ key.jei.showRecipe=Zeige Rezept key.jei.showUses=Zeige Verwendung key.jei.recipeBack=Zeige vorherige Rezeptseite key.jei.toggleCheatMode=Item-Cheating (de-)aktivieren +key.jei.toggleBookmark=Lesezeichen (de-)aktivieren # Config config.jei.default=Standard diff --git a/src/main/resources/assets/jei/lang/el_GR.lang b/src/main/resources/assets/jei/lang/el_GR.lang index 1a7dbc750..541c3fff6 100644 --- a/src/main/resources/assets/jei/lang/el_GR.lang +++ b/src/main/resources/assets/jei/lang/el_GR.lang @@ -28,6 +28,7 @@ key.jei.showRecipe=Δείξε Συνταγή Αντικειμένου key.jei.showUses=Δείξε Χρήσεις Αντικειμένου key.jei.recipeBack=Δείξε Προηγούμενη Σελίδα Συνταγών key.jei.toggleCheatMode=Ενάλλαξε Λειτουργία Cheat Αντικειμένων +key.jei.toggleBookmark=Εναλλαγή Σελιδοδείκτη # Config config.jei.default=Αρχικό diff --git a/src/main/resources/assets/jei/lang/en_US.lang b/src/main/resources/assets/jei/lang/en_US.lang index 75790131d..c1c1e604a 100644 --- a/src/main/resources/assets/jei/lang/en_US.lang +++ b/src/main/resources/assets/jei/lang/en_US.lang @@ -31,6 +31,7 @@ key.jei.showRecipe=Show Item Recipe key.jei.showUses=Show Item Uses key.jei.recipeBack=Show Previous Recipe Page key.jei.toggleCheatMode=Toggle Item Cheating Mode +key.jei.toggleBookmark=Toggle Bookmark # Config config.jei.default=Default diff --git a/src/main/resources/assets/jei/lang/he_IL.lang b/src/main/resources/assets/jei/lang/he_IL.lang index 2e182dacf..660f6793a 100644 --- a/src/main/resources/assets/jei/lang/he_IL.lang +++ b/src/main/resources/assets/jei/lang/he_IL.lang @@ -28,6 +28,7 @@ key.jei.showRecipe=הצג מתכונים לחפצים key.jei.showUses=הצג שימוש של חפצים key.jei.recipeBack=הצג עמוד חפצים קודם key.jei.toggleCheatMode=הפעל.הפסק מצב רמאות חפצים +key.jei.toggleBookmark=הפעל/הפסק סימניה # Config config.jei.default=ברירת מחדל diff --git a/src/main/resources/assets/jei/lang/it_IT.lang b/src/main/resources/assets/jei/lang/it_IT.lang index 4dd698f43..ececaa2b9 100644 --- a/src/main/resources/assets/jei/lang/it_IT.lang +++ b/src/main/resources/assets/jei/lang/it_IT.lang @@ -27,6 +27,7 @@ key.jei.showRecipe=Mostra la ricetta dell'item key.jei.showUses=Mostra gli usi dell'item key.jei.recipeBack=Torna alla ricetta precedente key.jei.toggleCheatMode=(Dis)attiva la modalita' cheat +key.jei.toggleBookmark=(Dis)attiva segnalibro # Config config.jei.default=Default diff --git a/src/main/resources/assets/jei/lang/ja_JP.lang b/src/main/resources/assets/jei/lang/ja_JP.lang index b6628bb94..cc9a34fb7 100644 --- a/src/main/resources/assets/jei/lang/ja_JP.lang +++ b/src/main/resources/assets/jei/lang/ja_JP.lang @@ -31,6 +31,7 @@ key.jei.showRecipe=アイテムのレシピの表示 key.jei.showUses=アイテムの用途の表示 key.jei.recipeBack=前のレシピページに戻る key.jei.toggleCheatMode=チートモードのオン/オフ +key.jei.toggleBookmark=ブックマークの切り替え # Config config.jei.default=デフォルト diff --git a/src/main/resources/assets/jei/lang/ko_KR.lang b/src/main/resources/assets/jei/lang/ko_KR.lang index d170cfa16..2eefa0259 100644 --- a/src/main/resources/assets/jei/lang/ko_KR.lang +++ b/src/main/resources/assets/jei/lang/ko_KR.lang @@ -28,6 +28,7 @@ key.jei.showRecipe=아이템 조합법 보기 key.jei.showUses=아이템 사용법 보기 key.jei.recipeBack=이전 아이템 조합법 보기 key.jei.toggleCheatMode=아이템 치트 모드 켜기/끄기 +key.jei.toggleBookmark=즐겨찾기 전환 # Config config.jei.default=기본값 diff --git a/src/main/resources/assets/jei/lang/pl_PL.lang b/src/main/resources/assets/jei/lang/pl_PL.lang index 76fda2202..4159d9d97 100644 --- a/src/main/resources/assets/jei/lang/pl_PL.lang +++ b/src/main/resources/assets/jei/lang/pl_PL.lang @@ -27,6 +27,7 @@ key.jei.showRecipe=Pokaż recepturę key.jei.showUses=Pokaż zastosowanie key.jei.recipeBack=Pokaż poprzednią stronę key.jei.toggleCheatMode=Włącz tryb duplikacji przedmiotu +key.jei.toggleBookmark=Przełącz zakładkę # Config config.jei.default=Domyślny diff --git a/src/main/resources/assets/jei/lang/pt_BR.lang b/src/main/resources/assets/jei/lang/pt_BR.lang index 436af03ff..22b19c2ea 100644 --- a/src/main/resources/assets/jei/lang/pt_BR.lang +++ b/src/main/resources/assets/jei/lang/pt_BR.lang @@ -29,6 +29,7 @@ key.jei.showRecipe=Mostrar Receita para o Item key.jei.showUses=Mostrar Usos do Item key.jei.recipeBack=Mostrar Página Anterior de Receitas key.jei.toggleCheatMode=Alternar Entre Modo de Trapaça de Itens +key.jei.toggleBookmark=Alternar Favorito # Config config.jei.default=Padrão diff --git a/src/main/resources/assets/jei/lang/ru_RU.lang b/src/main/resources/assets/jei/lang/ru_RU.lang index 7d79a3157..8555b4243 100644 --- a/src/main/resources/assets/jei/lang/ru_RU.lang +++ b/src/main/resources/assets/jei/lang/ru_RU.lang @@ -31,6 +31,7 @@ key.jei.showRecipe=Показывать рецепты предметов key.jei.showUses=Показывать применения предметов key.jei.recipeBack=Показать предыдущую страницу рецептов key.jei.toggleCheatMode=Переключить режим жульничества +key.jei.toggleBookmark=Переключить закладку # Config config.jei.default=По-умолчанию diff --git a/src/main/resources/assets/jei/lang/sv_SE.lang b/src/main/resources/assets/jei/lang/sv_SE.lang index abe9d59e0..179960a42 100644 --- a/src/main/resources/assets/jei/lang/sv_SE.lang +++ b/src/main/resources/assets/jei/lang/sv_SE.lang @@ -27,6 +27,7 @@ key.jei.showRecipe=Visa föremålsrecept key.jei.showUses=Visa användningar av föremål key.jei.recipeBack=Visa föregående receptsida key.jei.toggleCheatMode=Slå på/av föremålsfusk +key.jei.toggleBookmark=Växla bokmärke # Config config.jei.default=Standard diff --git a/src/main/resources/assets/jei/lang/uk_UA.lang b/src/main/resources/assets/jei/lang/uk_UA.lang index 6c35d7603..71a381c19 100644 --- a/src/main/resources/assets/jei/lang/uk_UA.lang +++ b/src/main/resources/assets/jei/lang/uk_UA.lang @@ -31,6 +31,7 @@ key.jei.showRecipe=Показувати рецепти предметів key.jei.showUses=Показувати використання предметів key.jei.recipeBack=Показувати минулу сторінку рецептів key.jei.toggleCheatMode=Перемкнути режим шахрайства +key.jei.toggleBookmark=Перемкнути закладку # Config config.jei.default=По замовчуванню diff --git a/src/main/resources/assets/jei/lang/zh_CN.lang b/src/main/resources/assets/jei/lang/zh_CN.lang index 054e9fc89..7a988832e 100644 --- a/src/main/resources/assets/jei/lang/zh_CN.lang +++ b/src/main/resources/assets/jei/lang/zh_CN.lang @@ -31,6 +31,7 @@ key.jei.showRecipe=显示物品合成表 key.jei.showUses=显示物品用途 key.jei.recipeBack=显示上一页 key.jei.toggleCheatMode=作弊模式开关 +key.jei.toggleBookmark=切换书签 # Config config.jei.default=默认 diff --git a/src/main/resources/assets/jei/lang/zh_TW.lang b/src/main/resources/assets/jei/lang/zh_TW.lang index 1dc455ef9..a9e98b8c7 100644 --- a/src/main/resources/assets/jei/lang/zh_TW.lang +++ b/src/main/resources/assets/jei/lang/zh_TW.lang @@ -31,6 +31,7 @@ key.jei.showRecipe=顯示物品合成錶 key.jei.showUses=顯示物品用途 key.jei.recipeBack=顯示上一頁 key.jei.toggleCheatMode=開關作弊模式 +key.jei.toggleBookmark=切換書籤 # Config 配寘 config.jei.default=默認 From cabf3c22bb2e01ee2b8ac738732fc1b6a0906333 Mon Sep 17 00:00:00 2001 From: Michael Carver <4365312+shortcarver@users.noreply.github.com> Date: Wed, 2 Oct 2024 19:06:33 -0500 Subject: [PATCH 5/8] cleaning up PR --- Makefile | 6 +- gradle.properties | 2 +- .../mezz/jei/gui/ItemListOverlayInternal.java | 1182 ++++++++--------- 3 files changed, 596 insertions(+), 594 deletions(-) diff --git a/Makefile b/Makefile index 03357e2a6..25f1163bf 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +# Build tools for arm based macos, running a test client through curseforge called "TestJEI + switch_java: export JAVA_HOME=`/usr/libexec/java_home -v 1.8.0_362` bd: @@ -5,5 +7,5 @@ bd: ./gradlew build make deploy deploy: - rm /Users/mcarver/Documents/curseforge/minecraft/Instances/TestJEI/mods/jei_1.10.2-3.14.8.jar - cp build/libs/jei_1.10.2-3.14.8.jar /Users/mcarver/Documents/curseforge/minecraft/Instances/TestJEI/mods/ + rm ~/Documents/curseforge/minecraft/Instances/TestJEI/mods/jei_1.10.2-3.14.8.jar + cp build/libs/jei_1.10.2-3.14.8.jar ~/Documents/curseforge/minecraft/Instances/TestJEI/mods/ diff --git a/gradle.properties b/gradle.properties index 4a9736a62..55b94a580 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,4 +5,4 @@ curse_project_id=238222 version_major=3 version_minor=14 -version_patch=8 +version_patch=9 diff --git a/src/main/java/mezz/jei/gui/ItemListOverlayInternal.java b/src/main/java/mezz/jei/gui/ItemListOverlayInternal.java index 64c36e1b6..17f5cbf11 100644 --- a/src/main/java/mezz/jei/gui/ItemListOverlayInternal.java +++ b/src/main/java/mezz/jei/gui/ItemListOverlayInternal.java @@ -51,596 +51,596 @@ public class ItemListOverlayInternal implements IShowsRecipeFocuses, IMouseHandler, IKeyable { - private static final int borderPadding = 2; - private static final int searchHeight = 16; - private static final int buttonSize = 20; - private static final String nextLabel = ">"; - private static final String backLabel = "<"; - - private static final int itemStackPadding = 1; - private static final int itemStackWidth = GuiItemStackGroup.getWidth(itemStackPadding); - private static final int itemStackHeight = GuiItemStackGroup.getHeight(itemStackPadding); - private static int firstItemIndex = 0; - - private final ItemListOverlay parent; - - private final GuiButton nextButton; - private final GuiButton backButton; - private final GuiButton configButton; - private final GuiButton clearButton; - private final IDrawable configButtonIcon; - private final IDrawable configButtonCheatIcon; - private final HoverChecker configButtonHoverChecker; - private final GuiTextFieldFilter searchField; - - private String pageNumDisplayString = "1/1"; - private int pageNumDisplayX; - private int pageNumDisplayY; - - private final GuiIngredientFastList guiIngredientList; - private final GuiIngredientFastList guiBookmarks; - @Nullable - private GuiIngredientFast hovered = null; - - // properties of the gui we're beside - private final GuiProperties guiProperties; - private final List guiAreas; - private List> activeAdvancedGuiHandlers = Collections.emptyList(); - - public ItemListOverlayInternal(ItemListOverlay parent, IIngredientRegistry ingredientRegistry, GuiScreen guiScreen, - GuiProperties guiProperties) { - this.parent = parent; - - this.guiBookmarks = new GuiIngredientFastList(ingredientRegistry); - this.guiIngredientList = new GuiIngredientFastList(ingredientRegistry); - - this.guiProperties = guiProperties; - this.activeAdvancedGuiHandlers = getActiveAdvancedGuiHandlers(guiScreen); - if (!activeAdvancedGuiHandlers.isEmpty() && guiScreen instanceof GuiContainer) { - GuiContainer guiContainer = (GuiContainer) guiScreen; - guiAreas = getGuiAreas(guiContainer); - } else { - guiAreas = Collections.emptyList(); - } - - final int columns = getColumns(guiProperties); - final int rows = getRows(guiProperties); - final int xSize = columns * itemStackWidth; - final int xEmptySpace = guiProperties.getScreenWidth() - guiProperties.getGuiLeft() - guiProperties.getGuiXSize() - - xSize; - - final int leftEdge = guiProperties.getGuiLeft() + guiProperties.getGuiXSize() + (xEmptySpace / 2); - final int rightEdge = leftEdge + xSize; - - final int yItemButtonSpace = getItemButtonYSpace(guiProperties); - final int itemButtonsHeight = rows * itemStackHeight; - - final int buttonStartY = buttonSize + (2 * borderPadding) + (yItemButtonSpace - itemButtonsHeight) / 2; - // this renders the items gui - createItemButtons(guiIngredientList, guiAreas, leftEdge, buttonStartY, columns, rows); - // Alight with bottom of clear button - createItemButtons(guiBookmarks, guiAreas, 0, guiProperties.getGuiTop() + buttonSize, columns, rows); - - nextButton = new GuiButton(0, rightEdge - buttonSize, borderPadding, buttonSize, buttonSize, nextLabel); - backButton = new GuiButton(1, leftEdge, borderPadding, buttonSize, buttonSize, backLabel); - // align with the top of inventory gui - clearButton = new GuiButton(3, 0, guiProperties.getGuiTop(), buttonSize * 3, buttonSize, "CLEAR"); - - final int searchFieldX; - final int searchFieldY = guiProperties.getScreenHeight() - searchHeight - borderPadding - 2; - final int searchFieldWidth; - - if (isSearchBarCentered(guiProperties)) { - searchFieldX = guiProperties.getGuiLeft(); - searchFieldWidth = guiProperties.getGuiXSize() - buttonSize - 1; - } else { - searchFieldX = leftEdge; - searchFieldWidth = rightEdge - leftEdge - buttonSize - 1; - } - - FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; - searchField = new GuiTextFieldFilter(0, fontRenderer, searchFieldX, searchFieldY, searchFieldWidth, searchHeight, - parent.getItemFilter()); - setKeyboardFocus(false); - - int configButtonX = searchFieldX + searchFieldWidth + 1; - int configButtonY = guiProperties.getScreenHeight() - buttonSize - borderPadding; - configButton = new GuiButton(2, configButtonX, configButtonY, buttonSize, buttonSize, ""); - ResourceLocation configButtonIconLocation = new ResourceLocation(Constants.RESOURCE_DOMAIN, - Constants.TEXTURE_RECIPE_BACKGROUND_PATH); - GuiHelper guiHelper = Internal.getHelpers().getGuiHelper(); - configButtonIcon = guiHelper.createDrawable(configButtonIconLocation, 0, 166, 16, 16); - configButtonCheatIcon = guiHelper.createDrawable(configButtonIconLocation, 16, 166, 16, 16); - configButtonHoverChecker = new HoverChecker(configButton, 0); - - updateLayout(); - } - - private static boolean isSearchBarCentered(GuiProperties guiProperties) { - return Config.isCenterSearchBarEnabled() && - guiProperties.getGuiTop() + guiProperties.getGuiYSize() + searchHeight < guiProperties.getScreenHeight(); - } - - private List> getActiveAdvancedGuiHandlers(GuiScreen guiScreen) { - List> activeAdvancedGuiHandler = new ArrayList>(); - if (guiScreen instanceof GuiContainer) { - for (IAdvancedGuiHandler advancedGuiHandler : parent.getAdvancedGuiHandlers()) { - Class guiContainerClass = advancedGuiHandler.getGuiContainerClass(); - if (guiContainerClass.isInstance(guiScreen)) { - activeAdvancedGuiHandler.add(advancedGuiHandler); - } - } - } - return activeAdvancedGuiHandler; - } - - private List getGuiAreas(GuiContainer guiContainer) { - List guiAreas = new ArrayList(); - for (IAdvancedGuiHandler advancedGuiHandler : activeAdvancedGuiHandlers) { - List guiExtraAreas = getGuiAreas(guiContainer, advancedGuiHandler); - if (guiExtraAreas != null) { - guiAreas.addAll(guiExtraAreas); - } - } - return guiAreas; - } - - @Nullable - private List getGuiAreas(GuiContainer gui, - IAdvancedGuiHandler advancedGuiHandler) { - Class guiClass = advancedGuiHandler.getGuiContainerClass(); - if (guiClass.isInstance(gui)) { - T guiT = guiClass.cast(gui); - return advancedGuiHandler.getGuiExtraAreas(guiT); - } - return null; - } - - public boolean hasScreenChanged(GuiScreen guiScreen) { - if (!Config.isOverlayEnabled()) { - return true; - } - GuiProperties guiProperties = GuiProperties.create(guiScreen); - if (guiProperties == null) { - return true; - } - if (!this.guiProperties.equals(guiProperties)) { - return true; - } else if (!activeAdvancedGuiHandlers.isEmpty() && guiScreen instanceof GuiContainer) { - GuiContainer guiContainer = (GuiContainer) guiScreen; - List guiAreas = getGuiAreas(guiContainer); - if (!Java6Helper.equals(this.guiAreas, guiAreas)) { - return true; - } - } - - return false; - } - - private static void createItemButtons(GuiIngredientFastList guiItemStacks, @Nullable List guiAreas, - final int xStart, final int yStart, final int columnCount, final int rowCount) { - guiItemStacks.clear(); - - for (int row = 0; row < rowCount; row++) { - int y = yStart + (row * itemStackHeight); - for (int column = 0; column < columnCount; column++) { - int x = xStart + (column * itemStackWidth); - GuiIngredientFast guiIngredientFast = new GuiIngredientFast(x, y, itemStackPadding); - if (guiAreas != null) { - Rectangle stackArea = guiIngredientFast.getArea(); - if (intersects(guiAreas, stackArea)) { - continue; - } - } - guiItemStacks.add(guiIngredientFast); - } - } - } - - private static boolean intersects(List areas, Rectangle comparisonArea) { - for (Rectangle area : areas) { - if (area.intersects(comparisonArea)) { - return true; - } - } - return false; - } - - public void updateLayout() { - ImmutableList ingredientList = parent.getItemFilter().getIngredientList(); - guiIngredientList.set(firstItemIndex, ingredientList); - - List bookmarkList = parent.getIngredientBookmarks().getIngredientList(); - guiBookmarks.set(0, bookmarkList); - - FontRenderer fontRendererObj = Minecraft.getMinecraft().fontRendererObj; - - pageNumDisplayString = (getPageNum() + 1) + "/" + getPageCount(); - int pageDisplayWidth = fontRendererObj.getStringWidth(pageNumDisplayString); - pageNumDisplayX = ((backButton.xPosition + backButton.width) + nextButton.xPosition) / 2 - (pageDisplayWidth / 2); - pageNumDisplayY = backButton.yPosition + Math.round((backButton.height - fontRendererObj.FONT_HEIGHT) / 2.0f); - - searchField.update(); - } - - private void nextPage() { - final int itemsCount = parent.getItemFilter().size(); - if (itemsCount == 0) { - firstItemIndex = 0; - return; - } - - firstItemIndex += guiIngredientList.size(); - if (firstItemIndex >= itemsCount) { - firstItemIndex = 0; - } - updateLayout(); - } - - private void previousPage() { - final int itemsPerPage = guiIngredientList.size(); - if (itemsPerPage == 0) { - firstItemIndex = 0; - return; - } - final int itemsCount = parent.getItemFilter().size(); - - int pageNum = firstItemIndex / itemsPerPage; - if (pageNum == 0) { - pageNum = itemsCount / itemsPerPage; - } else { - pageNum--; - } - - firstItemIndex = itemsPerPage * pageNum; - if (firstItemIndex > 0 && firstItemIndex == itemsCount) { - pageNum--; - firstItemIndex = itemsPerPage * pageNum; - } - updateLayout(); - } - - public void drawScreen(Minecraft minecraft, int mouseX, int mouseY) { - GlStateManager.disableLighting(); - - minecraft.fontRendererObj.drawString(pageNumDisplayString, pageNumDisplayX, pageNumDisplayY, Color.white.getRGB(), - true); - searchField.drawTextBox(); - - nextButton.drawButton(minecraft, mouseX, mouseY); - backButton.drawButton(minecraft, mouseX, mouseY); - configButton.drawButton(minecraft, mouseX, mouseY); - clearButton.drawButton(minecraft, mouseX, mouseY); - - IDrawable icon = Config.isCheatItemsEnabled() ? configButtonCheatIcon : configButtonIcon; - icon.draw(minecraft, configButton.xPosition + 2, configButton.yPosition + 2); - - GlStateManager.disableBlend(); - - if (shouldShowDeleteItemTooltip(minecraft)) { - hovered = guiIngredientList.render(minecraft, false, mouseX, mouseY); - } else { - boolean mouseOver = isMouseOver(mouseX, mouseY); - hovered = guiIngredientList.render(minecraft, mouseOver, mouseX, mouseY); - } - - if (hovered == null) { - hovered = guiBookmarks.render(minecraft, isMouseOver(mouseX, mouseY), mouseX, mouseY); - } else { - guiBookmarks.render(minecraft, isMouseOver(mouseX, mouseY), mouseX, mouseY); - } - - Set highlightedStacks = parent.getHighlightedStacks(); - if (!highlightedStacks.isEmpty()) { - StackHelper helper = Internal.getHelpers().getStackHelper(); - for (GuiIngredientFast guiItemStack : guiIngredientList.getAllGuiIngredients()) { - Object ingredient = guiItemStack.getIngredient(); - if (ingredient instanceof ItemStack) { - if (helper.containsStack(highlightedStacks, (ItemStack) ingredient) != null) { - guiItemStack.drawHighlight(); - } - } - } - for (GuiIngredientFast guiItemStack : guiBookmarks.getAllGuiIngredients()) { - Object ingredient = guiItemStack.getIngredient(); - if (ingredient instanceof ItemStack) { - if (helper.containsStack(highlightedStacks, (ItemStack) ingredient) != null) { - guiItemStack.drawHighlight(); - } - } - } - } - - if (hovered != null) { - hovered.drawHovered(minecraft); - } - - GlStateManager.enableAlpha(); - } - - private boolean shouldShowDeleteItemTooltip(Minecraft minecraft) { - if (Config.isDeleteItemsInCheatModeActive()) { - EntityPlayer player = minecraft.thePlayer; - if (player.inventory.getItemStack() != null) { - return true; - } - } - return false; - } - - public void drawTooltips(Minecraft minecraft, int mouseX, int mouseY) { - boolean mouseOver = isMouseOver(mouseX, mouseY); - if (mouseOver && shouldShowDeleteItemTooltip(minecraft)) { - String deleteItem = Translator.translateToLocal("jei.tooltip.delete.item"); - TooltipRenderer.drawHoveringText(minecraft, deleteItem, mouseX, mouseY); - } - - if (hovered != null) { - hovered.drawTooltip(minecraft, mouseX, mouseY); - } - - if (configButtonHoverChecker.checkHover(mouseX, mouseY)) { - String configString = Translator.translateToLocal("jei.tooltip.config"); - if (Config.isCheatItemsEnabled()) { - List tooltip = Arrays.asList( - configString, - TextFormatting.RED + Translator.translateToLocal("jei.tooltip.cheat.mode")); - TooltipRenderer.drawHoveringText(minecraft, tooltip, mouseX, mouseY); - } else { - TooltipRenderer.drawHoveringText(minecraft, configString, mouseX, mouseY); - } - } - } - - public void handleTick() { - searchField.updateCursorCounter(); - } - - @Override - public boolean isMouseOver(int mouseX, int mouseY) { - // Clickable area is anywhere outside of the inventory screen. Should probably - // narrow this down, but I don't know how do detect other mods that might be - // using the screen. - if (mouseX > guiProperties.getGuiLeft() && mouseX < guiProperties.getGuiLeft() + guiProperties.getGuiXSize() - && mouseY > guiProperties.getGuiTop() && mouseY < guiProperties.getGuiTop() + guiProperties.getGuiYSize()) { - return false; - } - // if (mouseX < guiProperties.getGuiLeft() + guiProperties.getGuiXSize()) { - // return isSearchBarCentered(guiProperties) && - // (searchField.isMouseOver(mouseX, mouseY) || - // configButtonHoverChecker.checkHover(mouseX, mouseY)); - // } - - // for (Rectangle guiArea : guiAreas) { - // if (guiArea.contains(mouseX, mouseY)) { - // return false; - // } - // } - - return true; - } - - @Override - @Nullable - public IClickedIngredient getIngredientUnderMouse(int mouseX, int mouseY) { - if (!isMouseOver(mouseX, mouseY)) { - return null; - } - - ClickedIngredient clicked = guiIngredientList.getIngredientUnderMouse(mouseX, mouseY); - if (clicked != null) { - setKeyboardFocus(false); - clicked.setAllowsCheating(); - return clicked; - } - clicked = guiBookmarks.getIngredientUnderMouse(mouseX, mouseY); - if (clicked != null) { - setKeyboardFocus(false); - clicked.setAllowsCheating(); - return clicked; - } - return null; - } - - @Override - public boolean canSetFocusWithMouse() { - return true; - } - - @Override - public boolean handleMouseClicked(int mouseX, int mouseY, int mouseButton) { - if (!isMouseOver(mouseX, mouseY)) { - setKeyboardFocus(false); - return false; - } - - if (Config.isDeleteItemsInCheatModeActive()) { - Minecraft minecraft = Minecraft.getMinecraft(); - EntityPlayerSP player = minecraft.thePlayer; - ItemStack itemStack = player.inventory.getItemStack(); - if (itemStack != null) { - player.inventory.setItemStack(null); - PacketJei packet = new PacketDeletePlayerItem(itemStack); - JustEnoughItems.getProxy().sendPacketToServer(packet); - return true; - } - } - - boolean buttonClicked = handleMouseClickedButtons(mouseX, mouseY); - if (buttonClicked) { - setKeyboardFocus(false); - return true; - } - - return handleMouseClickedSearch(mouseX, mouseY, mouseButton); - } - - @Override - public boolean handleMouseScrolled(int mouseX, int mouseY, int scrollDelta) { - if (!isMouseOver(mouseX, mouseY)) { - return false; - } - if (scrollDelta < 0) { - nextPage(); - return true; - } else if (scrollDelta > 0) { - previousPage(); - return true; - } - return false; - } - - private boolean handleMouseClickedButtons(int mouseX, int mouseY) { - Minecraft minecraft = Minecraft.getMinecraft(); - if (nextButton.mousePressed(minecraft, mouseX, mouseY)) { - nextPage(); - nextButton.playPressSound(minecraft.getSoundHandler()); - return true; - } else if (backButton.mousePressed(minecraft, mouseX, mouseY)) { - previousPage(); - backButton.playPressSound(minecraft.getSoundHandler()); - return true; - } else if (configButton.mousePressed(minecraft, mouseX, mouseY)) { - configButton.playPressSound(minecraft.getSoundHandler()); - if (Keyboard.getEventKeyState() - && (Keyboard.getEventKey() == Keyboard.KEY_LCONTROL || Keyboard.getEventKey() == Keyboard.KEY_RCONTROL)) { - Config.toggleCheatItemsEnabled(); - } else { - if (minecraft.currentScreen != null) { - parent.close(); - GuiScreen configScreen = new JEIModConfigGui(minecraft.currentScreen); - minecraft.displayGuiScreen(configScreen); - } - } - return true; - } else if (clearButton.mousePressed(minecraft, mouseX, mouseY)) { - clearButton.playPressSound(minecraft.getSoundHandler()); - parent.getIngredientBookmarks().clear(); - updateLayout(); - return true; - } - return false; - } - - private boolean handleMouseClickedSearch(int mouseX, int mouseY, int mouseButton) { - boolean searchClicked = searchField.isMouseOver(mouseX, mouseY); - setKeyboardFocus(searchClicked); - if (searchClicked && searchField.handleMouseClicked(mouseX, mouseY, mouseButton)) { - updateLayout(); - } - return searchClicked; - } - - @Override - public boolean hasKeyboardFocus() { - return searchField.isFocused(); - } - - @Override - public void setKeyboardFocus(boolean keyboardFocus) { - searchField.setFocused(keyboardFocus); - } - - @Override - public boolean onKeyPressed(char typedChar, int keyCode) { - if (hasKeyboardFocus()) { - boolean handled = searchField.textboxKeyTyped(typedChar, keyCode); - if (handled) { - boolean changed = Config.setFilterText(searchField.getText()); - if (changed) { - firstItemIndex = 0; - updateLayout(); - } - } - return handled; - } - return false; - } - - // Finds the right edge of the inventory screen - private static int getItemButtonXSpace(GuiProperties guiProperties) { - return guiProperties.getScreenWidth() - - (guiProperties.getGuiLeft() + guiProperties.getGuiXSize() + (2 * borderPadding)); - } - - private static int getItemButtonYSpace(GuiProperties guiProperties) { - if (isSearchBarCentered(guiProperties)) { - return guiProperties.getScreenHeight() - (buttonSize + (3 * borderPadding)); - } - // finds the height of the list screen area minus the search and the buttons - return guiProperties.getScreenHeight() - (buttonSize + searchHeight + 2 + (4 * borderPadding)); - } - - public static int getColumns(GuiProperties guiProperties) { - return getItemButtonXSpace(guiProperties) / itemStackWidth; - } - - public static int getRows(GuiProperties guiProperties) { - return getItemButtonYSpace(guiProperties) / itemStackHeight; - } - - private int getPageCount() { - final int itemCount = parent.getItemFilter().size(); - final int stacksPerPage = guiIngredientList.size(); - if (stacksPerPage == 0) { - return 1; - } - int pageCount = MathUtil.divideCeil(itemCount, stacksPerPage); - pageCount = Math.max(1, pageCount); - return pageCount; - } - - private int getPageNum() { - final int stacksPerPage = guiIngredientList.size(); - if (stacksPerPage == 0) { - return 1; - } - return firstItemIndex / stacksPerPage; - } - - public void close() { - setKeyboardFocus(false); - Config.saveFilterText(); - } - - @Nullable - public ItemStack getStackUnderMouse() { - if (hovered != null) { - Object ingredient = hovered.getIngredient(); - if (ingredient instanceof ItemStack) { - return (ItemStack) ingredient; - } - } - return null; - } - - public void setFilterText(String filterText) { - searchField.setText(filterText); - setToFirstPage(); - updateLayout(); - } - - public static void setToFirstPage() { - firstItemIndex = 0; - } - - public ImmutableList getVisibleStacks() { - ImmutableList.Builder visibleStacks = ImmutableList.builder(); - for (GuiIngredientFast guiItemStack : guiIngredientList.getAllGuiIngredients()) { - Object ingredient = guiItemStack.getIngredient(); - if (ingredient instanceof ItemStack) { - ItemStack itemStack = (ItemStack) ingredient; - visibleStacks.add(itemStack); - } - } - for (GuiIngredientFast guiItemStack : guiBookmarks.getAllGuiIngredients()) { - Object ingredient = guiItemStack.getIngredient(); - if (ingredient instanceof ItemStack) { - ItemStack itemStack = (ItemStack) ingredient; - visibleStacks.add(itemStack); - } - } - return visibleStacks.build(); - } + private static final int borderPadding = 2; + private static final int searchHeight = 16; + private static final int buttonSize = 20; + private static final String nextLabel = ">"; + private static final String backLabel = "<"; + + private static final int itemStackPadding = 1; + private static final int itemStackWidth = GuiItemStackGroup.getWidth(itemStackPadding); + private static final int itemStackHeight = GuiItemStackGroup.getHeight(itemStackPadding); + private static int firstItemIndex = 0; + + private final ItemListOverlay parent; + + private final GuiButton nextButton; + private final GuiButton backButton; + private final GuiButton configButton; + private final GuiButton clearButton; + private final IDrawable configButtonIcon; + private final IDrawable configButtonCheatIcon; + private final HoverChecker configButtonHoverChecker; + private final GuiTextFieldFilter searchField; + + private String pageNumDisplayString = "1/1"; + private int pageNumDisplayX; + private int pageNumDisplayY; + + private final GuiIngredientFastList guiIngredientList; + private final GuiIngredientFastList guiBookmarks; + @Nullable + private GuiIngredientFast hovered = null; + + // properties of the gui we're beside + private final GuiProperties guiProperties; + private final List guiAreas; + private List> activeAdvancedGuiHandlers = Collections.emptyList(); + + public ItemListOverlayInternal(ItemListOverlay parent, IIngredientRegistry ingredientRegistry, GuiScreen guiScreen, + GuiProperties guiProperties) { + this.parent = parent; + + this.guiBookmarks = new GuiIngredientFastList(ingredientRegistry); + this.guiIngredientList = new GuiIngredientFastList(ingredientRegistry); + + this.guiProperties = guiProperties; + this.activeAdvancedGuiHandlers = getActiveAdvancedGuiHandlers(guiScreen); + if (!activeAdvancedGuiHandlers.isEmpty() && guiScreen instanceof GuiContainer) { + GuiContainer guiContainer = (GuiContainer) guiScreen; + guiAreas = getGuiAreas(guiContainer); + } else { + guiAreas = Collections.emptyList(); + } + + final int columns = getColumns(guiProperties); + final int rows = getRows(guiProperties); + final int xSize = columns * itemStackWidth; + final int xEmptySpace = guiProperties.getScreenWidth() - guiProperties.getGuiLeft() - guiProperties.getGuiXSize() + - xSize; + + final int leftEdge = guiProperties.getGuiLeft() + guiProperties.getGuiXSize() + (xEmptySpace / 2); + final int rightEdge = leftEdge + xSize; + + final int yItemButtonSpace = getItemButtonYSpace(guiProperties); + final int itemButtonsHeight = rows * itemStackHeight; + + final int buttonStartY = buttonSize + (2 * borderPadding) + (yItemButtonSpace - itemButtonsHeight) / 2; + // this renders the items gui + createItemButtons(guiIngredientList, guiAreas, leftEdge, buttonStartY, columns, rows); + // Alight with bottom of clear button + createItemButtons(guiBookmarks, guiAreas, 0, guiProperties.getGuiTop() + buttonSize, columns, rows); + + nextButton = new GuiButton(0, rightEdge - buttonSize, borderPadding, buttonSize, buttonSize, nextLabel); + backButton = new GuiButton(1, leftEdge, borderPadding, buttonSize, buttonSize, backLabel); + // align with the top of inventory gui + clearButton = new GuiButton(3, 0, guiProperties.getGuiTop(), buttonSize * 3, buttonSize, "CLEAR"); + + final int searchFieldX; + final int searchFieldY = guiProperties.getScreenHeight() - searchHeight - borderPadding - 2; + final int searchFieldWidth; + + if (isSearchBarCentered(guiProperties)) { + searchFieldX = guiProperties.getGuiLeft(); + searchFieldWidth = guiProperties.getGuiXSize() - buttonSize - 1; + } else { + searchFieldX = leftEdge; + searchFieldWidth = rightEdge - leftEdge - buttonSize - 1; + } + + FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; + searchField = new GuiTextFieldFilter(0, fontRenderer, searchFieldX, searchFieldY, searchFieldWidth, searchHeight, + parent.getItemFilter()); + setKeyboardFocus(false); + + int configButtonX = searchFieldX + searchFieldWidth + 1; + int configButtonY = guiProperties.getScreenHeight() - buttonSize - borderPadding; + configButton = new GuiButton(2, configButtonX, configButtonY, buttonSize, buttonSize, ""); + ResourceLocation configButtonIconLocation = new ResourceLocation(Constants.RESOURCE_DOMAIN, + Constants.TEXTURE_RECIPE_BACKGROUND_PATH); + GuiHelper guiHelper = Internal.getHelpers().getGuiHelper(); + configButtonIcon = guiHelper.createDrawable(configButtonIconLocation, 0, 166, 16, 16); + configButtonCheatIcon = guiHelper.createDrawable(configButtonIconLocation, 16, 166, 16, 16); + configButtonHoverChecker = new HoverChecker(configButton, 0); + + updateLayout(); + } + + private static boolean isSearchBarCentered(GuiProperties guiProperties) { + return Config.isCenterSearchBarEnabled() && + guiProperties.getGuiTop() + guiProperties.getGuiYSize() + searchHeight < guiProperties.getScreenHeight(); + } + + private List> getActiveAdvancedGuiHandlers(GuiScreen guiScreen) { + List> activeAdvancedGuiHandler = new ArrayList>(); + if (guiScreen instanceof GuiContainer) { + for (IAdvancedGuiHandler advancedGuiHandler : parent.getAdvancedGuiHandlers()) { + Class guiContainerClass = advancedGuiHandler.getGuiContainerClass(); + if (guiContainerClass.isInstance(guiScreen)) { + activeAdvancedGuiHandler.add(advancedGuiHandler); + } + } + } + return activeAdvancedGuiHandler; + } + + private List getGuiAreas(GuiContainer guiContainer) { + List guiAreas = new ArrayList(); + for (IAdvancedGuiHandler advancedGuiHandler : activeAdvancedGuiHandlers) { + List guiExtraAreas = getGuiAreas(guiContainer, advancedGuiHandler); + if (guiExtraAreas != null) { + guiAreas.addAll(guiExtraAreas); + } + } + return guiAreas; + } + + @Nullable + private List getGuiAreas(GuiContainer gui, + IAdvancedGuiHandler advancedGuiHandler) { + Class guiClass = advancedGuiHandler.getGuiContainerClass(); + if (guiClass.isInstance(gui)) { + T guiT = guiClass.cast(gui); + return advancedGuiHandler.getGuiExtraAreas(guiT); + } + return null; + } + + public boolean hasScreenChanged(GuiScreen guiScreen) { + if (!Config.isOverlayEnabled()) { + return true; + } + GuiProperties guiProperties = GuiProperties.create(guiScreen); + if (guiProperties == null) { + return true; + } + if (!this.guiProperties.equals(guiProperties)) { + return true; + } else if (!activeAdvancedGuiHandlers.isEmpty() && guiScreen instanceof GuiContainer) { + GuiContainer guiContainer = (GuiContainer) guiScreen; + List guiAreas = getGuiAreas(guiContainer); + if (!Java6Helper.equals(this.guiAreas, guiAreas)) { + return true; + } + } + + return false; + } + + private static void createItemButtons(GuiIngredientFastList guiItemStacks, @Nullable List guiAreas, + final int xStart, final int yStart, final int columnCount, final int rowCount) { + guiItemStacks.clear(); + + for (int row = 0; row < rowCount; row++) { + int y = yStart + (row * itemStackHeight); + for (int column = 0; column < columnCount; column++) { + int x = xStart + (column * itemStackWidth); + GuiIngredientFast guiIngredientFast = new GuiIngredientFast(x, y, itemStackPadding); + if (guiAreas != null) { + Rectangle stackArea = guiIngredientFast.getArea(); + if (intersects(guiAreas, stackArea)) { + continue; + } + } + guiItemStacks.add(guiIngredientFast); + } + } + } + + private static boolean intersects(List areas, Rectangle comparisonArea) { + for (Rectangle area : areas) { + if (area.intersects(comparisonArea)) { + return true; + } + } + return false; + } + + public void updateLayout() { + ImmutableList ingredientList = parent.getItemFilter().getIngredientList(); + guiIngredientList.set(firstItemIndex, ingredientList); + + List bookmarkList = parent.getIngredientBookmarks().getIngredientList(); + guiBookmarks.set(0, bookmarkList); + + FontRenderer fontRendererObj = Minecraft.getMinecraft().fontRendererObj; + + pageNumDisplayString = (getPageNum() + 1) + "/" + getPageCount(); + int pageDisplayWidth = fontRendererObj.getStringWidth(pageNumDisplayString); + pageNumDisplayX = ((backButton.xPosition + backButton.width) + nextButton.xPosition) / 2 - (pageDisplayWidth / 2); + pageNumDisplayY = backButton.yPosition + Math.round((backButton.height - fontRendererObj.FONT_HEIGHT) / 2.0f); + + searchField.update(); + } + + private void nextPage() { + final int itemsCount = parent.getItemFilter().size(); + if (itemsCount == 0) { + firstItemIndex = 0; + return; + } + + firstItemIndex += guiIngredientList.size(); + if (firstItemIndex >= itemsCount) { + firstItemIndex = 0; + } + updateLayout(); + } + + private void previousPage() { + final int itemsPerPage = guiIngredientList.size(); + if (itemsPerPage == 0) { + firstItemIndex = 0; + return; + } + final int itemsCount = parent.getItemFilter().size(); + + int pageNum = firstItemIndex / itemsPerPage; + if (pageNum == 0) { + pageNum = itemsCount / itemsPerPage; + } else { + pageNum--; + } + + firstItemIndex = itemsPerPage * pageNum; + if (firstItemIndex > 0 && firstItemIndex == itemsCount) { + pageNum--; + firstItemIndex = itemsPerPage * pageNum; + } + updateLayout(); + } + + public void drawScreen(Minecraft minecraft, int mouseX, int mouseY) { + GlStateManager.disableLighting(); + + minecraft.fontRendererObj.drawString(pageNumDisplayString, pageNumDisplayX, pageNumDisplayY, Color.white.getRGB(), + true); + searchField.drawTextBox(); + + nextButton.drawButton(minecraft, mouseX, mouseY); + backButton.drawButton(minecraft, mouseX, mouseY); + configButton.drawButton(minecraft, mouseX, mouseY); + clearButton.drawButton(minecraft, mouseX, mouseY); + + IDrawable icon = Config.isCheatItemsEnabled() ? configButtonCheatIcon : configButtonIcon; + icon.draw(minecraft, configButton.xPosition + 2, configButton.yPosition + 2); + + GlStateManager.disableBlend(); + + if (shouldShowDeleteItemTooltip(minecraft)) { + hovered = guiIngredientList.render(minecraft, false, mouseX, mouseY); + } else { + boolean mouseOver = isMouseOver(mouseX, mouseY); + hovered = guiIngredientList.render(minecraft, mouseOver, mouseX, mouseY); + } + + if (hovered == null) { + hovered = guiBookmarks.render(minecraft, isMouseOver(mouseX, mouseY), mouseX, mouseY); + } else { + guiBookmarks.render(minecraft, isMouseOver(mouseX, mouseY), mouseX, mouseY); + } + + Set highlightedStacks = parent.getHighlightedStacks(); + if (!highlightedStacks.isEmpty()) { + StackHelper helper = Internal.getHelpers().getStackHelper(); + for (GuiIngredientFast guiItemStack : guiIngredientList.getAllGuiIngredients()) { + Object ingredient = guiItemStack.getIngredient(); + if (ingredient instanceof ItemStack) { + if (helper.containsStack(highlightedStacks, (ItemStack) ingredient) != null) { + guiItemStack.drawHighlight(); + } + } + } + for (GuiIngredientFast guiItemStack : guiBookmarks.getAllGuiIngredients()) { + Object ingredient = guiItemStack.getIngredient(); + if (ingredient instanceof ItemStack) { + if (helper.containsStack(highlightedStacks, (ItemStack) ingredient) != null) { + guiItemStack.drawHighlight(); + } + } + } + } + + if (hovered != null) { + hovered.drawHovered(minecraft); + } + + GlStateManager.enableAlpha(); + } + + private boolean shouldShowDeleteItemTooltip(Minecraft minecraft) { + if (Config.isDeleteItemsInCheatModeActive()) { + EntityPlayer player = minecraft.thePlayer; + if (player.inventory.getItemStack() != null) { + return true; + } + } + return false; + } + + public void drawTooltips(Minecraft minecraft, int mouseX, int mouseY) { + boolean mouseOver = isMouseOver(mouseX, mouseY); + if (mouseOver && shouldShowDeleteItemTooltip(minecraft)) { + String deleteItem = Translator.translateToLocal("jei.tooltip.delete.item"); + TooltipRenderer.drawHoveringText(minecraft, deleteItem, mouseX, mouseY); + } + + if (hovered != null) { + hovered.drawTooltip(minecraft, mouseX, mouseY); + } + + if (configButtonHoverChecker.checkHover(mouseX, mouseY)) { + String configString = Translator.translateToLocal("jei.tooltip.config"); + if (Config.isCheatItemsEnabled()) { + List tooltip = Arrays.asList( + configString, + TextFormatting.RED + Translator.translateToLocal("jei.tooltip.cheat.mode")); + TooltipRenderer.drawHoveringText(minecraft, tooltip, mouseX, mouseY); + } else { + TooltipRenderer.drawHoveringText(minecraft, configString, mouseX, mouseY); + } + } + } + + public void handleTick() { + searchField.updateCursorCounter(); + } + + @Override + public boolean isMouseOver(int mouseX, int mouseY) { + // Clickable area is anywhere outside of the inventory screen. Should probably + // narrow this down, but I don't know how do detect other mods that might be + // using the screen. + if (mouseX > guiProperties.getGuiLeft() && mouseX < guiProperties.getGuiLeft() + guiProperties.getGuiXSize() + && mouseY > guiProperties.getGuiTop() && mouseY < guiProperties.getGuiTop() + guiProperties.getGuiYSize()) { + return false; + } + // if (mouseX < guiProperties.getGuiLeft() + guiProperties.getGuiXSize()) { + // return isSearchBarCentered(guiProperties) && + // (searchField.isMouseOver(mouseX, mouseY) || + // configButtonHoverChecker.checkHover(mouseX, mouseY)); + // } + + // for (Rectangle guiArea : guiAreas) { + // if (guiArea.contains(mouseX, mouseY)) { + // return false; + // } + // } + + return true; + } + + @Override + @Nullable + public IClickedIngredient getIngredientUnderMouse(int mouseX, int mouseY) { + if (!isMouseOver(mouseX, mouseY)) { + return null; + } + + ClickedIngredient clicked = guiIngredientList.getIngredientUnderMouse(mouseX, mouseY); + if (clicked != null) { + setKeyboardFocus(false); + clicked.setAllowsCheating(); + return clicked; + } + clicked = guiBookmarks.getIngredientUnderMouse(mouseX, mouseY); + if (clicked != null) { + setKeyboardFocus(false); + clicked.setAllowsCheating(); + return clicked; + } + return null; + } + + @Override + public boolean canSetFocusWithMouse() { + return true; + } + + @Override + public boolean handleMouseClicked(int mouseX, int mouseY, int mouseButton) { + if (!isMouseOver(mouseX, mouseY)) { + setKeyboardFocus(false); + return false; + } + + if (Config.isDeleteItemsInCheatModeActive()) { + Minecraft minecraft = Minecraft.getMinecraft(); + EntityPlayerSP player = minecraft.thePlayer; + ItemStack itemStack = player.inventory.getItemStack(); + if (itemStack != null) { + player.inventory.setItemStack(null); + PacketJei packet = new PacketDeletePlayerItem(itemStack); + JustEnoughItems.getProxy().sendPacketToServer(packet); + return true; + } + } + + boolean buttonClicked = handleMouseClickedButtons(mouseX, mouseY); + if (buttonClicked) { + setKeyboardFocus(false); + return true; + } + + return handleMouseClickedSearch(mouseX, mouseY, mouseButton); + } + + @Override + public boolean handleMouseScrolled(int mouseX, int mouseY, int scrollDelta) { + if (!isMouseOver(mouseX, mouseY)) { + return false; + } + if (scrollDelta < 0) { + nextPage(); + return true; + } else if (scrollDelta > 0) { + previousPage(); + return true; + } + return false; + } + + private boolean handleMouseClickedButtons(int mouseX, int mouseY) { + Minecraft minecraft = Minecraft.getMinecraft(); + if (nextButton.mousePressed(minecraft, mouseX, mouseY)) { + nextPage(); + nextButton.playPressSound(minecraft.getSoundHandler()); + return true; + } else if (backButton.mousePressed(minecraft, mouseX, mouseY)) { + previousPage(); + backButton.playPressSound(minecraft.getSoundHandler()); + return true; + } else if (configButton.mousePressed(minecraft, mouseX, mouseY)) { + configButton.playPressSound(minecraft.getSoundHandler()); + if (Keyboard.getEventKeyState() + && (Keyboard.getEventKey() == Keyboard.KEY_LCONTROL || Keyboard.getEventKey() == Keyboard.KEY_RCONTROL)) { + Config.toggleCheatItemsEnabled(); + } else { + if (minecraft.currentScreen != null) { + parent.close(); + GuiScreen configScreen = new JEIModConfigGui(minecraft.currentScreen); + minecraft.displayGuiScreen(configScreen); + } + } + return true; + } else if (clearButton.mousePressed(minecraft, mouseX, mouseY)) { + clearButton.playPressSound(minecraft.getSoundHandler()); + parent.getIngredientBookmarks().clear(); + updateLayout(); + return true; + } + return false; + } + + private boolean handleMouseClickedSearch(int mouseX, int mouseY, int mouseButton) { + boolean searchClicked = searchField.isMouseOver(mouseX, mouseY); + setKeyboardFocus(searchClicked); + if (searchClicked && searchField.handleMouseClicked(mouseX, mouseY, mouseButton)) { + updateLayout(); + } + return searchClicked; + } + + @Override + public boolean hasKeyboardFocus() { + return searchField.isFocused(); + } + + @Override + public void setKeyboardFocus(boolean keyboardFocus) { + searchField.setFocused(keyboardFocus); + } + + @Override + public boolean onKeyPressed(char typedChar, int keyCode) { + if (hasKeyboardFocus()) { + boolean handled = searchField.textboxKeyTyped(typedChar, keyCode); + if (handled) { + boolean changed = Config.setFilterText(searchField.getText()); + if (changed) { + firstItemIndex = 0; + updateLayout(); + } + } + return handled; + } + return false; + } + + // Finds the right edge of the inventory screen + private static int getItemButtonXSpace(GuiProperties guiProperties) { + return guiProperties.getScreenWidth() + - (guiProperties.getGuiLeft() + guiProperties.getGuiXSize() + (2 * borderPadding)); + } + + private static int getItemButtonYSpace(GuiProperties guiProperties) { + if (isSearchBarCentered(guiProperties)) { + return guiProperties.getScreenHeight() - (buttonSize + (3 * borderPadding)); + } + // finds the height of the list screen area minus the search and the buttons + return guiProperties.getScreenHeight() - (buttonSize + searchHeight + 2 + (4 * borderPadding)); + } + + public static int getColumns(GuiProperties guiProperties) { + return getItemButtonXSpace(guiProperties) / itemStackWidth; + } + + public static int getRows(GuiProperties guiProperties) { + return getItemButtonYSpace(guiProperties) / itemStackHeight; + } + + private int getPageCount() { + final int itemCount = parent.getItemFilter().size(); + final int stacksPerPage = guiIngredientList.size(); + if (stacksPerPage == 0) { + return 1; + } + int pageCount = MathUtil.divideCeil(itemCount, stacksPerPage); + pageCount = Math.max(1, pageCount); + return pageCount; + } + + private int getPageNum() { + final int stacksPerPage = guiIngredientList.size(); + if (stacksPerPage == 0) { + return 1; + } + return firstItemIndex / stacksPerPage; + } + + public void close() { + setKeyboardFocus(false); + Config.saveFilterText(); + } + + @Nullable + public ItemStack getStackUnderMouse() { + if (hovered != null) { + Object ingredient = hovered.getIngredient(); + if (ingredient instanceof ItemStack) { + return (ItemStack) ingredient; + } + } + return null; + } + + public void setFilterText(String filterText) { + searchField.setText(filterText); + setToFirstPage(); + updateLayout(); + } + + public static void setToFirstPage() { + firstItemIndex = 0; + } + + public ImmutableList getVisibleStacks() { + ImmutableList.Builder visibleStacks = ImmutableList.builder(); + for (GuiIngredientFast guiItemStack : guiIngredientList.getAllGuiIngredients()) { + Object ingredient = guiItemStack.getIngredient(); + if (ingredient instanceof ItemStack) { + ItemStack itemStack = (ItemStack) ingredient; + visibleStacks.add(itemStack); + } + } + for (GuiIngredientFast guiItemStack : guiBookmarks.getAllGuiIngredients()) { + Object ingredient = guiItemStack.getIngredient(); + if (ingredient instanceof ItemStack) { + ItemStack itemStack = (ItemStack) ingredient; + visibleStacks.add(itemStack); + } + } + return visibleStacks.build(); + } } From ed594b771ad21e572cc18059907834662db41adc Mon Sep 17 00:00:00 2001 From: Michael Carver <4365312+shortcarver@users.noreply.github.com> Date: Wed, 2 Oct 2024 19:12:38 -0500 Subject: [PATCH 6/8] removed makefile --- Makefile | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 Makefile diff --git a/Makefile b/Makefile deleted file mode 100644 index 25f1163bf..000000000 --- a/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# Build tools for arm based macos, running a test client through curseforge called "TestJEI - -switch_java: - export JAVA_HOME=`/usr/libexec/java_home -v 1.8.0_362` -bd: - JAVA_HOME=`/usr/libexec/java_home -v 1.8.0_362` - ./gradlew build - make deploy -deploy: - rm ~/Documents/curseforge/minecraft/Instances/TestJEI/mods/jei_1.10.2-3.14.8.jar - cp build/libs/jei_1.10.2-3.14.8.jar ~/Documents/curseforge/minecraft/Instances/TestJEI/mods/ From a501ef3946123263c7148156f241f7f9109b47cc Mon Sep 17 00:00:00 2001 From: Michael Carver <4365312+shortcarver@users.noreply.github.com> Date: Wed, 2 Oct 2024 20:52:25 -0500 Subject: [PATCH 7/8] added config file --- .../java/mezz/jei/IngredientBookmarks.java | 38 +++++++++----- src/main/java/mezz/jei/config/Config.java | 52 ++++++++++++++++++- 2 files changed, 74 insertions(+), 16 deletions(-) diff --git a/src/main/java/mezz/jei/IngredientBookmarks.java b/src/main/java/mezz/jei/IngredientBookmarks.java index 9f55e5f4e..21b659262 100644 --- a/src/main/java/mezz/jei/IngredientBookmarks.java +++ b/src/main/java/mezz/jei/IngredientBookmarks.java @@ -8,6 +8,7 @@ import mezz.jei.api.ingredients.IIngredientHelper; import mezz.jei.api.ingredients.IIngredientRegistry; import mezz.jei.api.ingredients.IIngredientRenderer; +import mezz.jei.config.Config; import mezz.jei.gui.ingredients.IIngredientListElement; import mezz.jei.util.IngredientListElement; import com.google.common.collect.ImmutableCollection; @@ -22,6 +23,13 @@ public class IngredientBookmarks implements IIngredientBookmarks { public IngredientBookmarks(IIngredientRegistry ingredientRegistry) { this.ingredientRegistry = ingredientRegistry; + + String[] bookmarks = Config.getBookmarks(); + + for (String uniqueId : bookmarks) { + bookmarkIds.add(uniqueId); + bookmarkList.put(uniqueId, findIngredientFromUniqueId(uniqueId)); + } } @Override @@ -29,27 +37,29 @@ public void toggleIngredientBookmark(V ingredient) { IIngredientHelper ingredientHelper = ingredientRegistry.getIngredientHelper(ingredient); String uniqueId = ingredientHelper.getUniqueId(ingredient); - // find ingredient in registry - ImmutableCollection clazzes = ingredientRegistry.getRegisteredIngredientClasses(); - for (Class clazz : clazzes) { - ImmutableList iList = ingredientRegistry.getIngredients(clazz); - IIngredientHelper iHelper = ingredientRegistry.getIngredientHelper(clazz); - for (V i : iList) { - if (iHelper.getUniqueId(i).equals(uniqueId)) { - ingredient = i; - break; - } - } - } - // System.out.println(ingredientHelper.getUniqueId(ingredient)); if (bookmarkIds.contains(uniqueId)) { bookmarkIds.remove(uniqueId); bookmarkList.remove(uniqueId); } else { bookmarkIds.add(uniqueId); - bookmarkList.put(uniqueId, ingredient); + bookmarkList.put(uniqueId, findIngredientFromUniqueId(uniqueId)); + } + Config.updateBookmarks(bookmarkIds.toArray(new String[bookmarkIds.size()])); + } + + private V findIngredientFromUniqueId(String uniqueId) { + ImmutableCollection classes = ingredientRegistry.getRegisteredIngredientClasses(); + for (Class clazz : classes) { + ImmutableList iList = ingredientRegistry.getIngredients(clazz); + IIngredientHelper iHelper = ingredientRegistry.getIngredientHelper(clazz); + for (V i : iList) { + if (iHelper.getUniqueId(i).equals(uniqueId)) { + return i; + } + } } + return null; } @Override diff --git a/src/main/java/mezz/jei/config/Config.java b/src/main/java/mezz/jei/config/Config.java index 54683a4d5..beb923653 100644 --- a/src/main/java/mezz/jei/config/Config.java +++ b/src/main/java/mezz/jei/config/Config.java @@ -6,6 +6,8 @@ import java.util.Collections; import java.util.EnumSet; import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; import java.util.Locale; import java.util.Set; @@ -40,6 +42,8 @@ public class Config { private static LocalizedConfiguration itemBlacklistConfig; @Nullable private static LocalizedConfiguration searchColorsConfig; + @Nullable + private static LocalizedConfiguration bookmarksConfig; // advanced private static boolean debugModeEnabled = false; @@ -73,7 +77,11 @@ public class Config { // item blacklist private static final Set itemBlacklist = new HashSet(); - private static final String[] defaultItemBlacklist = new String[]{}; + private static final String[] defaultItemBlacklist = new String[] {}; + + // bookmarks + private static final String[] defaultBookmarks = new String[] {}; + private static String[] bookmarks; private Config() { @@ -226,6 +234,8 @@ public static void preInit(FMLPreInitializationEvent event) { final File itemBlacklistConfigFile = new File(jeiConfigurationDir, "itemBlacklist.cfg"); final File searchColorsConfigFile = new File(jeiConfigurationDir, "searchColors.cfg"); final File worldConfigFile = new File(jeiConfigurationDir, "worldSettings.cfg"); + final File bookmarksConfigFile = new File(jeiConfigurationDir, "bookmarks.cfg"); + worldConfig = new Configuration(worldConfigFile, "0.1.0"); { @@ -257,10 +267,12 @@ public static void preInit(FMLPreInitializationEvent event) { config = new LocalizedConfiguration(configKeyPrefix, configFile, "0.2.0"); itemBlacklistConfig = new LocalizedConfiguration(configKeyPrefix, itemBlacklistConfigFile, "0.1.0"); searchColorsConfig = new LocalizedConfiguration(configKeyPrefix, searchColorsConfigFile, "0.1.0"); + bookmarksConfig = new LocalizedConfiguration(configKeyPrefix, bookmarksConfigFile, "0.1.0"); syncConfig(); syncItemBlacklistConfig(); syncSearchColorsConfig(); + syncBookmarksConfig(); } public static boolean syncAllConfig() { @@ -315,7 +327,7 @@ private static boolean syncConfig() { searchCategory.remove("prefixRequiredForCreativeTabSearch"); searchCategory.remove("prefixRequiredForColorSearch"); - SearchMode[] searchModes = SearchMode.values(); + SearchMode[] searchModes = SearchMode.values(); modNameSearchMode = config.getEnum("modNameSearchMode", CATEGORY_SEARCH, defaultModNameSearchMode, searchModes); tooltipSearchMode = config.getEnum("tooltipSearchMode", CATEGORY_SEARCH, defaultTooltipSearchMode, searchModes); oreDictSearchMode = config.getEnum("oreDictSearchMode", CATEGORY_SEARCH, defaultOreDictSearchMode, searchModes); @@ -402,6 +414,42 @@ private static boolean syncItemBlacklistConfig() { return configChanged; } + private static boolean syncBookmarksConfig() { + if (bookmarksConfig == null) { + return false; + } + + bookmarksConfig.addCategory(CATEGORY_ADVANCED); + + bookmarks = bookmarksConfig.getStringList("bookmarks", CATEGORY_ADVANCED, defaultBookmarks); + + final boolean configChanged = bookmarksConfig.hasChanged(); + if (configChanged) { + bookmarksConfig.save(); + } + return configChanged; + } + + public static boolean updateBookmarks(String[] bookmarkIds) { + bookmarks = bookmarkIds; + if (bookmarksConfig == null) { + return false; + } + Property property = bookmarksConfig.get(CATEGORY_ADVANCED, "bookmarks", defaultBookmarks); + + property.set(bookmarks); + + boolean changed = bookmarksConfig.hasChanged(); + if (changed) { + bookmarksConfig.save(); + } + return changed; + } + + public static String[] getBookmarks() { + return bookmarks; + } + public static boolean syncWorldConfig() { if (worldConfig == null) { return false; From dfa1ff82b7c15ab81c0a83db2632d9426cb6ff70 Mon Sep 17 00:00:00 2001 From: Michael Carver <4365312+shortcarver@users.noreply.github.com> Date: Wed, 2 Oct 2024 21:06:43 -0500 Subject: [PATCH 8/8] fixing some formatting issues --- .../java/mezz/jei/IngredientBookmarks.java | 2 +- src/main/java/mezz/jei/JeiRuntime.java | 4 +-- .../api/ingredients/IIngredientBookmarks.java | 20 ++++--------- .../java/mezz/jei/gui/ItemListOverlay.java | 3 +- .../mezz/jei/gui/ItemListOverlayInternal.java | 30 +++++++------------ .../java/mezz/jei/input/InputHandler.java | 3 +- 6 files changed, 21 insertions(+), 41 deletions(-) diff --git a/src/main/java/mezz/jei/IngredientBookmarks.java b/src/main/java/mezz/jei/IngredientBookmarks.java index 21b659262..15f92d976 100644 --- a/src/main/java/mezz/jei/IngredientBookmarks.java +++ b/src/main/java/mezz/jei/IngredientBookmarks.java @@ -17,7 +17,7 @@ public class IngredientBookmarks implements IIngredientBookmarks { private final IIngredientRegistry ingredientRegistry; - // Using both so cause linked list will retain order of insertion + // Using both cause linked list will retain order of insertion private List bookmarkIds = new LinkedList(); private HashMap bookmarkList = new HashMap(); diff --git a/src/main/java/mezz/jei/JeiRuntime.java b/src/main/java/mezz/jei/JeiRuntime.java index 69323c76b..267da142e 100644 --- a/src/main/java/mezz/jei/JeiRuntime.java +++ b/src/main/java/mezz/jei/JeiRuntime.java @@ -20,9 +20,7 @@ public class JeiRuntime implements IJeiRuntime { private final List> advancedGuiHandlers; private final IngredientBookmarks ingredientBookmarks; - public JeiRuntime(RecipeRegistry recipeRegistry, ItemListOverlay itemListOverlay, RecipesGui recipesGui, - IngredientRegistry ingredientRegistry, List> advancedGuiHandlers, - IngredientBookmarks ingredientBookmarks) { + public JeiRuntime(RecipeRegistry recipeRegistry, ItemListOverlay itemListOverlay, RecipesGui recipesGui, IngredientRegistry ingredientRegistry, List> advancedGuiHandlers, IngredientBookmarks ingredientBookmarks) { this.recipeRegistry = recipeRegistry; this.itemListOverlay = itemListOverlay; this.recipesGui = recipesGui; diff --git a/src/main/java/mezz/jei/api/ingredients/IIngredientBookmarks.java b/src/main/java/mezz/jei/api/ingredients/IIngredientBookmarks.java index 579ab19cb..e2ee02be7 100644 --- a/src/main/java/mezz/jei/api/ingredients/IIngredientBookmarks.java +++ b/src/main/java/mezz/jei/api/ingredients/IIngredientBookmarks.java @@ -2,23 +2,15 @@ import java.util.List; -import mezz.jei.api.IJeiHelpers; import mezz.jei.gui.ingredients.IIngredientListElement; -/** - * The Ingredient bookmaks allows mods add and remove ingredients from JEI's - * bookmark list - * Get the instance from {@link IJeiHelpers#getIngredientBookmarks()}. - * - * @Since JEI 3.14.9 - */ public interface IIngredientBookmarks { - /** - * Toggles visibility of ingredient in the bookmark list. - */ - void toggleIngredientBookmark(V ingredient); + /** + * Toggles visibility of ingredient in the bookmark list. + */ + void toggleIngredientBookmark(V ingredient); - List getIngredientList(); + List getIngredientList(); - void clear(); + void clear(); } diff --git a/src/main/java/mezz/jei/gui/ItemListOverlay.java b/src/main/java/mezz/jei/gui/ItemListOverlay.java index 3b4824c22..5bcf233fb 100644 --- a/src/main/java/mezz/jei/gui/ItemListOverlay.java +++ b/src/main/java/mezz/jei/gui/ItemListOverlay.java @@ -27,8 +27,7 @@ public class ItemListOverlay implements IItemListOverlay { @Nullable private ItemListOverlayInternal internal; - public ItemListOverlay(ItemFilter itemFilter, List> advancedGuiHandlers, - IIngredientRegistry ingredientRegistry, IIngredientBookmarks ingredientBookmarks) { + public ItemListOverlay(ItemFilter itemFilter, List> advancedGuiHandlers, IIngredientRegistry ingredientRegistry, IIngredientBookmarks ingredientBookmarks) { this.itemFilter = itemFilter; this.advancedGuiHandlers = advancedGuiHandlers; this.ingredientRegistry = ingredientRegistry; diff --git a/src/main/java/mezz/jei/gui/ItemListOverlayInternal.java b/src/main/java/mezz/jei/gui/ItemListOverlayInternal.java index 17f5cbf11..821b1a6ca 100644 --- a/src/main/java/mezz/jei/gui/ItemListOverlayInternal.java +++ b/src/main/java/mezz/jei/gui/ItemListOverlayInternal.java @@ -87,8 +87,7 @@ public class ItemListOverlayInternal implements IShowsRecipeFocuses, IMouseHandl private final List guiAreas; private List> activeAdvancedGuiHandlers = Collections.emptyList(); - public ItemListOverlayInternal(ItemListOverlay parent, IIngredientRegistry ingredientRegistry, GuiScreen guiScreen, - GuiProperties guiProperties) { + public ItemListOverlayInternal(ItemListOverlay parent, IIngredientRegistry ingredientRegistry, GuiScreen guiScreen, GuiProperties guiProperties) { this.parent = parent; this.guiBookmarks = new GuiIngredientFastList(ingredientRegistry); @@ -106,8 +105,7 @@ public ItemListOverlayInternal(ItemListOverlay parent, IIngredientRegistry ingre final int columns = getColumns(guiProperties); final int rows = getRows(guiProperties); final int xSize = columns * itemStackWidth; - final int xEmptySpace = guiProperties.getScreenWidth() - guiProperties.getGuiLeft() - guiProperties.getGuiXSize() - - xSize; + final int xEmptySpace = guiProperties.getScreenWidth() - guiProperties.getGuiLeft() - guiProperties.getGuiXSize() - xSize; final int leftEdge = guiProperties.getGuiLeft() + guiProperties.getGuiXSize() + (xEmptySpace / 2); final int rightEdge = leftEdge + xSize; @@ -139,15 +137,13 @@ public ItemListOverlayInternal(ItemListOverlay parent, IIngredientRegistry ingre } FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; - searchField = new GuiTextFieldFilter(0, fontRenderer, searchFieldX, searchFieldY, searchFieldWidth, searchHeight, - parent.getItemFilter()); + searchField = new GuiTextFieldFilter(0, fontRenderer, searchFieldX, searchFieldY, searchFieldWidth, searchHeight, parent.getItemFilter()); setKeyboardFocus(false); int configButtonX = searchFieldX + searchFieldWidth + 1; int configButtonY = guiProperties.getScreenHeight() - buttonSize - borderPadding; configButton = new GuiButton(2, configButtonX, configButtonY, buttonSize, buttonSize, ""); - ResourceLocation configButtonIconLocation = new ResourceLocation(Constants.RESOURCE_DOMAIN, - Constants.TEXTURE_RECIPE_BACKGROUND_PATH); + ResourceLocation configButtonIconLocation = new ResourceLocation(Constants.RESOURCE_DOMAIN, Constants.TEXTURE_RECIPE_BACKGROUND_PATH); GuiHelper guiHelper = Internal.getHelpers().getGuiHelper(); configButtonIcon = guiHelper.createDrawable(configButtonIconLocation, 0, 166, 16, 16); configButtonCheatIcon = guiHelper.createDrawable(configButtonIconLocation, 16, 166, 16, 16); @@ -186,8 +182,7 @@ private List getGuiAreas(GuiContainer guiContainer) { } @Nullable - private List getGuiAreas(GuiContainer gui, - IAdvancedGuiHandler advancedGuiHandler) { + private List getGuiAreas(GuiContainer gui, IAdvancedGuiHandler advancedGuiHandler) { Class guiClass = advancedGuiHandler.getGuiContainerClass(); if (guiClass.isInstance(gui)) { T guiT = guiClass.cast(gui); @@ -217,8 +212,7 @@ public boolean hasScreenChanged(GuiScreen guiScreen) { return false; } - private static void createItemButtons(GuiIngredientFastList guiItemStacks, @Nullable List guiAreas, - final int xStart, final int yStart, final int columnCount, final int rowCount) { + private static void createItemButtons(GuiIngredientFastList guiItemStacks, @Nullable List guiAreas, final int xStart, final int yStart, final int columnCount, final int rowCount) { guiItemStacks.clear(); for (int row = 0; row < rowCount; row++) { @@ -303,8 +297,7 @@ private void previousPage() { public void drawScreen(Minecraft minecraft, int mouseX, int mouseY) { GlStateManager.disableLighting(); - minecraft.fontRendererObj.drawString(pageNumDisplayString, pageNumDisplayX, pageNumDisplayY, Color.white.getRGB(), - true); + minecraft.fontRendererObj.drawString(pageNumDisplayString, pageNumDisplayX, pageNumDisplayY, Color.white.getRGB(), true); searchField.drawTextBox(); nextButton.drawButton(minecraft, mouseX, mouseY); @@ -384,7 +377,8 @@ public void drawTooltips(Minecraft minecraft, int mouseX, int mouseY) { if (Config.isCheatItemsEnabled()) { List tooltip = Arrays.asList( configString, - TextFormatting.RED + Translator.translateToLocal("jei.tooltip.cheat.mode")); + TextFormatting.RED + Translator.translateToLocal("jei.tooltip.cheat.mode") + ); TooltipRenderer.drawHoveringText(minecraft, tooltip, mouseX, mouseY); } else { TooltipRenderer.drawHoveringText(minecraft, configString, mouseX, mouseY); @@ -502,8 +496,7 @@ private boolean handleMouseClickedButtons(int mouseX, int mouseY) { return true; } else if (configButton.mousePressed(minecraft, mouseX, mouseY)) { configButton.playPressSound(minecraft.getSoundHandler()); - if (Keyboard.getEventKeyState() - && (Keyboard.getEventKey() == Keyboard.KEY_LCONTROL || Keyboard.getEventKey() == Keyboard.KEY_RCONTROL)) { + if (Keyboard.getEventKeyState() && (Keyboard.getEventKey() == Keyboard.KEY_LCONTROL || Keyboard.getEventKey() == Keyboard.KEY_RCONTROL)) { Config.toggleCheatItemsEnabled(); } else { if (minecraft.currentScreen != null) { @@ -559,8 +552,7 @@ public boolean onKeyPressed(char typedChar, int keyCode) { // Finds the right edge of the inventory screen private static int getItemButtonXSpace(GuiProperties guiProperties) { - return guiProperties.getScreenWidth() - - (guiProperties.getGuiLeft() + guiProperties.getGuiXSize() + (2 * borderPadding)); + return guiProperties.getScreenWidth() - (guiProperties.getGuiLeft() + guiProperties.getGuiXSize() + (2 * borderPadding)); } private static int getItemButtonYSpace(GuiProperties guiProperties) { diff --git a/src/main/java/mezz/jei/input/InputHandler.java b/src/main/java/mezz/jei/input/InputHandler.java index 09d96768e..845bd177d 100644 --- a/src/main/java/mezz/jei/input/InputHandler.java +++ b/src/main/java/mezz/jei/input/InputHandler.java @@ -90,8 +90,7 @@ private boolean handleMouseClick(GuiScreen guiScreen, int mouseButton, int mouse if (guiScreen instanceof GuiContainer) { GuiContainer guiContainer = (GuiContainer) guiScreen; - RecipeClickableArea clickableArea = recipeRegistry.getRecipeClickableArea(guiContainer, - mouseX - guiContainer.guiLeft, mouseY - guiContainer.guiTop); + RecipeClickableArea clickableArea = recipeRegistry.getRecipeClickableArea(guiContainer, mouseX - guiContainer.guiLeft, mouseY - guiContainer.guiTop); if (clickableArea != null) { List recipeCategoryUids = clickableArea.getRecipeCategoryUids(); recipesGui.showCategories(recipeCategoryUids);