aboutsummaryrefslogtreecommitdiff
path: root/runtime/src/main/java/me/shedaniel
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2021-10-22 15:15:08 +0800
committershedaniel <daniel@shedaniel.me>2021-10-22 15:16:30 +0800
commit1eed4cdcea68a9b305120b51390a18868c550ef2 (patch)
tree0b27ddba671ab6cf875537c786bf9548930af9ae /runtime/src/main/java/me/shedaniel
parentfc32ca29ab21871b339c6f55de83d1d4ba9932ec (diff)
downloadRoughlyEnoughItems-1eed4cdcea68a9b305120b51390a18868c550ef2.tar.gz
RoughlyEnoughItems-1eed4cdcea68a9b305120b51390a18868c550ef2.tar.bz2
RoughlyEnoughItems-1eed4cdcea68a9b305120b51390a18868c550ef2.zip
Fix #645
Diffstat (limited to 'runtime/src/main/java/me/shedaniel')
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java2
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/entry/renderer/EntryRendererRegistryImpl.java66
2 files changed, 68 insertions, 0 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java
index 131592218..094bbe4ea 100644
--- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java
+++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java
@@ -56,6 +56,7 @@ import me.shedaniel.rei.api.common.util.EntryStacks;
import me.shedaniel.rei.impl.ClientInternals;
import me.shedaniel.rei.impl.client.REIRuntimeImpl;
import me.shedaniel.rei.impl.client.config.ConfigManagerImpl;
+import me.shedaniel.rei.impl.client.entry.renderer.EntryRendererRegistryImpl;
import me.shedaniel.rei.impl.client.favorites.DelegatingFavoriteEntryProviderImpl;
import me.shedaniel.rei.impl.client.favorites.FavoriteEntryTypeRegistryImpl;
import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl;
@@ -176,6 +177,7 @@ public class RoughlyEnoughItemsCoreClient {
usedTime
);
},
+ new EntryRendererRegistryImpl(),
new ViewsImpl(),
new SearchProviderImpl(),
new ConfigManagerImpl(),
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/renderer/EntryRendererRegistryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/renderer/EntryRendererRegistryImpl.java
new file mode 100644
index 000000000..62b3235a2
--- /dev/null
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/renderer/EntryRendererRegistryImpl.java
@@ -0,0 +1,66 @@
+/*
+ * This file is licensed under the MIT License, part of Roughly Enough Items.
+ * Copyright (c) 2018, 2019, 2020, 2021 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.entry.renderer;
+
+import com.google.common.collect.Multimap;
+import com.google.common.collect.Multimaps;
+import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
+import me.shedaniel.rei.api.client.entry.renderer.EntryRenderer;
+import me.shedaniel.rei.api.client.entry.renderer.EntryRendererProvider;
+import me.shedaniel.rei.api.client.entry.renderer.EntryRendererRegistry;
+import me.shedaniel.rei.api.client.plugins.REIClientPlugin;
+import me.shedaniel.rei.api.common.entry.EntryStack;
+import me.shedaniel.rei.api.common.entry.type.EntryType;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Objects;
+
+public class EntryRendererRegistryImpl implements EntryRendererRegistry {
+ private final Multimap<EntryType<?>, EntryRendererProvider<?>> providers = Multimaps.newListMultimap(new Reference2ObjectOpenHashMap<>(), ArrayList::new);
+
+ @Override
+ public <T> void register(EntryType<T> type, EntryRendererProvider<T> provider) {
+ this.providers.put(type, provider);
+ }
+
+ @Override
+ public <T> EntryRenderer<T> get(EntryStack<T> stack) {
+ EntryRenderer<T> renderer = stack.getDefinition().getRenderer();
+ for (EntryRendererProvider<T> provider : (Collection<EntryRendererProvider<T>>) (Collection<? extends EntryRendererProvider<?>>) providers.get(stack.getType())) {
+ renderer = Objects.requireNonNull(provider.provide(stack, renderer));
+ }
+ return renderer;
+ }
+
+ @Override
+ public void startReload() {
+ providers.clear();
+ }
+
+ @Override
+ public void acceptPlugin(REIClientPlugin plugin) {
+ plugin.registerEntryRenderers(this);
+ }
+}