From 6645993cb8028cce4f0f95f4f079952414246188 Mon Sep 17 00:00:00 2001 From: slprime Date: Sat, 16 Nov 2024 10:57:09 +0200 Subject: [PATCH] Small Changes --- .../codechicken/nei/CollapsibleItems.java | 2 - .../java/codechicken/nei/GuiNEIButton.java | 47 ++++++++++--------- .../codechicken/nei/ItemHistoryPanel.java | 8 ++-- src/main/java/codechicken/nei/ItemList.java | 13 +++-- .../codechicken/nei/ItemQuantityField.java | 1 + .../java/codechicken/nei/ItemStackSet.java | 4 +- .../java/codechicken/nei/NEIClientUtils.java | 11 +---- .../java/codechicken/nei/SearchField.java | 2 +- .../nei/config/preset/GuiPresetList.java | 10 ++-- .../nei/config/preset/LeftPanel.java | 7 +++ .../nei/guihook/IContainerTooltipHandler.java | 14 ++++-- .../codechicken/nei/recipe/GuiRecipe.java | 2 +- .../nei/recipe/SearchRecipeHandler.java | 17 +++---- 13 files changed, 70 insertions(+), 68 deletions(-) diff --git a/src/main/java/codechicken/nei/CollapsibleItems.java b/src/main/java/codechicken/nei/CollapsibleItems.java index 899b502fb..ad1a5a9ab 100644 --- a/src/main/java/codechicken/nei/CollapsibleItems.java +++ b/src/main/java/codechicken/nei/CollapsibleItems.java @@ -35,8 +35,6 @@ protected static class GroupItem { public boolean expanded = false; public String displayName = ""; - public GroupItem() {} - public void setFilter(String filter) { this.filter = ItemStackFilterParser.parse(filter.trim()); this.guid = this.filter != null ? UUID.nameUUIDFromBytes(filter.getBytes()).toString() : ""; diff --git a/src/main/java/codechicken/nei/GuiNEIButton.java b/src/main/java/codechicken/nei/GuiNEIButton.java index 962f5720e..2774d0877 100644 --- a/src/main/java/codechicken/nei/GuiNEIButton.java +++ b/src/main/java/codechicken/nei/GuiNEIButton.java @@ -15,14 +15,13 @@ public GuiNEIButton(int i, int j, int k, int l, int i1, String s) { super(i, j, k, l, i1, s); } - public void drawButton(Minecraft minecraft, int i, int j) { + public void drawButton(Minecraft minecraft, int x, int y) { if (!visible) return; - FontRenderer fontrenderer = minecraft.fontRenderer; minecraft.renderEngine.bindTexture(guiTex); GL11.glColor4f(1, 1, 1, 1); - boolean flag = i >= xPosition && j >= yPosition && i < xPosition + width && j < yPosition + height; - int k = getHoverState(flag); + boolean mouseOver = x >= xPosition && y >= yPosition && x < xPosition + width && y < yPosition + height; + int k = getHoverState(mouseOver); drawTexturedModalRect(xPosition, yPosition, 0, 46 + k * 20, width / 2, height / 2); // top left drawTexturedModalRect(xPosition + width / 2, yPosition, 200 - width / 2, 46 + k * 20, width / 2, height / 2); // top // right @@ -40,25 +39,27 @@ public void drawButton(Minecraft minecraft, int i, int j) { 46 + k * 20 + 20 - height / 2, width / 2, height / 2); // bottom right - mouseDragged(minecraft, i, j); + mouseDragged(minecraft, x, y); - if (!enabled) drawCenteredString( - fontrenderer, - displayString, - xPosition + width / 2, - yPosition + (height - 8) / 2, - 0xffa0a0a0); - else if (flag) drawCenteredString( - fontrenderer, - displayString, - xPosition + width / 2, - yPosition + (height - 8) / 2, - 0xffffa0); - else drawCenteredString( - fontrenderer, - displayString, - xPosition + width / 2, - yPosition + (height - 8) / 2, - 0xe0e0e0); + drawContent(minecraft, x, y, mouseOver); + } + + protected int getTextColour(boolean mouseOver) { + int color = 0xe0e0e0; + + if (!enabled) { + color = 0xffa0a0a0; + } else if (mouseOver) { + color = 0xffffa0; + } + + return color; + } + + protected void drawContent(Minecraft minecraft, int y, int x, boolean mouseOver) { + FontRenderer fontrenderer = minecraft.fontRenderer; + int color = getTextColour(mouseOver); + + drawCenteredString(fontrenderer, displayString, xPosition + width / 2, yPosition + (height - 8) / 2, color); } } diff --git a/src/main/java/codechicken/nei/ItemHistoryPanel.java b/src/main/java/codechicken/nei/ItemHistoryPanel.java index b1580816b..4c46cf5de 100644 --- a/src/main/java/codechicken/nei/ItemHistoryPanel.java +++ b/src/main/java/codechicken/nei/ItemHistoryPanel.java @@ -69,10 +69,10 @@ public ItemPanelSlot getSlotMouseOver(int mousex, int mousey) { private void drawSplittingArea(int x, int y, int width, int height, int color) { - float alpha = (float) (color >> 24 & 255) / 255.0F; - float red = (float) (color >> 16 & 255) / 255.0F; - float green = (float) (color >> 8 & 255) / 255.0F; - float blue = (float) (color & 255) / 255.0F; + float alpha = (color >> 24 & 255) / 255.0F; + float red = (color >> 16 & 255) / 255.0F; + float green = (color >> 8 & 255) / 255.0F; + float blue = (color & 255) / 255.0F; GL11.glPushMatrix(); diff --git a/src/main/java/codechicken/nei/ItemList.java b/src/main/java/codechicken/nei/ItemList.java index 1753c0624..1dee2d44b 100644 --- a/src/main/java/codechicken/nei/ItemList.java +++ b/src/main/java/codechicken/nei/ItemList.java @@ -93,7 +93,7 @@ public PatternItemFilter(Pattern pattern) { public boolean matches(ItemStack item) { String displayName = EnumChatFormatting.getTextWithoutFormattingCodes(item.getDisplayName()); - if (!displayName.isEmpty() && pattern.matcher(displayName).find()) { + if (displayName != null && !displayName.isEmpty() && pattern.matcher(displayName).find()) { return true; } @@ -101,7 +101,7 @@ public boolean matches(ItemStack item) { displayName = EnumChatFormatting .getTextWithoutFormattingCodes(item.getItem().getItemStackDisplayName(item)); - return !displayName.isEmpty() && pattern.matcher(displayName).find(); + return displayName != null && !displayName.isEmpty() && pattern.matcher(displayName).find(); } return false; @@ -129,7 +129,8 @@ public boolean matches(ItemStack item) { for (ItemFilter filter : filters) try { if (filter != null && !filter.matches(item)) return false; } catch (Exception e) { - NEIClientConfig.logger.error("Exception filtering " + item + " with " + filter, e); + NEIClientConfig.logger + .error("Exception filtering " + item + " with " + filter + " (" + e.getMessage() + ")", e); } return true; @@ -153,7 +154,8 @@ public boolean matches(ItemStack item) { for (ItemFilter filter : filters) try { if (filter != null && filter.matches(item)) return true; } catch (Exception e) { - NEIClientConfig.logger.error("Exception filtering " + item + " with " + filter, e); + NEIClientConfig.logger + .error("Exception filtering " + item + " with " + filter + " (" + e.getMessage() + ")", e); } return false; @@ -170,7 +172,8 @@ public static boolean itemMatchesAll(ItemStack item, List filters) { try { if (filter != null && !filter.matches(item)) return false; } catch (Exception e) { - NEIClientConfig.logger.error("Exception filtering " + item + " with " + filter, e); + NEIClientConfig.logger + .error("Exception filtering " + item + " with " + filter + " (" + e.getMessage() + ")", e); } } diff --git a/src/main/java/codechicken/nei/ItemQuantityField.java b/src/main/java/codechicken/nei/ItemQuantityField.java index f1002169f..b1bd01f7e 100644 --- a/src/main/java/codechicken/nei/ItemQuantityField.java +++ b/src/main/java/codechicken/nei/ItemQuantityField.java @@ -44,6 +44,7 @@ public void draw(int mousex, int mousey) { if (!focused() && intValue() == 0) { field.setText(translate("itempanel.quantity.default")); + field.setCursorPositionZero(); field.setEnabled(false); super.draw(mousex, mousey); field.setEnabled(true); diff --git a/src/main/java/codechicken/nei/ItemStackSet.java b/src/main/java/codechicken/nei/ItemStackSet.java index 12b9056c1..e11a3cc92 100644 --- a/src/main/java/codechicken/nei/ItemStackSet.java +++ b/src/main/java/codechicken/nei/ItemStackSet.java @@ -1,7 +1,5 @@ package codechicken.nei; -import java.util.List; - import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -29,7 +27,7 @@ public void add(ItemStack item) { put(item, item); } - public ItemStackSet addAll(List items) { + public ItemStackSet addAll(Iterable items) { for (ItemStack item : items) add(item); return this; } diff --git a/src/main/java/codechicken/nei/NEIClientUtils.java b/src/main/java/codechicken/nei/NEIClientUtils.java index 58125b27c..dcaa933bf 100644 --- a/src/main/java/codechicken/nei/NEIClientUtils.java +++ b/src/main/java/codechicken/nei/NEIClientUtils.java @@ -37,8 +37,6 @@ import net.minecraft.inventory.Slot; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.util.ChatComponentTranslation; -import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IChatComponent; import net.minecraft.util.ResourceLocation; @@ -512,16 +510,9 @@ public static void reportErrorBuffered(Throwable e, Set buffer, String c String stackTrace = cause + sw; if (buffer.contains(stackTrace)) return; - System.err.println("Error while rendering: " + cause); + System.err.println("Error while rendering: " + cause + " (" + e.getMessage() + ")"); e.printStackTrace(); buffer.add(stackTrace); - - EntityPlayer player = Minecraft.getMinecraft().thePlayer; - if (player != null) { - IChatComponent chat = new ChatComponentTranslation("nei.chat.render.error"); - chat.getChatStyle().setColor(EnumChatFormatting.RED); - player.addChatComponentMessage(chat); - } } public static void reportErrorBuffered(Throwable e, Set buffer, ItemStack cause) { diff --git a/src/main/java/codechicken/nei/SearchField.java b/src/main/java/codechicken/nei/SearchField.java index 556a80622..71733cdf6 100644 --- a/src/main/java/codechicken/nei/SearchField.java +++ b/src/main/java/codechicken/nei/SearchField.java @@ -243,7 +243,7 @@ public static Pattern getPattern(String search, int patternMode) { search = search.substring(2, search.length() - 1); } else { final Matcher matcher = Pattern.compile("(\\?|\\*)").matcher(search); - StringBuilder cleanedString = new StringBuilder(); + final StringBuilder cleanedString = new StringBuilder(); int lastEndIndex = 0; while (matcher.find()) { diff --git a/src/main/java/codechicken/nei/config/preset/GuiPresetList.java b/src/main/java/codechicken/nei/config/preset/GuiPresetList.java index bf7b2c64f..0848f4c01 100644 --- a/src/main/java/codechicken/nei/config/preset/GuiPresetList.java +++ b/src/main/java/codechicken/nei/config/preset/GuiPresetList.java @@ -23,8 +23,8 @@ public class GuiPresetList extends GuiOptionPane { private final Option opt; - protected final static int SLOT_HEIGHT = 24; - protected final static int BUTTON_HEIGHT = 20; + protected static final int SLOT_HEIGHT = 24; + protected static final int BUTTON_HEIGHT = 20; protected GuiCCButton createButton; protected GuiCCButton toggleButton; protected int sortingItemIndex = -1; @@ -68,10 +68,6 @@ public void actionPerformed(String ident, Object... params) { } } - protected void mouseClicked(int x, int y, int button) { - super.mouseClicked(x, y, button); - } - @Override protected void mouseMovedOrUp(int x, int y, int button) { super.mouseMovedOrUp(x, y, button); @@ -151,7 +147,7 @@ protected void cretePreset() { } protected void togglePreset() { - boolean enabled = !PresetsList.presets.stream().filter(g -> g.enabled).findAny().isPresent(); + boolean enabled = PresetsList.presets.stream().noneMatch(g -> g.enabled); for (Preset preset : PresetsList.presets) { preset.enabled = enabled; diff --git a/src/main/java/codechicken/nei/config/preset/LeftPanel.java b/src/main/java/codechicken/nei/config/preset/LeftPanel.java index b2f267321..01518868e 100644 --- a/src/main/java/codechicken/nei/config/preset/LeftPanel.java +++ b/src/main/java/codechicken/nei/config/preset/LeftPanel.java @@ -326,4 +326,11 @@ public void keyTyped(char c, int keycode) { nameField.handleKeyPress(keycode, c); } + @Override + public void mouseScrolled(int x, int y, int scroll) { + if (grid.contains(x, y)) { + grid.shiftPage(-scroll); + } + } + } diff --git a/src/main/java/codechicken/nei/guihook/IContainerTooltipHandler.java b/src/main/java/codechicken/nei/guihook/IContainerTooltipHandler.java index 05fb11263..26d3a5ef4 100644 --- a/src/main/java/codechicken/nei/guihook/IContainerTooltipHandler.java +++ b/src/main/java/codechicken/nei/guihook/IContainerTooltipHandler.java @@ -23,7 +23,9 @@ public interface IContainerTooltipHandler { * @param currenttip A list of strings, representing each line of the current tooltip as modified by other handlers * @return The modified list. NOTE: Do not return null */ - public List handleTooltip(GuiContainer gui, int mousex, int mousey, List currenttip); + default List handleTooltip(GuiContainer gui, int mousex, int mousey, List currenttip) { + return currenttip; + } /** * Use this for modifying the multiline display name of an item which may not necessarily be under the mouse. @@ -35,7 +37,9 @@ public interface IContainerTooltipHandler { * @param currenttip A list of strings, representing each line of the current tooltip as modified by other handlers * @return The modified list. NOTE: Do not return null */ - public List handleItemDisplayName(GuiContainer gui, ItemStack itemstack, List currenttip); + default List handleItemDisplayName(GuiContainer gui, ItemStack itemstack, List currenttip) { + return currenttip; + } /** * Use this for modifying the tooltips of items that are under the mouse. GuiContainerManager.shouldShowTooltip is @@ -46,8 +50,10 @@ public interface IContainerTooltipHandler { * @param currenttip A list of strings, representing each line of the current tooltip as modified by other handlers * @return The modified list. NOTE: Do not return null */ - public List handleItemTooltip(GuiContainer gui, ItemStack itemstack, int mousex, int mousey, - List currenttip); + default List handleItemTooltip(GuiContainer gui, ItemStack itemstack, int mousex, int mousey, + List currenttip) { + return currenttip; + } /** * Use this to specify a list of hotkeys that will work when hovering over an element that is under the mouse diff --git a/src/main/java/codechicken/nei/recipe/GuiRecipe.java b/src/main/java/codechicken/nei/recipe/GuiRecipe.java index cd9cd6c1c..da8428f97 100644 --- a/src/main/java/codechicken/nei/recipe/GuiRecipe.java +++ b/src/main/java/codechicken/nei/recipe/GuiRecipe.java @@ -237,7 +237,7 @@ public void execute() { guiRecipe.changePage(0); } else { final IRecipeFilter filter = new ItemRecipeFilter(GuiRecipe.searchField.getFilter()); - ArrayList filtered = searchHandler.getSearchResult(filter); + List filtered = searchHandler.getSearchResult(filter); if (filtered == null) { stop(); diff --git a/src/main/java/codechicken/nei/recipe/SearchRecipeHandler.java b/src/main/java/codechicken/nei/recipe/SearchRecipeHandler.java index 2887b99c6..d5078cc2e 100644 --- a/src/main/java/codechicken/nei/recipe/SearchRecipeHandler.java +++ b/src/main/java/codechicken/nei/recipe/SearchRecipeHandler.java @@ -1,8 +1,9 @@ package codechicken.nei.recipe; import java.util.ArrayList; +import java.util.List; import java.util.concurrent.ExecutionException; -import java.util.function.Predicate; +import java.util.function.IntPredicate; import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.Stream; @@ -14,9 +15,9 @@ class SearchRecipeHandler { public H original; - private ArrayList filteredRecipes; + private List filteredRecipes; - private ArrayList searchRecipes; + private List searchRecipes; public SearchRecipeHandler(H handler) { this.original = handler; @@ -52,7 +53,7 @@ private static boolean searchingAvailable(IRecipeHandler handler) { return handler instanceof TemplateRecipeHandler; } - public static int findFirst(IRecipeHandler handler, Predicate predicate) { + public static int findFirst(IRecipeHandler handler, IntPredicate predicate) { final IRecipeFilter filter = searchingAvailable(handler) ? GuiRecipe.getRecipeListFilter() : null; int refIndex = -1; @@ -69,14 +70,14 @@ public static int findFirst(IRecipeHandler handler, Predicate predicate return -1; } - public ArrayList getSearchResult(IRecipeFilter filter) { + public List getSearchResult(IRecipeFilter filter) { if (filteredRecipes.isEmpty() || !this.searchingAvailable()) { return null; } - ArrayList filtered = null; - final ArrayList recipes = IntStream.range(0, filteredRecipes.size()).boxed() + List filtered = null; + final List recipes = IntStream.range(0, filteredRecipes.size()).boxed() .collect(Collectors.toCollection(ArrayList::new)); try { @@ -95,7 +96,7 @@ public ArrayList getSearchResult(IRecipeFilter filter) { return filtered; } - public void setSearchIndices(ArrayList searchRecipes) { + public void setSearchIndices(List searchRecipes) { this.searchRecipes = searchRecipes; }