Skip to content

Commit

Permalink
Merge remote-tracking branch 'slprime/extend_subset_widget' into dev
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/codechicken/nei/ItemPanel.java
#	src/main/java/codechicken/nei/guihook/GuiContainerManager.java
  • Loading branch information
Dream-Master committed Dec 27, 2024
2 parents 4e808cb + bde9a20 commit 2448008
Show file tree
Hide file tree
Showing 16 changed files with 887 additions and 655 deletions.
15 changes: 15 additions & 0 deletions src/main/java/codechicken/nei/BookmarkPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -2585,6 +2585,21 @@ private List<String> craftingChainTooltip(int groupId, List<String> currenttip)
return currenttip;
}

@Override
public boolean contains(int px, int py) {

if (new Rectangle4i(pagePrev.x + pagePrev.w, pagePrev.y, pageNext.x - (pagePrev.x + pagePrev.w), pagePrev.h)
.contains(px, py)) {
return true;
}

if (((BookmarkGrid) grid).getHoveredRowIndex(true) != -1) {
return true;
}

return super.contains(px, py);
}

@Override
public List<String> handleItemTooltip(GuiContainer gui, ItemStack itemstack, int mousex, int mousey,
List<String> currenttip) {
Expand Down
20 changes: 6 additions & 14 deletions src/main/java/codechicken/nei/CollapsibleItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,24 +145,16 @@ public static ItemFilter getItemFilter() {
return filter;
}

public static void updateCache(final List<ItemStack> items) {
public static void clearCache() {
CollapsibleItems.cache.clear();
}

try {

ItemList.forkJoinPool.submit(() -> items.parallelStream().forEach(stack -> {
GroupItem group = CollapsibleItems.groups.stream().filter(g -> g.matches(stack)).findFirst()
.orElse(null);
public static void putItem(ItemStack stack) {
final GroupItem group = CollapsibleItems.groups.stream().filter(g -> g.matches(stack)).findFirst().orElse(null);

if (group != null) {
CollapsibleItems.cache.put(stack, CollapsibleItems.groups.indexOf(group));
}
})).get();

} catch (Exception e) {
NEIClientConfig.logger.error("Error create collapsible items groups", e);
if (group != null) {
CollapsibleItems.cache.put(stack, CollapsibleItems.groups.indexOf(group));
}

}

public static int getGroupIndex(ItemStack stack) {
Expand Down
91 changes: 66 additions & 25 deletions src/main/java/codechicken/nei/ItemList.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.concurrent.ForkJoinWorkerThread;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import net.minecraft.client.Minecraft;
import net.minecraft.item.Item;
Expand All @@ -25,6 +26,7 @@
import codechicken.nei.api.ItemFilter;
import codechicken.nei.api.ItemFilter.ItemFilterProvider;
import codechicken.nei.api.ItemInfo;
import codechicken.nei.search.TooltipFilter;

public class ItemList {

Expand Down Expand Up @@ -265,50 +267,84 @@ private void updateOrdering(List<ItemStack> items) {
}
}

private List<ItemStack> getPermutations(Item item) {
final List<ItemStack> permutations = new LinkedList<>(ItemInfo.itemOverrides.get(item));

if (permutations.isEmpty()) {
item.getSubItems(item, null, permutations);
}

if (permutations.isEmpty()) {
damageSearch(item, permutations);
}

permutations.addAll(ItemInfo.itemVariants.get(item));

return permutations.stream()
.filter(
stack -> stack.getItem() != null && stack.getItem().delegate.name() != null
&& !ItemInfo.isHidden(stack))
.collect(Collectors.toCollection(ArrayList::new));
}

// For optimization it generate itemslist, permutations, orders & collapsibleitems
@Override
@SuppressWarnings("unchecked")
public void execute() {
if (!NEIClientConfig.isEnabled()) return;

ThreadOperationTimer timer = getTimer(NEIClientConfig.getItemLoadingTimeout());
LayoutManager.itemsLoaded = true;
loadFinished = false;

List<ItemStack> items = new LinkedList<>();
List<ItemStack> permutations = new LinkedList<>();
SearchField.searchParser.clearCache();
ItemSorter.instance.ordering.clear();
CollapsibleItems.clearCache();
TooltipFilter.clearCache();

List<ItemStack> items = new ArrayList<>();
ListMultimap<Item, ItemStack> itemMap = ArrayListMultimap.create();
ItemStackSet unique = new ItemStackSet();

timer.setLimit(NEIClientConfig.getItemLoadingTimeout());
for (Item item : (Iterable<Item>) Item.itemRegistry) {
if (interrupted()) return;

if (item == null || erroredItems.contains(item)) continue;
StreamSupport.stream(((Iterable<Item>) Item.itemRegistry).spliterator(), true).forEach(item -> {
if (item == null || item.delegate.name() == null || erroredItems.contains(item)) return;

try {
timer.reset(item);
List<ItemStack> permutations = getPermutations(item);
timer.reset();

permutations.clear();
permutations.addAll(ItemInfo.itemOverrides.get(item));

if (permutations.isEmpty()) {
item.getSubItems(item, null, permutations);
}

if (permutations.isEmpty()) {
damageSearch(item, permutations);
}
for (ItemStack stack : permutations) {
if (!unique.contains(stack)) {

permutations.addAll(ItemInfo.itemVariants.get(item));
synchronized (unique) {
unique.add(stack);
}

timer.reset();
synchronized (items) {
items.add(stack);
}

permutations = permutations.stream().filter(stack -> !ItemInfo.isHidden(stack))
.collect(Collectors.toCollection(ArrayList::new));
CollapsibleItems.putItem(stack);
}
}

items.addAll(permutations);
itemMap.putAll(item, permutations);
synchronized (itemMap) {
itemMap.putAll(item, permutations);
}
} catch (Throwable t) {
NEIServerConfig.logger.error("Removing item: " + item + " from list.", t);
NEIServerConfig.logger.error("Removing item: {} from list.", item, t);
erroredItems.add(item);
}

});

int index = 0;
for (Item item : (Iterable<Item>) Item.itemRegistry) {
for (ItemStack stack : itemMap.get(item)) {
ItemSorter.instance.ordering.put(stack, index++);
}
}

if (interrupted()) return;
Expand All @@ -317,10 +353,15 @@ public void execute() {
for (ItemsLoadedCallback callback : loadCallbacks) callback.itemsLoaded();

if (interrupted()) return;
CollapsibleItems.updateCache(items);
updateOrdering(items);
updateOrdering(ItemList.items);

new Thread(
() -> ItemList.items.parallelStream().forEach(TooltipFilter::getSearchTooltip),
"NEI Tooltip Filter Loader").start();

loadFinished = true;

SubsetWidget.updateHiddenItems();
updateFilter.restart();
}
};
Expand Down
73 changes: 3 additions & 70 deletions src/main/java/codechicken/nei/ItemPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ public ItemStack getStackMouseOver(int mousex, int mousey) {
return super.getStackMouseOver(mousex, mousey);
}

public Button more;
public Button less;
public ItemQuantityField quantity;
public ItemHistoryPanel historyPanel;
public Button toggleGroups;

Expand Down Expand Up @@ -345,42 +342,6 @@ public boolean onButtonPress(boolean rightclick) {
}
};

more = new Button("+") {

@Override
public boolean onButtonPress(boolean rightclick) {
if (rightclick) return false;

int modifier = NEIClientUtils.controlKey() ? 64 : NEIClientUtils.shiftKey() ? 10 : 1;
int quantity = NEIClientConfig.getItemQuantity() + modifier;

if (quantity < 0) {
quantity = 0;
}

ItemPanels.itemPanel.quantity.setText(Integer.toString(quantity));
return true;
}
};
less = new Button("-") {

@Override
public boolean onButtonPress(boolean rightclick) {
if (rightclick) return false;

int modifier = NEIClientUtils.controlKey() ? -64 : NEIClientUtils.shiftKey() ? -10 : -1;
int quantity = NEIClientConfig.getItemQuantity() + modifier;

if (quantity < 0) {
quantity = 0;
}

ItemPanels.itemPanel.quantity.setText(Integer.toString(quantity));
return true;
}
};

quantity = new ItemQuantityField("quantity");
historyPanel = new ItemHistoryPanel();
}

Expand Down Expand Up @@ -431,56 +392,28 @@ protected int resizeFooter(GuiContainer gui) {
return 0;
}

final int BUTTON_SIZE = 20;
more.w = less.w = BUTTON_SIZE;
quantity.h = BUTTON_SIZE;

if (NEIClientConfig.isSearchWidgetCentered()) {
more.h = less.h = BUTTON_SIZE;
more.x = x + w - BUTTON_SIZE;
more.y = less.y = quantity.y = y + h - BUTTON_SIZE;
less.x = x;
quantity.x = x + BUTTON_SIZE + 2;
quantity.w = more.x - quantity.x - 2;
} else {
quantity.x = (int) (x + (w * 0.7)) + 3;
quantity.y = y + h - BUTTON_SIZE;
quantity.w = (int) ((w * 0.3) - BUTTON_SIZE - 1);

more.h = less.h = BUTTON_SIZE / 2;
more.y = y + h - (more.h * 2);

less.x = more.x = quantity.x + quantity.w;
less.y = more.y + more.h;
}

if (NEIClientConfig.showHistoryPanelWidget()) {
historyPanel.x = x;
historyPanel.w = w;
historyPanel.h = ItemsGrid.SLOT_SIZE * NEIClientConfig.getIntSetting("inventory.history.useRows");

if (NEIClientConfig.showItemQuantityWidget() || !NEIClientConfig.isSearchWidgetCentered()) {
historyPanel.y = quantity.y - historyPanel.h - PanelWidget.PADDING;
return quantity.h + historyPanel.h + PanelWidget.PADDING * 2;
historyPanel.y = LayoutManager.quantity.y - historyPanel.h - PanelWidget.PADDING;
return LayoutManager.quantity.h + historyPanel.h + PanelWidget.PADDING * 2;
} else {
historyPanel.y = y + h - historyPanel.h;
return historyPanel.h + PanelWidget.PADDING;
}
}

return quantity.h + PanelWidget.PADDING;
return LayoutManager.quantity.h + PanelWidget.PADDING;
}

@Override
public void setVisible() {
super.setVisible();

if (grid.getPerPage() > 0) {
if (NEIClientConfig.showItemQuantityWidget()) {
LayoutManager.addWidget(more);
LayoutManager.addWidget(less);
LayoutManager.addWidget(quantity);
}

if (!CollapsibleItems.isEmpty() && !grid.isEmpty()) {
LayoutManager.addWidget(toggleGroups);
Expand Down
17 changes: 3 additions & 14 deletions src/main/java/codechicken/nei/ItemSorter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.StatCollector;

import codechicken.lib.config.ConfigTagParent;
import codechicken.nei.ItemList.ItemsLoadedCallback;
import codechicken.nei.api.API;
import codechicken.nei.api.ItemInfo;
import codechicken.nei.config.GuiItemSorter;
import codechicken.nei.config.OptionOpenGui;

public class ItemSorter implements Comparator<ItemStack>, ItemsLoadedCallback {
public class ItemSorter implements Comparator<ItemStack> {

public static class SortEntry {

Expand Down Expand Up @@ -44,12 +44,10 @@ public String getTooltip() {
public static final ItemSorter instance = new ItemSorter();

// optimisations
public HashMap<ItemStack, Integer> ordering = null;
public Map<ItemStack, Integer> ordering = new HashMap<>();

public static void sort(List<ItemStack> items) {
try {
// items = (ArrayList<ItemStack>)
// items.parallelStream().sorted(instance).collect(Collectors.toList());
items.sort(instance);
} catch (Exception e) {
NEIClientConfig.logger.error("Exception sorting item list", e);
Expand All @@ -65,14 +63,6 @@ public int compare(ItemStack o1, ItemStack o2) {
return 0;
}

@Override
public void itemsLoaded() {
HashMap<ItemStack, Integer> newMap = new HashMap<>();
int i = 0;
for (ItemStack stack : ItemList.items) newMap.put(stack, i++);
ordering = newMap;
}

public static SortEntry find(String name) {
for (SortEntry e : entries) if (e.name.equals(name)) return e;

Expand Down Expand Up @@ -136,7 +126,6 @@ public void useGlobals() {
list = fromSaveString(activeTag().getValue());
}
});
ItemList.loadCallbacks.add(instance);
}

public static String getSaveString(List<SortEntry> list) {
Expand Down
Loading

0 comments on commit 2448008

Please sign in to comment.