diff options
| author | shedaniel <daniel@shedaniel.me> | 2023-10-23 21:52:30 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2023-10-23 21:53:29 +0800 |
| commit | 11278f48effaa9a7ccc212ce0a047e356d9c4859 (patch) | |
| tree | 14232c052a102a9ec50ea844ba3b9f9b0c294fc5 /runtime/src/main/java/me/shedaniel/rei/impl/common | |
| parent | b1e8b40fba11fc523eb514f3e7fa004cf9de6980 (diff) | |
| parent | 032a0ff4989fdb276e0b4c8b6b15bb60ac723bff (diff) | |
| download | RoughlyEnoughItems-11278f48effaa9a7ccc212ce0a047e356d9c4859.tar.gz RoughlyEnoughItems-11278f48effaa9a7ccc212ce0a047e356d9c4859.tar.bz2 RoughlyEnoughItems-11278f48effaa9a7ccc212ce0a047e356d9c4859.zip | |
Merge remote-tracking branch 'origin/9.x-1.19' into 11.x-1.19.4
# Conflicts:
# runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/CraftableFilterButtonWidget.java
# runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryListImpl.java
Diffstat (limited to 'runtime/src/main/java/me/shedaniel/rei/impl/common')
8 files changed, 98 insertions, 37 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 942e61ad8..c756205e3 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 @@ -35,7 +35,7 @@ import me.shedaniel.rei.api.common.registry.ReloadStage; import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.api.common.util.EntryStacks; import me.shedaniel.rei.impl.common.InternalLogger; -import me.shedaniel.rei.impl.common.util.HashedEntryStackWrapper; +import me.shedaniel.rei.impl.common.util.HNEntryStackWrapper; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.world.item.Item; @@ -76,7 +76,7 @@ public class EntryRegistryImpl implements EntryRegistry { @Override public void startReload() { this.listeners.clear(); - this.registryList.collectHashed().clear(); + this.registryList.collectHN().clear(); this.entriesHash = new LongOpenHashSet(); this.filteredList = new PreFilteredEntryList(this, this.registryList); this.listeners.add(filteredList); @@ -116,17 +116,17 @@ public class EntryRegistryImpl implements EntryRegistry { return Collections.unmodifiableList(filteredList.getList()); } - public List<HashedEntryStackWrapper> getPreFilteredComplexList() { + public List<HNEntryStackWrapper> getPreFilteredComplexList() { return Collections.unmodifiableList(filteredList.getComplexList()); } - public List<HashedEntryStackWrapper> getComplexList() { - return Collections.unmodifiableList(registryList.collectHashed()); + public List<HNEntryStackWrapper> getComplexList() { + return Collections.unmodifiableList(registryList.collectHN()); } @Override public void refilter() { - List<HashedEntryStackWrapper> stacks = registryList.collectHashed(); + List<HNEntryStackWrapper> stacks = registryList.collectHN(); for (EntryRegistryListener listener : listeners) { listener.onReFilter(stacks); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryList.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryList.java index 5b39024d8..101743097 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryList.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryList.java @@ -25,7 +25,7 @@ package me.shedaniel.rei.impl.common.entry.type; import it.unimi.dsi.fastutil.longs.LongList; import me.shedaniel.rei.api.common.entry.EntryStack; -import me.shedaniel.rei.impl.common.util.HashedEntryStackWrapper; +import me.shedaniel.rei.impl.common.util.HNEntryStackWrapper; import java.util.List; import java.util.stream.Stream; @@ -37,7 +37,7 @@ public interface EntryRegistryList { List<EntryStack<?>> collect(); - List<HashedEntryStackWrapper> collectHashed(); + List<HNEntryStackWrapper> collectHN(); int indexOf(EntryStack<?> stack); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryListImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryListImpl.java index d82343d49..6c260455a 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryListImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryListImpl.java @@ -25,6 +25,7 @@ package me.shedaniel.rei.impl.common.entry.type; import it.unimi.dsi.fastutil.longs.LongList; import me.shedaniel.rei.api.common.entry.EntryStack; +import me.shedaniel.rei.impl.common.util.HNEntryStackWrapper; import me.shedaniel.rei.impl.common.util.HashedEntryStackWrapper; import net.minecraft.core.registries.BuiltInRegistries; @@ -35,7 +36,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; public class EntryRegistryListImpl implements EntryRegistryList { - private final List<HashedEntryStackWrapper> hashedList = new ArrayList<>(BuiltInRegistries.ITEM.keySet().size() + 100); + private final List<HNEntryStackWrapper> hashedList = new ArrayList<>(BuiltInRegistries.ITEM.keySet().size() + 100); private final List<EntryStack<?>> list = createMappedList(hashedList); public EntryRegistryListImpl() { @@ -61,7 +62,7 @@ public class EntryRegistryListImpl implements EntryRegistryList { } @Override - public List<HashedEntryStackWrapper> collectHashed() { + public List<HNEntryStackWrapper> collectHN() { return hashedList; } @@ -77,20 +78,20 @@ public class EntryRegistryListImpl implements EntryRegistryList { @Override public void add(EntryStack<?> stack, long hashExact) { - hashedList.add(new HashedEntryStackWrapper(stack, hashExact)); + hashedList.add(new HNEntryStackWrapper(stack, hashExact)); } @Override public void add(int index, EntryStack<?> stack, long hashExact) { - hashedList.add(index, new HashedEntryStackWrapper(stack, hashExact)); + hashedList.add(index, new HNEntryStackWrapper(stack, hashExact)); } @Override public void addAll(List<EntryStack<?>> stacks, LongList hashes) { hashedList.addAll(new AbstractList<>() { @Override - public HashedEntryStackWrapper get(int index) { - return new HashedEntryStackWrapper(stacks.get(index), hashes.getLong(index)); + public HNEntryStackWrapper get(int index) { + return new HNEntryStackWrapper(stacks.get(index), hashes.getLong(index)); } @Override @@ -104,8 +105,8 @@ public class EntryRegistryListImpl implements EntryRegistryList { public void addAll(int index, List<EntryStack<?>> stacks, LongList hashes) { hashedList.addAll(index, new AbstractList<>() { @Override - public HashedEntryStackWrapper get(int index) { - return new HashedEntryStackWrapper(stacks.get(index), hashes.getLong(index)); + public HNEntryStackWrapper get(int index) { + return new HNEntryStackWrapper(stacks.get(index), hashes.getLong(index)); } @Override @@ -134,7 +135,7 @@ public class EntryRegistryListImpl implements EntryRegistryList { return list; } - private static List<EntryStack<?>> createMappedList(List<HashedEntryStackWrapper> hashedList) { + private static List<EntryStack<?>> createMappedList(List<HNEntryStackWrapper> hashedList) { return new AbstractList<>() { @Override public EntryStack<?> get(int index) { @@ -148,12 +149,12 @@ public class EntryRegistryListImpl implements EntryRegistryList { @Override public void add(int index, EntryStack<?> element) { - hashedList.add(index, new HashedEntryStackWrapper(element)); + hashedList.add(index, new HNEntryStackWrapper(element)); } @Override public EntryStack<?> set(int index, EntryStack<?> element) { - return hashedList.set(index, new HashedEntryStackWrapper(element)).unwrap(); + return hashedList.set(index, new HNEntryStackWrapper(element)).unwrap(); } @Override diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryListener.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryListener.java index df91ea28f..2d0f3d238 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryListener.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryListener.java @@ -25,7 +25,7 @@ package me.shedaniel.rei.impl.common.entry.type; import it.unimi.dsi.fastutil.longs.LongList; import me.shedaniel.rei.api.common.entry.EntryStack; -import me.shedaniel.rei.impl.common.util.HashedEntryStackWrapper; +import me.shedaniel.rei.impl.common.util.HNEntryStackWrapper; import org.jetbrains.annotations.Nullable; import java.util.List; @@ -39,5 +39,5 @@ public interface EntryRegistryListener { default void removeEntries(List<EntryStack<?>> stacks, @Nullable LongList hashes) {} - default void onReFilter(List<HashedEntryStackWrapper> stacks) {} + default void onReFilter(List<HNEntryStackWrapper> stacks) {} } 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 76393a51d..efe289659 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 @@ -26,7 +26,7 @@ package me.shedaniel.rei.impl.common.entry.type; import it.unimi.dsi.fastutil.longs.LongCollection; import me.shedaniel.rei.api.client.entry.filtering.FilteringRule; import me.shedaniel.rei.api.common.entry.EntryStack; -import me.shedaniel.rei.impl.common.util.HashedEntryStackWrapper; +import me.shedaniel.rei.impl.common.util.HNEntryStackWrapper; import org.jetbrains.annotations.Nullable; import java.util.Collection; @@ -40,7 +40,7 @@ public interface FilteredEntryList extends EntryRegistryListener { List<EntryStack<?>> getList(); - List<HashedEntryStackWrapper> getComplexList(); + List<HNEntryStackWrapper> getComplexList(); boolean isFiltered(EntryStack<?> stack, long hashExact); } 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 03a4b47c3..3133afb20 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 @@ -39,6 +39,7 @@ import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.api.common.util.EntryStacks; import me.shedaniel.rei.impl.client.entry.filtering.FilteringContextType; import me.shedaniel.rei.impl.common.InternalLogger; +import me.shedaniel.rei.impl.common.util.HNEntryStackWrapper; import me.shedaniel.rei.impl.common.util.HashedEntryStackWrapper; import org.jetbrains.annotations.Nullable; @@ -49,7 +50,7 @@ public class PreFilteredEntryList implements FilteredEntryList { private final EntryRegistryList list; private final Map<FilteringRule<?>, DataPair> filteringData = new HashMap<>(); private final Long2BooleanMap cached = new Long2BooleanOpenHashMap(); - private final List<HashedEntryStackWrapper> listView = new InternalListView(); + private final List<HNEntryStackWrapper> listView = new InternalListView(); private final List<EntryStack<?>> simpleListView = new InternalSimpleListView(listView); private long mod = 0; @@ -87,7 +88,7 @@ public class PreFilteredEntryList implements FilteredEntryList { } @Override - public void onReFilter(List<HashedEntryStackWrapper> stacks) { + public void onReFilter(List<HNEntryStackWrapper> stacks) { ConfigObject config = ConfigObject.getInstance(); if (config.getFilteredStackProviders() != null) { List<EntryStack<?>> normalizedFilteredStacks = CollectionUtils.map(config.getFilteredStackProviders(), EntryStackProvider::provide); @@ -97,7 +98,7 @@ public class PreFilteredEntryList implements FilteredEntryList { } Stopwatch stopwatch = Stopwatch.createStarted(); - refreshFilteringFor(true, null, Lists.transform(stacks, HashedEntryStackWrapper::unwrap), new AbstractLongList() { + refreshFilteringFor(true, null, Lists.transform(stacks, HNEntryStackWrapper::unwrap), new AbstractLongList() { @Override public long getLong(int index) { return stacks.get(index).hashExact(); @@ -216,16 +217,16 @@ public class PreFilteredEntryList implements FilteredEntryList { } @Override - public List<HashedEntryStackWrapper> getComplexList() { + public List<HNEntryStackWrapper> getComplexList() { return listView; } - private class InternalListView extends AbstractList<HashedEntryStackWrapper> { + private class InternalListView extends AbstractList<HNEntryStackWrapper> { private long prevMod = -1; - private List<HashedEntryStackWrapper> stacks; + private List<HNEntryStackWrapper> stacks; @Override - public HashedEntryStackWrapper get(int index) { + public HNEntryStackWrapper get(int index) { if (prevMod == mod) { return stacks.get(index); } @@ -250,18 +251,18 @@ public class PreFilteredEntryList implements FilteredEntryList { } @Override - public Iterator<HashedEntryStackWrapper> iterator() { + public Iterator<HNEntryStackWrapper> iterator() { if (prevMod == mod) { return stacks.iterator(); } - Iterator<HashedEntryStackWrapper> iterator = list.collectHashed().iterator(); + Iterator<HNEntryStackWrapper> iterator = list.collectHN().iterator(); return new AbstractIterator<>() { @Nullable @Override - protected HashedEntryStackWrapper computeNext() { + protected HNEntryStackWrapper computeNext() { while (iterator.hasNext()) { - HashedEntryStackWrapper wrapper = iterator.next(); + HNEntryStackWrapper wrapper = iterator.next(); if (isFiltered(wrapper.unwrap(), wrapper.hashExact())) return wrapper; } @@ -272,9 +273,9 @@ public class PreFilteredEntryList implements FilteredEntryList { } private static class InternalSimpleListView extends AbstractList<EntryStack<?>> { - private final List<HashedEntryStackWrapper> list; + private final List<HNEntryStackWrapper> list; - public InternalSimpleListView(List<HashedEntryStackWrapper> list) { + public InternalSimpleListView(List<HNEntryStackWrapper> list) { this.list = list; } @@ -290,7 +291,7 @@ public class PreFilteredEntryList implements FilteredEntryList { @Override public Iterator<EntryStack<?>> iterator() { - return Iterators.transform(list.iterator(), HashedEntryStackWrapper::unwrap); + return Iterators.transform(list.iterator(), HNEntryStackWrapper::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 482d7100b..50f57d3bc 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 @@ -47,6 +47,10 @@ public class CollapsibleEntryRegistryImpl implements CollapsibleEntryRegistry { if (old != null) { InternalLogger.getInstance().warn("Overwritten collapsible entry group [%s] %s with %d entries", id, name.getString(), stacks.size()); } + if (stacks.isEmpty()) { + InternalLogger.getInstance().warn("Collapsible entry group [%s] %s has no entries, ignoring.", id, name.getString()); + this.entries.remove(id); + } } @Override diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/util/HNEntryStackWrapper.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/util/HNEntryStackWrapper.java new file mode 100644 index 000000000..b442ff8c4 --- /dev/null +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/util/HNEntryStackWrapper.java @@ -0,0 +1,55 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.impl.common.util; + +import me.shedaniel.rei.api.common.entry.EntryStack; +import me.shedaniel.rei.api.common.util.EntryStacks; +import org.jetbrains.annotations.ApiStatus; + +@ApiStatus.Internal +public class HNEntryStackWrapper extends HashedEntryStackWrapper { + private final EntryStack<?> normalized; + private final long normalizedHash; + + public HNEntryStackWrapper(EntryStack<?> stack) { + super(stack); + this.normalized = stack.normalize(); + this.normalizedHash = EntryStacks.hashExact(this.normalized); + } + + public HNEntryStackWrapper(EntryStack<?> stack, long hash) { + super(stack, hash); + this.normalized = stack.normalize(); + this.normalizedHash = EntryStacks.hashExact(this.normalized); + } + + public EntryStack<?> normalized() { + return normalized; + } + + @Override + public HashedEntryStackWrapper normalize() { + return new HashedEntryStackWrapper(normalized, normalizedHash); + } +}
\ No newline at end of file |
