diff options
| author | shedaniel <daniel@shedaniel.me> | 2023-02-01 02:18:42 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2024-04-16 00:38:18 +0900 |
| commit | 8b8ded201bda1597bb8bacdda7f9882d6026976f (patch) | |
| tree | d8cc138c113ba3c2ee1074df886ed7db64d81eee /runtime/src/main/java/me/shedaniel/rei/impl/common | |
| parent | 45bffbf6342f77da096f12f967db6b4553e34d0f (diff) | |
| download | RoughlyEnoughItems-8b8ded201bda1597bb8bacdda7f9882d6026976f.tar.gz RoughlyEnoughItems-8b8ded201bda1597bb8bacdda7f9882d6026976f.tar.bz2 RoughlyEnoughItems-8b8ded201bda1597bb8bacdda7f9882d6026976f.zip | |
Close #1249
Diffstat (limited to 'runtime/src/main/java/me/shedaniel/rei/impl/common')
4 files changed, 51 insertions, 7 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryImpl.java index 811f95f53..d285bec8d 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryImpl.java @@ -118,7 +118,11 @@ public class EntryRegistryImpl implements EntryRegistry { @Override public List<EntryStack<?>> getPreFilteredList() { - return Collections.unmodifiableList(filteredList.getList()); + return Collections.unmodifiableList(filteredList.getUnwrappedList()); + } + + public FilteredEntryList getFilteredList() { + return filteredList; } public List<HNEntryStackWrapper> getPreFilteredComplexList() { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/FilteredEntryList.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/FilteredEntryList.java index efe289659..6dea48816 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/FilteredEntryList.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/FilteredEntryList.java @@ -38,7 +38,9 @@ public interface FilteredEntryList extends EntryRegistryListener { void refreshFilteringFor(boolean log, @Nullable Set<FilteringRule<?>> refilterRules, Collection<EntryStack<?>> stacks, @Nullable LongCollection hashes); - List<EntryStack<?>> getList(); + List<HashedEntryStackWrapper> getList(); + + List<EntryStack<?>> getUnwrappedList(); List<HNEntryStackWrapper> getComplexList(); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/PreFilteredEntryList.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/PreFilteredEntryList.java index 3133afb20..78376daa2 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/PreFilteredEntryList.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/PreFilteredEntryList.java @@ -212,13 +212,13 @@ public class PreFilteredEntryList implements FilteredEntryList { } @Override - public List<EntryStack<?>> getList() { - return simpleListView; + public List<HNEntryStackWrapper> getList() { + return listView; } @Override - public List<HNEntryStackWrapper> getComplexList() { - return listView; + public List<EntryStack<?>> getUnwrappedList() { + return simpleListView; } private class InternalListView extends AbstractList<HNEntryStackWrapper> { @@ -291,7 +291,18 @@ public class PreFilteredEntryList implements FilteredEntryList { @Override public Iterator<EntryStack<?>> iterator() { - return Iterators.transform(list.iterator(), HNEntryStackWrapper::unwrap); + Iterator<HNEntryStackWrapper> iterator = list.iterator(); + return new Iterator<>() { + @Override + public boolean hasNext() { + return iterator.hasNext(); + } + + @Override + public EntryStack<?> next() { + return iterator.next().unwrap(); + } + }; } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/collapsed/CollapsibleEntryRegistryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/collapsed/CollapsibleEntryRegistryImpl.java index 50f57d3bc..fbb1428de 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/collapsed/CollapsibleEntryRegistryImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/collapsed/CollapsibleEntryRegistryImpl.java @@ -23,13 +23,16 @@ package me.shedaniel.rei.impl.common.entry.type.collapsed; +import me.shedaniel.rei.api.client.config.entry.EntryStackProvider; import me.shedaniel.rei.api.client.plugins.REIClientPlugin; import me.shedaniel.rei.api.client.registry.entry.CollapsibleEntryRegistry; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.util.CollectionUtils; +import me.shedaniel.rei.impl.client.config.collapsible.CollapsibleConfigManager; import me.shedaniel.rei.impl.common.InternalLogger; import me.shedaniel.rei.impl.common.util.HashedEntryStackWrapper; import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; import net.minecraft.resources.ResourceLocation; import java.util.*; @@ -38,6 +41,7 @@ import java.util.stream.Collectors; public class CollapsibleEntryRegistryImpl implements CollapsibleEntryRegistry { private final Map<ResourceLocation, Entry> entries = new LinkedHashMap<>(); + private final List<Entry> customEntries = new ArrayList<>(); @Override public <T> void group(ResourceLocation id, Component name, List<? extends EntryStack<? extends T>> stacks) { @@ -70,6 +74,7 @@ public class CollapsibleEntryRegistryImpl implements CollapsibleEntryRegistry { @Override public void endReload() { + this.recollectCustomEntries(); InternalLogger.getInstance().debug("Registered %d collapsible entry groups: %s", entries.values().size(), entries.values().stream().map(entry -> entry.getName().getString()).collect(Collectors.joining(", "))); } @@ -79,10 +84,28 @@ public class CollapsibleEntryRegistryImpl implements CollapsibleEntryRegistry { plugin.registerCollapsibleEntries(this); } + public void recollectCustomEntries() { + InternalLogger.getInstance().debug("Recollecting custom collapsible entry groups"); + this.customEntries.clear(); + for (CollapsibleConfigManager.CustomGroup customEntry : CollapsibleConfigManager.getInstance().getConfig().customGroups) { + List<? extends EntryStack<?>> stacks = CollectionUtils.filterAndMap(customEntry.stacks, EntryStackProvider::isValid, EntryStackProvider::provide); + Entry entry = new Entry(customEntry.id, new TextComponent(customEntry.name), + new ListMatcher(stacks)); + this.customEntries.add(entry); + InternalLogger.getInstance().debug("Added custom collapsible entry group [%s] %s with %d entries", entry.getId(), entry.getName().getString(), stacks.size()); + } + InternalLogger.getInstance().debug("Registered %d custom collapsible entry groups: ", customEntries.size(), + customEntries.stream().map(entry -> entry.getName().getString()).collect(Collectors.joining(", "))); + } + public Collection<Entry> getEntries() { return entries.values(); } + public List<Entry> getCustomEntries() { + return customEntries; + } + public static class Entry { private final ResourceLocation id; private final Component name; @@ -101,6 +124,10 @@ public class CollapsibleEntryRegistryImpl implements CollapsibleEntryRegistry { return id; } + public ResourceLocation getId() { + return id; + } + public String getModId() { return id.getNamespace(); } |
