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