diff options
| author | shedaniel <daniel@shedaniel.me> | 2022-10-21 23:48:30 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2022-10-21 23:48:30 +0800 |
| commit | 22e1bf58aeb4204bed30200b28da60284f384f88 (patch) | |
| tree | fe84b955a8f3469dda08a2f636818c955a5c459e /forge/src/main/java | |
| parent | d70b8353a6db5fc5d835af5d662372952703d2fd (diff) | |
| parent | d8c250d378a2cbaede41093a80973e47f34aec00 (diff) | |
| download | RoughlyEnoughItems-22e1bf58aeb4204bed30200b28da60284f384f88.tar.gz RoughlyEnoughItems-22e1bf58aeb4204bed30200b28da60284f384f88.tar.bz2 RoughlyEnoughItems-22e1bf58aeb4204bed30200b28da60284f384f88.zip | |
Merge remote-tracking branch 'origin/8.x-1.18.2' into modularity
# Conflicts:
# api/build.gradle
# default-plugin/build.gradle
# forge/src/main/java/me/shedaniel/rei/forge/PluginDetectorImpl.java
# runtime-frontend/overlay-entries/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/entries/EntryListStackEntry.java
# runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java
# runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java
# runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.java
# runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java
Diffstat (limited to 'forge/src/main/java')
| -rw-r--r-- | forge/src/main/java/me/shedaniel/rei/forge/PluginDetectorImpl.java | 163 | ||||
| -rw-r--r-- | forge/src/main/java/me/shedaniel/rei/forge/REIPlugin.java | 1 | ||||
| -rw-r--r-- | forge/src/main/java/me/shedaniel/rei/forge/REIPluginClient.java (renamed from forge/src/main/java/me/shedaniel/rei/forge/JEIStub.java) | 11 | ||||
| -rw-r--r-- | forge/src/main/java/me/shedaniel/rei/forge/REIPluginCommon.java | 34 | ||||
| -rw-r--r-- | forge/src/main/java/me/shedaniel/rei/forge/REIPluginDedicatedServer.java | 34 | ||||
| -rw-r--r-- | forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoader.java | 38 | ||||
| -rw-r--r-- | forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoaderClient.java | 34 | ||||
| -rw-r--r-- | forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoaderCommon.java | 34 | ||||
| -rw-r--r-- | forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoaderDedicatedServer.java | 34 | ||||
| -rw-r--r-- | forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinInputConstants.java | 52 |
10 files changed, 414 insertions, 21 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 21397c373..6b432b932 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,9 @@ 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; @@ -40,16 +43,16 @@ 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.Collection; -import java.util.Collections; -import java.util.List; +import java.util.*; import java.util.function.Supplier; public class PluginDetectorImpl implements PluginDetector { private static <P extends me.shedaniel.rei.api.common.plugins.REIPlugin<?>> REIPluginProvider<P> wrapPlugin(List<String> modId, REIPluginProvider<P> plugin) { return new REIPluginProvider<P>() { - String nameSuffix = " [" + String.join(", ", modId) + "]"; + final String nameSuffix = " [" + String.join(", ", modId) + "]"; @Override public Collection<P> provide() { @@ -68,22 +71,108 @@ public class PluginDetectorImpl implements PluginDetector { }; } + private static final Supplier<List<Map.Entry<REIPluginProvider<me.shedaniel.rei.api.common.plugins.REIPlugin<?>>, List<String>>>> loaderProvided = + Suppliers.memoize(() -> getPluginsLoader(REIPluginLoader.class)); + private static final Supplier<List<Map.Entry<REIPluginProvider<me.shedaniel.rei.api.common.plugins.REIPlugin<?>>, List<String>>>> loaderProvidedCommon = + Suppliers.memoize(() -> getPluginsLoader(REIPluginLoaderCommon.class)); + private static final Supplier<List<Map.Entry<REIPluginProvider<me.shedaniel.rei.api.common.plugins.REIPlugin<?>>, List<String>>>> loaderProvidedDist; + + static { + Supplier<List<Map.Entry<REIPluginProvider<me.shedaniel.rei.api.common.plugins.REIPlugin<?>>, List<String>>>> 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 <T, P extends me.shedaniel.rei.api.common.plugins.REIPlugin<?>> List<Map.Entry<REIPluginProvider<P>, List<String>>> getPluginsLoader(Class<T> annotation) { + List<Map.Entry<REIPluginProvider<P>, List<String>>> list = new ArrayList<>(); + AnnotationUtils.<T, REIPluginProvider<P>>scanAnnotation(annotation, REIPluginProvider.class::isAssignableFrom, (modId, provider, clazz) -> { + try { + list.add(new AbstractMap.SimpleEntry<>(provider.get(), modId)); + } catch (Throwable throwable) { + throwable.printStackTrace(); + } + }); + return list; + } + @Override 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())); + + // Legacy Annotation AnnotationUtils.<REIPlugin, REIServerPlugin>scanAnnotation(REIPlugin.class, REIServerPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { ((PluginView<REIServerPlugin>) PluginManager.getServerInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); }); + + // Common plugins + AnnotationUtils.<REIPluginCommon, REIServerPlugin>scanAnnotation(REIPluginCommon.class, REIServerPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { + ((PluginView<REIServerPlugin>) PluginManager.getServerInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); + }); + + // Dist plugins + if (FMLEnvironment.dist == Dist.DEDICATED_SERVER) { + AnnotationUtils.<REIPluginDedicatedServer, REIServerPlugin>scanAnnotation(REIPluginDedicatedServer.class, REIServerPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { + ((PluginView<REIServerPlugin>) PluginManager.getServerInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); + }); + } else { + AnnotationUtils.<REIPluginClient, REIServerPlugin>scanAnnotation(REIPluginClient.class, REIServerPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { + ((PluginView<REIServerPlugin>) PluginManager.getServerInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); + }); + } + + // Loaders + for (Map.Entry<REIPluginProvider<me.shedaniel.rei.api.common.plugins.REIPlugin<?>>, List<String>> entry : loaderProvided.get()) { + ((PluginView<REIServerPlugin>) PluginManager.getServerInstance()).registerPlugin(wrapPlugin(entry.getValue(), wrapAndFilter(entry.getKey(), REIServerPlugin.class))); + } + for (Map.Entry<REIPluginProvider<me.shedaniel.rei.api.common.plugins.REIPlugin<?>>, List<String>> entry : loaderProvidedCommon.get()) { + ((PluginView<REIServerPlugin>) PluginManager.getServerInstance()).registerPlugin(wrapPlugin(entry.getValue(), wrapAndFilter(entry.getKey(), REIServerPlugin.class))); + } + for (Map.Entry<REIPluginProvider<me.shedaniel.rei.api.common.plugins.REIPlugin<?>>, List<String>> entry : loaderProvidedDist.get()) { + ((PluginView<REIServerPlugin>) PluginManager.getServerInstance()).registerPlugin(wrapPlugin(entry.getValue(), wrapAndFilter(entry.getKey(), REIServerPlugin.class))); + } } @Override public void detectCommonPlugins() { EventBuses.registerModEventBus("roughlyenoughitems", FMLJavaModLoadingContext.get().getModEventBus()); + + // Legacy Annotation AnnotationUtils.<REIPlugin, me.shedaniel.rei.api.common.plugins.REIPlugin<?>>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.<REIPluginCommon, me.shedaniel.rei.api.common.plugins.REIPlugin<?>>scanAnnotation(REIPluginCommon.class, me.shedaniel.rei.api.common.plugins.REIPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { + ((PluginView) PluginManager.getInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); + }); + + // Dist plugins + if (FMLEnvironment.dist == Dist.CLIENT) { + AnnotationUtils.<REIPluginClient, me.shedaniel.rei.api.common.plugins.REIPlugin>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.<REIPluginDedicatedServer, me.shedaniel.rei.api.common.plugins.REIPlugin>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<REIPluginProvider<me.shedaniel.rei.api.common.plugins.REIPlugin<?>>, List<String>> entry : loaderProvided.get()) { + ((PluginView) PluginManager.getInstance()).registerPlugin(wrapPlugin(entry.getValue(), entry.getKey())); + } + for (Map.Entry<REIPluginProvider<me.shedaniel.rei.api.common.plugins.REIPlugin<?>>, List<String>> entry : loaderProvidedCommon.get()) { + ((PluginView) PluginManager.getInstance()).registerPlugin(wrapPlugin(entry.getValue(), entry.getKey())); + } + for (Map.Entry<REIPluginProvider<me.shedaniel.rei.api.common.plugins.REIPlugin<?>>, List<String>> entry : loaderProvidedDist.get()) { + ((PluginView) PluginManager.getInstance()).registerPlugin(wrapPlugin(entry.getValue(), entry.getKey())); + } } @OnlyIn(Dist.CLIENT) @@ -95,21 +184,61 @@ public class PluginDetectorImpl implements PluginDetector { PluginView.getClientInstance().registerPlugin(wrapPlugin(Collections.singletonList("roughlyenoughitems"), new DefaultRuntimeInputMethodPlugin())); PluginView.getClientInstance().registerPlugin(wrapPlugin(Collections.singletonList("roughlyenoughitems"), new DefaultClientTransferCategoryPlugin())); PluginView.getClientInstance().registerPlugin(wrapPlugin(Collections.singletonList("roughlyenoughitems"), new FavoritesEntriesBuiltinPlugin())); - // PluginView.getClientInstance().registerPlugin(wrapPlugin(Collections.singletonList("roughlyenoughitems"), new JEIExtraClientPlugin())); + + // Legacy Annotation AnnotationUtils.<REIPlugin, REIClientPlugin>scanAnnotation(REIPlugin.class, REIClientPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { ((PluginView<REIClientPlugin>) PluginManager.getClientInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); }); -// ClientInternals.attachInstance((Supplier<List<String>>) () -> { -// List<String> modIds = new ArrayList<>(); -// for (REIPluginProvider<REIClientPlugin> 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<Object>) aClass, c -> true, -// (TriConsumer<List<String>, Supplier<Object>, Class<Object>>) (TriConsumer) consumer), PluginView.getClientInstance()::registerPlugin); + + // Common plugins + AnnotationUtils.<REIPluginCommon, REIClientPlugin>scanAnnotation(REIPluginCommon.class, REIClientPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { + ((PluginView<REIClientPlugin>) PluginManager.getClientInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); + }); + + // Dist plugins + AnnotationUtils.<REIPluginClient, REIClientPlugin>scanAnnotation(REIPluginClient.class, REIClientPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { + ((PluginView<REIClientPlugin>) PluginManager.getClientInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); + }); + + // Loaders + for (Map.Entry<REIPluginProvider<me.shedaniel.rei.api.common.plugins.REIPlugin<?>>, List<String>> entry : loaderProvided.get()) { + ((PluginView<REIClientPlugin>) PluginManager.getClientInstance()).registerPlugin(wrapPlugin(entry.getValue(), wrapAndFilter(entry.getKey(), REIClientPlugin.class))); + } + for (Map.Entry<REIPluginProvider<me.shedaniel.rei.api.common.plugins.REIPlugin<?>>, List<String>> entry : loaderProvidedCommon.get()) { + ((PluginView<REIClientPlugin>) PluginManager.getClientInstance()).registerPlugin(wrapPlugin(entry.getValue(), wrapAndFilter(entry.getKey(), REIClientPlugin.class))); + } + for (Map.Entry<REIPluginProvider<me.shedaniel.rei.api.common.plugins.REIPlugin<?>>, List<String>> entry : loaderProvidedDist.get()) { + ((PluginView<REIClientPlugin>) PluginManager.getClientInstance()).registerPlugin(wrapPlugin(entry.getValue(), wrapAndFilter(entry.getKey(), REIClientPlugin.class))); + } + }; + } + + private static <P extends me.shedaniel.rei.api.common.plugins.REIPlugin<P>> REIPluginProvider<P> wrapAndFilter(REIPluginProvider<?> provider, Class<P> clazz) { + return new REIPluginProvider<>() { + @Override + public Collection<P> provide() { + return new AbstractCollection<>() { + @Override + public Iterator<P> iterator() { + return Iterables.filter(provider.provide(), clazz).iterator(); + } + + @Override + public int size() { + return Iterators.size(iterator()); + } + }; + } + + @Override + public Class<P> getPluginProviderClass() { + return clazz; + } + + @Override + public String getPluginProviderName() { + return provider.getPluginProviderName(); + } }; } } 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/JEIStub.java b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginClient.java index 63634d56b..5584b5f7c 100644 --- a/forge/src/main/java/me/shedaniel/rei/forge/JEIStub.java +++ b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginClient.java @@ -23,9 +23,12 @@ package me.shedaniel.rei.forge; -import net.minecraftforge.fml.common.Mod; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; -// Hello mods, JEI is present!! Please give in and trust me! -@Mod("jei") -public class JEIStub { +@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 new file mode 100644 index 000000000..1303b14cf --- /dev/null +++ b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoader.java @@ -0,0 +1,38 @@ +/* + * 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) +@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 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..0097c8df6 --- /dev/null +++ b/forge/src/main/java/me/shedaniel/rei/mixin/forge/MixinInputConstants.java @@ -0,0 +1,52 @@ +/* + * 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<Boolean> cir) { + if (isPatchingAsyncThreadCrash() && !RenderSystem.isOnRenderThread()) { + cir.setReturnValue(false); + } + } + + @Unique + private static boolean isPatchingAsyncThreadCrash() { + try { + return ConfigObject.getInstance().isPatchingAsyncThreadCrash(); + } catch (Throwable throwable) { + return false; + } + } +} |
