diff --git a/loader/src/main/java/net/neoforged/fml/IExtensionPoint.java b/loader/src/main/java/net/neoforged/fml/IExtensionPoint.java
index 2665f40eb..c69620ff9 100644
--- a/loader/src/main/java/net/neoforged/fml/IExtensionPoint.java
+++ b/loader/src/main/java/net/neoforged/fml/IExtensionPoint.java
@@ -13,19 +13,10 @@
*
*
An extension point can be registered for a mod container using {@link ModContainer#registerExtensionPoint(Class, Supplier)}
* and retrieved (if present) using {@link ModContainer#getCustomExtension(Class)}. An extension point allows a mod to
- * supply an arbitrary value as a record class to another mod or framework through their mod container class, avoiding
+ * supply an arbitrary value to another mod or framework through their mod container class, avoiding
* the use of {@link InterModComms} or other external frameworks to pass around these values.
- *
- * The usual way to declare an extension point is to implement this interface on a record class, with the type
- * parameter being a reference to the class itself. For example, {@code record MyExtension(...) extends
- * IExtensionPoint} would declare an extension point which supplies a {@code MyExtension} object. However,
- * there is no hard requirement that an extension point's type parameter must be in reference to itself; the type
- * parameter may reference another record class instead.
- *
- * @param the type of the record which is held by the extension point
*/
-@SuppressWarnings("unused") // Type parameter T
-public interface IExtensionPoint
+public interface IExtensionPoint
{
/**
* Extension point for the compatibility display test used on the server selection screen.
@@ -93,7 +84,7 @@ public interface IExtensionPoint
* @see net.neoforged.client.ForgeHooksClient#processForgeListPingData(net.minecraft.network.protocol.status.ServerStatus, net.minecraft.client.multiplayer.ServerData)
*/
@SuppressWarnings("JavadocReference") // reference to NetworkConstants, ForgeHooksClient
- record DisplayTest(Supplier suppliedVersion, BiPredicate remoteVersionTest) implements 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";
}
}
diff --git a/loader/src/main/java/net/neoforged/fml/ModContainer.java b/loader/src/main/java/net/neoforged/fml/ModContainer.java
index 3adeaf55b..dff66dab6 100644
--- a/loader/src/main/java/net/neoforged/fml/ModContainer.java
+++ b/loader/src/main/java/net/neoforged/fml/ModContainer.java
@@ -54,7 +54,7 @@ public abstract class ModContainer
protected ModLoadingStage modLoadingStage;
protected Supplier> contextExtension;
protected final Map activityMap = new HashMap<>();
- protected final Map>, Supplier>> extensionPoints = new IdentityHashMap<>();
+ protected final Map, Supplier>> extensionPoints = new IdentityHashMap<>();
protected final EnumMap configs = new EnumMap<>(ModConfig.Type.class);
public ModContainer(IModInfo info)
@@ -66,20 +66,20 @@ public ModContainer(IModInfo info)
this.modLoadingStage = ModLoadingStage.CONSTRUCT;
final String displayTestString = info.getConfig().getConfigElement("displayTest").orElse("MATCH_VERSION"); // missing defaults to DEFAULT type
- Supplier displayTestSupplier = switch (displayTestString) {
+ var displayTest = switch (displayTestString) {
case "MATCH_VERSION" -> // default displaytest checks for version string match
- () -> new IExtensionPoint.DisplayTest(() -> this.modInfo.getVersion().toString(),
+ 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);
+ new IExtensionPoint.DisplayTest(() -> IExtensionPoint.DisplayTest.IGNORESERVERONLY, (incoming, isNetwork) -> true);
case "IGNORE_ALL_VERSION" -> // Ignores all information and provides no information
- () -> new IExtensionPoint.DisplayTest(() -> "", (incoming, isNetwork) -> true);
+ new IExtensionPoint.DisplayTest(() -> "", (incoming, isNetwork) -> true);
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");
};
- if (displayTestSupplier != null)
- registerExtensionPoint(IExtensionPoint.DisplayTest.class, displayTestSupplier);
+ if (displayTest != null)
+ registerExtensionPoint(IExtensionPoint.DisplayTest.class, displayTest);
else
extensionPoints.remove(IExtensionPoint.DisplayTest.class);
}
@@ -143,12 +143,22 @@ public IModInfo getModInfo()
}
@SuppressWarnings("unchecked")
- public Optional getCustomExtension(Class extends IExtensionPoint> point) {
+ public Optional getCustomExtension(Class point) {
return Optional.ofNullable((T)extensionPoints.getOrDefault(point,()-> null).get());
}
- public > void registerExtensionPoint(Class extends IExtensionPoint> point, Supplier extension)
- {
+ /**
+ * Registers an {@link IExtensionPoint} with the mod container.
+ */
+ public void registerExtensionPoint(Class point, T extension) {
+ extensionPoints.put(point, () -> extension);
+ }
+
+ /**
+ * Registers an {@link IExtensionPoint} with the mod container.
+ * This overload allows passing a supplier that will only be evaluated when the extension is requested.
+ */
+ public void registerExtensionPoint(Class point, Supplier extension) {
extensionPoints.put(point, extension);
}
diff --git a/loader/src/main/java/net/neoforged/fml/ModLoadingContext.java b/loader/src/main/java/net/neoforged/fml/ModLoadingContext.java
index ba6d47f36..823c7da77 100644
--- a/loader/src/main/java/net/neoforged/fml/ModLoadingContext.java
+++ b/loader/src/main/java/net/neoforged/fml/ModLoadingContext.java
@@ -44,7 +44,7 @@ public String getActiveNamespace() {
* @param extension An extension operator
* @param The type signature of the extension operator
*/
- public > void registerExtensionPoint(Class extends IExtensionPoint> point, Supplier extension) {
+ public void registerExtensionPoint(Class point, Supplier extension) {
getActiveContainer().registerExtensionPoint(point, extension);
}