diff options
| author | shedaniel <daniel@shedaniel.me> | 2022-01-18 03:23:18 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2022-01-18 22:29:39 +0800 |
| commit | de37c7de7d6800a1d574ba96e2516f2c16311ee7 (patch) | |
| tree | 42a1eb3baab4c366e41c90027487828326a272c9 /forge/src/main/java | |
| parent | 707d0f07ad88997db663414c3c545cc8615b8d37 (diff) | |
| download | RoughlyEnoughItems-de37c7de7d6800a1d574ba96e2516f2c16311ee7.tar.gz RoughlyEnoughItems-de37c7de7d6800a1d574ba96e2516f2c16311ee7.tar.bz2 RoughlyEnoughItems-de37c7de7d6800a1d574ba96e2516f2c16311ee7.zip | |
Add option to specify the dists
Diffstat (limited to 'forge/src/main/java')
| -rw-r--r-- | forge/src/main/java/me/shedaniel/rei/forge/AnnotationUtils.java | 19 | ||||
| -rw-r--r-- | forge/src/main/java/me/shedaniel/rei/forge/REIPlugin.java | 3 |
2 files changed, 20 insertions, 2 deletions
diff --git a/forge/src/main/java/me/shedaniel/rei/forge/AnnotationUtils.java b/forge/src/main/java/me/shedaniel/rei/forge/AnnotationUtils.java index f315c20b6..57aa959c6 100644 --- a/forge/src/main/java/me/shedaniel/rei/forge/AnnotationUtils.java +++ b/forge/src/main/java/me/shedaniel/rei/forge/AnnotationUtils.java @@ -25,7 +25,9 @@ package me.shedaniel.rei.forge; import com.google.common.collect.Lists; import me.shedaniel.rei.RoughlyEnoughItemsInitializer; +import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.ModList; +import net.minecraftforge.fml.loading.FMLEnvironment; import net.minecraftforge.forgespi.language.IModInfo; import net.minecraftforge.forgespi.language.ModFileScanData; import org.apache.commons.lang3.tuple.ImmutableTriple; @@ -35,6 +37,7 @@ import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.util.TriConsumer; import org.objectweb.asm.Type; +import java.util.Arrays; import java.util.List; import java.util.function.Predicate; import java.util.function.Supplier; @@ -56,7 +59,16 @@ public class AnnotationUtils { .collect(Collectors.toList()); out: for (ModFileScanData.AnnotationData annotation : data.getAnnotations()) { - if (annotationType.equals(annotation.getAnnotationType())) { + Object value = annotation.getAnnotationData().get("value"); + boolean enabled; + + if (value instanceof Dist[]) { + enabled = Arrays.asList((Dist[]) value).contains(FMLEnvironment.dist); + } else { + enabled = true; + } + + if (enabled && annotationType.equals(annotation.getAnnotationType())) { try { Class<T> clazz = (Class<T>) Class.forName(annotation.getMemberName()); if (predicate.test(clazz)) { @@ -72,8 +84,11 @@ public class AnnotationUtils { } catch (Throwable throwable) { Throwable t = throwable; while (t != null) { - if (t.getMessage() != null && t.getMessage().contains("invalid dist DEDICATED_SERVER") && !RoughlyEnoughItemsInitializer.isClient()) + if (t.getMessage() != null && t.getMessage().contains("invalid dist DEDICATED_SERVER") && !RoughlyEnoughItemsInitializer.isClient()) { + LOGGER.warn("Plugin " + annotation.getMemberName() + " is attempting to load on the server, but is not compatible with the server. " + + "The mod should declare the environments it is compatible with in the @" + annotationType.getClassName() + " annotation."); continue out; + } t = t.getCause(); } AnnotationUtils.LOGGER.error("Failed to load plugin: " + annotation.getMemberName(), throwable); 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 1a6a0e6c7..db15c8093 100644 --- a/forge/src/main/java/me/shedaniel/rei/forge/REIPlugin.java +++ b/forge/src/main/java/me/shedaniel/rei/forge/REIPlugin.java @@ -23,6 +23,8 @@ 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; @@ -31,4 +33,5 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface REIPlugin { + Dist[] value() default {Dist.CLIENT, Dist.DEDICATED_SERVER}; } |
