Skip to content

Commit

Permalink
Update display test with feedback and added the mods.toml discussion …
Browse files Browse the repository at this point in the history
…in mdk.

Signed-off-by: cpw <cpw+github@weeksfamily.ca>
  • Loading branch information
cpw committed Jun 7, 2022
1 parent 237efd1 commit c26f495
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
22 changes: 13 additions & 9 deletions fmlcore/src/main/java/net/minecraftforge/fml/ModContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,23 @@ public ModContainer(IModInfo info)
this.modInfo = info;
this.modLoadingStage = ModLoadingStage.CONSTRUCT;

final String displayTestString = info.getConfig().<String>getConfigElement("displayTest").orElse("DEFAULT"); // missing defaults to DEFAULT type
final String displayTestString = info.getConfig().<String>getConfigElement("displayTest").orElse("MATCH_VERSION"); // missing defaults to DEFAULT type
Supplier<IExtensionPoint.DisplayTest> displayTestSupplier = switch (displayTestString) {
case "DEFAULT" -> // default displaytest checks for version string match
()->new IExtensionPoint.DisplayTest(()->this.modInfo.getVersion().toString(),
(incoming, isNetwork)->Objects.equals(incoming, this.modInfo.getVersion().toString()));
case "SERVERONLY" -> // server only displaytest returns special IGNORESERVERONLY value and accepts anything
()->new IExtensionPoint.DisplayTest(()->IExtensionPoint.DisplayTest.IGNORESERVERONLY, (incoming, isNetwork)->true);
case "CLIENTONLY" -> // client only displaytest sends empty string and accepts anything
()->new IExtensionPoint.DisplayTest(()->"", (incoming, isNetwork)->true);
case "MATCH_VERSION" -> // default displaytest checks for version string match
() -> 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);
case "IGNORE_ALL_VERSION" -> // Ignores all information and provides no information
() -> 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");
};
registerExtensionPoint(IExtensionPoint.DisplayTest.class, displayTestSupplier);
if (displayTestSupplier != null)
registerExtensionPoint(IExtensionPoint.DisplayTest.class, displayTestSupplier);
else
extensionPoints.remove(IExtensionPoint.DisplayTest.class);
}

/**
Expand Down
8 changes: 8 additions & 0 deletions mdk/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ logoFile="examplemod.png" #optional
credits="Thanks for this example mod goes to Java" #optional
# A text field displayed in the mod UI
authors="Love, Cheese and small house plants" #optional
# Display Test controls the display for your mod in the server connection screen
# MATCH_VERSION means that your mod will cause a red X if the versions on client and server differ. This is the default behaviour and should be what you choose if you have server and client elements to your mod.
# IGNORE_SERVER_VERSION means that your mod will not cause a red X if it's present on the server but not on the client. This is what you should use if you're a server only mod.
# IGNORE_ALL_VERSION means that your mod will not cause a red X if it's present on the client or the server. This is a special case and should only be used if your mod has no server component.
# NONE means that no display test is set on your mod. You need to do this yourself, see IExtensionPoint.DisplayTest for more information. You can define any scheme you wish with this value.
# IMPORTANT NOTE: this is NOT an instruction as to which environments (CLIENT or DEDICATED SERVER) your mod loads on. Your mod should load (and maybe do nothing!) whereever it finds itself.
#displayTest="MATCH_VERSION" # MATCH_VERSION is the default if nothing is specified (#optional)

# The description text for the mod (multi line!) (#mandatory)
description='''
This is a long form description of the mod. You can write whatever you want here
Expand Down

0 comments on commit c26f495

Please sign in to comment.