From 620b7b47c9c2a3d7e1f54c5a8c82113acaff7438 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Wed, 12 Feb 2020 01:55:38 +0800 Subject: fix favorites saving Signed-off-by: shedaniel --- .../java/me/shedaniel/rei/impl/EntryRegistryImpl.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/main/java/me/shedaniel/rei/impl/EntryRegistryImpl.java') diff --git a/src/main/java/me/shedaniel/rei/impl/EntryRegistryImpl.java b/src/main/java/me/shedaniel/rei/impl/EntryRegistryImpl.java index cb78e0ab8..98e2c53e9 100644 --- a/src/main/java/me/shedaniel/rei/impl/EntryRegistryImpl.java +++ b/src/main/java/me/shedaniel/rei/impl/EntryRegistryImpl.java @@ -7,6 +7,7 @@ package me.shedaniel.rei.impl; import com.google.common.collect.Lists; import com.google.common.collect.Queues; +import me.shedaniel.rei.api.ConfigObject; import me.shedaniel.rei.api.EntryRegistry; import me.shedaniel.rei.api.EntryStack; import me.shedaniel.rei.api.RecipeHelper; @@ -26,8 +27,10 @@ public class EntryRegistryImpl implements EntryRegistry { private final CopyOnWriteArrayList entries = Lists.newCopyOnWriteArrayList(); private final Queue>> queueRegisterEntryStackAfter = Queues.newConcurrentLinkedQueue(); private List reloadList; + private boolean doingDistinct = false; public void distinct() { + doingDistinct = true; TreeSet set = new TreeSet<>((i, j) -> i.equalsAll(j) ? 0 : 1); set.addAll(reloadList); entries.clear(); @@ -40,14 +43,25 @@ public class EntryRegistryImpl implements EntryRegistry { break; registerEntriesAfter(pair.getLeft(), pair.getRight()); } + set.clear(); + set.addAll(entries); + set.removeIf(EntryStack::isEmpty); + entries.clear(); + entries.addAll(set); + set.clear(); + for (EntryStack stack : ConfigObject.getInstance().getFilteredStacks()) { + entries.remove(stack); + } + doingDistinct = false; } @Override public List getStacksList() { - return RecipeHelper.getInstance().arePluginsLoading() ? reloadList : entries; + return RecipeHelper.getInstance().arePluginsLoading() && !doingDistinct ? reloadList : entries; } public void reset() { + doingDistinct = false; reloadList = Lists.newArrayList(); queueRegisterEntryStackAfter.clear(); entries.clear(); @@ -94,8 +108,9 @@ public class EntryRegistryImpl implements EntryRegistry { public void queueRegisterEntryAfter(EntryStack afterEntry, Collection stacks) { if (RecipeHelper.getInstance().arePluginsLoading()) { queueRegisterEntryStackAfter.add(new Pair<>(afterEntry, stacks)); - } else + } else { registerEntriesAfter(afterEntry, stacks); + } } @Override -- cgit