aboutsummaryrefslogtreecommitdiff
path: root/runtime/src/main/java/me/shedaniel/rei/impl/client
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2023-06-01 16:58:17 +0800
committershedaniel <daniel@shedaniel.me>2023-06-01 16:58:17 +0800
commita6e09ed07e4079cc1bfa10776b79d4a32bca941e (patch)
treedae7d67eeebd2993a5ecdc2b8d337d41c1127fb9 /runtime/src/main/java/me/shedaniel/rei/impl/client
parent981d975f0e1ddff61bfedd0d45ecbe0803372d8e (diff)
parent31d1e1935eae254ba2ff18df57dcd8ad9d9b0fa5 (diff)
downloadRoughlyEnoughItems-a6e09ed07e4079cc1bfa10776b79d4a32bca941e.tar.gz
RoughlyEnoughItems-a6e09ed07e4079cc1bfa10776b79d4a32bca941e.tar.bz2
RoughlyEnoughItems-a6e09ed07e4079cc1bfa10776b79d4a32bca941e.zip
Merge remote-tracking branch 'shedaniel/9.x-1.19' into 10.x-1.19.3
Diffstat (limited to 'runtime/src/main/java/me/shedaniel/rei/impl/client')
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java3
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java6
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java65
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java35
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/PanelWidget.java2
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/history/DisplayEntry.java20
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/hint/HintsContainerWidget.java3
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplayRegistryImpl.java153
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplaysHolder.java96
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplaysHolderImpl.java193
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/RemappingMap.java124
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/registry/screen/DefaultScreenOverlayRenderer.java112
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/registry/screen/ScreenRegistryImpl.java79
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/search/SearchRuntime.java46
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/view/ViewsImpl.java27
15 files changed, 772 insertions, 192 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java
index 2e7018ad8..fad1fdf6c 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java
@@ -47,7 +47,6 @@ import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl;
import me.shedaniel.rei.impl.client.gui.hints.HintProvider;
import me.shedaniel.rei.impl.client.gui.widget.CachedEntryListRender;
import me.shedaniel.rei.impl.client.gui.widget.search.OverlaySearchField;
-import me.shedaniel.rei.impl.client.search.argument.Argument;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
@@ -255,7 +254,6 @@ public class REIRuntimeImpl implements REIRuntime {
@Override
public void startReload() {
- Argument.resetCache(false);
getOverlay().ifPresent(ScreenOverlay::queueReloadOverlay);
lastDisplayScreen.clear();
if (!RenderSystem.isOnRenderThread()) {
@@ -272,7 +270,6 @@ public class REIRuntimeImpl implements REIRuntime {
@Override
public void endReload(ReloadStage stage) {
- Argument.resetCache(true);
getOverlay().ifPresent(ScreenOverlay::queueReloadOverlay);
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java
index f8e1f02d0..47f84a7c4 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java
@@ -303,6 +303,11 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData {
}
@Override
+ public boolean doesCacheDisplayLookup() {
+ return advanced.miscellaneous.cachingDisplayLookup;
+ }
+
+ @Override
public boolean doDebugRenderTimeRequired() {
return advanced.layout.debugRenderTimeRequired;
}
@@ -726,6 +731,7 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData {
private boolean newFastEntryRendering = true;
@ConfigEntry.Gui.PrefixText
private boolean cachingFastEntryRendering = false;
+ private boolean cachingDisplayLookup = true;
}
public static class Filtering {
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java
index a95d52069..c0e9e2b01 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java
@@ -54,10 +54,7 @@ import net.minecraft.util.Mth;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
+import java.util.*;
@ApiStatus.Internal
public class CompositeDisplayViewingScreen extends AbstractDisplayViewingScreen {
@@ -183,7 +180,7 @@ public class CompositeDisplayViewingScreen extends AbstractDisplayViewingScreen
ViewSearchBuilder.builder().addAllCategories().open();
}).tooltip(Component.translatable("text.rei.view_all_categories")).noShadow().color(0xFF404040, 0xFFBBBBBB).hoveredColor(0xFF0041FF, 0xFFFFBD4D));
- this.children().addAll(buttonList);
+ this.widgets.add(new ButtonListWidget(buttonList));
this.children().addAll(widgets);
}
@@ -270,6 +267,7 @@ public class CompositeDisplayViewingScreen extends AbstractDisplayViewingScreen
@Override
public void render(PoseStack matrices, int mouseX, int mouseY, float delta) {
+ this.widgets.sort(Comparator.comparingDouble(Widget::getZRenderingPriority));
if (ConfigObject.getInstance().isCompositeScrollBarPermanent()) {
scrollBarAlphaFutureTime = System.currentTimeMillis();
scrollBarAlphaFuture = 0;
@@ -294,32 +292,12 @@ public class CompositeDisplayViewingScreen extends AbstractDisplayViewingScreen
}
scrolling.updatePosition(delta);
renderBackground(matrices);
- int yOffset = 0;
getOverlay().render(matrices, mouseX, mouseY, delta);
super.render(matrices, mouseX, mouseY, delta);
for (Widget widget : widgets) {
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
widget.render(matrices, mouseX, mouseY, delta);
}
- matrices.pushPose();
- ScissorsHandler.INSTANCE.scissor(scrolling.getBounds());
- for (Button button : buttonList) {
- button.getBounds().y = scrollListBounds.y + 1 + yOffset - scrolling.scrollAmountInt();
- if (button.getBounds().getMaxY() > scrollListBounds.getMinY() && button.getBounds().getMinY() < scrollListBounds.getMaxY()) {
- button.render(matrices, mouseX, mouseY, delta);
- }
- yOffset += button.getBounds().height;
- }
- for (int i = 0; i < buttonList.size(); i++) {
- if (buttonList.get(i).getBounds().getMaxY() > scrollListBounds.getMinY() && buttonList.get(i).getBounds().getMinY() < scrollListBounds.getMaxY()) {
- displayRenderers.get(i).setZ(1);
- displayRenderers.get(i).render(matrices, buttonList.get(i).getBounds(), mouseX, mouseY, delta);
- Optional.ofNullable(displayRenderers.get(i).getTooltip(TooltipContext.of(new Point(mouseX, mouseY)))).ifPresent(Tooltip::queue);
- }
- }
- scrolling.renderScrollBar(0, scrollBarAlpha, REIRuntime.getInstance().isDarkThemeEnabled() ? 0.8f : 1f);
- ScissorsHandler.INSTANCE.removeLastScissor();
- matrices.popPose();
}
@Override
@@ -379,4 +357,41 @@ public class CompositeDisplayViewingScreen extends AbstractDisplayViewingScreen
}
return super.keyPressed(keyCode, scanCode, modifiers);
}
+
+ private class ButtonListWidget extends Widget {
+ private final List<Button> buttonList;
+
+ public ButtonListWidget(List<Button> buttonList) {
+ this.buttonList = buttonList;
+ }
+
+ @Override
+ public void render(PoseStack matrices, int mouseX, int mouseY, float delta) {
+ int yOffset = 0;
+ matrices.pushPose();
+ ScissorsHandler.INSTANCE.scissor(scrolling.getBounds());
+ for (Button button : buttonList) {
+ button.getBounds().y = scrollListBounds.y + 1 + yOffset - scrolling.scrollAmountInt();
+ if (button.getBounds().getMaxY() > scrollListBounds.getMinY() && button.getBounds().getMinY() < scrollListBounds.getMaxY()) {
+ button.render(matrices, mouseX, mouseY, delta);
+ }
+ yOffset += button.getBounds().height;
+ }
+ for (int i = 0; i < buttonList.size(); i++) {
+ if (buttonList.get(i).getBounds().getMaxY() > scrollListBounds.getMinY() && buttonList.get(i).getBounds().getMinY() < scrollListBounds.getMaxY()) {
+ displayRenderers.get(i).setZ(1);
+ displayRenderers.get(i).render(matrices, buttonList.get(i).getBounds(), mouseX, mouseY, delta);
+ Optional.ofNullable(displayRenderers.get(i).getTooltip(TooltipContext.of(new Point(mouseX, mouseY)))).ifPresent(Tooltip::queue);
+ }
+ }
+ scrolling.renderScrollBar(0, scrollBarAlpha, REIRuntime.getInstance().isDarkThemeEnabled() ? 0.8f : 1f);
+ ScissorsHandler.INSTANCE.removeLastScissor();
+ matrices.popPose();
+ }
+
+ @Override
+ public List<? extends GuiEventListener> children() {
+ return buttonList;
+ }
+ }
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java
index 7d23a89d7..777b44d06 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java
@@ -60,6 +60,8 @@ import me.shedaniel.rei.impl.client.gui.InternalTextures;
import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl;
import me.shedaniel.rei.impl.client.gui.dragging.CurrentDraggingStack;
import me.shedaniel.rei.impl.client.gui.widget.favorites.FavoritesListWidget;
+import me.shedaniel.rei.impl.client.registry.display.DisplayRegistryImpl;
+import me.shedaniel.rei.impl.client.registry.display.DisplaysHolder;
import me.shedaniel.rei.impl.client.view.ViewsImpl;
import net.minecraft.ChatFormatting;
import net.minecraft.CrashReport;
@@ -317,22 +319,24 @@ public class EntryWidget extends Slot implements DraggableStackProviderWidget {
try {
DisplayRegistry displayRegistry = DisplayRegistry.getInstance();
+ DisplaysHolder displaysHolder = ((DisplayRegistryImpl) displayRegistry).displaysHolder();
CategoryRegistry categoryRegistry = CategoryRegistry.getInstance();
Map<CategoryIdentifier<?>, Boolean> filteringQuickCraftCategories = ConfigObject.getInstance().getFilteringQuickCraftCategories();
- for (Map.Entry<CategoryIdentifier<?>, List<Display>> entry : displayRegistry.getAll().entrySet()) {
+ boolean shouldFilterDisplays = ConfigObject.getInstance().shouldFilterDisplays();
+
+ for (Display display : displaysHolder.getAllDisplaysByOutputs(getEntries())) {
+ CategoryIdentifier<?> categoryIdentifier = display.getCategoryIdentifier();
Optional<? extends CategoryRegistry.CategoryConfiguration<?>> configuration;
- if ((configuration = categoryRegistry.tryGet(entry.getKey())).isEmpty()
- || categoryRegistry.isCategoryInvisible(configuration.get().getCategory())) continue;
- if (!filteringQuickCraftCategories.getOrDefault(entry.getKey(), configuration.get().isQuickCraftingEnabledByDefault())) continue;
- for (Display display : entry.getValue()) {
- if ((!ConfigObject.getInstance().shouldFilterDisplays() || displayRegistry.isDisplayVisible(display))
- && ViewsImpl.isRecipesFor(getEntries(), display)) {
- AutoCraftingEvaluator.AutoCraftingResult result = AutoCraftingEvaluator.evaluateAutoCrafting(false, false, display, null);
- if (result.successful) {
- this.display = display;
- this.displayTooltipComponent = Suppliers.memoize(() -> new DisplayTooltipComponent(display));
- return result.successfulHandler;
- }
+ if ((configuration = categoryRegistry.tryGet(categoryIdentifier)).isEmpty()
+ || categoryRegistry.isCategoryInvisible(configuration.get().getCategory())) continue;
+ if (!filteringQuickCraftCategories.getOrDefault(categoryIdentifier, configuration.get().isQuickCraftingEnabledByDefault()))
+ continue;
+ if ((!shouldFilterDisplays || displayRegistry.isDisplayVisible(display))) {
+ AutoCraftingEvaluator.AutoCraftingResult result = AutoCraftingEvaluator.evaluateAutoCrafting(false, false, display, null);
+ if (result.successful) {
+ this.display = display;
+ this.displayTooltipComponent = Suppliers.memoize(() -> new DisplayTooltipComponent(display));
+ return result.successfulHandler;
}
}
}
@@ -351,7 +355,7 @@ public class EntryWidget extends Slot implements DraggableStackProviderWidget {
}
if (display != null) {
- if (ViewsImpl.isRecipesFor(getEntries(), display)) {
+ if (ViewsImpl.isRecipesFor(null, getEntries(), display)) {
AutoCraftingEvaluator.AutoCraftingResult result = AutoCraftingEvaluator.evaluateAutoCrafting(false, false, display, null);
if (result.successful) {
return result.successfulHandler;
@@ -428,7 +432,8 @@ public class EntryWidget extends Slot implements DraggableStackProviderWidget {
}
}
- protected void drawExtra(PoseStack matrices, int mouseX, int mouseY, float delta) {}
+ protected void drawExtra(PoseStack matrices, int mouseX, int mouseY, float delta) {
+ }
@Override
@Nullable
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/PanelWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/PanelWidget.java
index 2980f5016..f2233fb8a 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/PanelWidget.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/PanelWidget.java
@@ -56,7 +56,7 @@ public final class PanelWidget extends Panel {
.asFloat();
public static boolean isRendering(Panel panel) {
- return ConfigObject.getInstance().getRecipeScreenType() != DisplayScreenType.COMPOSITE;
+ return true;
}
public PanelWidget(Rectangle bounds) {
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/history/DisplayEntry.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/history/DisplayEntry.java
index 148840d08..2fea96c39 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/history/DisplayEntry.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/history/DisplayEntry.java
@@ -44,10 +44,7 @@ import net.minecraft.network.chat.Component;
import org.jetbrains.annotations.Nullable;
import org.joml.Vector4f;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
+import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
@@ -99,7 +96,7 @@ public class DisplayEntry extends WidgetWithBounds {
CategoryRegistry.CategoryConfiguration<Display> configuration = CategoryRegistry.getInstance().get((CategoryIdentifier<Display>) display.getCategoryIdentifier());
DisplayCategory<Display> category = configuration.getCategory();
Rectangle displayBounds = new Rectangle(0, 0, category.getDisplayWidth(display), category.getDisplayHeight());
- List<Widget> widgets = configuration.getView(display).setupDisplay(display, displayBounds);
+ List<Widget> widgets = setupDisplay(configuration, displayBounds);
float scale = 1.0F;
if (parentBounds.width * scale < displayBounds.width) {
scale = Math.min(scale, parentBounds.width * scale / (float) displayBounds.width);
@@ -124,6 +121,19 @@ public class DisplayEntry extends WidgetWithBounds {
return widgets;
}
+ private List<Widget> setupDisplay(CategoryRegistry.CategoryConfiguration<Display> configuration, Rectangle displayBounds) {
+ try {
+ return configuration.getView(display).setupDisplay(display, displayBounds);
+ } catch (Throwable throwable) {
+ throwable.printStackTrace();
+ List<Widget> w = new ArrayList<>();
+ w.add(Widgets.createRecipeBase(displayBounds).color(0xFFBB0000));
+ w.add(Widgets.createLabel(new Point(displayBounds.getCenterX(), displayBounds.getCenterY() - 8), Component.literal("Failed to initiate setupDisplay")));
+ w.add(Widgets.createLabel(new Point(displayBounds.getCenterX(), displayBounds.getCenterY() + 1), Component.literal("Check console for error")));
+ return w;
+ }
+ }
+
@Override
public Rectangle getBounds() {
return bounds.value().getBounds();
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/hint/HintsContainerWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/hint/HintsContainerWidget.java
index ce31a07c3..28fda4336 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/hint/HintsContainerWidget.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/hint/HintsContainerWidget.java
@@ -85,8 +85,9 @@ public class HintsContainerWidget extends DelegateWidget {
if (!uuid.equals(this.config.UUID)) {
this.config = new HintsConfig();
}
- } catch (IOException e) {
+ } catch (Throwable e) {
e.printStackTrace();
+ this.config = new HintsConfig();
}
}
this.config.UUID = uuid;
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplayRegistryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplayRegistryImpl.java
index b875b8530..1aff7f720 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplayRegistryImpl.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplayRegistryImpl.java
@@ -24,10 +24,6 @@
package me.shedaniel.rei.impl.client.registry.display;
import com.google.common.base.Preconditions;
-import com.google.common.collect.ForwardingMap;
-import com.google.common.collect.ForwardingMapEntry;
-import com.google.common.collect.Iterators;
-import com.google.common.collect.Sets;
import dev.architectury.event.EventResult;
import me.shedaniel.rei.api.client.plugins.REIClientPlugin;
import me.shedaniel.rei.api.client.registry.category.CategoryRegistry;
@@ -43,9 +39,7 @@ import me.shedaniel.rei.api.common.plugins.PluginManager;
import me.shedaniel.rei.impl.common.InternalLogger;
import me.shedaniel.rei.impl.common.registry.RecipeManagerContextImpl;
import net.minecraft.world.item.crafting.Recipe;
-import org.apache.commons.lang3.mutable.MutableInt;
import org.apache.commons.lang3.mutable.MutableLong;
-import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
@@ -53,127 +47,17 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.function.BiPredicate;
import java.util.function.Function;
import java.util.function.Predicate;
-import java.util.function.UnaryOperator;
public class DisplayRegistryImpl extends RecipeManagerContextImpl<REIClientPlugin> implements DisplayRegistry {
- private final WeakHashMap<Display, Object> displaysBase = new WeakHashMap<>();
- private final Map<CategoryIdentifier<?>, DisplaysList> displays = new ConcurrentHashMap<>();
- private final Map<CategoryIdentifier<?>, List<Display>> unmodifiableDisplays;
private final Map<CategoryIdentifier<?>, List<DynamicDisplayGenerator<?>>> displayGenerators = new ConcurrentHashMap<>();
private final List<DynamicDisplayGenerator<?>> globalDisplayGenerators = new ArrayList<>();
private final List<DisplayVisibilityPredicate> visibilityPredicates = new ArrayList<>();
private final List<DisplayFiller<?>> fillers = new ArrayList<>();
- private final MutableInt displayCount = new MutableInt(0);
+ private final MutableLong lastAddWarning = new MutableLong(-1);
+ private DisplaysHolder displaysHolder = new DisplaysHolderImpl(false);
public DisplayRegistryImpl() {
super(RecipeManagerContextImpl.supplier());
-
- this.unmodifiableDisplays = new RemappingMap<>(Collections.unmodifiableMap(displays), list -> {
- if (list == null) {
- return null;
- } else {
- return ((DisplaysList) list).unmodifiableList;
- }
- }, key -> CategoryRegistry.getInstance().tryGet(key).isPresent());
- }
-
- private static class RemappingMap<K, V> extends ForwardingMap<K, V> {
- protected final Map<K, V> map;
- protected final UnaryOperator<V> remapper;
- protected final Predicate<K> keyPredicate;
-
- public RemappingMap(Map<K, V> map, UnaryOperator<V> remapper, Predicate<K> keyPredicate) {
- this.map = map;
- this.remapper = remapper;
- this.keyPredicate = keyPredicate;
- }
-
- @Override
- @NotNull
- protected Map<K, V> delegate() {
- return map;
- }
-
- @Override
- public V get(Object key) {
- if (keyPredicate.test((K) key)) {
- return remapper.apply(super.get(key));
- } else {
- return null;
- }
- }
-
- @Override
- public boolean containsKey(@Nullable Object key) {
- return super.containsKey(key) && keyPredicate.test((K) key);
- }
-
- @Override
- public Set<K> keySet() {
- return Sets.filter(super.keySet(), keyPredicate::test);
- }
-
- @SuppressWarnings("UnstableApiUsage")
- @Override
- @NotNull
- public Set<Entry<K, V>> entrySet() {
- return this.new StandardEntrySet() {
- @Override
- public Iterator<Entry<K, V>> iterator() {
- return mapIterator(map.entrySet().iterator());
- }
- };
- }
-
- @Override
- public int size() {
- return keySet().size();
- }
-
- @Override
- public Collection<V> values() {
- return new AbstractCollection<V>() {
- @Override
- public Iterator<V> iterator() {
- return Iterators.transform(entrySet().iterator(), Entry::getValue);
- }
-
- @Override
- public int size() {
- return RemappingMap.this.size();
- }
- };
- }
-
- private Iterator<Entry<K, V>> mapIterator(Iterator<Entry<K, V>> iterator) {
- return Iterators.transform(Iterators.filter(iterator, entry -> this.keyPredicate.test(entry.getKey())),
- this::mapEntry);
- }
-
- private Entry<K, V> mapEntry(Entry<K, V> entry) {
- return new ForwardingMapEntry<>() {
- @Override
- @NotNull
- protected Entry<K, V> delegate() {
- return entry;
- }
-
- @Override
- public V getValue() {
- return remapper.apply(entry.getValue());
- }
- };
- }
- }
-
- private static class DisplaysList extends ArrayList<Display> {
- private final List<Display> unmodifiableList;
- private final List<Display> synchronizedList;
-
- public DisplaysList() {
- this.synchronizedList = Collections.synchronizedList(this);
- this.unmodifiableList = Collections.unmodifiableList(synchronizedList);
- }
}
@Override
@@ -183,11 +67,9 @@ public class DisplayRegistryImpl extends RecipeManagerContextImpl<REIClientPlugi
@Override
public int displaySize() {
- return displayCount.getValue();
+ return this.displaysHolder.size();
}
- private MutableLong lastAddWarning = new MutableLong(-1);
-
@Override
public void add(Display display, @Nullable Object origin) {
if (!PluginManager.areAnyReloading()) {
@@ -199,19 +81,12 @@ public class DisplayRegistryImpl extends RecipeManagerContextImpl<REIClientPlugi
}
}
- displays.computeIfAbsent(display.getCategoryIdentifier(), location -> new DisplaysList())
- .add(display);
- displayCount.increment();
- if (origin != null) {
- synchronized (displaysBase) {
- displaysBase.put(display, origin);
- }
- }
+ this.displaysHolder.add(display, origin);
}
@Override
public Map<CategoryIdentifier<?>, List<Display>> getAll() {
- return unmodifiableDisplays;
+ return this.displaysHolder.get();
}
@Override
@@ -287,11 +162,10 @@ public class DisplayRegistryImpl extends RecipeManagerContextImpl<REIClientPlugi
@Override
public void startReload() {
super.startReload();
- this.displays.clear();
+ this.displaysHolder = new DisplaysHolderImpl(true);
this.displayGenerators.clear();
this.visibilityPredicates.clear();
this.fillers.clear();
- this.displayCount.setValue(0);
}
@Override
@@ -304,13 +178,19 @@ public class DisplayRegistryImpl extends RecipeManagerContextImpl<REIClientPlugi
}
}
- for (CategoryIdentifier<?> identifier : displays.keySet()) {
+ for (CategoryIdentifier<?> identifier : getAll().keySet()) {
if (CategoryRegistry.getInstance().tryGet(identifier).isEmpty()) {
InternalLogger.getInstance().error("Found displays registered for unknown registry", new IllegalStateException(identifier.toString()));
}
}
- InternalLogger.getInstance().debug("Registered %d displays", displayCount.getValue());
+ this.displaysHolder.endReload();
+
+ InternalLogger.getInstance().debug("Registered %d displays", displaySize());
+ }
+
+ public DisplaysHolder displaysHolder() {
+ return displaysHolder;
}
@Override
@@ -349,12 +229,13 @@ public class DisplayRegistryImpl extends RecipeManagerContextImpl<REIClientPlugi
@Override
@Nullable
public Object getDisplayOrigin(Display display) {
- return displaysBase.get(display);
+ return this.displaysHolder.getDisplayOrigin(display);
}
private record DisplayFiller<D extends Display>(
BiPredicate<Object, DisplayAdditionReasons> predicate,
Function<Object, D> mappingFunction
- ) {}
+ ) {
+ }
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplaysHolder.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplaysHolder.java
new file mode 100644
index 000000000..07b5879cf
--- /dev/null
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplaysHolder.java
@@ -0,0 +1,96 @@
+/*
+ * 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.client.registry.display;
+
+import com.google.common.collect.Iterables;
+import me.shedaniel.rei.api.common.category.CategoryIdentifier;
+import me.shedaniel.rei.api.common.display.Display;
+import me.shedaniel.rei.api.common.entry.EntryStack;
+import me.shedaniel.rei.api.common.util.CollectionUtils;
+import me.shedaniel.rei.impl.client.view.ViewsImpl;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public interface DisplaysHolder {
+ boolean doesCache();
+
+ void add(Display display, @Nullable Object origin);
+
+ int size();
+
+ Map<CategoryIdentifier<?>, List<Display>> get();
+
+ @Nullable
+ Object getDisplayOrigin(Display display);
+
+ void endReload();
+
+ boolean isCached(Display display);
+
+ Set<Display> getDisplaysNotCached();
+
+ Set<Display> getDisplaysByInput(EntryStack<?> stack);
+
+ Set<Display> getDisplaysByOutput(EntryStack<?> stack);
+
+ default Iterable<Display> getAllDisplaysByInputs(List<EntryStack<?>> stacks) {
+ if (stacks.isEmpty()) return List.of();
+ Iterable<Display> inputCached = null;
+ if (doesCache()) {
+ for (EntryStack<?> stack : stacks) {
+ Set<Display> set = getDisplaysByInput(stack);
+ inputCached = inputCached == null ? set : Iterables.concat(inputCached, set);
+ }
+ if (stacks.size() > 1) inputCached = CollectionUtils.distinctReferenceOf(in