fix bookmarks (#307)

Co-authored-by: slprime <[email protected]>
This commit is contained in:
slprimeandslprime authored and GitHub committed 2022-10-13 10:06:08 +02:00
1 parent 14aa3728ca
commit 7c2fb2df5f
7 files changed
+119 -308

No files matched your search

@@ -1,76 +0,0 @@
package codechicken.nei;
import static codechicken.nei.ItemsGrid.SLOT_SIZE;
import codechicken.nei.guihook.GuiContainerManager;
import net.minecraft.item.ItemStack;
import org.lwjgl.opengl.GL11;
public class AnimatedItemStack {
private static final int steep = 10;
private static final float scaleSpeed = 0.1f;
private int lastPosX = -1;
private int lastPosY = -1;
private float currentScale = 0;
private final boolean doMoveAnim;
private final boolean doPopAnim;
public ItemStack itemStack;
public AnimatedItemStack(ItemStack itemStack, boolean doMoveAnim, boolean doPopAnim) {
this.itemStack = itemStack;
this.doMoveAnim = doMoveAnim;
this.doPopAnim = doPopAnim;
}
public void drawItem(int x, int y) {
drawItem(x, y, false, null, false);
}
public void drawItem(int x, int y, boolean smallAmount, String stackSize, boolean blockMoveAnimOnce) {
if (NEIClientConfig.areBookmarksAnimated()) {
if (doPopAnim && currentScale < 1) {
drawPoppingItem(x, y, smallAmount, stackSize);
return;
}
if (doMoveAnim && (lastPosX != x || lastPosY != y) && !blockMoveAnimOnce) {
drawMovingItem(x, y, smallAmount, stackSize);
return;
}
}
currentScale = 1;
lastPosX = x;
lastPosY = y;
GuiContainerManager.drawItem(x, y, itemStack, smallAmount, stackSize);
}
private void drawPoppingItem(int x, int y, boolean smallAmount, String stackSize) {
currentScale += scaleSpeed;
GL11.glScalef(currentScale, currentScale, currentScale); // push & pop matrix crashes the game
GuiContainerManager.drawItem(
(int) ((x + (SLOT_SIZE / 2 - currentScale * SLOT_SIZE / 2)) / currentScale),
(int) ((y + (SLOT_SIZE / 2 - currentScale * SLOT_SIZE / 2)) / currentScale),
itemStack,
smallAmount,
stackSize);
GL11.glScalef(1 / currentScale, 1 / currentScale, 1 / currentScale);
}
private void drawMovingItem(int x, int y, boolean smallAmount, String stackSize) {
if (lastPosX != -1 && lastPosY != -1) {
int xDiff = x - lastPosX;
int yDiff = y - lastPosY;
int moveX = xDiff / steep + ((xDiff % steep == 0) ? 0 : (xDiff > 0 ? 1 : -1));
int moveY = yDiff / steep + ((yDiff % steep == 0) ? 0 : (yDiff > 0 ? 1 : -1));
GuiContainerManager.drawItem(lastPosX + moveX, lastPosY + moveY, itemStack, smallAmount, stackSize);
lastPosX = lastPosX + moveX;
lastPosY = lastPosY + moveY;
} else {
lastPosX = x;
lastPosY = y;
GuiContainerManager.drawItem(x, y, itemStack, smallAmount, stackSize);
}
}
}
+67 -174
View File
@@ -1,7 +1,8 @@
package codechicken.nei;
import static codechicken.lib.gui.GuiDraw.*;
import static codechicken.nei.NEIClientUtils.*;
import static codechicken.lib.gui.GuiDraw.drawRect;
import static codechicken.lib.gui.GuiDraw.getMousePosition;
import static codechicken.nei.NEIClientUtils.translate;
import codechicken.core.CommonUtils;
import codechicken.lib.vec.Rectangle4i;
@@ -26,10 +27,10 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import javax.annotation.Nullable;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import org.apache.commons.io.IOUtils;
@@ -49,9 +50,6 @@ public class BookmarkPanel extends PanelWidget {
protected List<BookmarkGrid> namespaces = new ArrayList<>();
protected int activeNamespaceIndex = 0;
private BookmarkStackMeta draggedStackMeta;
private int draggedStackOriginIndex = -1;
protected static class BookmarkStackMeta {
public int factor;
public BookmarkRecipeId recipeId;
@@ -73,8 +71,11 @@ public class BookmarkPanel extends PanelWidget {
protected static class BookmarkGrid extends ItemsGrid {
protected static final float SCALE_SPEED = 0.1f;
protected List<List<Integer>> gridMask;
protected List<BookmarkStackMeta> metadata = new ArrayList<>();
protected WeakHashMap<ItemStack, Float> animation = new WeakHashMap<>();
protected BookmarkViewMode viewMode = BookmarkViewMode.DEFAULT;
protected boolean[] todoSpaces;
@@ -222,24 +223,23 @@ public class BookmarkPanel extends PanelWidget {
return metadata.get(idx);
}
public void addItem(ItemStack stackA, BookmarkStackMeta meta, boolean doPopAnim) {
addRealItem(stackA, true, doPopAnim);
metadata.add(meta);
onGridChanged();
public void addItem(ItemStack stackA, BookmarkStackMeta meta) {
addItem(stackA, meta, true);
}
public void addItem(ItemStack stackA, BookmarkStackMeta meta, int index) {
if (index == -1) {
addItem(stackA, meta, true);
return;
public void addItem(ItemStack stackA, BookmarkStackMeta meta, boolean animate) {
realItems.add(stackA);
metadata.add(meta);
if (animate && !NEIClientConfig.shouldCacheItemRendering() && NEIClientConfig.areBookmarksAnimated()) {
animation.put(stackA, 0f);
}
addRealItem(index, stackA, true, true);
metadata.add(index, meta);
onGridChanged();
}
public void replaceItem(int idx, ItemStack stack) {
setRealItem(idx, stack, true, true);
realItems.set(idx, stack);
onGridChanged();
}
@@ -266,6 +266,7 @@ public class BookmarkPanel extends PanelWidget {
}
protected boolean removeItem(int idx) {
animation.remove(getItem(idx));
realItems.remove(idx);
metadata.remove(idx);
onGridChanged();
@@ -330,22 +331,36 @@ public class BookmarkPanel extends PanelWidget {
|| LayoutManager.bookmarkPanel.sortedStackIndex != idx) {
final ItemStack stack = getItem(idx);
final BookmarkStackMeta meta = getMetadata(idx);
final String stackSize = meta.factor < 0 || meta.fluidDisplay ? "" : String.valueOf(stack.stackSize);
realItems
.get(idx)
.drawItem(
rect.x + 1,
rect.y + 1,
true,
meta.factor < 0 || meta.fluidDisplay ? "" : String.valueOf(stack.stackSize),
draggedStack == null);
if (animation.containsKey(stack) && animation.get(stack) < 1) {
final float currentScale = animation.get(stack) + SCALE_SPEED;
animation.put(stack, currentScale);
drawPoppingItem(rect, stack, stackSize, currentScale);
} else {
if (meta.recipeId != null && !meta.ingredient && NEIClientConfig.showRecipeMarker()) {
drawRecipeMarker(rect.x, rect.y, GuiContainerManager.getFontRenderer(stack));
GuiContainerManager.drawItem(rect.x + 1, rect.y + 1, stack, true, stackSize);
if (meta.recipeId != null && !meta.ingredient && NEIClientConfig.showRecipeMarker()) {
drawRecipeMarker(rect.x, rect.y, GuiContainerManager.getFontRenderer(stack));
}
}
}
}
protected void drawPoppingItem(Rectangle4i rect, ItemStack stack, String stackSize, float currentScale) {
GL11.glScalef(currentScale, currentScale, currentScale); // push & pop matrix crashes the game
GuiContainerManager.drawItem(
Math.round((rect.x + 1 + (SLOT_SIZE / 2 - currentScale * SLOT_SIZE / 2)) / currentScale),
Math.round((rect.y + 1 + (SLOT_SIZE / 2 - currentScale * SLOT_SIZE / 2)) / currentScale),
stack,
true,
stackSize);
GL11.glScalef(1 / currentScale, 1 / currentScale, 1 / currentScale);
}
protected void drawRecipeMarker(int offsetX, int offsetY, FontRenderer fontRenderer) {
final float scaleFactor = fontRenderer.getUnicodeFlag() ? 0.85f : 0.5f;
final float inverseScaleFactor = 1.0f / scaleFactor;
@@ -422,26 +437,12 @@ public class BookmarkPanel extends PanelWidget {
addOrRemoveItem(stackA, null, null, false, false);
}
public void addOrRemoveItem(ItemStack stackA, int index) {
addOrRemoveItem(stackA, null, null, false, false, index);
}
public void addOrRemoveItem(
ItemStack stackover,
final String handlerName,
final List<PositionedStack> ingredients,
boolean saveIngredients,
boolean saveStackSize) {
addOrRemoveItem(stackover, handlerName, ingredients, saveIngredients, saveStackSize, -1);
}
public void addOrRemoveItem(
ItemStack stackover,
final String handlerName,
final List<PositionedStack> ingredients,
boolean saveIngredients,
boolean saveStackSize,
int addIndex) {
loadBookmarksIfNeeded();
final Point mousePos = getMousePosition();
@@ -491,8 +492,7 @@ public class BookmarkPanel extends PanelWidget {
recipeId != null ? recipeId.copy() : null,
(saveStackSize ? 1 : -1) * count,
true,
nbTag.hasKey("gtFluidName")),
addIndex);
nbTag.hasKey("gtFluidName")));
}
}
@@ -502,8 +502,7 @@ public class BookmarkPanel extends PanelWidget {
recipeId,
(saveStackSize ? 1 : -1) * nbTagA.getInteger("Count"),
false,
nbTagA.hasKey("gtFluidName")),
addIndex);
nbTagA.hasKey("gtFluidName")));
}
}
@@ -895,8 +894,8 @@ public class BookmarkPanel extends PanelWidget {
@Override
public void mouseDragged(int mousex, int mousey, int button, long heldTime) {
// legacy sort
if (button == 0 && NEIClientUtils.shiftKey() && mouseDownSlot >= 0 && draggedStack == null) {
if (button == 0 && NEIClientUtils.shiftKey() && mouseDownSlot >= 0) {
ItemPanelSlot mouseOverSlot = getSlotMouseOver(mousex, mousey);
if (sortedStackIndex == -1) {
@@ -915,17 +914,12 @@ public class BookmarkPanel extends PanelWidget {
final BookmarkGrid hoverGrid = namespaces.get(activeNamespaceIndex);
final BookmarkGrid sortedGrid = namespaces.get(sortedNamespaceIndex);
if (mouseOverSlot == null) {
mouseOverSlot =
getNextSlot(mousex, mousey, hoverGrid.getViewMode() == BookmarkViewMode.TODO_LIST);
}
if (mouseOverSlot != null) {
if (mouseOverSlot != null || getNextSlot(new Point(mousex, mousey)) >= 0) {
final ItemStack stack = sortedGrid.getItem(sortedStackIndex);
final BookmarkStackMeta meta = sortedGrid.getMetadata(sortedStackIndex);
sortedGrid.removeItem(sortedStackIndex);
hoverGrid.addItem(stack, meta, true);
hoverGrid.addItem(stack, meta, false);
sortedNamespaceIndex = activeNamespaceIndex;
sortedStackIndex = hoverGrid.indexOf(stack, meta.recipeId);
@@ -967,106 +961,33 @@ public class BookmarkPanel extends PanelWidget {
return;
}
if (mouseDownSlot >= 0
&& draggedStack == null
&& NEIClientUtils.getHeldItem() == null
&& NEIClientConfig.hasSMPCounterPart()) {
ItemPanelSlot mouseOverSlot = getSlotMouseOver(mousex, mousey);
if (mouseOverSlot == null || mouseOverSlot.slotIndex != mouseDownSlot || heldTime > 500) {
draggedStack = getDraggedStackWithQuantity(mouseDownSlot);
draggedStackMeta = ((BookmarkGrid) grid).getMetadata(mouseDownSlot);
draggedStackOriginIndex = mouseDownSlot;
((BookmarkGrid) grid).removeItem(mouseDownSlot);
saveBookmarks();
fixCountOfNamespaces();
mouseDownSlot = -1;
}
}
super.mouseDragged(mousex, mousey, button, heldTime);
}
@Override
public void update() {
int mouseX = getMousePosition().x;
int mouseY = getMousePosition().y;
if (draggedStack != null) {
if (!contains(mouseX, mouseY)) {
if (sortedStackIndex != -1 && sortedStackIndex < grid.realItems.size()) {
((BookmarkGrid) grid).removeItem(sortedStackIndex);
sortedStackIndex = -1;
}
} else {
ItemPanelSlot mouseOverSlot = getSlotMouseOver(mouseX, mouseY);
if (sortedStackIndex == -1) {
sortedNamespaceIndex = activeNamespaceIndex;
if (mouseOverSlot != null) {
sortedStackIndex = mouseOverSlot.slotIndex;
} else {
sortedStackIndex = grid.size();
}
// dummy item
addOrRemoveItem(
new ItemStack(Items.paper).setStackDisplayName("this is a dummy item"), sortedStackIndex);
} else if (mouseOverSlot != null && mouseOverSlot.slotIndex != sortedStackIndex) {
final BookmarkGrid sortedGrid = namespaces.get(sortedNamespaceIndex);
if (sortedStackIndex >= grid.size()) sortedStackIndex = grid.size() - 1;
if (sortedGrid.getViewMode() == BookmarkViewMode.DEFAULT) {
sortedGrid.moveItem(sortedStackIndex, mouseOverSlot.slotIndex);
sortedStackIndex = mouseOverSlot.slotIndex;
} else if (sortedGrid.getViewMode() == BookmarkViewMode.TODO_LIST) {
final ItemStack stack = sortedGrid.getItem(sortedStackIndex);
final BookmarkStackMeta meta = sortedGrid.getMetadata(sortedStackIndex);
final boolean isIngredient = sortedStackIndex > 0
&& meta.recipeId != null
&& meta.ingredient
&& meta.recipeId.equals(sortedGrid.getRecipeId(sortedStackIndex - 1));
if (!isIngredient) {
mouseOverSlot = getSlotMouseOver(grid.marginLeft + grid.paddingLeft, mouseY);
if (mouseOverSlot != null && sortedStackIndex != mouseOverSlot.slotIndex) {
sortedGrid.moveItem(sortedStackIndex, mouseOverSlot.slotIndex);
sortedStackIndex = sortedGrid.indexOf(stack, meta.recipeId);
}
} else if (meta.recipeId != null
&& sortedGrid.getMetadata(mouseOverSlot.slotIndex).ingredient
&& meta.recipeId.equals(sortedGrid.getRecipeId(mouseOverSlot.slotIndex))) {
sortedGrid.moveItem(sortedStackIndex, mouseOverSlot.slotIndex);
sortedStackIndex = sortedGrid.indexOf(stack, meta.recipeId);
}
}
}
}
}
super.update();
}
private ItemPanelSlot getNextSlot(int mousex, int mousey, boolean line) {
private int getNextSlot(final Point point) {
final List<Integer> mask = grid.getMask();
final int columns = grid.getColumns();
final int perPage = grid.getRows() * columns;
final boolean line = ((BookmarkGrid) grid).getViewMode() == BookmarkViewMode.TODO_LIST;
for (int i = mask.size(); i < perPage; i++) {
if (!grid.isInvalidSlot(i) && (!line || (i % columns) == 0)) {
if (grid.getSlotRect(i).contains(mousex, mousey)) {
return new ItemPanelSlot(grid.size() - 1, null);
if (point == null || grid.getSlotRect(i).contains(point.x, point.y)) {
return i;
}
return null;
return -1;
}
}
return null;
return -1;
}
@Override
public void postDraw(int mousex, int mousey) {
// legacy sort
if (sortedStackIndex != -1 && shiftKey() && draggedStack == null) {
if (sortedStackIndex != -1) {
GuiContainerManager.drawItems.zLevel += 100;
GuiContainerManager.drawItem(
mousex - 8,
@@ -1079,6 +1000,15 @@ public class BookmarkPanel extends PanelWidget {
GuiContainerManager.drawItems.zLevel -= 100;
}
if (ItemPanels.itemPanel.draggedStack != null && this.contains(mousex, mousey)) {
final int idx = getNextSlot(null);
if (idx >= 0) {
Rectangle4i rect = grid.getSlotRect(idx);
drawRect(rect.x, rect.y, rect.w, rect.h, 0xee555555); // highlight
}
}
super.postDraw(mousex, mousey);
}
@@ -1102,39 +1032,6 @@ public class BookmarkPanel extends PanelWidget {
}
}
@Override
protected boolean handleDraggedClick(int mouseX, int mouseY, int button) {
if (contains(mouseX, mouseY)) {
((BookmarkGrid) grid).removeItem(sortedStackIndex);
if (draggedStackMeta != null) {
((BookmarkGrid) grid).addItem(draggedStack, draggedStackMeta, sortedStackIndex);
fixCountOfNamespaces();
saveBookmarks();
} else addOrRemoveItem(draggedStack, sortedStackIndex);
sortedStackIndex = -1;
draggedStack = null;
draggedStackMeta = null;
draggedStackOriginIndex = -1;
return true;
}
return false;
}
public void restoreBookmark() {
if (draggedStack != null && draggedStackOriginIndex != -1) {
if (sortedStackIndex != -1) ((BookmarkGrid) grid).removeItem(sortedStackIndex);
if (draggedStackMeta != null) {
((BookmarkGrid) grid).addItem(draggedStack, draggedStackMeta, draggedStackOriginIndex);
fixCountOfNamespaces();
saveBookmarks();
} else addOrRemoveItem(draggedStack, draggedStackOriginIndex);
sortedStackIndex = -1;
draggedStack = null;
draggedStackMeta = null;
draggedStackOriginIndex = -1;
}
}
@Override
public List<String> handleTooltip(int mx, int my, List<String> tooltip) {
@@ -1148,7 +1045,8 @@ public class BookmarkPanel extends PanelWidget {
@Override
public void mouseUp(int mousex, int mousey, int button) {
if (sortedStackIndex != -1 && draggedStack == null) {
if (sortedStackIndex != -1) {
draggedStack = null;
sortedNamespaceIndex = -1;
sortedStackIndex = -1;
mouseDownSlot = -1;
@@ -1227,9 +1125,4 @@ public class BookmarkPanel extends PanelWidget {
BGrid.replaceItem(slotIndex, StackInfo.loadFromNBT(nbTag));
}
}
public void deleteDraggedMeta() {
draggedStackMeta = null;
draggedStackOriginIndex = -1;
}
}
+1 -2
View File
@@ -57,8 +57,7 @@ public class ItemPanel extends PanelWidget {
public void refresh(GuiContainer gui) {
if (newItems != null) {
realItems.clear();
addRealItems(newItems, false, false);
realItems = newItems;
newItems = null;
onGridChanged();
}
+4 -22
View File
@@ -9,9 +9,7 @@ import codechicken.nei.guihook.GuiContainerManager;
import codechicken.nei.recipe.StackInfo;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
@@ -33,7 +31,7 @@ public class ItemsGrid {
protected int paddingLeft;
protected ArrayList<AnimatedItemStack> realItems = new ArrayList<>();
protected ArrayList<ItemStack> realItems = new ArrayList<>();
protected int page;
protected int perPage;
@@ -51,27 +49,11 @@ public class ItemsGrid {
protected boolean refreshBuffer = true;
public ArrayList<ItemStack> getItems() {
return realItems.stream().map(e -> e.itemStack).collect(Collectors.toCollection(ArrayList::new));
return realItems;
}
public ItemStack getItem(int idx) {
return realItems.get(idx).itemStack;
}
protected void addRealItems(Collection<ItemStack> itemStack, boolean doMoveAnim, boolean doPopAnim) {
itemStack.forEach(e -> addRealItem(e, doMoveAnim, doPopAnim));
}
protected void addRealItem(ItemStack itemStack, boolean doMoveAnim, boolean doPopAnim) {
realItems.add(new AnimatedItemStack(itemStack, doMoveAnim, doPopAnim));
}
protected void addRealItem(int index, ItemStack itemStack, boolean doMoveAnim, boolean doPopAnim) {
realItems.add(index, new AnimatedItemStack(itemStack, doMoveAnim, doPopAnim));
}
protected void setRealItem(int index, ItemStack itemStack, boolean doMoveAnim, boolean doPopAnim) {
realItems.set(index, new AnimatedItemStack(itemStack, doMoveAnim, doPopAnim));
return realItems.get(idx);
}
public int size() {
@@ -335,7 +317,7 @@ public class ItemsGrid {
}
protected void drawItem(Rectangle4i rect, int idx) {
realItems.get(idx).drawItem(rect.x + 1, rect.y + 1);
GuiContainerManager.drawItem(rect.x + 1, rect.y + 1, getItem(idx));
}
public ItemPanelSlot getSlotMouseOver(int mousex, int mousey) {
+36 -24
View File
@@ -15,7 +15,7 @@ import net.minecraft.item.ItemStack;
public abstract class PanelWidget extends Widget {
protected static final int PADDING = 2;
public static ItemStack draggedStack;
public ItemStack draggedStack;
public int mouseDownSlot = -1;
public Button pagePrev;
@@ -240,30 +240,21 @@ public abstract class PanelWidget extends Widget {
@Override
public boolean handleClickExt(int mouseX, int mouseY, int button) {
if (draggedStack != null) {
boolean succeed = ItemPanels.bookmarkPanel.handleDraggedClick(mouseX, mouseY, button)
|| ItemPanels.itemPanel.handleDraggedClick(mouseX, mouseY, button);
if (succeed) return true;
if (handleGUIContainerClick(draggedStack, mouseX, mouseY, button)) {
if (draggedStack.stackSize == 0) {
ItemPanels.bookmarkPanel.restoreBookmark();
draggedStack = null;
}
return true;
}
final GuiContainer gui = NEIClientUtils.getGuiContainer();
if (mouseX < gui.guiLeft
|| mouseY < gui.guiTop
|| mouseX >= gui.guiLeft + gui.xSize
|| mouseY >= gui.guiTop + gui.ySize) {
ItemPanels.bookmarkPanel.deleteDraggedMeta();
draggedStack = null;
return true;
}
if (ItemPanels.itemPanel.draggedStack != null && ItemPanels.bookmarkPanel.contains(mouseX, mouseY)) {
ItemPanels.bookmarkPanel.addOrRemoveItem(ItemPanels.itemPanel.draggedStack, null, null, false, true);
ItemPanels.itemPanel.draggedStack = null;
return true;
}
if (ItemPanels.itemPanel.draggedStack != null) {
return ItemPanels.itemPanel.handleDraggedClick(mouseX, mouseY, button);
}
if (ItemPanels.bookmarkPanel.draggedStack != null) {
return ItemPanels.bookmarkPanel.handleDraggedClick(mouseX, mouseY, button);
}
if (NEIClientUtils.getHeldItem() != null) {
final ItemStack draggedStack = NEIClientUtils.getHeldItem().copy();
return handleGUIContainerClick(draggedStack, mouseX, mouseY, button);
@@ -273,7 +264,28 @@ public abstract class PanelWidget extends Widget {
}
protected boolean handleDraggedClick(int mouseX, int mouseY, int button) {
return false;
if (draggedStack == null) {
return false;
}
if (handleGUIContainerClick(draggedStack, mouseX, mouseY, button)) {
if (draggedStack.stackSize == 0) {
draggedStack = null;
}
return true;
}
final GuiContainer gui = NEIClientUtils.getGuiContainer();
if (mouseX < gui.guiLeft
|| mouseY < gui.guiTop
|| mouseX >= gui.guiLeft + gui.xSize
|| mouseY >= gui.guiTop + gui.ySize) {
draggedStack = null;
}
return true;
}
protected boolean handleGUIContainerClick(final ItemStack draggedStack, int mouseX, int mouseY, int button) {
@@ -3,13 +3,18 @@ package codechicken.nei.api;
import codechicken.nei.VisiblityData;
import java.util.Collections;
import java.util.List;
import java.util.regex.Pattern;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
/**
* Lets you just override those things you want to
*/
public class INEIGuiAdapter implements INEIGuiHandler {
static final Pattern SPECIAL_REGEX_CHARS = Pattern.compile("[{}()\\[\\].+*?^$\\\\|]");
@Override
public VisiblityData modifyVisiblity(GuiContainer gui, VisiblityData currentVisibility) {
return currentVisibility;
@@ -34,4 +39,10 @@ public class INEIGuiAdapter implements INEIGuiHandler {
public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h) {
return false;
}
protected String formattingText(String displayName) {
return SPECIAL_REGEX_CHARS
.matcher(EnumChatFormatting.getTextWithoutFormattingCodes(displayName))
.replaceAll("\\\\$0");
}
}
@@ -3,16 +3,12 @@ package codechicken.nei.recipe;
import static codechicken.nei.LayoutManager.searchField;
import codechicken.nei.api.INEIGuiAdapter;
import java.util.regex.Pattern;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.fluids.FluidStack;
public class SearchInputDropHandler extends INEIGuiAdapter {
protected static final Pattern SPECIAL_REGEX_CHARS = Pattern.compile("[{}()\\[\\].+*?^$\\\\|]");
@Override
public boolean handleDragNDrop(GuiContainer gui, int mouseX, int mouseY, ItemStack draggedStack, int button) {
@@ -30,10 +26,4 @@ public class SearchInputDropHandler extends INEIGuiAdapter {
return false;
}
protected String formattingText(String displayName) {
return SPECIAL_REGEX_CHARS
.matcher(EnumChatFormatting.getTextWithoutFormattingCodes(displayName))
.replaceAll("\\\\$0");
}
}