diff --git a/docs/README.md b/docs/README.md index 64b96d8e0e..cf7d48e835 100644 --- a/docs/README.md +++ b/docs/README.md @@ -63,5 +63,5 @@ We require all contributors to acknowledge the [Forge Contributor [Download]: https://files.minecraftforge.net/ [Forum]: https://www.minecraftforge.net/forum/ -[Discord]: https://discord.gg/UvedJ9m +[Discord]: https://discord.minecraftforge.net [Documentation]: https://mcforge.readthedocs.io diff --git a/fmlcore/src/main/java/net/minecraftforge/fml/IExtensionPoint.java b/fmlcore/src/main/java/net/minecraftforge/fml/IExtensionPoint.java index 0b147d3ac5..570bb6355b 100644 --- a/fmlcore/src/main/java/net/minecraftforge/fml/IExtensionPoint.java +++ b/fmlcore/src/main/java/net/minecraftforge/fml/IExtensionPoint.java @@ -46,5 +46,24 @@ public interface IExtensionPoint */ record DisplayTest(Supplier suppliedVersion, BiPredicate remoteVersionTest) implements IExtensionPoint { public static final String IGNORESERVERONLY = "OHNOES\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31"; + + /** + * Ignores any version information coming from the server - use for server only mods + */ + public static final Supplier IGNORE_SERVER_VERSION = () -> new DisplayTest(IGNORESERVERONLY, (remoteVersion, isFromServer) -> true); + + /** + * Ignores all information and provides no information + */ + public static final Supplier IGNORE_ALL_VERSION = () -> new DisplayTest("", (remoteVersion, isFromServer) -> true); + + /** + * An optional alternative to {@link #DisplayTest(Supplier, BiPredicate)} which accepts a constant version string + * instead of a {@link Supplier}. + *

Internally, the provided version string is wrapped in a Supplier for you.

+ */ + public DisplayTest(String version, BiPredicate remoteVersionTest) { + this(() -> version, remoteVersionTest); + } } } \ No newline at end of file diff --git a/fmlcore/src/main/java/net/minecraftforge/fml/ModContainer.java b/fmlcore/src/main/java/net/minecraftforge/fml/ModContainer.java index eac10f51ad..a82ebea87d 100644 --- a/fmlcore/src/main/java/net/minecraftforge/fml/ModContainer.java +++ b/fmlcore/src/main/java/net/minecraftforge/fml/ModContainer.java @@ -20,6 +20,7 @@ import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; import java.util.function.BiFunction; +import java.util.function.BiPredicate; import java.util.function.Consumer; import java.util.function.Supplier; @@ -63,9 +64,9 @@ public abstract class ModContainer () -> new IExtensionPoint.DisplayTest(() -> this.modInfo.getVersion().toString(), (incoming, isNetwork) -> Objects.equals(incoming, this.modInfo.getVersion().toString())); case "IGNORE_SERVER_VERSION" -> // Ignores any version information coming from the server - use for server only mods - () -> new IExtensionPoint.DisplayTest(() -> IExtensionPoint.DisplayTest.IGNORESERVERONLY, (incoming, isNetwork) -> true); + IExtensionPoint.DisplayTest.IGNORE_SERVER_VERSION; case "IGNORE_ALL_VERSION" -> // Ignores all information and provides no information - () -> new IExtensionPoint.DisplayTest(() -> "", (incoming, isNetwork) -> true); + IExtensionPoint.DisplayTest.IGNORE_ALL_VERSION; case "NONE" -> null; // NO display test at all - use this if you're going to do your own display test default -> // any other value throws an exception throw new IllegalArgumentException("Invalid displayTest value supplied in mods.toml"); @@ -142,6 +143,22 @@ public abstract class ModContainer extensionPoints.put(point, extension); } + public void registerDisplayTest(IExtensionPoint.DisplayTest displayTest) { + registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> displayTest); + } + + public void registerDisplayTest(Supplier displayTest) { + registerExtensionPoint(IExtensionPoint.DisplayTest.class, displayTest); + } + + public void registerDisplayTest(String version, BiPredicate remoteVersionTest) { + registerDisplayTest(new IExtensionPoint.DisplayTest(version, remoteVersionTest)); + } + + public void registerDisplayTest(Supplier suppliedVersion, BiPredicate remoteVersionTest) { + registerDisplayTest(new IExtensionPoint.DisplayTest(suppliedVersion, remoteVersionTest)); + } + public void addConfig(final ModConfig modConfig) { configs.put(modConfig.getType(), modConfig); } diff --git a/fmlcore/src/main/java/net/minecraftforge/fml/ModLoadingContext.java b/fmlcore/src/main/java/net/minecraftforge/fml/ModLoadingContext.java index 0d36c1b308..1f65e2be7c 100644 --- a/fmlcore/src/main/java/net/minecraftforge/fml/ModLoadingContext.java +++ b/fmlcore/src/main/java/net/minecraftforge/fml/ModLoadingContext.java @@ -8,6 +8,7 @@ package net.minecraftforge.fml; import net.minecraftforge.fml.config.IConfigSpec; import net.minecraftforge.fml.config.ModConfig; +import java.util.function.BiPredicate; import java.util.function.Supplier; public class ModLoadingContext @@ -45,6 +46,44 @@ public class ModLoadingContext getActiveContainer().registerExtensionPoint(point, extension); } + /** + * Register a {@link IExtensionPoint.DisplayTest} with the mod container. + *

A shorthand for registering a DisplayTest with {@link #registerExtensionPoint(Class, Supplier)}.

+ * @param displayTest The {@link IExtensionPoint.DisplayTest} to register + */ + public void registerDisplayTest(IExtensionPoint.DisplayTest displayTest) { + getActiveContainer().registerDisplayTest(() -> displayTest); + } + + /** + * Register a {@link IExtensionPoint.DisplayTest} with the mod container. + *

A shorthand for registering a DisplayTest supplier with {@link #registerExtensionPoint(Class, Supplier)}.

+ * @param displayTest The {@link Supplier} to register + */ + public void registerDisplayTest(Supplier displayTest) { + getActiveContainer().registerDisplayTest(displayTest); + } + + /** + * Register a {@link IExtensionPoint.DisplayTest} with the mod container. + *

A shorthand for registering a DisplayTest with {@link #registerExtensionPoint(Class, Supplier)} that also + * creates the DisplayTest instance for you using the provided parameters.

+ * @see IExtensionPoint.DisplayTest#DisplayTest(String, BiPredicate) + */ + public void registerDisplayTest(String version, BiPredicate remoteVersionTest) { + getActiveContainer().registerDisplayTest(new IExtensionPoint.DisplayTest(version, remoteVersionTest)); + } + + /** + * Register a {@link IExtensionPoint.DisplayTest} with the mod container. + *

A shorthand for registering a DisplayTest with {@link #registerExtensionPoint(Class, Supplier)} that also + * creates the DisplayTest instance for you using the provided parameters.

+ * @see IExtensionPoint.DisplayTest#DisplayTest(Supplier, BiPredicate) + */ + public void registerDisplayTest(Supplier suppliedVersion, BiPredicate remoteVersionTest) { + getActiveContainer().registerDisplayTest(new IExtensionPoint.DisplayTest(suppliedVersion, remoteVersionTest)); + } + public void registerConfig(ModConfig.Type type, IConfigSpec spec) { getActiveContainer().addConfig(new ModConfig(type, spec, getActiveContainer())); }