From 95ea1663038362efb2bdb61d521ee6e4274a34f7 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sun, 18 Sep 2022 02:20:25 +0800 Subject: Fix #1034 --- .../rei/api/client/config/ConfigObject.java | 3 ++ .../rei/mixin/fabric/MixinInputConstants.java | 48 ++++++++++++++++++++++ fabric/src/main/resources/rei.mixins.json | 1 + forge/build.gradle | 10 ----- .../me/shedaniel/rei/forge/PluginDetectorImpl.java | 20 --------- .../rei/mixin/forge/MixinInputConstants.java | 48 ++++++++++++++++++++++ forge/src/main/resources/rei.mixins.json | 1 + .../rei/impl/client/config/ConfigObjectImpl.java | 7 ++++ .../assets/roughlyenoughitems/lang/en_us.json | 1 + settings.gradle | 3 -- 10 files changed, 109 insertions(+), 33 deletions(-) create mode 100644 fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinInputConstants.java create mode 100644 forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinInputConstants.java diff --git a/api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java b/api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java index 4da17b6c0..c994980cd 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java @@ -316,6 +316,9 @@ public interface ConfigObject { @ApiStatus.Experimental int getAsyncSearchPartitionSize(); + @ApiStatus.Experimental + boolean isPatchingAsyncThreadCrash(); + @ApiStatus.Experimental boolean doDebugSearchTimeRequired(); diff --git a/fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinInputConstants.java b/fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinInputConstants.java new file mode 100644 index 000000000..6fa7979e4 --- /dev/null +++ b/fabric/src/main/java/me/shedaniel/rei/mixin/fabric/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.fabric; + +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/fabric/src/main/resources/rei.mixins.json b/fabric/src/main/resources/rei.mixins.json index 7d240b971..3946fe5a8 100644 --- a/fabric/src/main/resources/rei.mixins.json +++ b/fabric/src/main/resources/rei.mixins.json @@ -6,6 +6,7 @@ "client": [ "MixinClientPacketListener", "MixinEffectRenderingInventoryScreen", + "MixinInputConstants", "MixinRecipeToast", "MixinScreen" ], diff --git a/forge/build.gradle b/forge/build.gradle index 2fc76b263..94719bf61 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -56,12 +56,6 @@ loom { } forge { - localMods { - jeiInternalsWorkaround { - add(project(":jei-internals-workaround").sourceSets.main) - } - } - mixinConfig "rei.mixins.json" } } @@ -73,10 +67,6 @@ dependencies { modApi("me.shedaniel.cloth:cloth-config-forge:${cloth_config_version}") modApi("dev.architectury:architectury-forge:${architectury_version}") - common(project(path: ":jei-compatibility-layer", configuration: "namedElements")) { transitive false } - shadowCommon(project(path: ":jei-compatibility-layer", configuration: "namedElements")) { transitive false } - runtimeClasspath(project(path: ":jei-internals-workaround", configuration: "namedElements")) { transitive false } - depProjects.forEach { common(project(path: it, configuration: "namedElements")) { transitive false } shadowCommon(project(path: it, configuration: "transformProductionForge")) { transitive false } 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": [ 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 83964e65c..f65e67dcb 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 @@ -425,6 +425,12 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { return advanced.search.asyncSearchPartitionSize; } + @Override + @ApiStatus.Experimental + public boolean isPatchingAsyncThreadCrash() { + return advanced.search.patchAsyncThreadCrash; + } + @Override @ApiStatus.Experimental public boolean doDebugSearchTimeRequired() { @@ -673,6 +679,7 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { @Comment("Declares whether REI should search async.") private boolean asyncSearch = true; @Comment("Declares how many entries should be grouped one async search.") @ConfigEntry.BoundedDiscrete(min = 25, max = 400) private int asyncSearchPartitionSize = 100; + private boolean patchAsyncThreadCrash = true; @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) private SearchMode tooltipSearch = SearchMode.ALWAYS; @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) diff --git a/runtime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json b/runtime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json index c701e1e10..9b4606603 100755 --- a/runtime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json +++ b/runtime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json @@ -249,6 +249,7 @@ "config.roughlyenoughitems.accessibility.entrySize": "Entry Size:", "config.roughlyenoughitems.search.asyncSearch": "Async Search:", "config.roughlyenoughitems.search.asyncSearchPartitionSize": "Async Search Partition Size:", + "config.roughlyenoughitems.search.patchAsyncThreadCrash": "Patch Async Thread Crash:", "config.roughlyenoughitems.accessibility.useCompactTabs": "Compact Tabs:", "config.roughlyenoughitems.accessibility.useCompactTabButtons": "Compact Tab Arrow Buttons:", "config.roughlyenoughitems.theme": "Appearance Theme:", diff --git a/settings.gradle b/settings.gradle index be97e596c..937a949bf 100755 --- a/settings.gradle +++ b/settings.gradle @@ -14,6 +14,3 @@ include "default-plugin" include "runtime" include "fabric" include "forge" - -include "jei-compatibility-layer" -include "jei-internals-workaround" -- cgit From 509356edea66bddee010062cf57b586339c57b6a Mon Sep 17 00:00:00 2001 From: shedaniel Date: Thu, 22 Sep 2022 21:03:25 +0800 Subject: Don't publish forge yet --- .github/workflows/curseforge.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/curseforge.yml b/.github/workflows/curseforge.yml index e46909da5..17d149f1a 100644 --- a/.github/workflows/curseforge.yml +++ b/.github/workflows/curseforge.yml @@ -25,7 +25,7 @@ jobs: - name: Upload Mod uses: gradle/gradle-build-action@v2 with: - arguments: build publish forge:publishUnified fabric:publishUnified jei-internals-workaround:publishUnified --stacktrace + arguments: build publish fabric:publishUnified --stacktrace env: danielshe_curse_api_key: ${{ secrets.CF_API_KEY }} modrinth_key: ${{ secrets.MODRINTH_KEY }} -- 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 --- .github/workflows/curseforge.yml | 2 +- .../me/shedaniel/rei/forge/PluginDetectorImpl.java | 32 +++++++++++++++++-- .../me/shedaniel/rei/forge/REIPluginLoader.java | 37 ++++++++++++++++++++++ 3 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoader.java diff --git a/.github/workflows/curseforge.yml b/.github/workflows/curseforge.yml index 17d149f1a..be653f15d 100644 --- a/.github/workflows/curseforge.yml +++ b/.github/workflows/curseforge.yml @@ -25,7 +25,7 @@ jobs: - name: Upload Mod uses: gradle/gradle-build-action@v2 with: - arguments: build publish fabric:publishUnified --stacktrace + arguments: build publish fabric:publishUnified forge:publishUnified --stacktrace env: danielshe_curse_api_key: ${{ secrets.CF_API_KEY }} modrinth_key: ${{ secrets.MODRINTH_KEY }} 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 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 --- api/build.gradle | 17 +++++---- default-plugin/build.gradle | 14 +++++--- fake/REIPlugin.class | Bin 556 -> 627 bytes fake/REIPluginClient.class | Bin 0 -> 404 bytes fake/REIPluginCommon.class | Bin 0 -> 404 bytes fake/REIPluginDedicatedServer.class | Bin 0 -> 422 bytes fake/REIPluginLoader.class | Bin 0 -> 639 bytes fake/REIPluginLoaderClient.class | Bin 0 -> 416 bytes fake/REIPluginLoaderCommon.class | Bin 0 -> 416 bytes fake/REIPluginLoaderDedicatedServer.class | Bin 0 -> 434 bytes fake/mods.toml | 10 ++++++ forge/build.gradle | 24 +++++++++---- .../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 ++++++++++++++++++ 21 files changed, 287 insertions(+), 22 deletions(-) create mode 100644 fake/REIPluginClient.class create mode 100644 fake/REIPluginCommon.class create mode 100644 fake/REIPluginDedicatedServer.class create mode 100644 fake/REIPluginLoader.class create mode 100644 fake/REIPluginLoaderClient.class create mode 100644 fake/REIPluginLoaderCommon.class create mode 100644 fake/REIPluginLoaderDedicatedServer.class create mode 100644 fake/mods.toml 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 diff --git a/api/build.gradle b/api/build.gradle index 9cbc69fa1..23ee2975c 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -1,3 +1,5 @@ +import net.fabricmc.loom.task.RemapJarTask + archivesBaseName = rootProject.name + "-" + project.name dependencies { @@ -22,13 +24,16 @@ task fakeJar(type: Jar, dependsOn: remapJar) { classifier null } -task fakeForgeJar(type: Jar, dependsOn: remapJar) { - from remapJar.archiveFile.map { zipTree(it) } - from(rootProject.file("fake/fabric.mod.json")) { - into "" +task fakeForgeJar(type: Jar, dependsOn: jar) { + from jar.archiveFile.map { zipTree(it) } + from(rootProject.file("fake/mods.toml")) { + into "META-INF" } - from(rootProject.file("fake/REIPlugin.class")) { - into "me/shedaniel/rei/forge" + ["REIPlugin", "REIPluginClient", "REIPluginCommon", "REIPluginDedicatedServer", + "REIPluginLoader", "REIPluginLoaderClient", "REIPluginLoaderCommon", "REIPluginLoaderDedicatedServer"].each { + from(rootProject.file("fake/$it.class")) { + into "me/shedaniel/rei/forge" + } } classifier "fake-forge" } diff --git a/default-plugin/build.gradle b/default-plugin/build.gradle index 52b92ba90..c47536992 100644 --- a/default-plugin/build.gradle +++ b/default-plugin/build.gradle @@ -27,10 +27,16 @@ task fakeJar(type: Jar, dependsOn: remapJar) { classifier null } -task fakeForgeJar(type: Jar, dependsOn: remapJar) { - from remapJar.archiveFile.map { zipTree(it) } - from(rootProject.file("fake/fabric.mod.json")) { - into "" +task fakeForgeJar(type: Jar, dependsOn: jar) { + from jar.archiveFile.map { zipTree(it) } + from(rootProject.file("fake/mods.toml")) { + into "META-INF" + } + ["REIPlugin", "REIPluginClient", "REIPluginCommon", "REIPluginDedicatedServer", + "REIPluginLoader", "REIPluginLoaderClient", "REIPluginLoaderCommon", "REIPluginLoaderDedicatedServer"].each { + from(rootProject.file("fake/$it.class")) { + into "me/shedaniel/rei/forge" + } } classifier "fake-forge" } diff --git a/fake/REIPlugin.class b/fake/REIPlugin.class index 52c4432dc..83ddc0db7 100644 Binary files a/fake/REIPlugin.class and b/fake/REIPlugin.class differ diff --git a/fake/REIPluginClient.class b/fake/REIPluginClient.class new file mode 100644 index 000000000..b9b15aad1 Binary files /dev/null and b/fake/REIPluginClient.class differ diff --git a/fake/REIPluginCommon.class b/fake/REIPluginCommon.class new file mode 100644 index 000000000..1317a21b7 Binary files /dev/null and b/fake/REIPluginCommon.class differ diff --git a/fake/REIPluginDedicatedServer.class b/fake/REIPluginDedicatedServer.class new file mode 100644 index 000000000..251fa80ee Binary files /dev/null and b/fake/REIPluginDedicatedServer.class differ diff --git a/fake/REIPluginLoader.class b/fake/REIPluginLoader.class new file mode 100644 index 000000000..e8112a583 Binary files /dev/null and b/fake/REIPluginLoader.class differ diff --git a/fake/REIPluginLoaderClient.class b/fake/REIPluginLoaderClient.class new file mode 100644 index 000000000..4a730e2eb Binary files /dev/null and b/fake/REIPluginLoaderClient.class differ diff --git a/fake/REIPluginLoaderCommon.class b/fake/REIPluginLoaderCommon.class new file mode 100644 index 000000000..22e44c6b4 Binary files /dev/null and b/fake/REIPluginLoaderCommon.class differ diff --git a/fake/REIPluginLoaderDedicatedServer.class b/fake/REIPluginLoaderDedicatedServer.class new file mode 100644 index 000000000..46e006300 Binary files /dev/null and b/fake/REIPluginLoaderDedicatedServer.class differ diff --git a/fake/mods.toml b/fake/mods.toml new file mode 100644 index 000000000..6df8b4b18 --- /dev/null +++ b/fake/mods.toml @@ -0,0 +1,10 @@ +modLoader = "javafml" +loaderVersion = "[1,)" +logoFile = "icon.png" +authors = "shedaniel" +license = "MIT" + +[[mods]] +modId = "rei_fake" +version = "ABC" +displayName = "THIS SHOULDN'T SHOW UP" diff --git a/forge/build.gradle b/forge/build.gradle index 94719bf61..9ac210ac0 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -185,19 +185,29 @@ components.java { publishing { publications { - mavenFabric(MavenPublication) { + mavenForge(MavenPublication) { artifactId = rootProject.name + "-" + project.name from components.java } ["api", "default-plugin"].forEach { projectName -> - create(projectName + "Fabric", MavenPublication.class) { publication -> + def remapSrg = tasks.create("remapSrgJarFor$projectName", net.fabricmc.loom.task.RemapJarTask) { + inputFile = project(":" + projectName).tasks.jar.archiveFile + classifier "srg-remapped-$projectName" + targetNamespace = "srg" + } + def remapSrgSourcesJar = tasks.create("remapSrgSourcesFor$projectName", net.fabricmc.loom.task.RemapSourcesJarTask) { + inputFile = project(":" + projectName).tasks.sourcesJar.archiveFile + classifier "srg-remapped-$projectName-sources" + targetNamespace = "srg" + } + create(projectName + "Forge", MavenPublication.class) { publication -> publication.artifactId = rootProject.name + "-" + projectName + "-forge" project.afterEvaluate { def project = project(":" + projectName) - publication.artifact(project.fakeForgeJar) { classifier null } - def remapSourcesJarTask = project.remapSourcesJar - publication.artifact(remapSourcesJarTask) { - builtBy remapSourcesJarTask + remapSrg.inputFile = project.fakeForgeJar.archiveFile + publication.artifact(remapSrg) { classifier null } + publication.artifact(remapSrgSourcesJar) { + builtBy remapSrgSourcesJar classifier "sources" } } @@ -232,7 +242,7 @@ unifiedPublishing { token = project.hasProperty("danielshe_curse_api_key") ? project.property("danielshe_curse_api_key") : System.getenv("danielshe_curse_api_key") id = "310111" gameVersions.addAll "Java 17" - + relations { depends "roughly-enough-items-hacks" } 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 --- .../java/me/shedaniel/rei/mixin/fabric/MixinInputConstants.java | 6 +++++- .../main/java/me/shedaniel/rei/mixin/forge/MixinInputConstants.java | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinInputConstants.java b/fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinInputConstants.java index 6fa7979e4..634c81339 100644 --- a/fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinInputConstants.java +++ b/fabric/src/main/java/me/shedaniel/rei/mixin/fabric/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; + } } } 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(-) 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