aboutsummaryrefslogtreecommitdiff
path: root/forge/src/main/java/me/shedaniel
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2022-09-22 22:45:24 +0800
committershedaniel <daniel@shedaniel.me>2022-09-22 22:45:24 +0800
commit445c8d99a69a43e441a0d9fb42874309f176d73c (patch)
treee496c5beb85b0408fffe425da194144452011f56 /forge/src/main/java/me/shedaniel
parent509356edea66bddee010062cf57b586339c57b6a (diff)
downloadRoughlyEnoughItems-445c8d99a69a43e441a0d9fb42874309f176d73c.tar.gz
RoughlyEnoughItems-445c8d99a69a43e441a0d9fb42874309f176d73c.tar.bz2
RoughlyEnoughItems-445c8d99a69a43e441a0d9fb42874309f176d73c.zip
Add REIPluginLoader and resolve dists properly
Diffstat (limited to 'forge/src/main/java/me/shedaniel')
-rw-r--r--forge/src/main/java/me/shedaniel/rei/forge/PluginDetectorImpl.java32
-rw-r--r--forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoader.java37
2 files changed, 66 insertions, 3 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 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<Map.Entry<REIPluginProvider<me.shedaniel.rei.api.common.plugins.REIPlugin<?>>, List<String>>>> loaderProvided = Suppliers.memoize(() -> {
+ List<Map.Entry<REIPluginProvider<me.shedaniel.rei.api.common.plugins.REIPlugin<?>>, List<String>>> list = new ArrayList<>();
+ AnnotationUtils.<REIPluginLoader, REIPluginProvider<me.shedaniel.rei.api.common.plugins.REIPlugin<?>>>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.<REIPlugin, REIServerPlugin>scanAnnotation(REIPlugin.class, REIServerPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> {
((PluginView<REIServerPlugin>) PluginManager.getServerInstance()).registerPlugin(wrapPlugin(modId, plugin.get()));
});
+ for (Map.Entry<REIPluginProvider<me.shedaniel.rei.api.common.plugins.REIPlugin<?>>, List<String>> entry : loaderProvided.get()) {
+ REIPluginProvider<me.shedaniel.rei.api.common.plugins.REIPlugin<?>> provider = entry.getKey();
+ Collection<me.shedaniel.rei.api.common.plugins.REIPlugin<?>> 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<REIServerPlugin>) PluginManager.getServerInstance()).registerPlugin(wrapPlugin(entry.getValue(), (REIServerPlugin) plugin));
+ }
+ }
+ }
}
@Override
@@ -91,6 +108,15 @@ public class PluginDetectorImpl implements PluginDetector {
AnnotationUtils.<REIPlugin, REIClientPlugin>scanAnnotation(REIPlugin.class, REIClientPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> {
((PluginView<REIClientPlugin>) PluginManager.getClientInstance()).registerPlugin(wrapPlugin(modId, plugin.get()));
});
+ for (Map.Entry<REIPluginProvider<me.shedaniel.rei.api.common.plugins.REIPlugin<?>>, List<String>> entry : loaderProvided.get()) {
+ REIPluginProvider<me.shedaniel.rei.api.common.plugins.REIPlugin<?>> provider = entry.getKey();
+ Collection<me.shedaniel.rei.api.common.plugins.REIPlugin<?>> objects = provider.provide();
+ for (me.shedaniel.rei.api.common.plugins.REIPlugin<?> plugin : objects) {
+ if (plugin instanceof REIClientPlugin) {
+ ((PluginView<REIClientPlugin>) 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