Record Class IExtensionPoint.DisplayTest

java.lang.Object
java.lang.Record
net.minecraftforge.fml.IExtensionPoint.DisplayTest
All Implemented Interfaces:
IExtensionPoint<IExtensionPoint.DisplayTest>
Enclosing interface:
IExtensionPoint<T extends Record>

public static record IExtensionPoint.DisplayTest(Supplier<String> suppliedVersion, BiPredicate<String,Boolean> remoteVersionTest) extends Record implements IExtensionPoint<IExtensionPoint.DisplayTest>
Extension point for the compatibility display test used on the server selection screen. Note: "server" and "client" refers to the dedicated server and game client physical distributions, rather than the logical server and client.

The Supplier provides the local compatibility version, which is sent from the server to the client for multiplayer connections or stored to disk for the world save. The BiPredicate accepts the remote compatibility version and a boolean indicating whether the remote version is from the server or a world save, where true means it is from the server and false means it is from the world save. The return value of the predicate determines whether the remote version is "compatible" for the purposes of the display test.

The local compatibility version may be of the value IGNORESERVERONLY, in which case clients will ignore the mod's presence if it is present on the server but not on the client. However, the remote version test predicate must still accept this value as a remote version in order to display as compatible if the mod is present on the client.

The compatibility display test does not necessarily indicate the success or failure of an actual connection attempt. Factors such as display test extension misconfiguration, truncation of ping data, difference of registry data or network channels between server and client, and others may cause the result of the compatibility test to not reflect the actual likelihood of a connection successfully being established between the server and the client.

An example declaration of a display test extension registration for a regular mod (requires to be present on server and client) is as follows:


 String compatibilityVersion = "1"; // Could be linked with a network channel version or mod version
 ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class,
         () -> new IExtensionPoint.DisplayTest(
                 () -> compatibilityVersion,
                 (remoteVersion, isFromServer) -> remoteVersion.equals(compatibilityVersion)
         )
 );
 

An example declaration of a display test extension registration for a server-side-only mod (does not require to be present on the client) is as follows:


 ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class,
         () -> new IExtensionPoint.DisplayTest(
                 // Ignore this mod if not present on the client
                 () -> NetworkConstants.IGNORESERVERONLY,
                 // If present on the client, accept any version if from a server
                 (remoteVersion, isFromServer) -> isFromServer
         )
 );
 

An example declaration of a display test extension registration for a client-side-only mod (does not require to be present on the server) is as follows:


 ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class,
         () -> new IExtensionPoint.DisplayTest(
                 // Send any version from server to client, since we will be accepting any version as well
                 () -> "dQw4w9WgXcQ",
                 // Accept any version on the client, from server or from save
                 (remoteVersion, isFromServer) -> true
         )
 );
 
See Also:
  • Field Details

    • suppliedVersion

      private final Supplier<String> suppliedVersion
      The field for the suppliedVersion record component.
    • remoteVersionTest

      private final BiPredicate<String,Boolean> remoteVersionTest
      The field for the remoteVersionTest record component.
    • IGNORESERVERONLY

      public static final String IGNORESERVERONLY
      See Also:
    • IGNORE_SERVER_VERSION

      public static final Supplier<IExtensionPoint.DisplayTest> IGNORE_SERVER_VERSION
      Ignores any version information coming from the server - use for server only mods
    • IGNORE_ALL_VERSION

      public static final Supplier<IExtensionPoint.DisplayTest> IGNORE_ALL_VERSION
      Ignores all information and provides no information

      Note: If your mod is purely client-side and has no multiplayer functionality (be it dedicated servers or Open to LAN), consider setting clientSideOnly=true in the root of your mods.toml.

  • Constructor Details

    • DisplayTest

      public DisplayTest(String version, BiPredicate<String,Boolean> remoteVersionTest)
      An optional alternative to DisplayTest(Supplier, BiPredicate) which accepts a constant version string instead of a Supplier.

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

    • DisplayTest

      public DisplayTest(Supplier<String> suppliedVersion, BiPredicate<String,Boolean> remoteVersionTest)
      Creates an instance of a DisplayTest record class.
      Parameters:
      suppliedVersion - the value for the suppliedVersion record component
      remoteVersionTest - the value for the remoteVersionTest record component
  • Method Details

    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • suppliedVersion

      public Supplier<String> suppliedVersion()
      Returns the value of the suppliedVersion record component.
      Returns:
      the value of the suppliedVersion record component
    • remoteVersionTest

      public BiPredicate<String,Boolean> remoteVersionTest()
      Returns the value of the remoteVersionTest record component.
      Returns:
      the value of the remoteVersionTest record component