Skip to content

Commit

Permalink
Fix Presets Scroll; Fix Placeholder position in the quantity field; H…
Browse files Browse the repository at this point in the history
…ide rendering error in chat; (#555)

Co-authored-by: slprime <[email protected]>
Co-authored-by: Martin Robertz <[email protected]>
  • Loading branch information
3 people authored Nov 17, 2024
1 parent e9ce5cf commit a0e1683
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 68 deletions.
2 changes: 0 additions & 2 deletions src/main/java/codechicken/nei/CollapsibleItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() : "";
Expand Down
47 changes: 24 additions & 23 deletions src/main/java/codechicken/nei/GuiNEIButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
8 changes: 4 additions & 4 deletions src/main/java/codechicken/nei/ItemHistoryPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
13 changes: 8 additions & 5 deletions src/main/java/codechicken/nei/ItemList.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ 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;
}

if (item.hasDisplayName()) {
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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -170,7 +172,8 @@ public static boolean itemMatchesAll(ItemStack item, List<ItemFilter> 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);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/codechicken/nei/ItemQuantityField.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/codechicken/nei/ItemStackSet.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -29,7 +27,7 @@ public void add(ItemStack item) {
put(item, item);
}

public ItemStackSet addAll(List<ItemStack> items) {
public ItemStackSet addAll(Iterable<ItemStack> items) {
for (ItemStack item : items) add(item);
return this;
}
Expand Down
11 changes: 1 addition & 10 deletions src/main/java/codechicken/nei/NEIClientUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -512,16 +510,9 @@ public static void reportErrorBuffered(Throwable e, Set<String> 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<String> buffer, ItemStack cause) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/codechicken/nei/SearchField.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/codechicken/nei/config/preset/GuiPresetList.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/codechicken/nei/config/preset/LeftPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> handleTooltip(GuiContainer gui, int mousex, int mousey, List<String> currenttip);
default List<String> handleTooltip(GuiContainer gui, int mousex, int mousey, List<String> currenttip) {
return currenttip;
}

/**
* Use this for modifying the multiline display name of an item which may not necessarily be under the mouse.
Expand All @@ -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<String> handleItemDisplayName(GuiContainer gui, ItemStack itemstack, List<String> currenttip);
default List<String> handleItemDisplayName(GuiContainer gui, ItemStack itemstack, List<String> currenttip) {
return currenttip;
}

/**
* Use this for modifying the tooltips of items that are under the mouse. GuiContainerManager.shouldShowTooltip is
Expand All @@ -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<String> handleItemTooltip(GuiContainer gui, ItemStack itemstack, int mousex, int mousey,
List<String> currenttip);
default List<String> handleItemTooltip(GuiContainer gui, ItemStack itemstack, int mousex, int mousey,
List<String> currenttip) {
return currenttip;
}

/**
* Use this to specify a list of hotkeys that will work when hovering over an element that is under the mouse
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/codechicken/nei/recipe/GuiRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public void execute() {
guiRecipe.changePage(0);
} else {
final IRecipeFilter filter = new ItemRecipeFilter(GuiRecipe.searchField.getFilter());
ArrayList<Integer> filtered = searchHandler.getSearchResult(filter);
List<Integer> filtered = searchHandler.getSearchResult(filter);

if (filtered == null) {
stop();
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/codechicken/nei/recipe/SearchRecipeHandler.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,9 +15,9 @@ class SearchRecipeHandler<H extends IRecipeHandler> {

public H original;

private ArrayList<Integer> filteredRecipes;
private List<Integer> filteredRecipes;

private ArrayList<Integer> searchRecipes;
private List<Integer> searchRecipes;

public SearchRecipeHandler(H handler) {
this.original = handler;
Expand Down Expand Up @@ -52,7 +53,7 @@ private static boolean searchingAvailable(IRecipeHandler handler) {
return handler instanceof TemplateRecipeHandler;
}

public static int findFirst(IRecipeHandler handler, Predicate<Integer> predicate) {
public static int findFirst(IRecipeHandler handler, IntPredicate predicate) {
final IRecipeFilter filter = searchingAvailable(handler) ? GuiRecipe.getRecipeListFilter() : null;
int refIndex = -1;

Expand All @@ -69,14 +70,14 @@ public static int findFirst(IRecipeHandler handler, Predicate<Integer> predicate
return -1;
}

public ArrayList<Integer> getSearchResult(IRecipeFilter filter) {
public List<Integer> getSearchResult(IRecipeFilter filter) {

if (filteredRecipes.isEmpty() || !this.searchingAvailable()) {
return null;
}

ArrayList<Integer> filtered = null;
final ArrayList<Integer> recipes = IntStream.range(0, filteredRecipes.size()).boxed()
List<Integer> filtered = null;
final List<Integer> recipes = IntStream.range(0, filteredRecipes.size()).boxed()
.collect(Collectors.toCollection(ArrayList::new));

try {
Expand All @@ -95,7 +96,7 @@ public ArrayList<Integer> getSearchResult(IRecipeFilter filter) {
return filtered;
}

public void setSearchIndices(ArrayList<Integer> searchRecipes) {
public void setSearchIndices(List<Integer> searchRecipes) {
this.searchRecipes = searchRecipes;
}

Expand Down

0 comments on commit a0e1683

Please sign in to comment.