diff options
| author | shedaniel <daniel@shedaniel.me> | 2022-01-18 03:23:18 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2022-01-18 03:23:18 +0800 |
| commit | d095053af792cc5b6368772a7c4e36914ca097f5 (patch) | |
| tree | d23421f8caf9a16c6cd84b8393f5ac7153cca132 /forge/src/main | |
| parent | 3b30945f5975d59ac4b2583a34a246cc88534640 (diff) | |
| download | RoughlyEnoughItems-d095053af792cc5b6368772a7c4e36914ca097f5.tar.gz RoughlyEnoughItems-d095053af792cc5b6368772a7c4e36914ca097f5.tar.bz2 RoughlyEnoughItems-d095053af792cc5b6368772a7c4e36914ca097f5.zip | |
Add option to specify the dists
Diffstat (limited to 'forge/src/main')
| -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 644fd8231..0f0e404d2 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.annotationType())) { + Object value = annotation.annotationData().get("value"); + boolean enabled; + + if (value instanceof Dist[]) { + enabled = Arrays.asList((Dist[]) value).contains(FMLEnvironment.dist); + } else { + enabled = true; + } + + if (enabled && annotationType.equals(annotation.annotationType())) { try { Class<T> clazz = (Class<T>) Class.forName(annotation.memberName()); 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.memberName() + " 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(); } LOGGER.error("Failed to load plugin: " + annotation.memberName(), 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}; } |
