mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-20 12:20:00 +00:00
Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e186c2a1b2 | ||
|
|
1ab46be684 | ||
|
|
57fd9ea582 | ||
|
|
b1a34c761b | ||
|
|
501fa70037 | ||
|
|
cc9715d9f2 | ||
|
|
be253a00d2 | ||
|
|
5dde3b2e2f | ||
|
|
8da541460f |
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ pluginManagement {
|
||||
}
|
||||
|
||||
plugins {
|
||||
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.22'
|
||||
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.23'
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -14,11 +14,13 @@ import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -98,8 +100,7 @@ public class BookmarkPanel extends PanelWidget {
|
||||
ItemStackMetadata meta = topItemIndex >= 0 ? BGrid.metadata.get(topItemIndex) : null;
|
||||
|
||||
if (meta != null && meta.recipeId != null) {
|
||||
while (topItemIndex > 0 && meta.groupId == BGrid.metadata.get(topItemIndex - 1).groupId
|
||||
&& meta.recipeId.equals(BGrid.metadata.get(topItemIndex - 1).recipeId)) {
|
||||
while (topItemIndex > 0 && meta.equalsRecipe(BGrid.metadata.get(topItemIndex - 1))) {
|
||||
topItemIndex--;
|
||||
}
|
||||
|
||||
@@ -118,8 +119,7 @@ public class BookmarkPanel extends PanelWidget {
|
||||
if (meta != null && meta.recipeId != null) {
|
||||
int size = BGrid.size();
|
||||
|
||||
while (bottomItemIndex < size - 1 && meta.groupId == BGrid.metadata.get(bottomItemIndex + 1).groupId
|
||||
&& meta.recipeId.equals(BGrid.metadata.get(bottomItemIndex + 1).recipeId)) {
|
||||
while (bottomItemIndex < size - 1 && meta.equalsRecipe(BGrid.metadata.get(bottomItemIndex + 1))) {
|
||||
bottomItemIndex++;
|
||||
}
|
||||
|
||||
@@ -148,9 +148,21 @@ public class BookmarkPanel extends PanelWidget {
|
||||
this.fluidDisplay = fluidDisplay;
|
||||
}
|
||||
|
||||
public ItemStackMetadata(BookmarkRecipeId recipeId, NBTTagCompound nbTag, boolean ingredient, Integer groupId) {
|
||||
this(recipeId, nbTag.getInteger("Count"), ingredient, groupId, nbTag.hasKey("gtFluidName"));
|
||||
}
|
||||
|
||||
public ItemStackMetadata copy() {
|
||||
return new ItemStackMetadata(this.recipeId, this.factor, this.ingredient, this.groupId, this.fluidDisplay);
|
||||
}
|
||||
|
||||
public boolean equalsRecipe(ItemStackMetadata meta) {
|
||||
return equalsRecipe(meta.recipeId, meta.groupId);
|
||||
}
|
||||
|
||||
public boolean equalsRecipe(BookmarkRecipeId recipeId, int groupId) {
|
||||
return groupId == this.groupId && recipeId != null && recipeId.equals(this.recipeId);
|
||||
}
|
||||
}
|
||||
|
||||
public static enum BookmarkViewMode {
|
||||
@@ -163,6 +175,26 @@ public class BookmarkPanel extends PanelWidget {
|
||||
LOADED
|
||||
}
|
||||
|
||||
public static class BookmarkRecipe {
|
||||
|
||||
public String handlerName = "";
|
||||
public List<ItemStack> result = new ArrayList<>();
|
||||
public List<ItemStack> ingredients = new ArrayList<>();
|
||||
|
||||
public BookmarkRecipe(ItemStack... result) {
|
||||
this.result.addAll(Arrays.asList(result));
|
||||
}
|
||||
|
||||
public BookmarkRecipeId getRecipeId() {
|
||||
|
||||
if (!handlerName.isEmpty() && !ingredients.isEmpty()) {
|
||||
return new BookmarkRecipeId(handlerName, ingredients);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected static class BookmarkGroup {
|
||||
|
||||
public BookmarkCraftingChain crafting = null;
|
||||
@@ -607,8 +639,7 @@ public class BookmarkPanel extends PanelWidget {
|
||||
final ArrayList<Integer> items = new ArrayList<>();
|
||||
|
||||
for (int index = idx; index < size; index++) {
|
||||
if (this.metadata.get(index).groupId == groupId
|
||||
&& meta.recipeId.equals(this.metadata.get(index).recipeId)) {
|
||||
if (meta.equalsRecipe(this.metadata.get(index))) {
|
||||
sortingRank.put(index, (this.metadata.get(index).ingredient ? 1 : -1) * dir);
|
||||
items.add(index);
|
||||
}
|
||||
@@ -756,7 +787,7 @@ public class BookmarkPanel extends PanelWidget {
|
||||
final ItemStackMetadata meta = getMetadata(idx);
|
||||
if (meta.groupId == groupId
|
||||
&& (recipeId == null && meta.recipeId == null
|
||||
|| recipeId != null && meta.recipeId != null && recipeId.equals(meta.recipeId))
|
||||
|| recipeId != null && recipeId.equals(meta.recipeId))
|
||||
&& StackInfo.equalItemAndNBT(stackA, getItem(idx), true)) {
|
||||
return idx;
|
||||
}
|
||||
@@ -797,9 +828,15 @@ public class BookmarkPanel extends PanelWidget {
|
||||
}
|
||||
|
||||
protected void removeRecipe(int idx, boolean removeFullRecipe) {
|
||||
final ItemStackMetadata meta = getMetadata(idx);
|
||||
final ItemStackMetadata meta = this.metadata.get(idx);
|
||||
|
||||
if (meta.recipeId != null && (removeFullRecipe || !meta.ingredient)) {
|
||||
if (!removeFullRecipe && meta.recipeId != null && !meta.ingredient) {
|
||||
final Optional<ItemStackMetadata> result = this.metadata.stream()
|
||||
.filter(m -> m != meta && !m.ingredient && meta.equalsRecipe(m)).findAny();
|
||||
removeFullRecipe = !result.isPresent();
|
||||
}
|
||||
|
||||
if (meta.recipeId != null && removeFullRecipe) {
|
||||
removeRecipe(meta.recipeId, meta.groupId);
|
||||
} else {
|
||||
removeItem(idx);
|
||||
@@ -807,12 +844,9 @@ public class BookmarkPanel extends PanelWidget {
|
||||
}
|
||||
|
||||
protected void removeRecipe(BookmarkRecipeId recipeIdA, int groupId) {
|
||||
BookmarkRecipeId recipeIdB;
|
||||
|
||||
for (int slotIndex = metadata.size() - 1; slotIndex >= 0; slotIndex--) {
|
||||
recipeIdB = metadata.get(slotIndex).recipeId;
|
||||
|
||||
if (recipeIdB != null && metadata.get(slotIndex).groupId == groupId && recipeIdB.equals(recipeIdA)) {
|
||||
if (metadata.get(slotIndex).equalsRecipe(recipeIdA, groupId)) {
|
||||
removeItem(slotIndex);
|
||||
}
|
||||
}
|
||||
@@ -889,14 +923,12 @@ public class BookmarkPanel extends PanelWidget {
|
||||
drawRect(rect.x, rect.y, rect.w, rect.h, 0x9966CCFF); // exports
|
||||
}
|
||||
|
||||
} else if (focus != null && meta.recipeId != null
|
||||
&& meta.groupId == getMetadata(focus.slotIndex).groupId
|
||||
&& meta.recipeId.equals(this.getRecipeId(focus.slotIndex))) {
|
||||
drawRect(rect.x, rect.y, rect.w, rect.h, meta.ingredient ? 0x6645DA75 : 0x9966CCFF); // highlight
|
||||
// recipe
|
||||
} else {
|
||||
super.beforeDrawSlot(focus, idx, rect);
|
||||
}
|
||||
} else if (focus != null && meta.equalsRecipe(getMetadata(focus.slotIndex))) {
|
||||
drawRect(rect.x, rect.y, rect.w, rect.h, meta.ingredient ? 0x6645DA75 : 0x9966CCFF); // highlight
|
||||
// recipe
|
||||
} else {
|
||||
super.beforeDrawSlot(focus, idx, rect);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -920,11 +952,9 @@ public class BookmarkPanel extends PanelWidget {
|
||||
if (groupMeta.crafting != null && meta.groupId == this.focusedGroupId
|
||||
&& groupMeta.crafting.multiplier.containsKey(stack)) {
|
||||
multiplier = this.groups.get(meta.groupId).crafting.multiplier.get(stack);
|
||||
} else if (focus != null && meta.factor > 0
|
||||
&& meta.groupId == this.metadata.get(focus.slotIndex).groupId
|
||||
&& meta.recipeId.equals(this.metadata.get(focus.slotIndex).recipeId)) {
|
||||
multiplier = StackInfo.itemStackToNBT(stack).getInteger("Count") / meta.factor;
|
||||
}
|
||||
} else if (focus != null && meta.factor > 0 && meta.equalsRecipe(getMetadata(focus.slotIndex))) {
|
||||
multiplier = StackInfo.itemStackToNBT(stack).getInteger("Count") / meta.factor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1219,7 +1249,7 @@ public class BookmarkPanel extends PanelWidget {
|
||||
addItem(itemStack, true);
|
||||
}
|
||||
|
||||
public void addItem(ItemStack itemStack, boolean saveStackSize) {
|
||||
public void addItem(ItemStack itemStack, boolean saveSize) {
|
||||
final BookmarkGrid BGrid = (BookmarkGrid) grid;
|
||||
int idx = BGrid.indexOf(itemStack, true);
|
||||
|
||||
@@ -1227,7 +1257,7 @@ public class BookmarkPanel extends PanelWidget {
|
||||
BGrid.removeItem(idx);
|
||||
}
|
||||
|
||||
addOrRemoveItem(itemStack, null, null, false, saveStackSize);
|
||||
addOrRemoveItem(itemStack, null, null, false, saveSize);
|
||||
}
|
||||
|
||||
public void addOrRemoveItem(ItemStack stackA) {
|
||||
@@ -1235,7 +1265,7 @@ public class BookmarkPanel extends PanelWidget {
|
||||
}
|
||||
|
||||
public void addOrRemoveItem(ItemStack stackover, final String handlerName, final List<PositionedStack> ingredients,
|
||||
boolean saveIngredients, boolean saveStackSize) {
|
||||
boolean saveIngredients, boolean saveSize) {
|
||||
loadBookmarksIfNeeded();
|
||||
|
||||
final Point mousePos = getMousePosition();
|
||||
@@ -1245,61 +1275,35 @@ public class BookmarkPanel extends PanelWidget {
|
||||
if (slot != null && StackInfo.equalItemAndNBT(slot.item, stackover, true)) {
|
||||
BGrid.removeRecipe(slot.slotIndex, saveIngredients);
|
||||
} else {
|
||||
final NBTTagCompound nbTagA = StackInfo.itemStackToNBT(stackover, saveStackSize);
|
||||
final ItemStack normalizedA = StackInfo.loadFromNBT(nbTagA, saveStackSize ? nbTagA.getInteger("Count") : 0);
|
||||
BookmarkRecipeId recipeId = null;
|
||||
|
||||
if (handlerName != "" && ingredients != null) {
|
||||
if (!handlerName.isEmpty() && ingredients != null) {
|
||||
recipeId = new BookmarkRecipeId(handlerName, ingredients);
|
||||
}
|
||||
|
||||
final int idx = BGrid.indexOf(normalizedA, recipeId);
|
||||
final int idx = BGrid.indexOf(stackover, recipeId);
|
||||
|
||||
if (idx != -1) {
|
||||
BGrid.removeRecipe(idx, saveIngredients);
|
||||
} else {
|
||||
} else if (saveIngredients && !handlerName.isEmpty() && ingredients != null) {
|
||||
BookmarkRecipe recipe = new BookmarkRecipe(stackover);
|
||||
recipe.handlerName = handlerName;
|
||||
|
||||
if (saveIngredients && handlerName != "" && ingredients != null) {
|
||||
final Map<String, Integer> ingredientCount = new HashMap<>();
|
||||
final Map<String, NBTTagCompound> uniqueIngredients = new LinkedHashMap<>();
|
||||
|
||||
BGrid.removeRecipe(recipeId, BookmarkGrid.DEFAULT_GROUP_ID);
|
||||
|
||||
for (PositionedStack stack : ingredients) {
|
||||
final NBTTagCompound nbTag = StackInfo.itemStackToNBT(stack.item, saveStackSize);
|
||||
final String GUID = StackInfo.getItemStackGUID(stack.item);
|
||||
|
||||
if (!uniqueIngredients.containsKey(GUID)) {
|
||||
ingredientCount.put(GUID, nbTag.getInteger("Count"));
|
||||
uniqueIngredients.put(GUID, nbTag);
|
||||
} else {
|
||||
ingredientCount.put(GUID, ingredientCount.get(GUID) + nbTag.getInteger("Count"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (String GUID : uniqueIngredients.keySet()) {
|
||||
BGrid.addItem(
|
||||
StackInfo.loadFromNBT(
|
||||
uniqueIngredients.get(GUID),
|
||||
saveStackSize ? ingredientCount.get(GUID) : 0),
|
||||
new ItemStackMetadata(
|
||||
recipeId != null ? recipeId.copy() : null,
|
||||
ingredientCount.get(GUID),
|
||||
true,
|
||||
BookmarkGrid.DEFAULT_GROUP_ID,
|
||||
uniqueIngredients.get(GUID).hasKey("gtFluidName")));
|
||||
}
|
||||
for (PositionedStack stack : ingredients) {
|
||||
recipe.ingredients.add(stack.item);
|
||||
}
|
||||
|
||||
BGrid.addItem(
|
||||
normalizedA,
|
||||
new ItemStackMetadata(
|
||||
recipeId,
|
||||
nbTagA.getInteger("Count"),
|
||||
false,
|
||||
BookmarkGrid.DEFAULT_GROUP_ID,
|
||||
nbTagA.hasKey("gtFluidName")));
|
||||
addRecipe(recipe, saveSize);
|
||||
} else {
|
||||
final NBTTagCompound nbTag = StackInfo.itemStackToNBT(stackover);
|
||||
final ItemStack normalized = StackInfo.loadFromNBT(nbTag, saveSize ? nbTag.getInteger("Count") : 0);
|
||||
final ItemStackMetadata metadata = new ItemStackMetadata(
|
||||
recipeId,
|
||||
nbTag,
|
||||
false,
|
||||
BookmarkGrid.DEFAULT_GROUP_ID);
|
||||
|
||||
BGrid.addItem(normalized, metadata);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1307,6 +1311,92 @@ public class BookmarkPanel extends PanelWidget {
|
||||
saveBookmarks();
|
||||
}
|
||||
|
||||
public void addRecipe(BookmarkRecipe recipe, boolean saveSize) {
|
||||
addRecipe(recipe, saveSize, BookmarkGrid.DEFAULT_GROUP_ID);
|
||||
}
|
||||
|
||||
public void addRecipe(BookmarkRecipe recipe, boolean saveSize, int groupId) {
|
||||
final BookmarkGrid BGrid = (BookmarkGrid) grid;
|
||||
final BookmarkRecipeId recipeId = recipe.getRecipeId();
|
||||
|
||||
if (!BGrid.groups.containsKey(groupId)) {
|
||||
groupId = BookmarkGrid.DEFAULT_GROUP_ID;
|
||||
}
|
||||
|
||||
if (recipeId != null) {
|
||||
final Map<String, NBTTagCompound> uniqueIngredients = new LinkedHashMap<>();
|
||||
|
||||
BGrid.removeRecipe(recipeId, groupId);
|
||||
|
||||
for (ItemStack stack : recipe.ingredients) {
|
||||
final String GUID = StackInfo.getItemStackGUID(stack);
|
||||
final NBTTagCompound nbTagU = uniqueIngredients.get(GUID);
|
||||
final NBTTagCompound nbTagS = StackInfo.itemStackToNBT(stack);
|
||||
|
||||
if (nbTagU == null) {
|
||||
uniqueIngredients.put(GUID, nbTagS);
|
||||
} else {
|
||||
nbTagU.setInteger("Count", nbTagU.getInteger("Count") + nbTagS.getInteger("Count"));
|
||||
}
|
||||
}
|
||||
|
||||
for (String GUID : uniqueIngredients.keySet()) {
|
||||
final NBTTagCompound nbTag = uniqueIngredients.get(GUID);
|
||||
final ItemStack normalized = StackInfo.loadFromNBT(nbTag, saveSize ? nbTag.getInteger("Count") : 0);
|
||||
final ItemStackMetadata metadata = new ItemStackMetadata(recipeId.copy(), nbTag, true, groupId);
|
||||
|
||||
BGrid.addItem(normalized, metadata);
|
||||
}
|
||||
}
|
||||
|
||||
for (ItemStack stack : recipe.result) {
|
||||
final NBTTagCompound nbTag = StackInfo.itemStackToNBT(stack);
|
||||
final ItemStack normalized = StackInfo.loadFromNBT(nbTag, saveSize ? nbTag.getInteger("Count") : 0);
|
||||
final ItemStackMetadata metadata = new ItemStackMetadata(recipeId, nbTag, false, groupId);
|
||||
|
||||
BGrid.addItem(normalized, metadata);
|
||||
}
|
||||
|
||||
fixCountOfNamespaces();
|
||||
saveBookmarks();
|
||||
}
|
||||
|
||||
public void addBookmarkGroup(List<ItemStack> items, BookmarkViewMode viewMode) {
|
||||
List<BookmarkRecipe> recipes = new ArrayList<>();
|
||||
|
||||
for (ItemStack stack : items) {
|
||||
recipes.add(new BookmarkRecipe(stack));
|
||||
}
|
||||
|
||||
addBookmarkGroup(recipes, viewMode, false);
|
||||
}
|
||||
|
||||
public void addBookmarkGroup(List<BookmarkRecipe> recipes, BookmarkViewMode viewMode, boolean crafting) {
|
||||
if (recipes.isEmpty()) return;
|
||||
|
||||
final BookmarkGrid BGrid = (BookmarkGrid) grid;
|
||||
int groupId = BookmarkGrid.DEFAULT_GROUP_ID;
|
||||
|
||||
if (viewMode == null) {
|
||||
viewMode = BGrid.getViewMode(BookmarkGrid.DEFAULT_GROUP_ID);
|
||||
}
|
||||
|
||||
for (ItemStackMetadata meta : BGrid.metadata) {
|
||||
if (meta.groupId > groupId) {
|
||||
groupId = meta.groupId;
|
||||
}
|
||||
}
|
||||
|
||||
BGrid.groups.put(++groupId, new BookmarkGroup(viewMode, crafting));
|
||||
|
||||
for (BookmarkRecipe recipe : recipes) {
|
||||
addRecipe(recipe, true, groupId);
|
||||
}
|
||||
|
||||
fixCountOfNamespaces();
|
||||
saveBookmarks();
|
||||
}
|
||||
|
||||
public BookmarkRecipeId getBookmarkRecipeId(int slotIndex) {
|
||||
ItemStackMetadata meta = ((BookmarkGrid) grid).getMetadata(slotIndex);
|
||||
return meta.ingredient ? null : meta.recipeId;
|
||||
@@ -1774,8 +1864,7 @@ public class BookmarkPanel extends PanelWidget {
|
||||
} else {
|
||||
|
||||
for (int i = 0; i < BGrid.metadata.size(); i++) {
|
||||
if (BGrid.metadata.get(i).recipeId != null && meta.groupId == BGrid.metadata.get(i).groupId
|
||||
&& meta.recipeId.equals(BGrid.metadata.get(i).recipeId)) {
|
||||
if (meta.equalsRecipe(BGrid.getMetadata(i))) {
|
||||
items.add(BGrid.realItems.get(i));
|
||||
metadata.add(BGrid.metadata.get(i));
|
||||
}
|
||||
@@ -1822,7 +1911,7 @@ public class BookmarkPanel extends PanelWidget {
|
||||
} else if (ySlot <= 0.25) {
|
||||
|
||||
if (BGrid.getViewMode(beforeGroupId) == BookmarkViewMode.TODO_LIST
|
||||
&& !existsRecipeIdInGroupId(beforeGroupId, sortMeta.recipeId)) {
|
||||
&& !existsRecipeIdInGroupId(sortMeta.recipeId, beforeGroupId)) {
|
||||
BGrid.moveItem(this.sortableItem, mouseOverSlot.slotIndex, beforeGroupId, true);
|
||||
}
|
||||
|
||||
@@ -1832,12 +1921,12 @@ public class BookmarkPanel extends PanelWidget {
|
||||
&& (afterGroupId != BookmarkGrid.DEFAULT_GROUP_ID
|
||||
|| BGrid.getViewMode(overGroupId) == BookmarkViewMode.DEFAULT)
|
||||
&& BGrid.getViewMode(BookmarkGrid.DEFAULT_GROUP_ID) == BookmarkViewMode.TODO_LIST
|
||||
&& !existsRecipeIdInGroupId(BookmarkGrid.DEFAULT_GROUP_ID, sortMeta.recipeId)) {
|
||||
&& !existsRecipeIdInGroupId(sortMeta.recipeId, BookmarkGrid.DEFAULT_GROUP_ID)) {
|
||||
beforeGroupId = BookmarkGrid.DEFAULT_GROUP_ID;
|
||||
}
|
||||
|
||||
if (BGrid.getViewMode(beforeGroupId) == BookmarkViewMode.TODO_LIST
|
||||
&& !existsRecipeIdInGroupId(beforeGroupId, sortMeta.recipeId)) {
|
||||
&& !existsRecipeIdInGroupId(sortMeta.recipeId, beforeGroupId)) {
|
||||
BGrid.moveItem(this.sortableItem, mouseOverSlot.slotIndex, beforeGroupId, true);
|
||||
}
|
||||
|
||||
@@ -1848,12 +1937,12 @@ public class BookmarkPanel extends PanelWidget {
|
||||
|| BGrid.getViewMode(overGroupId) == BookmarkViewMode.DEFAULT)
|
||||
&& afterGroupId != BookmarkGrid.DEFAULT_GROUP_ID
|
||||
&& BGrid.getViewMode(BookmarkGrid.DEFAULT_GROUP_ID) == BookmarkViewMode.TODO_LIST
|
||||
&& !existsRecipeIdInGroupId(BookmarkGrid.DEFAULT_GROUP_ID, sortMeta.recipeId)) {
|
||||
&& !existsRecipeIdInGroupId(sortMeta.recipeId, BookmarkGrid.DEFAULT_GROUP_ID)) {
|
||||
afterGroupId = BookmarkGrid.DEFAULT_GROUP_ID;
|
||||
}
|
||||
|
||||
if (BGrid.getViewMode(afterGroupId) == BookmarkViewMode.TODO_LIST
|
||||
&& !existsRecipeIdInGroupId(afterGroupId, sortMeta.recipeId)) {
|
||||
&& !existsRecipeIdInGroupId(sortMeta.recipeId, afterGroupId)) {
|
||||
BGrid.moveItem(
|
||||
this.sortableItem,
|
||||
BGrid.getRowItemIndex(overRowIndex, false),
|
||||
@@ -1864,7 +1953,7 @@ public class BookmarkPanel extends PanelWidget {
|
||||
} else if (ySlot >= 0.75) {
|
||||
|
||||
if (BGrid.getViewMode(afterGroupId) == BookmarkViewMode.TODO_LIST
|
||||
&& !existsRecipeIdInGroupId(afterGroupId, sortMeta.recipeId)) {
|
||||
&& !existsRecipeIdInGroupId(sortMeta.recipeId, afterGroupId)) {
|
||||
BGrid.moveItem(
|
||||
this.sortableItem,
|
||||
BGrid.getRowItemIndex(overRowIndex, false),
|
||||
@@ -1909,12 +1998,11 @@ public class BookmarkPanel extends PanelWidget {
|
||||
super.mouseDragged(mousex, mousey, button, heldTime);
|
||||
}
|
||||
|
||||
private boolean existsRecipeIdInGroupId(int groupId, BookmarkRecipeId recipeId) {
|
||||
private boolean existsRecipeIdInGroupId(BookmarkRecipeId recipeId, int groupId) {
|
||||
if (recipeId == null) return false;
|
||||
|
||||
for (ItemStackMetadata meta : ((BookmarkGrid) grid).metadata) {
|
||||
if (meta.groupId == groupId && this.sortableItem.metadata.indexOf(meta) == -1
|
||||
&& recipeId.equals(meta.recipeId)) {
|
||||
if (meta.equalsRecipe(recipeId, groupId) && this.sortableItem.metadata.indexOf(meta) == -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -2077,18 +2165,12 @@ public class BookmarkPanel extends PanelWidget {
|
||||
}
|
||||
|
||||
if (NEIClientUtils.shiftKey()) {
|
||||
ItemStackMetadata ingrMeta;
|
||||
|
||||
for (int slotIndex = grid.size() - 1; slotIndex >= 0; slotIndex--) {
|
||||
ingrMeta = BGrid.getMetadata(slotIndex);
|
||||
|
||||
if (ingrMeta.recipeId != null && ingrMeta.groupId == overMeta.groupId
|
||||
&& ingrMeta.recipeId.equals(overMeta.recipeId)
|
||||
&& slotIndex != slot.slotIndex) {
|
||||
if (overMeta.equalsRecipe(BGrid.getMetadata(slotIndex)) && slotIndex != slot.slotIndex) {
|
||||
items.put(slotIndex, shiftStackSize(BGrid, slotIndex, shift, shiftMultiplier));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
items.put(slot.slotIndex, shiftStackSize(BGrid, slot.slotIndex, shift, shiftMultiplier));
|
||||
|
||||
@@ -149,6 +149,7 @@ public class ClientHandler {
|
||||
loadSerialHandlers();
|
||||
loadHeightHackHandlers();
|
||||
loadHiddenHandlers();
|
||||
loadEnableAutoFocus();
|
||||
ItemInfo.preInit();
|
||||
StackInfo.loadGuidFilters();
|
||||
}
|
||||
@@ -225,6 +226,30 @@ public class ClientHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadEnableAutoFocus() {
|
||||
File file = NEIClientConfig.enableAutoFocusFile;
|
||||
if (!file.exists()) {
|
||||
try (FileWriter writer = new FileWriter(file)) {
|
||||
NEIClientConfig.logger.info("Creating default enable auto focus list {}", file);
|
||||
URL defaultEnableAutoFocusResource = ClientHandler.class
|
||||
.getResource("/assets/nei/cfg/enableautofocus.cfg");
|
||||
if (defaultEnableAutoFocusResource != null) {
|
||||
IOUtils.copy(defaultEnableAutoFocusResource.openStream(), writer);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
NEIClientConfig.logger.error("Failed to save default enable auto focus list to file {}", file, e);
|
||||
}
|
||||
}
|
||||
|
||||
try (FileReader reader = new FileReader(file)) {
|
||||
NEIClientConfig.logger.info("Loading enable auto focus from file {}", file);
|
||||
NEIClientConfig.enableAutoFocusPrefixes = IOUtils.readLines(reader).stream()
|
||||
.filter((line) -> !line.startsWith("#")).collect(Collectors.toCollection(ArrayList::new));
|
||||
} catch (IOException e) {
|
||||
NEIClientConfig.logger.error("Failed to load enable auto focus from file {}", file, e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void load() {
|
||||
instance = new ClientHandler();
|
||||
|
||||
|
||||
@@ -12,10 +12,11 @@ import org.lwjgl.opengl.GL11;
|
||||
|
||||
import codechicken.lib.render.CCRenderState;
|
||||
import codechicken.lib.vec.Rectangle4i;
|
||||
import codechicken.nei.api.INEIAutoFocusSearchEnable;
|
||||
import codechicken.nei.api.INEIGuiHandler;
|
||||
import codechicken.nei.api.TaggedInventoryArea;
|
||||
|
||||
public class GuiExtendedCreativeInv extends GuiContainer implements INEIGuiHandler {
|
||||
public class GuiExtendedCreativeInv extends GuiContainer implements INEIGuiHandler, INEIAutoFocusSearchEnable {
|
||||
|
||||
public GuiExtendedCreativeInv(Container par1Container) {
|
||||
super(par1Container);
|
||||
|
||||
@@ -40,6 +40,7 @@ import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.gui.inventory.GuiContainerCreative;
|
||||
import net.minecraft.client.renderer.InventoryEffectRenderer;
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -52,6 +53,7 @@ import codechicken.lib.gui.GuiDraw;
|
||||
import codechicken.nei.KeyManager.IKeyStateTracker;
|
||||
import codechicken.nei.api.API;
|
||||
import codechicken.nei.api.GuiInfo;
|
||||
import codechicken.nei.api.INEIAutoFocusSearchEnable;
|
||||
import codechicken.nei.api.IRecipeOverlayRenderer;
|
||||
import codechicken.nei.api.ItemInfo;
|
||||
import codechicken.nei.api.LayoutStyle;
|
||||
@@ -87,6 +89,9 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH
|
||||
public static SubsetWidget dropDown;
|
||||
public static PresetsWidget presetsPanel;
|
||||
public static SearchField searchField;
|
||||
public static boolean searchInitFocusedCancellable = false;
|
||||
protected static int mousePriorX;
|
||||
protected static int mousePriorY;
|
||||
|
||||
public static ButtonCycled options;
|
||||
public static ButtonCycled bookmarksButton;
|
||||
@@ -163,10 +168,38 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH
|
||||
return getSideWidth(gui);
|
||||
}
|
||||
|
||||
protected boolean isAllowedGuiAutoSearchFocus(GuiContainer gui) {
|
||||
if (gui instanceof INEIAutoFocusSearchEnable) {
|
||||
return true;
|
||||
}
|
||||
String guiClassName = gui.getClass().getName();
|
||||
for (String prefix : NEIClientConfig.enableAutoFocusPrefixes) {
|
||||
if (guiClassName.startsWith(prefix)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// Maybe make this an option to make it easier to figure out what GPU class to add to the configuration?
|
||||
// NEIClientConfig.logger.info("Checking for autofocus on " + guiClassName + " had no match");
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void searchFocusInitCancelCheck() {
|
||||
if (searchInitFocusedCancellable) {
|
||||
if (searchField.isVisible() && NEIClientConfig.searchWidgetAutofocus()
|
||||
&& getInputFocused() == searchField) {
|
||||
searchField.setFocus(false);
|
||||
setInputFocused(null);
|
||||
}
|
||||
searchInitFocusedCancellable = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMouseClicked(GuiContainer gui, int mousex, int mousey, int button) {
|
||||
if (isHidden()) return;
|
||||
|
||||
searchFocusInitCancelCheck();
|
||||
|
||||
for (Widget widget : controlWidgets) widget.onGuiClick(mousex, mousey);
|
||||
}
|
||||
|
||||
@@ -176,6 +209,8 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH
|
||||
|
||||
if (!isEnabled()) return options.contains(mousex, mousey) && options.handleClick(mousex, mousey, button);
|
||||
|
||||
searchFocusInitCancelCheck();
|
||||
|
||||
for (Widget widget : controlWidgets) {
|
||||
widget.onGuiClick(mousex, mousey);
|
||||
if (widget.contains(mousex, mousey) ? widget.handleClick(mousex, mousey, button)
|
||||
@@ -196,6 +231,14 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH
|
||||
|
||||
public boolean keyTyped(GuiContainer gui, char keyChar, int keyID) {
|
||||
if (isEnabled() && !isHidden()) {
|
||||
if (searchInitFocusedCancellable) {
|
||||
searchInitFocusedCancellable = false;
|
||||
if (NEIClientConfig.isFirstInvCloseClosesInSearch()
|
||||
&& GameSettings.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindInventory)) {
|
||||
searchField.setFocus(false);
|
||||
setInputFocused(null);
|
||||
}
|
||||
}
|
||||
if (inputFocused != null) return inputFocused.handleKeyPress(keyID, keyChar);
|
||||
|
||||
for (Widget widget : controlWidgets) if (widget.handleKeyPress(keyID, keyChar)) return true;
|
||||
@@ -234,6 +277,7 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH
|
||||
|
||||
public void onMouseUp(GuiContainer gui, int mx, int my, int button) {
|
||||
if (!isHidden() && isEnabled()) {
|
||||
searchFocusInitCancelCheck();
|
||||
for (Widget widget : controlWidgets) widget.mouseUp(mx, my, button);
|
||||
}
|
||||
}
|
||||
@@ -241,6 +285,7 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH
|
||||
@Override
|
||||
public void onMouseDragged(GuiContainer gui, int mx, int my, int button, long heldTime) {
|
||||
if (!isHidden() && isEnabled()) {
|
||||
searchFocusInitCancelCheck();
|
||||
for (Widget widget : controlWidgets) widget.mouseDragged(mx, my, button, heldTime);
|
||||
}
|
||||
}
|
||||
@@ -259,6 +304,14 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH
|
||||
public void renderObjects(GuiContainer gui, int mousex, int mousey) {
|
||||
if (!isHidden()) {
|
||||
layout(gui);
|
||||
if (mousePriorX == -1) {
|
||||
mousePriorX = mousex;
|
||||
mousePriorY = mousey;
|
||||
} else if (mousePriorX != mousex || mousePriorY != mousey) {
|
||||
searchFocusInitCancelCheck();
|
||||
mousePriorX = mousex;
|
||||
mousePriorY = mousey;
|
||||
}
|
||||
if (isEnabled()) {
|
||||
getLayoutStyle().drawBackground(GuiContainerManager.getManager(gui));
|
||||
for (Widget widget : drawWidgets) widget.draw(mousex, mousey);
|
||||
@@ -620,6 +673,15 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH
|
||||
|
||||
getLayoutStyle().init();
|
||||
layout(gui);
|
||||
mousePriorX = -1;
|
||||
mousePriorY = -1;
|
||||
|
||||
if (searchField.isVisible() && NEIClientConfig.searchWidgetAutofocus()
|
||||
&& isAllowedGuiAutoSearchFocus(gui)) {
|
||||
searchField.setFocus(true);
|
||||
setInputFocused(searchField);
|
||||
searchInitFocusedCancellable = true;
|
||||
}
|
||||
}
|
||||
|
||||
NEIController.load(gui);
|
||||
@@ -721,6 +783,7 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH
|
||||
@Override
|
||||
public boolean mouseScrolled(GuiContainer gui, int mousex, int mousey, int scrolled) {
|
||||
if (isHidden() || !isEnabled()) return false;
|
||||
searchFocusInitCancelCheck();
|
||||
|
||||
for (Widget widget : drawWidgets) if (widget.onMouseWheel(scrolled, mousex, mousey)) return true;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package codechicken.nei;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -77,6 +78,7 @@ public class NEIClientConfig {
|
||||
public static final File heightHackHandlersFile = new File(configDir, "heighthackhandlers.cfg");
|
||||
public static final File handlerOrderingFile = new File(configDir, "handlerordering.csv");
|
||||
public static final File hiddenHandlersFile = new File(configDir, "hiddenhandlers.csv");
|
||||
public static final File enableAutoFocusFile = new File(configDir, "enableautofocus.cfg");
|
||||
|
||||
@Deprecated
|
||||
public static File bookmarkFile;
|
||||
@@ -96,6 +98,9 @@ public class NEIClientConfig {
|
||||
// Any handler not in the map will be assigned to 0, and negative numbers are fine.
|
||||
public static HashMap<String, Integer> handlerOrdering = new HashMap<>();
|
||||
|
||||
// List of prefixes of classes that should enable the autofocus search widget on open.
|
||||
public static ArrayList<String> enableAutoFocusPrefixes = new ArrayList<>();
|
||||
|
||||
// Function that extracts the handler ID from a handler, with special logic for
|
||||
// TemplateRecipeHandler: prefer using the overlay ID if it exists.
|
||||
public static final Function<IRecipeHandler, String> HANDLER_ID_FUNCTION = handler -> Objects
|
||||
@@ -167,6 +172,12 @@ public class NEIClientConfig {
|
||||
tag.getTag("inventory.search.widgetPosition").setComment("Widget Position").getBooleanValue(true);
|
||||
API.addOption(new OptionToggleButton("inventory.search.widgetPosition", true));
|
||||
|
||||
tag.getTag("inventory.search.widgetAutofocus")
|
||||
.setComment(
|
||||
"Focus Search Widget on Open, blurs/unfocuses on mouse move unless typing has started first")
|
||||
.getBooleanValue(false);
|
||||
API.addOption(new OptionToggleButton("inventory.search.widgetAutofocus", true));
|
||||
|
||||
tag.getTag("inventory.search.patternMode").setComment("Search Mode").getIntValue(1);
|
||||
API.addOption(new OptionCycled("inventory.search.patternMode", 3, true));
|
||||
|
||||
@@ -185,7 +196,7 @@ public class NEIClientConfig {
|
||||
});
|
||||
|
||||
tag.getTag("inventory.search.tooltipSearchMode").setComment("Search mode for Tooltips (prefix: #)")
|
||||
.getIntValue(1);
|
||||
.getIntValue(0);
|
||||
API.addOption(new OptionCycled("inventory.search.tooltipSearchMode", 3, true) {
|
||||
|
||||
@Override
|
||||
@@ -196,7 +207,7 @@ public class NEIClientConfig {
|
||||
});
|
||||
|
||||
tag.getTag("inventory.search.identifierSearchMode").setComment("Search mode for identifier (prefix: &)")
|
||||
.getIntValue(1);
|
||||
.getIntValue(0);
|
||||
API.addOption(new OptionCycled("inventory.search.identifierSearchMode", 3, true) {
|
||||
|
||||
@Override
|
||||
@@ -207,7 +218,7 @@ public class NEIClientConfig {
|
||||
});
|
||||
|
||||
tag.getTag("inventory.search.oreDictSearchMode").setComment("Search mode for Tag Names (prefix: $)")
|
||||
.getIntValue(1);
|
||||
.getIntValue(0);
|
||||
API.addOption(new OptionCycled("inventory.search.oreDictSearchMode", 3, true) {
|
||||
|
||||
@Override
|
||||
@@ -218,7 +229,7 @@ public class NEIClientConfig {
|
||||
});
|
||||
|
||||
tag.getTag("inventory.search.subsetsSearchMode").setComment("Search mode for Item Subsets (prefix: %)")
|
||||
.getIntValue(1);
|
||||
.getIntValue(2);
|
||||
API.addOption(new OptionCycled("inventory.search.subsetsSearchMode", 3, true) {
|
||||
|
||||
@Override
|
||||
@@ -332,6 +343,11 @@ public class NEIClientConfig {
|
||||
tag.getTag("inventory.showItemQuantityWidget").setComment("Show Item Quantity Widget").getBooleanValue(true);
|
||||
API.addOption(new OptionToggleButton("inventory.showItemQuantityWidget", true));
|
||||
|
||||
tag.getTag("inventory.firstInvCloseClosesInSearch").setComment(
|
||||
"Pressing the open inventory key when the inventory was just opened when the search is focused will close it instead of typing in the search")
|
||||
.getBooleanValue(true);
|
||||
API.addOption(new OptionToggleButton("inventory.firstInvCloseClosesInSearch", true));
|
||||
|
||||
tag.getTag("inventory.jei_style_tabs").setComment("Enable/disable JEI Style Tabs").getBooleanValue(true);
|
||||
API.addOption(new OptionToggleButtonBoubs("inventory.jei_style_tabs", true));
|
||||
|
||||
@@ -674,6 +690,14 @@ public class NEIClientConfig {
|
||||
return getBooleanSetting("inventory.search.widgetPosition");
|
||||
}
|
||||
|
||||
public static boolean searchWidgetAutofocus() {
|
||||
return getBooleanSetting("inventory.search.widgetAutofocus");
|
||||
}
|
||||
|
||||
public static boolean isFirstInvCloseClosesInSearch() {
|
||||
return getBooleanSetting("inventory.firstInvCloseClosesInSearch");
|
||||
}
|
||||
|
||||
public static boolean areJEIStyleTabsVisible() {
|
||||
return getBooleanSetting("inventory.jei_style_tabs");
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package codechicken.nei;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
import codechicken.nei.SearchField.SearchTextFormatter;
|
||||
import codechicken.nei.api.ItemFilter;
|
||||
import codechicken.nei.util.TextHistory;
|
||||
|
||||
@@ -19,7 +18,7 @@ public abstract class RecipeSearchField extends TextField {
|
||||
@Override
|
||||
protected void initInternalTextField() {
|
||||
field = new FormattedTextField(Minecraft.getMinecraft().fontRenderer, 0, 0, 0, 0);
|
||||
((FormattedTextField) field).setFormatter(new SearchTextFormatter());
|
||||
((FormattedTextField) field).setFormatter(new SearchTextFormatter(SearchField.searchParser));
|
||||
field.setMaxStringLength(maxSearchLength);
|
||||
field.setCursorPositionZero();
|
||||
}
|
||||
|
||||
@@ -2,18 +2,12 @@ package codechicken.nei;
|
||||
|
||||
import static codechicken.nei.NEIClientConfig.world;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -21,46 +15,17 @@ import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import codechicken.lib.gui.GuiDraw;
|
||||
import codechicken.nei.FormattedTextField.TextFormatter;
|
||||
import codechicken.nei.ItemList.AllMultiItemFilter;
|
||||
import codechicken.nei.ItemList.AnyMultiItemFilter;
|
||||
import codechicken.nei.ItemList.EverythingItemFilter;
|
||||
import codechicken.nei.ItemList.NegatedItemFilter;
|
||||
import codechicken.nei.ItemList.NothingItemFilter;
|
||||
import codechicken.nei.ItemList.PatternItemFilter;
|
||||
import codechicken.nei.SearchTokenParser.ISearchParserProvider;
|
||||
import codechicken.nei.SearchTokenParser.SearchMode;
|
||||
import codechicken.nei.api.API;
|
||||
import codechicken.nei.api.ItemFilter;
|
||||
import codechicken.nei.api.ItemFilter.ItemFilterProvider;
|
||||
import codechicken.nei.recipe.StackInfo;
|
||||
import codechicken.nei.search.IdentifierFilter;
|
||||
import codechicken.nei.search.ModNameFilter;
|
||||
import codechicken.nei.search.OreDictionaryFilter;
|
||||
import codechicken.nei.search.TooltipFilter;
|
||||
import codechicken.nei.util.TextHistory;
|
||||
import scala.collection.mutable.StringBuilder;
|
||||
|
||||
public class SearchField extends TextField implements ItemFilterProvider {
|
||||
|
||||
public enum SearchMode {
|
||||
|
||||
ALWAYS,
|
||||
PREFIX,
|
||||
NEVER;
|
||||
|
||||
public static SearchMode fromInt(int value) {
|
||||
switch (value) {
|
||||
case 0:
|
||||
return ALWAYS;
|
||||
case 1:
|
||||
return PREFIX;
|
||||
case 2:
|
||||
return NEVER;
|
||||
default:
|
||||
return ALWAYS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface for returning a custom filter based on search field text
|
||||
*/
|
||||
@@ -78,20 +43,9 @@ public class SearchField extends TextField implements ItemFilterProvider {
|
||||
public ItemFilter getFilter(String searchText);
|
||||
}
|
||||
|
||||
public static interface ISearchParserProvider {
|
||||
|
||||
public ItemFilter getFilter(String searchText);
|
||||
|
||||
public char getPrefix();
|
||||
|
||||
public EnumChatFormatting getHighlightedColor();
|
||||
|
||||
public SearchMode getSearchMode();
|
||||
}
|
||||
|
||||
public static class SearchParserProvider implements ISearchParserProvider {
|
||||
|
||||
protected final List<Function<Pattern, ItemFilter>> subFilters = new ArrayList<>();
|
||||
protected final Function<Pattern, ItemFilter> createFilter;
|
||||
protected final String name;
|
||||
protected final char prefix;
|
||||
protected final EnumChatFormatting highlightedColor;
|
||||
@@ -101,11 +55,7 @@ public class SearchField extends TextField implements ItemFilterProvider {
|
||||
this.prefix = prefix;
|
||||
this.name = name;
|
||||
this.highlightedColor = highlightedColor;
|
||||
this.addSubFilter(createFilter);
|
||||
}
|
||||
|
||||
public void addSubFilter(Function<Pattern, ItemFilter> subFilter) {
|
||||
this.subFilters.add(subFilter);
|
||||
this.createFilter = createFilter;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -116,21 +66,13 @@ public class SearchField extends TextField implements ItemFilterProvider {
|
||||
return this.createFilter(pattern);
|
||||
}
|
||||
|
||||
return null;
|
||||
return new NothingItemFilter();
|
||||
}
|
||||
|
||||
protected ItemFilter createFilter(Pattern pattern) {
|
||||
final List<ItemFilter> filters = new ArrayList<>();
|
||||
final ItemFilter filter = this.createFilter.apply(pattern);
|
||||
|
||||
for (Function<Pattern, ItemFilter> createFilter : this.subFilters) {
|
||||
ItemFilter filter = createFilter.apply(pattern);
|
||||
if (filter != null) {
|
||||
filters.add(filter);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return filters.isEmpty() ? null : new AnyMultiItemFilter(filters);
|
||||
return filter == null ? new NothingItemFilter() : filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -149,72 +91,9 @@ public class SearchField extends TextField implements ItemFilterProvider {
|
||||
}
|
||||
}
|
||||
|
||||
public static class SearchTextFormatter implements TextFormatter {
|
||||
|
||||
public String format(String text) {
|
||||
final String[] parts = text.split("\\|");
|
||||
StringJoiner formattedText = new StringJoiner(EnumChatFormatting.GRAY + "|");
|
||||
|
||||
for (String filterText : parts) {
|
||||
Matcher filterMatcher = SearchField.getFilterSplitPattern().matcher(filterText);
|
||||
StringBuilder formattedPart = new StringBuilder();
|
||||
int startIndex = 0;
|
||||
|
||||
while (filterMatcher.find()) {
|
||||
boolean ignore = "-".equals(filterMatcher.group(2));
|
||||
String firstChar = filterMatcher.group(3);
|
||||
String token = filterMatcher.group(4);
|
||||
boolean quotes = token.length() > 1 && token.startsWith("\"") && token.endsWith("\"");
|
||||
|
||||
if (quotes) {
|
||||
token = token.substring(1, token.length() - 1);
|
||||
}
|
||||
|
||||
formattedPart.append(filterText.substring(startIndex, filterMatcher.start()));
|
||||
EnumChatFormatting tokenColor = EnumChatFormatting.RESET;
|
||||
|
||||
if (!firstChar.isEmpty()) {
|
||||
tokenColor = SearchField.searchParserProviders.get(firstChar.charAt(0)).getHighlightedColor();
|
||||
}
|
||||
|
||||
if (ignore) {
|
||||
formattedPart.append(EnumChatFormatting.BLUE + "-");
|
||||
}
|
||||
|
||||
if (!firstChar.isEmpty()) {
|
||||
formattedPart.append(tokenColor + firstChar);
|
||||
}
|
||||
|
||||
if (quotes) {
|
||||
formattedPart.append(EnumChatFormatting.GOLD + "\"");
|
||||
}
|
||||
|
||||
if (!token.isEmpty()) {
|
||||
formattedPart.append(tokenColor + token);
|
||||
}
|
||||
|
||||
if (quotes) {
|
||||
formattedPart.append(EnumChatFormatting.GOLD + "\"");
|
||||
}
|
||||
|
||||
startIndex = filterMatcher.end();
|
||||
}
|
||||
|
||||
formattedPart.append(filterText.substring(startIndex, filterText.length()));
|
||||
formattedText.add(formattedPart);
|
||||
}
|
||||
|
||||
if (text.endsWith("|")) {
|
||||
formattedText.add("");
|
||||
}
|
||||
|
||||
return formattedText.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static List<ISearchProvider> searchProviders = new LinkedList<>();
|
||||
public static final Map<Character, ISearchParserProvider> searchParserProviders = new HashMap<>();
|
||||
public static SearchTokenParser searchParser = new SearchTokenParser();
|
||||
private static final TextHistory history = new TextHistory();
|
||||
private boolean isVisible = true;
|
||||
private long lastclicktime;
|
||||
@@ -222,49 +101,12 @@ public class SearchField extends TextField implements ItemFilterProvider {
|
||||
public SearchField(String ident) {
|
||||
super(ident);
|
||||
API.addItemFilter(this);
|
||||
API.addSearchProvider(
|
||||
new SearchParserProvider(
|
||||
'\0',
|
||||
"default",
|
||||
EnumChatFormatting.RESET,
|
||||
(pattern) -> new PatternItemFilter(pattern)) {
|
||||
|
||||
@Override
|
||||
public SearchMode getSearchMode() {
|
||||
return SearchMode.ALWAYS;
|
||||
}
|
||||
|
||||
});
|
||||
API.addSearchProvider(
|
||||
new SearchParserProvider(
|
||||
'@',
|
||||
"modName",
|
||||
EnumChatFormatting.LIGHT_PURPLE,
|
||||
(pattern) -> new ModNameFilter(pattern)));
|
||||
API.addSearchProvider(
|
||||
new SearchParserProvider(
|
||||
'$',
|
||||
"oreDict",
|
||||
EnumChatFormatting.AQUA,
|
||||
(pattern) -> new OreDictionaryFilter(pattern)));
|
||||
API.addSearchProvider(
|
||||
new SearchParserProvider(
|
||||
'#',
|
||||
"tooltip",
|
||||
EnumChatFormatting.YELLOW,
|
||||
(pattern) -> new TooltipFilter(pattern)));
|
||||
API.addSearchProvider(
|
||||
new SearchParserProvider(
|
||||
'&',
|
||||
"identifier",
|
||||
EnumChatFormatting.GOLD,
|
||||
(pattern) -> new IdentifierFilter(pattern)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initInternalTextField() {
|
||||
field = new FormattedTextField(Minecraft.getMinecraft().fontRenderer, 0, 0, 0, 0);
|
||||
((FormattedTextField) field).setFormatter(new SearchTextFormatter());
|
||||
((FormattedTextField) field).setFormatter(new SearchTextFormatter(SearchField.searchParser));
|
||||
field.setMaxStringLength(maxSearchLength);
|
||||
field.setCursorPositionZero();
|
||||
}
|
||||
@@ -292,7 +134,6 @@ public class SearchField extends TextField implements ItemFilterProvider {
|
||||
|
||||
@Override
|
||||
public void draw(int mousex, int mousey) {
|
||||
|
||||
super.draw(mousex, mousey);
|
||||
|
||||
if (searchInventories()) {
|
||||
@@ -317,9 +158,11 @@ public class SearchField extends TextField implements ItemFilterProvider {
|
||||
@Override
|
||||
public void onTextChange(String oldText) {
|
||||
final String newText = text();
|
||||
if (newText.length() > 0) NEIClientConfig.logger.debug("Searching for " + newText);
|
||||
NEIClientConfig.setSearchExpression(newText);
|
||||
ItemList.updateFilter.restart();
|
||||
if (!newText.equals(oldText)) {
|
||||
if (newText.length() > 0) NEIClientConfig.logger.debug("Searching for " + newText);
|
||||
NEIClientConfig.setSearchExpression(newText);
|
||||
ItemList.updateFilter.restart();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -343,33 +186,42 @@ public class SearchField extends TextField implements ItemFilterProvider {
|
||||
}
|
||||
|
||||
public static Pattern getPattern(String search) {
|
||||
switch (NEIClientConfig.getIntSetting("inventory.search.patternMode")) {
|
||||
return getPattern(search, NEIClientConfig.getIntSetting("inventory.search.patternMode"));
|
||||
}
|
||||
|
||||
public static Pattern getPattern(String search, int patternMode) {
|
||||
switch (patternMode) {
|
||||
case 0: // plain
|
||||
search = Pattern.quote(search);
|
||||
break;
|
||||
case 1: // extended
|
||||
final Matcher matcher = Pattern.compile("(\\?|\\*)").matcher(search);
|
||||
String cleanedString = "";
|
||||
int lastEndIndex = 0;
|
||||
|
||||
while (matcher.find()) {
|
||||
cleanedString += Pattern.quote(search.substring(lastEndIndex, matcher.start()));
|
||||
if (search.length() >= 3 && search.startsWith("r/") && search.endsWith("/")) {
|
||||
search = search.substring(2, search.length() - 1);
|
||||
} else {
|
||||
final Matcher matcher = Pattern.compile("(\\?|\\*)").matcher(search);
|
||||
String cleanedString = "";
|
||||
int lastEndIndex = 0;
|
||||
|
||||
switch (matcher.group(0).charAt(0)) {
|
||||
case '?':
|
||||
cleanedString += ".";
|
||||
break;
|
||||
case '*':
|
||||
cleanedString += ".+?";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
while (matcher.find()) {
|
||||
cleanedString += Pattern.quote(search.substring(lastEndIndex, matcher.start()));
|
||||
|
||||
switch (matcher.group(0).charAt(0)) {
|
||||
case '?':
|
||||
cleanedString += ".";
|
||||
break;
|
||||
case '*':
|
||||
cleanedString += ".+?";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
lastEndIndex = matcher.end();
|
||||
}
|
||||
|
||||
lastEndIndex = matcher.end();
|
||||
search = cleanedString + Pattern.quote(search.substring(lastEndIndex, search.length()));
|
||||
}
|
||||
|
||||
search = cleanedString + Pattern.quote(search.substring(lastEndIndex, search.length()));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -383,7 +235,7 @@ public class SearchField extends TextField implements ItemFilterProvider {
|
||||
}
|
||||
|
||||
public static String getEscapedSearchText(ItemStack stack) {
|
||||
final FluidStack fluidStack = StackInfo.getFluid(stack);
|
||||
final FluidStack fluidStack = StackInfo.isFluidContainer(stack) ? null : StackInfo.getFluid(stack);
|
||||
String displayName;
|
||||
|
||||
if (fluidStack != null) {
|
||||
@@ -419,87 +271,8 @@ public class SearchField extends TextField implements ItemFilterProvider {
|
||||
return getFilter(text());
|
||||
}
|
||||
|
||||
protected static Pattern getFilterSplitPattern() {
|
||||
StringJoiner prefixes = new StringJoiner("");
|
||||
prefixes.add(String.valueOf('\0'));
|
||||
|
||||
for (ISearchParserProvider provider : SearchField.searchParserProviders.values()) {
|
||||
if (provider.getSearchMode() == SearchMode.PREFIX) {
|
||||
prefixes.add(String.valueOf(provider.getPrefix()));
|
||||
}
|
||||
}
|
||||
|
||||
return Pattern.compile("((-*)([" + Pattern.quote(prefixes.toString()) + "]*)(\\\".*?(?:\\\"|$)|\\S+))");
|
||||
}
|
||||
|
||||
public static ItemFilter getFilter(String filterText) {
|
||||
final String[] parts = EnumChatFormatting.getTextWithoutFormattingCodes(filterText).toLowerCase().split("\\|");
|
||||
final List<ItemFilter> searchTokens = Arrays.stream(parts).map(SearchField::parseSearchTokens)
|
||||
.filter(s -> s != null).collect(Collectors.toCollection(ArrayList::new));
|
||||
|
||||
if (searchTokens.isEmpty()) {
|
||||
return new EverythingItemFilter();
|
||||
} else {
|
||||
return new AnyMultiItemFilter(searchTokens);
|
||||
}
|
||||
}
|
||||
|
||||
private static ItemFilter parseSearchTokens(String filterText) {
|
||||
|
||||
if (filterText.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Matcher filterMatcher = getFilterSplitPattern().matcher(filterText);
|
||||
final AllMultiItemFilter searchTokens = new AllMultiItemFilter();
|
||||
|
||||
while (filterMatcher.find()) {
|
||||
boolean ignore = "-".equals(filterMatcher.group(2));
|
||||
String firstChar = filterMatcher.group(3);
|
||||
String token = filterMatcher.group(4);
|
||||
boolean quotes = token.length() > 1 && token.startsWith("\"") && token.endsWith("\"");
|
||||
|
||||
if (quotes) {
|
||||
token = token.substring(1, token.length() - 1);
|
||||
}
|
||||
|
||||
if (!token.isEmpty()) {
|
||||
ItemFilter result = parseToken(firstChar, token);
|
||||
|
||||
if (ignore) {
|
||||
searchTokens.filters.add(new NegatedItemFilter(result));
|
||||
} else {
|
||||
searchTokens.filters.add(result);
|
||||
}
|
||||
} else if (!ignore) {
|
||||
searchTokens.filters.add(new NothingItemFilter());
|
||||
}
|
||||
}
|
||||
|
||||
return searchTokens;
|
||||
}
|
||||
|
||||
private static ItemFilter parseToken(String firstChar, String token) {
|
||||
final ISearchParserProvider provider = firstChar.isEmpty() ? null
|
||||
: SearchField.searchParserProviders.get(firstChar.charAt(0));
|
||||
|
||||
if (provider == null || provider.getSearchMode() == SearchMode.NEVER) {
|
||||
final List<ItemFilter> filters = new ArrayList<>();
|
||||
|
||||
for (ISearchParserProvider _provider : SearchField.searchParserProviders.values()) {
|
||||
if (_provider.getSearchMode() == SearchMode.ALWAYS) {
|
||||
ItemFilter filter = _provider.getFilter(token);
|
||||
if (filter != null) {
|
||||
filters.add(filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return filters.isEmpty() ? new NothingItemFilter() : new AnyMultiItemFilter(filters);
|
||||
} else {
|
||||
ItemFilter filter = provider.getFilter(token);
|
||||
return filter != null ? filter : new NothingItemFilter();
|
||||
}
|
||||
return SearchField.searchParser.getFilter(filterText);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package codechicken.nei;
|
||||
|
||||
import java.util.StringJoiner;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
import codechicken.nei.FormattedTextField.TextFormatter;
|
||||
|
||||
public class SearchTextFormatter implements TextFormatter {
|
||||
|
||||
protected final SearchTokenParser searchParser;
|
||||
|
||||
public SearchTextFormatter(SearchTokenParser searchParser) {
|
||||
this.searchParser = searchParser;
|
||||
}
|
||||
|
||||
public String format(String text) {
|
||||
final String[] parts = text.split("\\|");
|
||||
final Pattern splitPattern = searchParser.getSplitPattern();
|
||||
StringJoiner formattedText = new StringJoiner(EnumChatFormatting.GRAY + "|");
|
||||
|
||||
for (String filterText : parts) {
|
||||
Matcher filterMatcher = splitPattern.matcher(filterText);
|
||||
StringBuilder formattedPart = new StringBuilder();
|
||||
int startIndex = 0;
|
||||
|
||||
while (filterMatcher.find()) {
|
||||
boolean ignore = "-".equals(filterMatcher.group(2));
|
||||
String firstChar = filterMatcher.group(3);
|
||||
String token = filterMatcher.group(4);
|
||||
boolean quotes = token.length() > 1 && token.startsWith("\"") && token.endsWith("\"");
|
||||
|
||||
if (quotes) {
|
||||
token = token.substring(1, token.length() - 1);
|
||||
}
|
||||
|
||||
formattedPart.append(filterText.substring(startIndex, filterMatcher.start()));
|
||||
EnumChatFormatting tokenColor = EnumChatFormatting.RESET;
|
||||
|
||||
if (!firstChar.isEmpty()) {
|
||||
tokenColor = searchParser.getProvider(firstChar.charAt(0)).getHighlightedColor();
|
||||
}
|
||||
|
||||
if (ignore) {
|
||||
formattedPart.append(EnumChatFormatting.BLUE + "-");
|
||||
}
|
||||
|
||||
if (!firstChar.isEmpty()) {
|
||||
formattedPart.append(tokenColor + firstChar);
|
||||
}
|
||||
|
||||
if (quotes) {
|
||||
formattedPart.append(EnumChatFormatting.GOLD + "\"");
|
||||
}
|
||||
|
||||
if (!token.isEmpty()) {
|
||||
formattedPart.append(tokenColor + token);
|
||||
}
|
||||
|
||||
if (quotes) {
|
||||
formattedPart.append(EnumChatFormatting.GOLD + "\"");
|
||||
}
|
||||
|
||||
startIndex = filterMatcher.end();
|
||||
}
|
||||
|
||||
formattedPart.append(filterText.substring(startIndex, filterText.length()));
|
||||
formattedText.add(formattedPart);
|
||||
}
|
||||
|
||||
if (text.endsWith("|")) {
|
||||
formattedText.add("");
|
||||
}
|
||||
|
||||
return formattedText.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
package codechicken.nei;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.Language;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
import codechicken.nei.ItemList.AllMultiItemFilter;
|
||||
import codechicken.nei.ItemList.AnyMultiItemFilter;
|
||||
import codechicken.nei.ItemList.EverythingItemFilter;
|
||||
import codechicken.nei.ItemList.NegatedItemFilter;
|
||||
import codechicken.nei.ItemList.NothingItemFilter;
|
||||
import codechicken.nei.api.ItemFilter;
|
||||
|
||||
public class SearchTokenParser {
|
||||
|
||||
public enum SearchMode {
|
||||
|
||||
ALWAYS,
|
||||
PREFIX,
|
||||
NEVER;
|
||||
|
||||
public static SearchMode fromInt(int value) {
|
||||
switch (value) {
|
||||
case 0:
|
||||
return ALWAYS;
|
||||
case 1:
|
||||
return PREFIX;
|
||||
case 2:
|
||||
return NEVER;
|
||||
default:
|
||||
return ALWAYS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static interface ISearchParserProvider {
|
||||
|
||||
public ItemFilter getFilter(String searchText);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<Language> getAllLanguages() {
|
||||
return new ArrayList<>(Minecraft.getMinecraft().getLanguageManager().getLanguages());
|
||||
}
|
||||
|
||||
default List<Language> getMatchingLanguages() {
|
||||
return getAllLanguages();
|
||||
}
|
||||
|
||||
public char getPrefix();
|
||||
|
||||
public EnumChatFormatting getHighlightedColor();
|
||||
|
||||
public SearchMode getSearchMode();
|
||||
}
|
||||
|
||||
private static class ProvidersCache {
|
||||
|
||||
public String languageCode = null;
|
||||
public List<ISearchParserProvider> providers = new ArrayList<>();
|
||||
|
||||
public void clear() {
|
||||
this.languageCode = null;
|
||||
this.providers.clear();
|
||||
}
|
||||
}
|
||||
|
||||
protected final List<ISearchParserProvider> searchProviders;
|
||||
protected final ProvidersCache providersCache = new ProvidersCache();
|
||||
|
||||
public SearchTokenParser(List<ISearchParserProvider> searchProviders) {
|
||||
this.searchProviders = searchProviders;
|
||||
}
|
||||
|
||||
public SearchTokenParser() {
|
||||
this(new ArrayList<>());
|
||||
}
|
||||
|
||||
public void addProvider(ISearchParserProvider provider) {
|
||||
this.searchProviders.add(provider);
|
||||
this.providersCache.clear();
|
||||
}
|
||||
|
||||
protected List<ISearchParserProvider> getProviders() {
|
||||
Language currentLanguage = Minecraft.getMinecraft().getLanguageManager().getCurrentLanguage();
|
||||
|
||||
if (!currentLanguage.getLanguageCode().equals(providersCache.languageCode)) {
|
||||
Map<Character, ISearchParserProvider> providers = new HashMap<>();
|
||||
|
||||
for (int index = this.searchProviders.size() - 1; index >= 0; index--) {
|
||||
ISearchParserProvider provider = this.searchProviders.get(index);
|
||||
|
||||
if (!providers.containsKey(provider.getPrefix())
|
||||
&& provider.getMatchingLanguages().contains(currentLanguage)) {
|
||||
providers.put(provider.getPrefix(), provider);
|
||||
}
|
||||
}
|
||||
|
||||
providersCache.providers = new ArrayList<>(providers.values());
|
||||
providersCache.languageCode = currentLanguage.getLanguageCode();
|
||||
}
|
||||
|
||||
return providersCache.providers;
|
||||
}
|
||||
|
||||
public ISearchParserProvider getProvider(char ch) {
|
||||
return getProviders().stream()
|
||||
.filter(provider -> provider.getSearchMode() == SearchMode.PREFIX && provider.getPrefix() == ch)
|
||||
.findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public ItemFilter getFilter(String filterText) {
|
||||
final String[] parts = EnumChatFormatting.getTextWithoutFormattingCodes(filterText).toLowerCase().split("\\|");
|
||||
final List<ItemFilter> searchTokens = Arrays.stream(parts).map(s -> parseSearchText(s)).filter(s -> s != null)
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
|
||||
if (searchTokens.isEmpty()) {
|
||||
return new EverythingItemFilter();
|
||||
} else if (searchTokens.size() == 1) {
|
||||
return searchTokens.get(0);
|
||||
} else {
|
||||
return new AnyMultiItemFilter(searchTokens);
|
||||
}
|
||||
}
|
||||
|
||||
public Pattern getSplitPattern() {
|
||||
StringJoiner prefixes = new StringJoiner("");
|
||||
prefixes.add(String.valueOf('\0'));
|
||||
|
||||
for (ISearchParserProvider provider : getProviders()) {
|
||||
if (provider.getSearchMode() == SearchMode.PREFIX) {
|
||||
prefixes.add(String.valueOf(provider.getPrefix()));
|
||||
}
|
||||
}
|
||||
|
||||
return Pattern.compile("((-*)([" + Pattern.quote(prefixes.toString()) + "]*)(\\\".*?(?:\\\"|$)|\\S+))");
|
||||
}
|
||||
|
||||
private ItemFilter parseSearchText(String filterText) {
|
||||
|
||||
if (filterText.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Matcher filterMatcher = getSplitPattern().matcher(filterText);
|
||||
final AllMultiItemFilter searchTokens = new AllMultiItemFilter();
|
||||
|
||||
while (filterMatcher.find()) {
|
||||
boolean ignore = "-".equals(filterMatcher.group(2));
|
||||
String firstChar = filterMatcher.group(3);
|
||||
String token = filterMatcher.group(4);
|
||||
boolean quotes = token.length() > 1 && token.startsWith("\"") && token.endsWith("\"");
|
||||
|
||||
if (quotes) {
|
||||
token = token.substring(1, token.length() - 1);
|
||||
}
|
||||
|
||||
if (!token.isEmpty()) {
|
||||
ItemFilter result = parseToken(firstChar, token);
|
||||
|
||||
if (ignore) {
|
||||
searchTokens.filters.add(new NegatedItemFilter(result));
|
||||
} else {
|
||||
searchTokens.filters.add(result);
|
||||
}
|
||||
} else if (!ignore) {
|
||||
searchTokens.filters.add(new NothingItemFilter());
|
||||
}
|
||||
}
|
||||
|
||||
return searchTokens;
|
||||
}
|
||||
|
||||
private ItemFilter parseToken(String firstChar, String token) {
|
||||
final ISearchParserProvider provider = firstChar.isEmpty() ? null : this.getProvider(firstChar.charAt(0));
|
||||
|
||||
if (provider == null || provider.getSearchMode() == SearchMode.NEVER) {
|
||||
final List<ItemFilter> filters = new ArrayList<>();
|
||||
|
||||
for (ISearchParserProvider _provider : getProviders()) {
|
||||
if (_provider.getSearchMode() == SearchMode.ALWAYS) {
|
||||
filters.add(_provider.getFilter(token));
|
||||
}
|
||||
}
|
||||
|
||||
return filters.isEmpty() ? new NothingItemFilter() : new AnyMultiItemFilter(filters);
|
||||
} else {
|
||||
return provider.getFilter(token);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,8 +28,8 @@ import codechicken.lib.vec.Rectangle4i;
|
||||
import codechicken.nei.ItemList.AnyMultiItemFilter;
|
||||
import codechicken.nei.ItemList.ItemsLoadedCallback;
|
||||
import codechicken.nei.ItemList.NothingItemFilter;
|
||||
import codechicken.nei.SearchField.ISearchParserProvider;
|
||||
import codechicken.nei.SearchField.SearchMode;
|
||||
import codechicken.nei.SearchTokenParser.ISearchParserProvider;
|
||||
import codechicken.nei.SearchTokenParser.SearchMode;
|
||||
import codechicken.nei.api.API;
|
||||
import codechicken.nei.api.ItemFilter;
|
||||
import codechicken.nei.api.ItemFilter.ItemFilterProvider;
|
||||
|
||||
@@ -24,8 +24,8 @@ import codechicken.nei.LayoutManager;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.OffsetPositioner;
|
||||
import codechicken.nei.SearchField;
|
||||
import codechicken.nei.SearchField.ISearchParserProvider;
|
||||
import codechicken.nei.SearchField.ISearchProvider;
|
||||
import codechicken.nei.SearchTokenParser.ISearchParserProvider;
|
||||
import codechicken.nei.SubsetWidget;
|
||||
import codechicken.nei.SubsetWidget.SubsetTag;
|
||||
import codechicken.nei.api.IRecipeFilter.IRecipeFilterProvider;
|
||||
@@ -322,7 +322,7 @@ public class API {
|
||||
* Adds a new search provider to the search field
|
||||
*/
|
||||
public static void addSearchProvider(ISearchParserProvider provider) {
|
||||
SearchField.searchParserProviders.put(provider.getPrefix(), provider);
|
||||
SearchField.searchParser.addProvider(provider);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package codechicken.nei.api;
|
||||
|
||||
/**
|
||||
* Implement this interface on a GuiContainer to enable the autofocus search in NEI (if the autofocus option is enabled)
|
||||
* without needing to add the classname to the config file .
|
||||
*/
|
||||
public interface INEIAutoFocusSearchEnable {
|
||||
}
|
||||
@@ -44,11 +44,14 @@ import codechicken.core.featurehack.GameDataManipulator;
|
||||
import codechicken.nei.InfiniteStackSizeHandler;
|
||||
import codechicken.nei.InfiniteToolHandler;
|
||||
import codechicken.nei.ItemList;
|
||||
import codechicken.nei.ItemList.PatternItemFilter;
|
||||
import codechicken.nei.ItemMobSpawner;
|
||||
import codechicken.nei.ItemStackMap;
|
||||
import codechicken.nei.ItemStackSet;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.PopupInputHandler;
|
||||
import codechicken.nei.SearchField.SearchParserProvider;
|
||||
import codechicken.nei.SearchTokenParser.SearchMode;
|
||||
import codechicken.nei.config.ArrayDumper;
|
||||
import codechicken.nei.config.HandlerDumper;
|
||||
import codechicken.nei.config.ItemPanelDumper;
|
||||
@@ -56,6 +59,9 @@ import codechicken.nei.config.RegistryDumper;
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
import codechicken.nei.recipe.BrewingRecipeHandler;
|
||||
import codechicken.nei.recipe.RecipeItemInputHandler;
|
||||
import codechicken.nei.search.IdentifierFilter;
|
||||
import codechicken.nei.search.ModNameFilter;
|
||||
import codechicken.nei.search.OreDictionaryFilter;
|
||||
import codechicken.nei.search.TooltipFilter;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
@@ -125,10 +131,7 @@ public class ItemInfo {
|
||||
addInputHandlers();
|
||||
addIDDumps();
|
||||
addHiddenItemFilter();
|
||||
addSearchOptimisation();
|
||||
}
|
||||
|
||||
private static void addSearchOptimisation() {
|
||||
addSearchProviders();
|
||||
ItemList.loadCallbacks.add(TooltipFilter::populateSearchMap);
|
||||
}
|
||||
|
||||
@@ -136,6 +139,46 @@ public class ItemInfo {
|
||||
API.addItemFilter(() -> item -> !hiddenItems.contains(item));
|
||||
}
|
||||
|
||||
private static void addSearchProviders() {
|
||||
API.addSearchProvider(
|
||||
new SearchParserProvider(
|
||||
'\0',
|
||||
"default",
|
||||
EnumChatFormatting.RESET,
|
||||
(pattern) -> new PatternItemFilter(pattern)) {
|
||||
|
||||
@Override
|
||||
public SearchMode getSearchMode() {
|
||||
return SearchMode.ALWAYS;
|
||||
}
|
||||
|
||||
});
|
||||
API.addSearchProvider(
|
||||
new SearchParserProvider(
|
||||
'@',
|
||||
"modName",
|
||||
EnumChatFormatting.LIGHT_PURPLE,
|
||||
(pattern) -> new ModNameFilter(pattern)));
|
||||
API.addSearchProvider(
|
||||
new SearchParserProvider(
|
||||
'$',
|
||||
"oreDict",
|
||||
EnumChatFormatting.AQUA,
|
||||
(pattern) -> new OreDictionaryFilter(pattern)));
|
||||
API.addSearchProvider(
|
||||
new SearchParserProvider(
|
||||
'#',
|
||||
"tooltip",
|
||||
EnumChatFormatting.YELLOW,
|
||||
(pattern) -> new TooltipFilter(pattern)));
|
||||
API.addSearchProvider(
|
||||
new SearchParserProvider(
|
||||
'&',
|
||||
"identifier",
|
||||
EnumChatFormatting.GOLD,
|
||||
(pattern) -> new IdentifierFilter(pattern)));
|
||||
}
|
||||
|
||||
private static void addIDDumps() {
|
||||
API.addOption(new RegistryDumper<Item>("tools.dump.item") {
|
||||
|
||||
|
||||
@@ -197,7 +197,7 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
return ingredients;
|
||||
}
|
||||
|
||||
protected void randomRenderPermutation(List<PositionedStack> stacks, long cycle) {
|
||||
public void randomRenderPermutation(List<PositionedStack> stacks, long cycle) {
|
||||
final ItemFilter filter = getItemFilter();
|
||||
final int randCycle = Math.abs(new Random(cycle + offset).nextInt());
|
||||
|
||||
@@ -228,7 +228,7 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
protected void randomRenderPermutation(PositionedStack stack, long cycle) {
|
||||
public void randomRenderPermutation(PositionedStack stack, long cycle) {
|
||||
Random rand = new Random(cycle + offset);
|
||||
stack.setPermutationToRender((int) (Math.abs(rand.nextInt()) % stack.items.length));
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import codechicken.nei.api.ItemFilter;
|
||||
import cpw.mods.fml.common.registry.GameData;
|
||||
|
||||
public class IdentifierFilter implements ItemFilter {
|
||||
|
||||
@@ -16,18 +17,17 @@ public class IdentifierFilter implements ItemFilter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ItemStack itemStack) {
|
||||
return this.pattern.matcher(getIdentifier(itemStack)).find();
|
||||
public boolean matches(ItemStack stack) {
|
||||
return this.pattern.matcher(getStringIdentifier(stack) + "\n" + getIdentifier(stack)).find();
|
||||
}
|
||||
|
||||
private String getIdentifier(ItemStack itemStack) {
|
||||
String mainname = String.valueOf(Item.getIdFromItem(itemStack.getItem()));
|
||||
protected String getIdentifier(ItemStack stack) {
|
||||
return Item.getIdFromItem(stack.getItem()) + ":" + stack.getItemDamage();
|
||||
}
|
||||
|
||||
if (itemStack.getItemDamage() != 0) {
|
||||
mainname += ":" + itemStack.getItemDamage();
|
||||
}
|
||||
|
||||
return mainname;
|
||||
protected String getStringIdentifier(ItemStack stack) {
|
||||
String name = GameData.getItemRegistry().getNameForObject(stack.getItem());
|
||||
return name == null || name.isEmpty() ? "Unknown:Unknown" : name;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,6 +8,8 @@ import net.minecraft.item.ItemStack;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.api.ItemFilter;
|
||||
import codechicken.nei.api.ItemInfo;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier;
|
||||
|
||||
@@ -21,7 +23,16 @@ public class ModNameFilter implements ItemFilter {
|
||||
|
||||
@Override
|
||||
public boolean matches(ItemStack itemStack) {
|
||||
return this.pattern.matcher(getModId(itemStack.getItem())).find();
|
||||
return this.pattern.matcher(nameFromStack(itemStack.getItem())).find();
|
||||
}
|
||||
|
||||
protected static String nameFromStack(Item item) {
|
||||
try {
|
||||
ModContainer mod = Loader.instance().getIndexedModList().get(getModId(item));
|
||||
return mod == null ? "Minecraft" : mod.getName();
|
||||
} catch (NullPointerException e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
protected static String getModId(Item item) {
|
||||
|
||||
@@ -54,7 +54,7 @@ public class TooltipFilter implements ItemFilter {
|
||||
|
||||
@Override
|
||||
public boolean matches(ItemStack itemStack) {
|
||||
return pattern.matcher(getSearchName(itemStack)).find();
|
||||
return pattern.matcher(getSearchTooltip(itemStack)).find();
|
||||
}
|
||||
|
||||
public static void populateSearchMap() {
|
||||
@@ -68,7 +68,7 @@ public class TooltipFilter implements ItemFilter {
|
||||
itemSearchNames.keySet().removeAll(oldItems);
|
||||
}
|
||||
|
||||
private static String getSearchName(ItemStack stack) {
|
||||
protected static String getSearchTooltip(ItemStack stack) {
|
||||
return itemSearchNames.computeIfAbsent(new ItemStackKey(stack), key -> getTooltip(key.stack));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
# Each line in this file should either be a comment (line starts with '#'), or a prefix of a fully-qualified class name
|
||||
# (that includes the package name) for a Minecraft GUI Container screen.
|
||||
# If you delete this file, it will be regenerated with the default enable autofocus list.
|
||||
net.minecraft.client.gui.inventory.GuiInventory
|
||||
makamys.satchels.gui.GuiSatchelsInventory
|
||||
@@ -176,11 +176,13 @@ nei.options.inventory.showRecipeMarker.false=No
|
||||
nei.options.inventory.showItemQuantityWidget=Show Item Quantity Widget
|
||||
nei.options.inventory.showItemQuantityWidget.true=Yes
|
||||
nei.options.inventory.showItemQuantityWidget.false=No
|
||||
|
||||
nei.options.inventory.search=Search Widget
|
||||
nei.options.inventory.search.widgetPosition=Widget Position
|
||||
nei.options.inventory.search.widgetPosition.true=Center
|
||||
nei.options.inventory.search.widgetPosition.false=Right
|
||||
nei.options.inventory.search.widgetAutofocus=Autofocus
|
||||
nei.options.inventory.search.widgetAutofocus.true=Yes
|
||||
nei.options.inventory.search.widgetAutofocus.false=No
|
||||
nei.options.inventory.search.patternMode=Search Mode
|
||||
nei.options.inventory.search.patternMode.0=Plain
|
||||
nei.options.inventory.search.patternMode.1=Extended
|
||||
@@ -208,7 +210,9 @@ nei.options.inventory.search.subsetsSearchMode=Item Subsets Search
|
||||
nei.options.inventory.search.subsetsSearchMode.0=Always
|
||||
nei.options.inventory.search.subsetsSearchMode.1=Prefix: %s
|
||||
nei.options.inventory.search.subsetsSearchMode.2=Never
|
||||
|
||||
nei.options.inventory.firstInvCloseClosesInSearch=First Inventory Close Closes in Search
|
||||
nei.options.inventory.firstInvCloseClosesInSearch.true=Yes
|
||||
nei.options.inventory.firstInvCloseClosesInSearch.false=No
|
||||
nei.options.inventory.creative_tab_style=Creative or JEI tab style
|
||||
nei.options.inventory.creative_tab_style.true=Creative
|
||||
nei.options.inventory.creative_tab_style.false=JEI
|
||||
|
||||
Reference in new issue
Block a user