mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-22 13:09:45 +00:00
Optimize ItemsTooltip sorting
This commit is contained in:
1 parent
f6cd66be3b
commit
9e7b279e37
10 files changed
+41
-49
No files matched your search
@@ -150,10 +150,16 @@ public class CollapsibleItems {
|
||||
}
|
||||
|
||||
public static void putItem(ItemStack stack) {
|
||||
final GroupItem group = CollapsibleItems.groups.stream().filter(g -> g.matches(stack)).findFirst().orElse(null);
|
||||
int groupIndex = -1;
|
||||
|
||||
if (group != null) {
|
||||
CollapsibleItems.cache.put(stack, CollapsibleItems.groups.indexOf(group));
|
||||
for (int i = 0; i < CollapsibleItems.groups.size() && groupIndex == -1; i++) {
|
||||
if (CollapsibleItems.groups.get(i).matches(stack)) {
|
||||
groupIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (groupIndex != -1) {
|
||||
CollapsibleItems.cache.put(stack, groupIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.concurrent.ForkJoinWorkerThread;
|
||||
@@ -29,7 +28,6 @@ import codechicken.nei.ThreadOperationTimer.TimeoutException;
|
||||
import codechicken.nei.api.ItemFilter;
|
||||
import codechicken.nei.api.ItemFilter.ItemFilterProvider;
|
||||
import codechicken.nei.api.ItemInfo;
|
||||
import codechicken.nei.recipe.StackInfo;
|
||||
import codechicken.nei.search.TooltipFilter;
|
||||
|
||||
public class ItemList {
|
||||
@@ -50,7 +48,7 @@ public class ItemList {
|
||||
|
||||
private static final HashSet<Item> erroredItems = new HashSet<>();
|
||||
private static final HashSet<String> stackTraces = new HashSet<>();
|
||||
private static HashMap<ItemStack, Integer> ordering = new HashMap<>();
|
||||
private static Map<ItemStack, Integer> ordering = new HashMap<>();
|
||||
/**
|
||||
* Unlike {@link LayoutManager#itemsLoaded}, this indicates whether item loading is actually finished or not.
|
||||
*/
|
||||
@@ -216,8 +214,7 @@ public class ItemList {
|
||||
IIcon icon = item.getIconIndex(itemstack);
|
||||
String name = getTooltip(itemstack);
|
||||
String s = name + "@" + (icon == null ? 0 : icon.hashCode());
|
||||
if (!damageIconSet.contains(s)) {
|
||||
damageIconSet.add(s);
|
||||
if (damageIconSet.add(s)) {
|
||||
permutations.add(itemstack);
|
||||
}
|
||||
} catch (TimeoutException t) {
|
||||
@@ -240,12 +237,11 @@ public class ItemList {
|
||||
}
|
||||
|
||||
private void updateOrdering(List<ItemStack> items) {
|
||||
final Map<ItemStack, Integer> newOrdering = new HashMap<>();
|
||||
ItemSorter.sort(items);
|
||||
|
||||
HashMap<ItemStack, Integer> newOrdering = new HashMap<>();
|
||||
|
||||
if (!CollapsibleItems.isEmpty()) {
|
||||
HashMap<Integer, Integer> groups = new HashMap<>();
|
||||
final HashMap<Integer, Integer> groups = new HashMap<>();
|
||||
int orderIndex = 0;
|
||||
|
||||
for (ItemStack stack : items) {
|
||||
@@ -312,7 +308,6 @@ public class ItemList {
|
||||
ListMultimap<Item, ItemStack> itemMap = ArrayListMultimap.create();
|
||||
ItemStackSet unique = new ItemStackSet();
|
||||
|
||||
timer.setLimit(NEIClientConfig.getItemLoadingTimeout());
|
||||
StreamSupport.stream(((Iterable<Item>) Item.itemRegistry).spliterator(), true).forEach(item -> {
|
||||
if (item == null || item.delegate.name() == null || erroredItems.contains(item)) return;
|
||||
|
||||
@@ -333,6 +328,7 @@ public class ItemList {
|
||||
}
|
||||
|
||||
CollapsibleItems.putItem(stack);
|
||||
TooltipFilter.getSearchTooltip(stack);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,10 +357,6 @@ public class ItemList {
|
||||
if (interrupted()) return;
|
||||
updateOrdering(ItemList.items);
|
||||
|
||||
new Thread(
|
||||
() -> ItemList.items.parallelStream().forEach(TooltipFilter::getSearchTooltip),
|
||||
"NEI Tooltip Filter Loader").start();
|
||||
|
||||
loadFinished = true;
|
||||
|
||||
SubsetWidget.updateHiddenItems();
|
||||
@@ -414,8 +406,7 @@ public class ItemList {
|
||||
|
||||
if (interrupted()) return;
|
||||
|
||||
Comparator<ItemStack> comparator = Comparator.comparingInt(ItemList.ordering::get);
|
||||
filtered.sort(comparator);
|
||||
filtered.sort(Comparator.comparingInt(ItemList.ordering::get));
|
||||
|
||||
if (interrupted()) return;
|
||||
|
||||
@@ -423,13 +414,6 @@ public class ItemList {
|
||||
}
|
||||
};
|
||||
|
||||
public static int getItemOrderIndex(ItemStack stack) {
|
||||
final Optional<Map.Entry<ItemStack, Integer>> orderingEntry = ItemList.ordering.entrySet().parallelStream()
|
||||
.filter(entry -> StackInfo.equalItemAndNBT(entry.getKey(), stack, true)).findAny();
|
||||
|
||||
return orderingEntry.isPresent() ? orderingEntry.get().getValue() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use updateFilter.restart()
|
||||
*/
|
||||
|
||||
@@ -51,13 +51,10 @@ public class ItemsPanelGrid extends ItemsGrid<ItemsPanelGrid.ItemsPanelGridSlot,
|
||||
public void drawItem(Rectangle4i rect) {
|
||||
|
||||
if (!this.extended && getBGItem() != null) {
|
||||
int panelFactor = (int) Math.ceil((Math.min(rect.w, rect.h) - 2) / (DEFAULT_SLOT_SIZE - 2));
|
||||
|
||||
GuiContainerManager.drawItems.zLevel -= 10F;
|
||||
super.drawItem(getBGItem(), rect.offset(1 * panelFactor, -1 * panelFactor));
|
||||
super.drawItem(getBGItem(), rect.offset(1, -1));
|
||||
GuiContainerManager.drawItems.zLevel += 10F;
|
||||
|
||||
super.drawItem(getItemStack(), rect.offset(-2 * panelFactor, 2 * panelFactor));
|
||||
super.drawItem(getItemStack(), rect.offset(-2, 2));
|
||||
} else {
|
||||
super.drawItem(rect);
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ public class SearchTokenParser {
|
||||
return this.filtersCache.computeIfAbsent(filterText, text -> {
|
||||
final String[] parts = text.split("\\|");
|
||||
final List<ItemFilter> searchTokens = Arrays.stream(parts).map(this::parseSearchText).filter(s -> s != null)
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (searchTokens.isEmpty()) {
|
||||
return new EverythingItemFilter();
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import codechicken.nei.BookmarkPanel.BookmarkViewMode;
|
||||
import codechicken.nei.ItemList;
|
||||
import codechicken.nei.ItemSorter;
|
||||
import codechicken.nei.bookmark.RecipeChainDetails.BookmarkChainItem;
|
||||
import codechicken.nei.bookmark.RecipeChainDetails.CalculatedType;
|
||||
import codechicken.nei.recipe.Recipe.RecipeId;
|
||||
@@ -286,7 +286,10 @@ public class BookmarkGridGenerator {
|
||||
private Comparator<Integer> generateSortingComparator(Map<Integer, BookmarkChainItem> calculatedItems) {
|
||||
return Comparator.comparingInt((Integer index) -> calculatedItems.get(index).calculatedType.toInt())
|
||||
.thenComparing(index -> StackInfo.getFluid(calculatedItems.get(index).getItem().itemStack) != null)
|
||||
.thenComparing(index -> ItemList.getItemOrderIndex(calculatedItems.get(index).getItem().itemStack));
|
||||
.thenComparing(
|
||||
(i1, i2) -> ItemSorter.instance.compare(
|
||||
calculatedItems.get(i1).getItem().itemStack,
|
||||
calculatedItems.get(i2).getItem().itemStack));
|
||||
}
|
||||
|
||||
private void splitGridMask() {
|
||||
|
||||
@@ -212,7 +212,7 @@ public class GuiContainerManager {
|
||||
|
||||
@Nullable
|
||||
public static String itemCountDetails(ItemStack stack) {
|
||||
FluidStack fluid = StackInfo.getFluid(stack);
|
||||
final FluidStack fluid = StackInfo.getFluid(stack);
|
||||
if (fluid != null) {
|
||||
return fluidAmountDetails(fluid.amount * Math.max(1, stack.stackSize));
|
||||
} else {
|
||||
|
||||
@@ -18,7 +18,7 @@ public class FillFluidContainerHandler extends INEIGuiAdapter {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (draggedStack.getItem() instanceof IFluidContainerItem || FluidContainerRegistry.isContainer(draggedStack)) {
|
||||
if (StackInfo.isFluidContainer(draggedStack)) {
|
||||
ItemStack overItemStack = ItemPanels.itemPanel.getStackMouseOver(mouseX, mouseY);
|
||||
|
||||
if (overItemStack == null) {
|
||||
|
||||
@@ -90,7 +90,7 @@ public class StackInfo {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (useNBT) {
|
||||
if (useNBT && stackA != stackB) {
|
||||
NBTTagCompound tagCompoundA = itemStackToNBT(stackA, false);
|
||||
NBTTagCompound tagCompoundB = itemStackToNBT(stackB, false);
|
||||
|
||||
|
||||
@@ -62,29 +62,31 @@ public class RecipeChainMath {
|
||||
while (true) {
|
||||
Map<BookmarkItem, BookmarkItem> maxReference = Collections.emptyMap();
|
||||
RecipeId maxRecipeId = null;
|
||||
long maxMultiplier = 0;
|
||||
int maxDepth = 0;
|
||||
|
||||
for (RecipeId recipeId : multipliers.keySet()) {
|
||||
for (Map.Entry<RecipeId, Long> entry : multipliers.entrySet()) {
|
||||
final RecipeId recipeId = entry.getKey();
|
||||
if (!this.outputRecipes.containsKey(recipeId) && this.preferredItems.values().stream()
|
||||
.noneMatch(resItem -> resItem.recipeId.equals(recipeId))) {
|
||||
final Map<BookmarkItem, BookmarkItem> references = new HashMap<>(this.preferredItems);
|
||||
final int depth = collectPreferredItems(recipeId, references, new HashSet<>());
|
||||
|
||||
if (maxDepth < depth) {
|
||||
if (maxDepth < depth || maxDepth == depth && entry.getValue() > maxMultiplier) {
|
||||
maxMultiplier = entry.getValue();
|
||||
maxReference = references;
|
||||
maxRecipeId = recipeId;
|
||||
maxDepth = depth;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (!maxReference.isEmpty()) {
|
||||
this.preferredItems.putAll(maxReference);
|
||||
this.outputRecipes.put(maxRecipeId, multipliers.get(maxRecipeId));
|
||||
} else {
|
||||
if (maxReference.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
this.preferredItems.putAll(maxReference);
|
||||
this.outputRecipes.put(maxRecipeId, multipliers.get(maxRecipeId));
|
||||
}
|
||||
|
||||
for (Map.Entry<RecipeId, Long> entry : multipliers.entrySet()) {
|
||||
@@ -113,7 +115,6 @@ public class RecipeChainMath {
|
||||
|
||||
for (BookmarkItem item : this.recipeResults) {
|
||||
if (item.factor > (prefItem == null ? 0 : prefItem.factor) && item.containsItems(ingrItem)
|
||||
&& !item.recipeId.equals(recipeId)
|
||||
&& !visited.contains(item.recipeId)) {
|
||||
prefItem = item;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
import codechicken.lib.gui.GuiDraw;
|
||||
import codechicken.lib.gui.GuiDraw.ITooltipLineHandler;
|
||||
import codechicken.nei.ItemList;
|
||||
import codechicken.nei.ItemSorter;
|
||||
import codechicken.nei.ItemStackAmount;
|
||||
import codechicken.nei.ItemsTooltipLineHandler;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
@@ -57,7 +57,8 @@ public class RecipeChainTooltipLineHandler implements ITooltipLineHandler {
|
||||
|
||||
if (lastShiftKey) {
|
||||
for (ItemStack stack : inventory.values()) {
|
||||
long invStackSize = inventory.get(stack);
|
||||
final long invStackSize = inventory.get(stack);
|
||||
|
||||
if (invStackSize > 0) {
|
||||
this.math.initialItems.add(BookmarkItem.of(-1, stack.copy()));
|
||||
}
|
||||
@@ -125,13 +126,13 @@ public class RecipeChainTooltipLineHandler implements ITooltipLineHandler {
|
||||
|
||||
inputs.sort(
|
||||
Comparator.comparing((ItemStack stack) -> StackInfo.getFluid(stack) != null)
|
||||
.thenComparing(stack -> ItemList.getItemOrderIndex(stack)));
|
||||
.thenComparing(ItemSorter.instance));
|
||||
outputs.sort(
|
||||
Comparator.comparing((ItemStack stack) -> StackInfo.getFluid(stack) != null)
|
||||
.thenComparing(stack -> ItemList.getItemOrderIndex(stack)));
|
||||
.thenComparing(ItemSorter.instance));
|
||||
remainder.sort(
|
||||
Comparator.comparing((ItemStack stack) -> StackInfo.getFluid(stack) != null)
|
||||
.thenComparing(stack -> ItemList.getItemOrderIndex(stack)));
|
||||
.thenComparing(ItemSorter.instance));
|
||||
|
||||
this.inputs = new ItemsTooltipLineHandler(
|
||||
lastShiftKey ? NEIClientUtils.translate("bookmark.crafting_chain.missing")
|
||||
|
||||
Reference in new issue
Block a user