From 95ea1663038362efb2bdb61d521ee6e4274a34f7 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sun, 18 Sep 2022 02:20:25 +0800 Subject: Fix #1034 --- .../me/shedaniel/rei/forge/PluginDetectorImpl.java | 20 --------- .../rei/mixin/forge/MixinInputConstants.java | 48 ++++++++++++++++++++++ forge/src/main/resources/rei.mixins.json | 1 + 3 files changed, 49 insertions(+), 20 deletions(-) create mode 100644 forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinInputConstants.java (limited to 'forge/src') diff --git a/forge/src/main/java/me/shedaniel/rei/forge/PluginDetectorImpl.java b/forge/src/main/java/me/shedaniel/rei/forge/PluginDetectorImpl.java index fc0731a88..76343f9f5 100644 --- a/forge/src/main/java/me/shedaniel/rei/forge/PluginDetectorImpl.java +++ b/forge/src/main/java/me/shedaniel/rei/forge/PluginDetectorImpl.java @@ -29,11 +29,6 @@ import me.shedaniel.rei.api.common.plugins.PluginManager; import me.shedaniel.rei.api.common.plugins.PluginView; import me.shedaniel.rei.api.common.plugins.REIPluginProvider; import me.shedaniel.rei.api.common.plugins.REIServerPlugin; -import me.shedaniel.rei.impl.ClientInternals; -import me.shedaniel.rei.jeicompat.JEIExtraClientPlugin; -import me.shedaniel.rei.jeicompat.JEIExtraPlugin; -import me.shedaniel.rei.jeicompat.JEIPluginDetector; -import me.shedaniel.rei.plugin.client.DefaultClientPlugin; import me.shedaniel.rei.impl.init.PluginDetector; import me.shedaniel.rei.plugin.client.forge.DefaultClientPluginImpl; import me.shedaniel.rei.plugin.client.runtime.DefaultClientRuntimePlugin; @@ -42,9 +37,7 @@ import me.shedaniel.rei.plugin.common.runtime.DefaultRuntimePlugin; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; -import org.apache.logging.log4j.util.TriConsumer; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -76,7 +69,6 @@ public class PluginDetectorImpl implements PluginDetector { public void detectServerPlugins() { PluginView.getServerInstance().registerPlugin(wrapPlugin(Collections.singletonList("roughlyenoughitems"), new DefaultPluginImpl())); PluginView.getServerInstance().registerPlugin(wrapPlugin(Collections.singletonList("roughlyenoughitems"), new DefaultRuntimePlugin())); - PluginView.getServerInstance().registerPlugin(wrapPlugin(Collections.singletonList("roughlyenoughitems"), new JEIExtraPlugin())); AnnotationUtils.scanAnnotation(REIPlugin.class, REIServerPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { ((PluginView) PluginManager.getServerInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); }); @@ -96,21 +88,9 @@ public class PluginDetectorImpl implements PluginDetector { return () -> () -> { PluginView.getClientInstance().registerPlugin(wrapPlugin(Collections.singletonList("roughlyenoughitems"), new DefaultClientPluginImpl())); PluginView.getClientInstance().registerPlugin(wrapPlugin(Collections.singletonList("roughlyenoughitems"), new DefaultClientRuntimePlugin())); - PluginView.getClientInstance().registerPlugin(wrapPlugin(Collections.singletonList("roughlyenoughitems"), new JEIExtraClientPlugin())); AnnotationUtils.scanAnnotation(REIPlugin.class, REIClientPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { ((PluginView) PluginManager.getClientInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); }); - ClientInternals.attachInstance((Supplier>) () -> { - List modIds = new ArrayList<>(); - for (REIPluginProvider plugin : PluginManager.getClientInstance().getPluginProviders()) { - if (plugin instanceof JEIPluginDetector.JEIPluginProvider) { - modIds.addAll(((JEIPluginDetector.JEIPluginProvider) plugin).modIds); - } - } - return modIds; - }, "jeiCompatMods"); - JEIPluginDetector.detect((aClass, consumer) -> AnnotationUtils.scanAnnotation((Class) aClass, c -> true, - (TriConsumer, Supplier, Class>) (TriConsumer) consumer), PluginView.getClientInstance()::registerPlugin); }; } } diff --git a/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinInputConstants.java b/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinInputConstants.java new file mode 100644 index 000000000..7d6b31a65 --- /dev/null +++ b/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinInputConstants.java @@ -0,0 +1,48 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 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.mixin.forge; + +import com.mojang.blaze3d.platform.InputConstants; +import com.mojang.blaze3d.systems.RenderSystem; +import me.shedaniel.rei.api.client.config.ConfigObject; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(InputConstants.class) +public class MixinInputConstants { + @Inject(method = "isKeyDown", at = @At("HEAD"), cancellable = true) + private static void isKeyDown(long windowId, int key, CallbackInfoReturnable cir) { + if (isPatchingAsyncThreadCrash() && !RenderSystem.isOnRenderThread()) { + cir.setReturnValue(false); + } + } + + @Unique + private static boolean isPatchingAsyncThreadCrash() { + return ConfigObject.getInstance().isPatchingAsyncThreadCrash(); + } +} diff --git a/forge/src/main/resources/rei.mixins.json b/forge/src/main/resources/rei.mixins.json index dbb1dc75c..5b75f9519 100644 --- a/forge/src/main/resources/rei.mixins.json +++ b/forge/src/main/resources/rei.mixins.json @@ -5,6 +5,7 @@ "client": [ "MixinClientPacketListener", "MixinEffectRenderingInventoryScreen", + "MixinInputConstants", "MixinRecipeToast" ], "mixins": [ -- cgit From 445c8d99a69a43e441a0d9fb42874309f176d73c Mon Sep 17 00:00:00 2001 From: shedaniel Date: Thu, 22 Sep 2022 22:45:24 +0800 Subject: Add REIPluginLoader and resolve dists properly --- .../me/shedaniel/rei/forge/PluginDetectorImpl.java | 32 +++++++++++++++++-- .../me/shedaniel/rei/forge/REIPluginLoader.java | 37 ++++++++++++++++++++++ 2 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoader.java (limited to 'forge/src') diff --git a/forge/src/main/java/me/shedaniel/rei/forge/PluginDetectorImpl.java b/forge/src/main/java/me/shedaniel/rei/forge/PluginDetectorImpl.java index 76343f9f5..23168f3ff 100644 --- a/forge/src/main/java/me/shedaniel/rei/forge/PluginDetectorImpl.java +++ b/forge/src/main/java/me/shedaniel/rei/forge/PluginDetectorImpl.java @@ -23,6 +23,7 @@ package me.shedaniel.rei.forge; +import com.google.common.base.Suppliers; import dev.architectury.platform.forge.EventBuses; import me.shedaniel.rei.api.client.plugins.REIClientPlugin; import me.shedaniel.rei.api.common.plugins.PluginManager; @@ -38,9 +39,7 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; -import java.util.Collection; -import java.util.Collections; -import java.util.List; +import java.util.*; import java.util.function.Supplier; public class PluginDetectorImpl implements PluginDetector { @@ -65,6 +64,14 @@ public class PluginDetectorImpl implements PluginDetector { }; } + private static final Supplier>, List>>> loaderProvided = Suppliers.memoize(() -> { + List>, List>> list = new ArrayList<>(); + AnnotationUtils.>>scanAnnotation(REIPluginLoader.class, REIPluginProvider.class::isAssignableFrom, (modId, provider, clazz) -> { + list.add(new AbstractMap.SimpleEntry<>(provider.get(), modId)); + }); + return list; + }); + @Override public void detectServerPlugins() { PluginView.getServerInstance().registerPlugin(wrapPlugin(Collections.singletonList("roughlyenoughitems"), new DefaultPluginImpl())); @@ -72,6 +79,16 @@ public class PluginDetectorImpl implements PluginDetector { AnnotationUtils.scanAnnotation(REIPlugin.class, REIServerPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { ((PluginView) PluginManager.getServerInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); }); + for (Map.Entry>, List> entry : loaderProvided.get()) { + REIPluginProvider> provider = entry.getKey(); + Collection> objects = provider.provide(); + for (me.shedaniel.rei.api.common.plugins.REIPlugin plugin : objects) { + ((PluginView) PluginManager.getInstance()).registerPlugin(wrapPlugin(entry.getValue(), plugin)); + if (plugin instanceof REIServerPlugin) { + ((PluginView) PluginManager.getServerInstance()).registerPlugin(wrapPlugin(entry.getValue(), (REIServerPlugin) plugin)); + } + } + } } @Override @@ -91,6 +108,15 @@ public class PluginDetectorImpl implements PluginDetector { AnnotationUtils.scanAnnotation(REIPlugin.class, REIClientPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { ((PluginView) PluginManager.getClientInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); }); + for (Map.Entry>, List> entry : loaderProvided.get()) { + REIPluginProvider> provider = entry.getKey(); + Collection> objects = provider.provide(); + for (me.shedaniel.rei.api.common.plugins.REIPlugin plugin : objects) { + if (plugin instanceof REIClientPlugin) { + ((PluginView) PluginManager.getClientInstance()).registerPlugin(wrapPlugin(entry.getValue(), (REIClientPlugin) plugin)); + } + } + } }; } } diff --git a/forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoader.java b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoader.java new file mode 100644 index 000000000..9a38ef1b0 --- /dev/null +++ b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoader.java @@ -0,0 +1,37 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 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.forge; + +import net.minecraftforge.api.distmarker.Dist; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface REIPluginLoader { + Dist[] value() default {Dist.CLIENT, Dist.DEDICATED_SERVER}; +} \ No newline at end of file -- cgit From 53b35a385d744a5f2da0b333ea52099fb9cb9cda Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sat, 24 Sep 2022 19:49:20 +0800 Subject: I am not JEI --- .../main/java/me/shedaniel/rei/forge/JEIStub.java | 31 ---------------------- forge/src/main/resources/META-INF/mods.toml | 8 ------ 2 files changed, 39 deletions(-) delete mode 100644 forge/src/main/java/me/shedaniel/rei/forge/JEIStub.java (limited to 'forge/src') diff --git a/forge/src/main/java/me/shedaniel/rei/forge/JEIStub.java b/forge/src/main/java/me/shedaniel/rei/forge/JEIStub.java deleted file mode 100644 index 63634d56b..000000000 --- a/forge/src/main/java/me/shedaniel/rei/forge/JEIStub.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020, 2021, 2022 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.forge; - -import net.minecraftforge.fml.common.Mod; - -// Hello mods, JEI is present!! Please give in and trust me! -@Mod("jei") -public class JEIStub { -} diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index b4e5942fe..df37b37c3 100644 --- a/forge/src/main/resources/META-INF/mods.toml +++ b/forge/src/main/resources/META-INF/mods.toml @@ -13,14 +13,6 @@ description = ''' To allow players to view items and recipes. ''' -[[mods]] -modId = "jei" -version = "9.9999" -displayName = "Roughly Enough Items (JEI Stub)" -description = ''' -To allow players to view items and recipes. -''' - [[dependencies.roughlyenoughitems]] modId = "architectury" mandatory = true -- cgit From ec5840a5adadb7e1af905348aae3f11c7c439df7 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sun, 25 Sep 2022 18:46:22 +0800 Subject: Fix forge api and default plugin publishing and fix #1055 --- .../me/shedaniel/rei/forge/PluginDetectorImpl.java | 38 +++++++++++++++++++--- .../java/me/shedaniel/rei/forge/REIPlugin.java | 1 + .../me/shedaniel/rei/forge/REIPluginClient.java | 34 +++++++++++++++++++ .../me/shedaniel/rei/forge/REIPluginCommon.java | 34 +++++++++++++++++++ .../rei/forge/REIPluginDedicatedServer.java | 34 +++++++++++++++++++ .../me/shedaniel/rei/forge/REIPluginLoader.java | 1 + .../shedaniel/rei/forge/REIPluginLoaderClient.java | 34 +++++++++++++++++++ .../shedaniel/rei/forge/REIPluginLoaderCommon.java | 34 +++++++++++++++++++ .../rei/forge/REIPluginLoaderDedicatedServer.java | 34 +++++++++++++++++++ 9 files changed, 239 insertions(+), 5 deletions(-) create mode 100644 forge/src/main/java/me/shedaniel/rei/forge/REIPluginClient.java create mode 100644 forge/src/main/java/me/shedaniel/rei/forge/REIPluginCommon.java create mode 100644 forge/src/main/java/me/shedaniel/rei/forge/REIPluginDedicatedServer.java create mode 100644 forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoaderClient.java create mode 100644 forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoaderCommon.java create mode 100644 forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoaderDedicatedServer.java (limited to 'forge/src') diff --git a/forge/src/main/java/me/shedaniel/rei/forge/PluginDetectorImpl.java b/forge/src/main/java/me/shedaniel/rei/forge/PluginDetectorImpl.java index 23168f3ff..d4286ac02 100644 --- a/forge/src/main/java/me/shedaniel/rei/forge/PluginDetectorImpl.java +++ b/forge/src/main/java/me/shedaniel/rei/forge/PluginDetectorImpl.java @@ -38,6 +38,8 @@ import me.shedaniel.rei.plugin.common.runtime.DefaultRuntimePlugin; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import net.minecraftforge.fml.loading.FMLEnvironment; +import org.jetbrains.annotations.NotNull; import java.util.*; import java.util.function.Supplier; @@ -45,7 +47,7 @@ import java.util.function.Supplier; public class PluginDetectorImpl implements PluginDetector { private static

> REIPluginProvider

wrapPlugin(List modId, REIPluginProvider

plugin) { return new REIPluginProvider

() { - String nameSuffix = " [" + String.join(", ", modId) + "]"; + final String nameSuffix = " [" + String.join(", ", modId) + "]"; @Override public Collection

provide() { @@ -64,13 +66,17 @@ public class PluginDetectorImpl implements PluginDetector { }; } - private static final Supplier>, List>>> loaderProvided = Suppliers.memoize(() -> { - List>, List>> list = new ArrayList<>(); - AnnotationUtils.>>scanAnnotation(REIPluginLoader.class, REIPluginProvider.class::isAssignableFrom, (modId, provider, clazz) -> { + private static final Supplier>, List>>> loaderProvided = + Suppliers.memoize(() -> getPluginsLoader(REIPluginLoader.class)); + + @NotNull + private static > List, List>> getPluginsLoader(Class annotation) { + List, List>> list = new ArrayList<>(); + AnnotationUtils.>scanAnnotation(annotation, REIPluginProvider.class::isAssignableFrom, (modId, provider, clazz) -> { list.add(new AbstractMap.SimpleEntry<>(provider.get(), modId)); }); return list; - }); + } @Override public void detectServerPlugins() { @@ -79,6 +85,11 @@ public class PluginDetectorImpl implements PluginDetector { AnnotationUtils.scanAnnotation(REIPlugin.class, REIServerPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { ((PluginView) PluginManager.getServerInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); }); + if (FMLEnvironment.dist == Dist.DEDICATED_SERVER) { + AnnotationUtils.scanAnnotation(REIPluginDedicatedServer.class, REIServerPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { + ((PluginView) PluginManager.getServerInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); + }); + } for (Map.Entry>, List> entry : loaderProvided.get()) { REIPluginProvider> provider = entry.getKey(); Collection> objects = provider.provide(); @@ -89,6 +100,11 @@ public class PluginDetectorImpl implements PluginDetector { } } } + if (FMLEnvironment.dist == Dist.DEDICATED_SERVER) { + for (Map.Entry, List> entry : PluginDetectorImpl.getPluginsLoader(REIPluginLoaderDedicatedServer.class)) { + ((PluginView) PluginManager.getServerInstance()).registerPlugin(wrapPlugin(entry.getValue(), entry.getKey())); + } + } } @Override @@ -97,6 +113,12 @@ public class PluginDetectorImpl implements PluginDetector { AnnotationUtils.>scanAnnotation(REIPlugin.class, me.shedaniel.rei.api.common.plugins.REIPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { ((PluginView) PluginManager.getInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); }); + AnnotationUtils.>scanAnnotation(REIPluginCommon.class, me.shedaniel.rei.api.common.plugins.REIPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { + ((PluginView) PluginManager.getInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); + }); + for (Map.Entry>, List> entry : PluginDetectorImpl.getPluginsLoader(REIPluginLoaderCommon.class)) { + ((PluginView) PluginManager.getInstance()).registerPlugin(wrapPlugin(entry.getValue(), entry.getKey())); + } } @OnlyIn(Dist.CLIENT) @@ -108,6 +130,9 @@ public class PluginDetectorImpl implements PluginDetector { AnnotationUtils.scanAnnotation(REIPlugin.class, REIClientPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { ((PluginView) PluginManager.getClientInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); }); + AnnotationUtils.scanAnnotation(REIPluginClient.class, REIClientPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { + ((PluginView) PluginManager.getClientInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); + }); for (Map.Entry>, List> entry : loaderProvided.get()) { REIPluginProvider> provider = entry.getKey(); Collection> objects = provider.provide(); @@ -117,6 +142,9 @@ public class PluginDetectorImpl implements PluginDetector { } } } + for (Map.Entry, List> entry : PluginDetectorImpl.getPluginsLoader(REIPluginLoaderClient.class)) { + ((PluginView) PluginManager.getClientInstance()).registerPlugin(wrapPlugin(entry.getValue(), entry.getKey())); + } }; } } diff --git a/forge/src/main/java/me/shedaniel/rei/forge/REIPlugin.java b/forge/src/main/java/me/shedaniel/rei/forge/REIPlugin.java index db15c8093..70593ad9a 100644 --- a/forge/src/main/java/me/shedaniel/rei/forge/REIPlugin.java +++ b/forge/src/main/java/me/shedaniel/rei/forge/REIPlugin.java @@ -32,6 +32,7 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) +@Deprecated(forRemoval = true) public @interface REIPlugin { Dist[] value() default {Dist.CLIENT, Dist.DEDICATED_SERVER}; } diff --git a/forge/src/main/java/me/shedaniel/rei/forge/REIPluginClient.java b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginClient.java new file mode 100644 index 000000000..5584b5f7c --- /dev/null +++ b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginClient.java @@ -0,0 +1,34 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 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.forge; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface REIPluginClient { +} diff --git a/forge/src/main/java/me/shedaniel/rei/forge/REIPluginCommon.java b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginCommon.java new file mode 100644 index 000000000..b07ee4e0b --- /dev/null +++ b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginCommon.java @@ -0,0 +1,34 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 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.forge; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface REIPluginCommon { +} diff --git a/forge/src/main/java/me/shedaniel/rei/forge/REIPluginDedicatedServer.java b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginDedicatedServer.java new file mode 100644 index 000000000..38545d041 --- /dev/null +++ b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginDedicatedServer.java @@ -0,0 +1,34 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 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.forge; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface REIPluginDedicatedServer { +} diff --git a/forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoader.java b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoader.java index 9a38ef1b0..1303b14cf 100644 --- a/forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoader.java +++ b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoader.java @@ -32,6 +32,7 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) +@Deprecated(forRemoval = true) public @interface REIPluginLoader { Dist[] value() default {Dist.CLIENT, Dist.DEDICATED_SERVER}; } \ No newline at end of file diff --git a/forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoaderClient.java b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoaderClient.java new file mode 100644 index 000000000..6824f511c --- /dev/null +++ b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoaderClient.java @@ -0,0 +1,34 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 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.forge; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface REIPluginLoaderClient { +} \ No newline at end of file diff --git a/forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoaderCommon.java b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoaderCommon.java new file mode 100644 index 000000000..7398e1d0d --- /dev/null +++ b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoaderCommon.java @@ -0,0 +1,34 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 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.forge; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface REIPluginLoaderCommon { +} \ No newline at end of file diff --git a/forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoaderDedicatedServer.java b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoaderDedicatedServer.java new file mode 100644 index 000000000..246b8c3cf --- /dev/null +++ b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoaderDedicatedServer.java @@ -0,0 +1,34 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 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.forge; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface REIPluginLoaderDedicatedServer { +} \ No newline at end of file -- cgit From eede518a231cfe2ec36c49b41fe7cb98008e9663 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Wed, 28 Sep 2022 17:27:18 +0800 Subject: Fix #1134 --- .../main/java/me/shedaniel/rei/mixin/forge/MixinInputConstants.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'forge/src') diff --git a/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinInputConstants.java b/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinInputConstants.java index 7d6b31a65..0097c8df6 100644 --- a/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinInputConstants.java +++ b/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinInputConstants.java @@ -43,6 +43,10 @@ public class MixinInputConstants { @Unique private static boolean isPatchingAsyncThreadCrash() { - return ConfigObject.getInstance().isPatchingAsyncThreadCrash(); + try { + return ConfigObject.getInstance().isPatchingAsyncThreadCrash(); + } catch (Throwable throwable) { + return false; + } } } -- cgit From 6c1d40eb5c0c167f530d0393476f02424955ae81 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Wed, 28 Sep 2022 18:23:40 +0800 Subject: Changes to how plugins are located, should be smarter and easier --- .../me/shedaniel/rei/forge/PluginDetectorImpl.java | 132 +++++++++++++++++---- 1 file changed, 110 insertions(+), 22 deletions(-) (limited to 'forge/src') diff --git a/forge/src/main/java/me/shedaniel/rei/forge/PluginDetectorImpl.java b/forge/src/main/java/me/shedaniel/rei/forge/PluginDetectorImpl.java index d4286ac02..2681299da 100644 --- a/forge/src/main/java/me/shedaniel/rei/forge/PluginDetectorImpl.java +++ b/forge/src/main/java/me/shedaniel/rei/forge/PluginDetectorImpl.java @@ -24,6 +24,8 @@ package me.shedaniel.rei.forge; import com.google.common.base.Suppliers; +import com.google.common.collect.Iterables; +import com.google.common.collect.Iterators; import dev.architectury.platform.forge.EventBuses; import me.shedaniel.rei.api.client.plugins.REIClientPlugin; import me.shedaniel.rei.api.common.plugins.PluginManager; @@ -68,12 +70,29 @@ public class PluginDetectorImpl implements PluginDetector { private static final Supplier>, List>>> loaderProvided = Suppliers.memoize(() -> getPluginsLoader(REIPluginLoader.class)); + private static final Supplier>, List>>> loaderProvidedCommon = + Suppliers.memoize(() -> getPluginsLoader(REIPluginLoaderCommon.class)); + private static final Supplier>, List>>> loaderProvidedDist; + + static { + Supplier>, List>>> dist; + if (FMLEnvironment.dist == Dist.CLIENT) { + dist = Suppliers.memoize(() -> getPluginsLoader(REIPluginLoaderClient.class)); + } else if (FMLEnvironment.dist == Dist.DEDICATED_SERVER) { + dist = Suppliers.memoize(() -> getPluginsLoader(REIPluginLoaderDedicatedServer.class)); + } else throw new IllegalStateException("Unknown environment: " + FMLEnvironment.dist); + loaderProvidedDist = dist; + } @NotNull private static > List, List>> getPluginsLoader(Class annotation) { List, List>> list = new ArrayList<>(); AnnotationUtils.>scanAnnotation(annotation, REIPluginProvider.class::isAssignableFrom, (modId, provider, clazz) -> { - list.add(new AbstractMap.SimpleEntry<>(provider.get(), modId)); + try { + list.add(new AbstractMap.SimpleEntry<>(provider.get(), modId)); + } catch (Throwable throwable) { + throwable.printStackTrace(); + } }); return list; } @@ -82,41 +101,73 @@ public class PluginDetectorImpl implements PluginDetector { public void detectServerPlugins() { PluginView.getServerInstance().registerPlugin(wrapPlugin(Collections.singletonList("roughlyenoughitems"), new DefaultPluginImpl())); PluginView.getServerInstance().registerPlugin(wrapPlugin(Collections.singletonList("roughlyenoughitems"), new DefaultRuntimePlugin())); + + // Legacy Annotation AnnotationUtils.scanAnnotation(REIPlugin.class, REIServerPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { ((PluginView) PluginManager.getServerInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); }); + + // Common plugins + AnnotationUtils.scanAnnotation(REIPluginCommon.class, REIServerPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { + ((PluginView) PluginManager.getServerInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); + }); + + // Dist plugins if (FMLEnvironment.dist == Dist.DEDICATED_SERVER) { AnnotationUtils.scanAnnotation(REIPluginDedicatedServer.class, REIServerPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { ((PluginView) PluginManager.getServerInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); }); + } else { + AnnotationUtils.scanAnnotation(REIPluginClient.class, REIServerPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { + ((PluginView) PluginManager.getServerInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); + }); } + + // Loaders for (Map.Entry>, List> entry : loaderProvided.get()) { - REIPluginProvider> provider = entry.getKey(); - Collection> objects = provider.provide(); - for (me.shedaniel.rei.api.common.plugins.REIPlugin plugin : objects) { - ((PluginView) PluginManager.getInstance()).registerPlugin(wrapPlugin(entry.getValue(), plugin)); - if (plugin instanceof REIServerPlugin) { - ((PluginView) PluginManager.getServerInstance()).registerPlugin(wrapPlugin(entry.getValue(), (REIServerPlugin) plugin)); - } - } + ((PluginView) PluginManager.getServerInstance()).registerPlugin(wrapPlugin(entry.getValue(), wrapAndFilter(entry.getKey(), REIServerPlugin.class))); } - if (FMLEnvironment.dist == Dist.DEDICATED_SERVER) { - for (Map.Entry, List> entry : PluginDetectorImpl.getPluginsLoader(REIPluginLoaderDedicatedServer.class)) { - ((PluginView) PluginManager.getServerInstance()).registerPlugin(wrapPlugin(entry.getValue(), entry.getKey())); - } + for (Map.Entry>, List> entry : loaderProvidedCommon.get()) { + ((PluginView) PluginManager.getServerInstance()).registerPlugin(wrapPlugin(entry.getValue(), wrapAndFilter(entry.getKey(), REIServerPlugin.class))); + } + for (Map.Entry>, List> entry : loaderProvidedDist.get()) { + ((PluginView) PluginManager.getServerInstance()).registerPlugin(wrapPlugin(entry.getValue(), wrapAndFilter(entry.getKey(), REIServerPlugin.class))); } } @Override public void detectCommonPlugins() { EventBuses.registerModEventBus("roughlyenoughitems", FMLJavaModLoadingContext.get().getModEventBus()); + + // Legacy Annotation AnnotationUtils.>scanAnnotation(REIPlugin.class, me.shedaniel.rei.api.common.plugins.REIPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { ((PluginView) PluginManager.getInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); }); + + // Common plugins AnnotationUtils.>scanAnnotation(REIPluginCommon.class, me.shedaniel.rei.api.common.plugins.REIPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { ((PluginView) PluginManager.getInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); }); - for (Map.Entry>, List> entry : PluginDetectorImpl.getPluginsLoader(REIPluginLoaderCommon.class)) { + + // Dist plugins + if (FMLEnvironment.dist == Dist.CLIENT) { + AnnotationUtils.scanAnnotation(REIPluginClient.class, me.shedaniel.rei.api.common.plugins.REIPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { + ((PluginView) PluginManager.getInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); + }); + } else if (FMLEnvironment.dist == Dist.DEDICATED_SERVER) { + AnnotationUtils.scanAnnotation(REIPluginDedicatedServer.class, me.shedaniel.rei.api.common.plugins.REIPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { + ((PluginView) PluginManager.getInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); + }); + } + + // Loaders + for (Map.Entry>, List> entry : loaderProvided.get()) { + ((PluginView) PluginManager.getInstance()).registerPlugin(wrapPlugin(entry.getValue(), entry.getKey())); + } + for (Map.Entry>, List> entry : loaderProvidedCommon.get()) { + ((PluginView) PluginManager.getInstance()).registerPlugin(wrapPlugin(entry.getValue(), entry.getKey())); + } + for (Map.Entry>, List> entry : loaderProvidedDist.get()) { ((PluginView) PluginManager.getInstance()).registerPlugin(wrapPlugin(entry.getValue(), entry.getKey())); } } @@ -127,23 +178,60 @@ public class PluginDetectorImpl implements PluginDetector { return () -> () -> { PluginView.getClientInstance().registerPlugin(wrapPlugin(Collections.singletonList("roughlyenoughitems"), new DefaultClientPluginImpl())); PluginView.getClientInstance().registerPlugin(wrapPlugin(Collections.singletonList("roughlyenoughitems"), new DefaultClientRuntimePlugin())); + + // Legacy Annotation AnnotationUtils.scanAnnotation(REIPlugin.class, REIClientPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { ((PluginView) PluginManager.getClientInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); }); + + // Common plugins + AnnotationUtils.scanAnnotation(REIPluginCommon.class, REIClientPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { + ((PluginView) PluginManager.getClientInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); + }); + + // Dist plugins AnnotationUtils.scanAnnotation(REIPluginClient.class, REIClientPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { ((PluginView) PluginManager.getClientInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); }); + + // Loaders for (Map.Entry>, List> entry : loaderProvided.get()) { - REIPluginProvider> provider = entry.getKey(); - Collection> objects = provider.provide(); - for (me.shedaniel.rei.api.common.plugins.REIPlugin plugin : objects) { - if (plugin instanceof REIClientPlugin) { - ((PluginView) PluginManager.getClientInstance()).registerPlugin(wrapPlugin(entry.getValue(), (REIClientPlugin) plugin)); + ((PluginView) PluginManager.getClientInstance()).registerPlugin(wrapPlugin(entry.getValue(), wrapAndFilter(entry.getKey(), REIClientPlugin.class))); + } + for (Map.Entry>, List> entry : loaderProvidedCommon.get()) { + ((PluginView) PluginManager.getClientInstance()).registerPlugin(wrapPlugin(entry.getValue(), wrapAndFilter(entry.getKey(), REIClientPlugin.class))); + } + for (Map.Entry>, List> entry : loaderProvidedDist.get()) { + ((PluginView) PluginManager.getClientInstance()).registerPlugin(wrapPlugin(entry.getValue(), wrapAndFilter(entry.getKey(), REIClientPlugin.class))); + } + }; + } + + private static

> REIPluginProvider

wrapAndFilter(REIPluginProvider provider, Class

clazz) { + return new REIPluginProvider<>() { + @Override + public Collection

provide() { + return new AbstractCollection<>() { + @Override + public Iterator

iterator() { + return Iterables.filter(provider.provide(), clazz).iterator(); + } + + @Override + public int size() { + return Iterators.size(iterator()); } - } + }; + } + + @Override + public Class

getPluginProviderClass() { + return clazz; } - for (Map.Entry, List> entry : PluginDetectorImpl.getPluginsLoader(REIPluginLoaderClient.class)) { - ((PluginView) PluginManager.getClientInstance()).registerPlugin(wrapPlugin(entry.getValue(), entry.getKey())); + + @Override + public String getPluginProviderName() { + return provider.getPluginProviderName(); } }; } -- cgit