mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-16 10:44:45 +00:00
Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7ac3e32635 | ||
|
|
088d37a11a | ||
|
|
6a787dd5b7 | ||
|
|
c305649b95 | ||
|
|
b5d2815eab | ||
|
|
6049d0e9c3 |
No files matched your search
Vendored
BIN
Binary file not shown.
+1
-1
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ pluginManagement {
|
||||
}
|
||||
|
||||
plugins {
|
||||
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.29'
|
||||
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.30'
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -52,40 +52,15 @@ public class CollapsibleItems {
|
||||
|
||||
private static final String STATE_KEY = "collapsibleitems";
|
||||
|
||||
protected File statesFile;
|
||||
protected final List<GroupItem> groups = new ArrayList<>();
|
||||
protected final Map<ItemStack, Integer> cache = new ConcurrentHashMap<>();
|
||||
protected static File statesFile;
|
||||
protected static final List<GroupItem> groups = new ArrayList<>();
|
||||
protected static final Map<ItemStack, Integer> cache = new ConcurrentHashMap<>();
|
||||
|
||||
public void load() {
|
||||
try {
|
||||
private CollapsibleItems() {}
|
||||
|
||||
if (NEIClientConfig.world.nbt.hasKey(STATE_KEY)) {
|
||||
NBTTagCompound states = NEIClientConfig.world.nbt.getCompoundTag(STATE_KEY);
|
||||
@SuppressWarnings("unchecked")
|
||||
final Map<String, NBTPrimitive> list = (Map<String, NBTPrimitive>) states.tagMap;
|
||||
final Map<String, GroupItem> mapping = new HashMap<>();
|
||||
|
||||
for (GroupItem group : this.groups) {
|
||||
mapping.put(group.guid, group);
|
||||
}
|
||||
|
||||
for (Map.Entry<String, NBTPrimitive> nbtEntry : list.entrySet()) {
|
||||
if (mapping.containsKey(nbtEntry.getKey())) {
|
||||
mapping.get(nbtEntry.getKey()).expanded = nbtEntry.getValue().func_150290_f() == 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
NEIClientConfig.logger.error("Error loading collapsible items states", e);
|
||||
}
|
||||
|
||||
reloadGroups();
|
||||
}
|
||||
|
||||
public void reloadGroups() {
|
||||
this.groups.clear();
|
||||
this.cache.clear();
|
||||
public static void load() {
|
||||
CollapsibleItems.groups.clear();
|
||||
CollapsibleItems.cache.clear();
|
||||
|
||||
for (int i = PresetsList.presets.size() - 1; i >= 0; i--) {
|
||||
Preset preset = PresetsList.presets.get(i);
|
||||
@@ -102,9 +77,11 @@ public class CollapsibleItems {
|
||||
"collapsibleitems.cfg",
|
||||
lines -> parseFile(lines.collect(Collectors.toCollection(ArrayList::new))));
|
||||
}
|
||||
|
||||
loadStates();
|
||||
}
|
||||
|
||||
private void parseFile(List<String> itemStrings) {
|
||||
private static void parseFile(List<String> itemStrings) {
|
||||
final JsonParser parser = new JsonParser();
|
||||
GroupItem group = new GroupItem();
|
||||
|
||||
@@ -146,38 +123,39 @@ public class CollapsibleItems {
|
||||
}
|
||||
}
|
||||
|
||||
protected void addGroup(GroupItem group) {
|
||||
private static void addGroup(GroupItem group) {
|
||||
if (group == null || group.filter == null
|
||||
|| group.filter instanceof EverythingItemFilter
|
||||
|| group.filter instanceof NothingItemFilter)
|
||||
return;
|
||||
this.groups.add(group);
|
||||
CollapsibleItems.groups.add(group);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return this.groups.isEmpty();
|
||||
public static boolean isEmpty() {
|
||||
return CollapsibleItems.groups.isEmpty();
|
||||
}
|
||||
|
||||
public ItemFilter getItemFilter() {
|
||||
public static ItemFilter getItemFilter() {
|
||||
AnyMultiItemFilter filter = new AnyMultiItemFilter();
|
||||
|
||||
for (GroupItem group : this.groups) {
|
||||
for (GroupItem group : CollapsibleItems.groups) {
|
||||
filter.filters.add(group.filter);
|
||||
}
|
||||
|
||||
return filter;
|
||||
}
|
||||
|
||||
public void updateCache(final List<ItemStack> items) {
|
||||
this.cache.clear();
|
||||
public static void updateCache(final List<ItemStack> items) {
|
||||
CollapsibleItems.cache.clear();
|
||||
|
||||
try {
|
||||
|
||||
ItemList.forkJoinPool.submit(() -> items.parallelStream().forEach(stack -> {
|
||||
GroupItem group = this.groups.stream().filter(g -> g.matches(stack)).findFirst().orElse(null);
|
||||
GroupItem group = CollapsibleItems.groups.stream().filter(g -> g.matches(stack)).findFirst()
|
||||
.orElse(null);
|
||||
|
||||
if (group != null) {
|
||||
this.cache.put(stack, this.groups.indexOf(group));
|
||||
CollapsibleItems.cache.put(stack, CollapsibleItems.groups.indexOf(group));
|
||||
}
|
||||
})).get();
|
||||
|
||||
@@ -187,62 +165,89 @@ public class CollapsibleItems {
|
||||
|
||||
}
|
||||
|
||||
public int getGroupIndex(ItemStack stack) {
|
||||
public static int getGroupIndex(ItemStack stack) {
|
||||
|
||||
if (stack == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return this.cache.getOrDefault(stack, -1);
|
||||
return CollapsibleItems.cache.getOrDefault(stack, -1);
|
||||
}
|
||||
|
||||
public String getDisplayName(int groupIndex) {
|
||||
public static String getDisplayName(int groupIndex) {
|
||||
|
||||
if (groupIndex < this.groups.size()) {
|
||||
return this.groups.get(groupIndex).displayName;
|
||||
if (groupIndex < CollapsibleItems.groups.size()) {
|
||||
return CollapsibleItems.groups.get(groupIndex).displayName;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isExpanded(int groupIndex) {
|
||||
public static boolean isExpanded(int groupIndex) {
|
||||
|
||||
if (groupIndex < this.groups.size()) {
|
||||
return this.groups.get(groupIndex).expanded;
|
||||
if (groupIndex < CollapsibleItems.groups.size()) {
|
||||
return CollapsibleItems.groups.get(groupIndex).expanded;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setExpanded(int groupIndex, boolean expanded) {
|
||||
public static void setExpanded(int groupIndex, boolean expanded) {
|
||||
|
||||
if (groupIndex < this.groups.size()) {
|
||||
this.groups.get(groupIndex).expanded = expanded;
|
||||
saveStates();
|
||||
if (groupIndex < CollapsibleItems.groups.size()) {
|
||||
CollapsibleItems.groups.get(groupIndex).expanded = expanded;
|
||||
}
|
||||
}
|
||||
|
||||
public void toggleGroups(Boolean expanded) {
|
||||
public static void toggleGroups(Boolean expanded) {
|
||||
|
||||
if (expanded == null) {
|
||||
expanded = this.groups.stream().noneMatch(g -> g.expanded);
|
||||
expanded = CollapsibleItems.groups.stream().noneMatch(g -> g.expanded);
|
||||
}
|
||||
|
||||
for (GroupItem group : this.groups) {
|
||||
for (GroupItem group : CollapsibleItems.groups) {
|
||||
group.expanded = expanded;
|
||||
}
|
||||
|
||||
saveStates();
|
||||
}
|
||||
|
||||
private void saveStates() {
|
||||
public static void saveStates() {
|
||||
NBTTagCompound list = new NBTTagCompound();
|
||||
|
||||
for (GroupItem group : this.groups) {
|
||||
for (GroupItem group : CollapsibleItems.groups) {
|
||||
list.setBoolean(group.guid, group.expanded);
|
||||
}
|
||||
|
||||
NEIClientConfig.world.nbt.setTag(STATE_KEY, list);
|
||||
if (NEIClientConfig.world != null) {
|
||||
NEIClientConfig.world.nbt.setTag(STATE_KEY, list);
|
||||
}
|
||||
}
|
||||
|
||||
private static void loadStates() {
|
||||
|
||||
try {
|
||||
|
||||
if (NEIClientConfig.world.nbt.hasKey(STATE_KEY)) {
|
||||
NBTTagCompound states = NEIClientConfig.world.nbt.getCompoundTag(STATE_KEY);
|
||||
@SuppressWarnings("unchecked")
|
||||
final Map<String, NBTPrimitive> list = (Map<String, NBTPrimitive>) states.tagMap;
|
||||
final Map<String, GroupItem> mapping = new HashMap<>();
|
||||
|
||||
for (GroupItem group : CollapsibleItems.groups) {
|
||||
mapping.put(group.guid, group);
|
||||
}
|
||||
|
||||
for (Map.Entry<String, NBTPrimitive> nbtEntry : list.entrySet()) {
|
||||
if (mapping.containsKey(nbtEntry.getKey())) {
|
||||
mapping.get(nbtEntry.getKey()).expanded = nbtEntry.getValue().func_150290_f() == 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
NEIClientConfig.logger.error("Error loading collapsible items states", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -41,7 +41,6 @@ public class ItemList {
|
||||
*/
|
||||
public static final List<ItemFilterProvider> itemFilterers = new LinkedList<>();
|
||||
public static final List<ItemsLoadedCallback> loadCallbacks = new LinkedList<>();
|
||||
public static final CollapsibleItems collapsibleItems = new CollapsibleItems();
|
||||
|
||||
private static final HashSet<Item> erroredItems = new HashSet<>();
|
||||
private static final HashSet<String> stackTraces = new HashSet<>();
|
||||
@@ -239,12 +238,12 @@ public class ItemList {
|
||||
|
||||
ItemSorter.sort(items);
|
||||
|
||||
if (!ItemList.collapsibleItems.isEmpty()) {
|
||||
if (!CollapsibleItems.isEmpty()) {
|
||||
HashMap<Integer, Integer> groups = new HashMap<>();
|
||||
int orderIndex = 0;
|
||||
|
||||
for (ItemStack stack : items) {
|
||||
final int groupIndex = ItemList.collapsibleItems.getGroupIndex(stack);
|
||||
final int groupIndex = CollapsibleItems.getGroupIndex(stack);
|
||||
|
||||
if (groupIndex == -1) {
|
||||
ItemList.ordering.put(stack, orderIndex++);
|
||||
@@ -318,7 +317,7 @@ public class ItemList {
|
||||
for (ItemsLoadedCallback callback : loadCallbacks) callback.itemsLoaded();
|
||||
|
||||
if (interrupted()) return;
|
||||
ItemList.collapsibleItems.updateCache(items);
|
||||
CollapsibleItems.updateCache(items);
|
||||
updateOrdering(items);
|
||||
|
||||
loadFinished = true;
|
||||
|
||||
@@ -98,7 +98,7 @@ public class ItemPanel extends PanelWidget {
|
||||
this.groupItems.clear();
|
||||
this.forceExpand = false;
|
||||
|
||||
if (!ItemList.collapsibleItems.isEmpty() && !this.newItems.isEmpty()) {
|
||||
if (!CollapsibleItems.isEmpty() && !this.newItems.isEmpty()) {
|
||||
final Set<Integer> groups = new HashSet<>();
|
||||
boolean outsideGroup = false;
|
||||
|
||||
@@ -106,14 +106,14 @@ public class ItemPanel extends PanelWidget {
|
||||
this.rawItems = new ArrayList<>(this.newItems);
|
||||
|
||||
for (ItemStack stack : this.newItems) {
|
||||
final int groupIndex = ItemList.collapsibleItems.getGroupIndex(stack);
|
||||
final int groupIndex = CollapsibleItems.getGroupIndex(stack);
|
||||
|
||||
if (groupIndex == -1) {
|
||||
this.realItems.add(stack);
|
||||
outsideGroup = true;
|
||||
} else {
|
||||
|
||||
if (!groups.contains(groupIndex) || ItemList.collapsibleItems.isExpanded(groupIndex)) {
|
||||
if (!groups.contains(groupIndex) || CollapsibleItems.isExpanded(groupIndex)) {
|
||||
this.realItems.add(stack);
|
||||
groups.add(groupIndex);
|
||||
}
|
||||
@@ -175,7 +175,7 @@ public class ItemPanel extends PanelWidget {
|
||||
}
|
||||
|
||||
int idx = mask.get(slotIndex);
|
||||
maskGroup.put(idx, ItemList.collapsibleItems.getGroupIndex(getItem(idx)));
|
||||
maskGroup.put(idx, CollapsibleItems.getGroupIndex(getItem(idx)));
|
||||
}
|
||||
|
||||
for (int slotIndex = 0; slotIndex < mask.size(); slotIndex++) {
|
||||
@@ -197,8 +197,8 @@ public class ItemPanel extends PanelWidget {
|
||||
MaskMetadata metadata = new MaskMetadata();
|
||||
|
||||
metadata.groupIndex = groupIndex;
|
||||
metadata.displayName = ItemList.collapsibleItems.getDisplayName(groupIndex);
|
||||
metadata.extended = this.forceExpand || ItemList.collapsibleItems.isExpanded(groupIndex);
|
||||
metadata.displayName = CollapsibleItems.getDisplayName(groupIndex);
|
||||
metadata.extended = this.forceExpand || CollapsibleItems.isExpanded(groupIndex);
|
||||
metadata.bgColor = metadata.extended ? expandedColor : collapsedColor;
|
||||
metadata.color = darkerColor(metadata.bgColor);
|
||||
metadata.left = column == 0 || idx == 0
|
||||
@@ -339,7 +339,7 @@ public class ItemPanel extends PanelWidget {
|
||||
|
||||
@Override
|
||||
public boolean onButtonPress(boolean rightclick) {
|
||||
ItemList.collapsibleItems.toggleGroups(rightclick ? false : null);
|
||||
CollapsibleItems.toggleGroups(rightclick ? false : null);
|
||||
ItemList.updateFilter.restart();
|
||||
return true;
|
||||
}
|
||||
@@ -482,7 +482,7 @@ public class ItemPanel extends PanelWidget {
|
||||
LayoutManager.addWidget(quantity);
|
||||
}
|
||||
|
||||
if (!ItemList.collapsibleItems.isEmpty()) {
|
||||
if (!CollapsibleItems.isEmpty()) {
|
||||
LayoutManager.addWidget(toggleGroups);
|
||||
}
|
||||
|
||||
@@ -560,7 +560,7 @@ public class ItemPanel extends PanelWidget {
|
||||
final MaskMetadata metadata = panelGrid.maskMetadata.get(hoverSlot.slotIndex);
|
||||
|
||||
if (metadata != null) {
|
||||
ItemList.collapsibleItems.setExpanded(metadata.groupIndex, !metadata.extended);
|
||||
CollapsibleItems.setExpanded(metadata.groupIndex, !metadata.extended);
|
||||
panelGrid.setItems(panelGrid.rawItems);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -255,7 +255,8 @@ public class NEIClientConfig {
|
||||
@Override
|
||||
public boolean onClick(int button) {
|
||||
super.onClick(button);
|
||||
ItemList.collapsibleItems.reloadGroups();
|
||||
CollapsibleItems.saveStates();
|
||||
CollapsibleItems.load();
|
||||
LayoutManager.markItemsDirty();
|
||||
return true;
|
||||
}
|
||||
@@ -431,7 +432,15 @@ public class NEIClientConfig {
|
||||
API.addOption(new OptionCycled("inventory.search.widgetAutofocus", 3, true));
|
||||
|
||||
tag.getTag("inventory.search.patternMode").setComment("Search Mode").getIntValue(1);
|
||||
API.addOption(new OptionCycled("inventory.search.patternMode", 3, true));
|
||||
API.addOption(new OptionCycled("inventory.search.patternMode", 3, true) {
|
||||
|
||||
@Override
|
||||
public boolean onClick(int button) {
|
||||
SearchField.searchParser.clearCache();
|
||||
return super.onClick(button);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
tag.getTag("inventory.search.quoteDropItemName").setComment("Quote Drop Item Name").getBooleanValue(true);
|
||||
API.addOption(new OptionToggleButton("inventory.search.quoteDropItemName", true));
|
||||
@@ -457,6 +466,7 @@ public class NEIClientConfig {
|
||||
SearchField.searchParser.prefixRedefinitions.clear();
|
||||
SearchField.searchParser.prefixRedefinitions.put('%', '@');
|
||||
SearchField.searchParser.prefixRedefinitions.put('@', '%');
|
||||
SearchField.searchParser.clearCache();
|
||||
} else {
|
||||
NEIClientConfig.setIntSetting("inventory.search.modNameSearchMode", 1);
|
||||
NEIClientConfig.setIntSetting("inventory.search.tooltipSearchMode", 0);
|
||||
@@ -465,6 +475,7 @@ public class NEIClientConfig {
|
||||
NEIClientConfig.setIntSetting("inventory.search.subsetsSearchMode", 1);
|
||||
tag.getTag("inventory.search.prefixRedefinitions").setValue("{}");
|
||||
SearchField.searchParser.prefixRedefinitions.clear();
|
||||
SearchField.searchParser.clearCache();
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -476,6 +487,12 @@ public class NEIClientConfig {
|
||||
.getIntValue(1);
|
||||
API.addOption(new OptionCycled("inventory.search.modNameSearchMode", 3, true) {
|
||||
|
||||
@Override
|
||||
public boolean onClick(int button) {
|
||||
SearchField.searchParser.clearCache();
|
||||
return super.onClick(button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getButtonText() {
|
||||
return translateN(
|
||||
@@ -495,6 +512,12 @@ public class NEIClientConfig {
|
||||
.getIntValue(0);
|
||||
API.addOption(new OptionCycled("inventory.search.tooltipSearchMode", 3, true) {
|
||||
|
||||
@Override
|
||||
public boolean onClick(int button) {
|
||||
SearchField.searchParser.clearCache();
|
||||
return super.onClick(button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getButtonText() {
|
||||
return translateN(
|
||||
@@ -513,6 +536,12 @@ public class NEIClientConfig {
|
||||
.getIntValue(0);
|
||||
API.addOption(new OptionCycled("inventory.search.identifierSearchMode", 3, true) {
|
||||
|
||||
@Override
|
||||
public boolean onClick(int button) {
|
||||
SearchField.searchParser.clearCache();
|
||||
return super.onClick(button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getButtonText() {
|
||||
return translateN(
|
||||
@@ -531,6 +560,12 @@ public class NEIClientConfig {
|
||||
.getIntValue(0);
|
||||
API.addOption(new OptionCycled("inventory.search.oreDictSearchMode", 3, true) {
|
||||
|
||||
@Override
|
||||
public boolean onClick(int button) {
|
||||
SearchField.searchParser.clearCache();
|
||||
return super.onClick(button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getButtonText() {
|
||||
return translateN(
|
||||
@@ -549,6 +584,12 @@ public class NEIClientConfig {
|
||||
.getIntValue(1);
|
||||
API.addOption(new OptionCycled("inventory.search.subsetsSearchMode", 3, true) {
|
||||
|
||||
@Override
|
||||
public boolean onClick(int button) {
|
||||
SearchField.searchParser.clearCache();
|
||||
return super.onClick(button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getButtonText() {
|
||||
return translateN(
|
||||
@@ -650,6 +691,7 @@ public class NEIClientConfig {
|
||||
|
||||
world = new ConfigSet(new File(specificDir, "NEI.dat"), new ConfigFile(new File(specificDir, "NEI.cfg")));
|
||||
bootNEI(ClientUtils.getWorld());
|
||||
CollapsibleItems.load();
|
||||
ItemPanels.bookmarkPanel.load();
|
||||
onWorldLoad(newWorld);
|
||||
}
|
||||
@@ -688,6 +730,8 @@ public class NEIClientConfig {
|
||||
ItemPanels.bookmarkPanel.saveBookmarks();
|
||||
}
|
||||
|
||||
CollapsibleItems.saveStates();
|
||||
|
||||
if (world != null) {
|
||||
world.saveNBT();
|
||||
}
|
||||
@@ -720,48 +764,50 @@ public class NEIClientConfig {
|
||||
}
|
||||
|
||||
public static void bootNEI(World world) {
|
||||
if (mainNEIConfigLoaded) return;
|
||||
if (!mainNEIConfigLoaded) {
|
||||
// main NEI config loading
|
||||
ItemInfo.load(world);
|
||||
GuiInfo.load();
|
||||
RecipeInfo.load();
|
||||
HeldItemHandler.load();
|
||||
LayoutManager.load();
|
||||
NEIController.load();
|
||||
BookmarkContainerInfo.load();
|
||||
mainNEIConfigLoaded = true;
|
||||
|
||||
// main NEI config loading
|
||||
ItemInfo.load(world);
|
||||
GuiInfo.load();
|
||||
RecipeInfo.load();
|
||||
HeldItemHandler.load();
|
||||
LayoutManager.load();
|
||||
NEIController.load();
|
||||
BookmarkContainerInfo.load();
|
||||
mainNEIConfigLoaded = true;
|
||||
new Thread("NEI Plugin Loader") {
|
||||
|
||||
new Thread("NEI Plugin Loader") {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
NEIClientConfig.pluginsList.parallelStream().forEach(clazz -> {
|
||||
try {
|
||||
IConfigureNEI config = (IConfigureNEI) clazz.getConstructor().newInstance();
|
||||
config.loadConfig();
|
||||
NEIModContainer.plugins.add(config);
|
||||
logger.debug("Loaded {}", clazz.getName());
|
||||
} catch (Throwable e) {
|
||||
logger.error("Failed to Load {}", clazz.getName(), e);
|
||||
}
|
||||
});
|
||||
|
||||
NEIClientConfig.pluginsList.parallelStream().forEach(clazz -> {
|
||||
try {
|
||||
IConfigureNEI config = (IConfigureNEI) clazz.getConstructor().newInstance();
|
||||
config.loadConfig();
|
||||
NEIModContainer.plugins.add(config);
|
||||
logger.debug("Loaded {}", clazz.getName());
|
||||
} catch (Throwable e) {
|
||||
logger.error("Failed to Load {}", clazz.getName(), e);
|
||||
}
|
||||
});
|
||||
RecipeCatalysts.loadCatalystInfo();
|
||||
ItemSorter.loadConfig();
|
||||
|
||||
RecipeCatalysts.loadCatalystInfo();
|
||||
ItemSorter.loadConfig();
|
||||
// Set pluginNEIConfigLoaded here before posting the NEIConfigsLoadedEvent. This used to be the
|
||||
// other way around, but apparently if your modpack includes 800 mods the event poster might not
|
||||
// return in time and cause issues when loading a world for a second time as configLoaded is still
|
||||
// false. This may cause issues in case one of the event handler calls the (non-thread-safe) NEI
|
||||
// API. I don't expect any handler to do this, but who knows what modders have come up with...
|
||||
pluginNEIConfigLoaded = true;
|
||||
MinecraftForge.EVENT_BUS.post(new NEIConfigsLoadedEvent());
|
||||
|
||||
// Set pluginNEIConfigLoaded here before posting the NEIConfigsLoadedEvent. This used to be the other
|
||||
// way around, but apparently if your modpack includes 800 mods the event poster might not return in
|
||||
// time and cause issues when loading a world for a second time as configLoaded is still false. This may
|
||||
// cause issues in case one of the event handler calls the (non-thread-safe) NEI API. I don't expect any
|
||||
// handler to do this, but who knows what modders have come up with...
|
||||
pluginNEIConfigLoaded = true;
|
||||
MinecraftForge.EVENT_BUS.post(new NEIConfigsLoadedEvent());
|
||||
|
||||
ItemList.loadItems.restart();
|
||||
}
|
||||
}.start();
|
||||
ItemList.loadItems.restart();
|
||||
}
|
||||
}.start();
|
||||
} else {
|
||||
ItemList.loadItems.restart();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isWorldSpecific(String setting) {
|
||||
|
||||
@@ -241,7 +241,8 @@ public class PresetsList {
|
||||
|
||||
recipeFilter.cache = null;
|
||||
itemFilter.cache = null;
|
||||
ItemList.collapsibleItems.reloadGroups();
|
||||
CollapsibleItems.saveStates();
|
||||
CollapsibleItems.load();
|
||||
LayoutManager.markItemsDirty();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package codechicken.nei;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -86,6 +87,16 @@ public class SearchTokenParser {
|
||||
}
|
||||
}
|
||||
|
||||
private final LinkedHashMap<String, ItemFilter> filtersCache = new LinkedHashMap<>() {
|
||||
|
||||
private static final long serialVersionUID = 1042213947848622164L;
|
||||
|
||||
@Override
|
||||
protected boolean removeEldestEntry(Map.Entry<String, ItemFilter> eldest) {
|
||||
return size() > 20;
|
||||
}
|
||||
};
|
||||
|
||||
protected final List<ISearchParserProvider> searchProviders;
|
||||
protected final ProvidersCache providersCache = new ProvidersCache();
|
||||
protected final TCharCharMap prefixRedefinitions = new TCharCharHashMap();
|
||||
@@ -101,6 +112,11 @@ public class SearchTokenParser {
|
||||
public void addProvider(ISearchParserProvider provider) {
|
||||
this.searchProviders.add(provider);
|
||||
this.providersCache.clear();
|
||||
this.filtersCache.clear();
|
||||
}
|
||||
|
||||
public void clearCache() {
|
||||
this.filtersCache.clear();
|
||||
}
|
||||
|
||||
protected List<ISearchParserProvider> getProviders() {
|
||||
@@ -133,18 +149,24 @@ public class SearchTokenParser {
|
||||
.findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public ItemFilter getFilter(String filterText) {
|
||||
final String[] parts = EnumChatFormatting.getTextWithoutFormattingCodes(filterText).toLowerCase().split("\\|");
|
||||
final List<ItemFilter> searchTokens = Arrays.stream(parts).map(this::parseSearchText).filter(s -> s != null)
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
public synchronized ItemFilter getFilter(String filterText) {
|
||||
filterText = EnumChatFormatting.getTextWithoutFormattingCodes(filterText).toLowerCase();
|
||||
|
||||
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));
|
||||
|
||||
if (searchTokens.isEmpty()) {
|
||||
return new EverythingItemFilter();
|
||||
} else if (searchTokens.size() == 1) {
|
||||
return new IsRegisteredItemFilter(searchTokens.get(0));
|
||||
} else {
|
||||
return new IsRegisteredItemFilter(new AnyMultiItemFilter(searchTokens));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
if (searchTokens.isEmpty()) {
|
||||
return new EverythingItemFilter();
|
||||
} else if (searchTokens.size() == 1) {
|
||||
return new IsRegisteredItemFilter(searchTokens.get(0));
|
||||
} else {
|
||||
return new IsRegisteredItemFilter(new AnyMultiItemFilter(searchTokens));
|
||||
}
|
||||
}
|
||||
|
||||
public Pattern getSplitPattern() {
|
||||
|
||||
@@ -136,7 +136,6 @@ public class ItemInfo {
|
||||
addIDDumps();
|
||||
addSearchProviders();
|
||||
PresetsList.load();
|
||||
ItemList.collapsibleItems.load();
|
||||
ItemList.loadCallbacks.add(TooltipFilter::populateSearchMap);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import org.lwjgl.opengl.GL12;
|
||||
import codechicken.core.gui.GuiWidget;
|
||||
import codechicken.lib.gui.GuiDraw;
|
||||
import codechicken.lib.vec.Rectangle4i;
|
||||
import codechicken.nei.ItemList;
|
||||
import codechicken.nei.CollapsibleItems;
|
||||
import codechicken.nei.ItemList.AllMultiItemFilter;
|
||||
import codechicken.nei.ItemList.AnyMultiItemFilter;
|
||||
import codechicken.nei.ItemList.NegatedItemFilter;
|
||||
@@ -142,7 +142,7 @@ public class RightPanel extends GuiWidget {
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
andFilter.filters.add(item -> !identifiers.contains(Preset.getIdentifier(item)));
|
||||
andFilter.filters.add(new NegatedItemFilter(ItemList.collapsibleItems.getItemFilter()));
|
||||
andFilter.filters.add(new NegatedItemFilter(CollapsibleItems.getItemFilter()));
|
||||
|
||||
if (slotIndex != -1) {
|
||||
orFilter.filters.add(PresetsList.presets.get(slotIndex));
|
||||
|
||||
@@ -43,7 +43,9 @@ import codechicken.lib.gui.GuiDraw;
|
||||
import codechicken.nei.ItemStackSet;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.SearchField;
|
||||
import codechicken.nei.recipe.StackInfo;
|
||||
import codechicken.nei.search.TooltipFilter;
|
||||
import codechicken.nei.util.ReadableNumberConverter;
|
||||
|
||||
public class GuiContainerManager {
|
||||
@@ -53,6 +55,8 @@ public class GuiContainerManager {
|
||||
@Override
|
||||
public void onResourceManagerReload(IResourceManager p_110549_1_) {
|
||||
renderingErrorItems.clear();
|
||||
TooltipFilter.populateSearchMap();
|
||||
SearchField.searchParser.clearCache();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,13 +8,14 @@ import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -311,7 +312,7 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
|
||||
public static class RecipeTransferRectHandler implements IContainerInputHandler, IContainerTooltipHandler {
|
||||
|
||||
private static final HashMap<Class<? extends GuiContainer>, HashSet<RecipeTransferRect>> guiMap = new HashMap<>();
|
||||
private static final Map<Class<? extends GuiContainer>, HashSet<RecipeTransferRect>> guiMap = new ConcurrentHashMap<>();
|
||||
|
||||
public static void registerRectsToGuis(List<Class<? extends GuiContainer>> classes,
|
||||
List<RecipeTransferRect> rects) {
|
||||
|
||||
@@ -1,48 +1,19 @@
|
||||
package codechicken.nei.search;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
import codechicken.nei.ItemList;
|
||||
import codechicken.nei.ItemStackMap;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.api.ItemFilter;
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
|
||||
public class TooltipFilter implements ItemFilter {
|
||||
|
||||
// lookup optimisation
|
||||
private static final ConcurrentHashMap<ItemStackKey, String> itemSearchNames = new ConcurrentHashMap<>();
|
||||
|
||||
private static class ItemStackKey {
|
||||
|
||||
public final ItemStack stack;
|
||||
|
||||
public ItemStackKey(ItemStack stack) {
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
if (this.stack == null) return 1;
|
||||
int hashCode = 1;
|
||||
hashCode = 31 * hashCode + stack.stackSize;
|
||||
hashCode = 31 * hashCode + Item.getIdFromItem(stack.getItem());
|
||||
hashCode = 31 * hashCode + stack.getItemDamage();
|
||||
hashCode = 31 * hashCode + (!stack.hasTagCompound() ? 0 : stack.getTagCompound().hashCode());
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof ItemStackKey)) return false;
|
||||
return ItemStack.areItemStacksEqual(this.stack, ((ItemStackKey) o).stack);
|
||||
}
|
||||
}
|
||||
private static final ItemStackMap<String> itemSearchNames = new ItemStackMap<>();
|
||||
|
||||
private final Pattern pattern;
|
||||
|
||||
@@ -56,22 +27,39 @@ public class TooltipFilter implements ItemFilter {
|
||||
}
|
||||
|
||||
public static void populateSearchMap() {
|
||||
new Thread("NEI populate Tooltip Filter") {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
ItemList.items.parallelStream().forEach(TooltipFilter::getSearchTooltip);
|
||||
}
|
||||
}.start();
|
||||
itemSearchNames.clear();
|
||||
new Thread(
|
||||
() -> ItemList.items.parallelStream().forEach(TooltipFilter::getSearchTooltip),
|
||||
"NEI populate Tooltip Filter").start();
|
||||
}
|
||||
|
||||
protected static String getSearchTooltip(ItemStack stack) {
|
||||
return itemSearchNames.computeIfAbsent(new ItemStackKey(stack), key -> getTooltip(key.stack));
|
||||
String tooltip = itemSearchNames.get(stack);
|
||||
|
||||
if (tooltip == null) {
|
||||
tooltip = getTooltip(stack.copy());
|
||||
|
||||
synchronized (itemSearchNames) {
|
||||
itemSearchNames.put(stack, tooltip);
|
||||
}
|
||||
}
|
||||
|
||||
return tooltip;
|
||||
}
|
||||
|
||||
private static String getTooltip(ItemStack itemstack) {
|
||||
final List<String> list = GuiContainerManager.itemDisplayNameMultiline(itemstack, null, true);
|
||||
return EnumChatFormatting.getTextWithoutFormattingCodes(String.join("\n", list.subList(1, list.size())));
|
||||
|
||||
try {
|
||||
List<String> namelist = itemstack.getTooltip(NEIClientUtils.mc().thePlayer, false);
|
||||
|
||||
if (namelist.size() > 1) {
|
||||
return EnumChatFormatting
|
||||
.getTextWithoutFormattingCodes(String.join("\n", namelist.subList(1, namelist.size())));
|
||||
}
|
||||
|
||||
} catch (Throwable ignored) {}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,7 +21,7 @@
|
||||
minecraft:spawn_egg
|
||||
minecraft:mob_spawner
|
||||
minecraft:record_
|
||||
#splash
|
||||
minecraft:potion >16000
|
||||
#lingering
|
||||
minecraft:potion >8000 <9000
|
||||
#splash potion
|
||||
minecraft:potion 16000-17000
|
||||
#lingering potion
|
||||
minecraft:potion 8000-9000
|
||||
Reference in new issue
Block a user