Difference between revisions of "Version Checker"

From Forge Community Wiki
(Inital Import from dokuwiki)
 
(Update to 1.19)
 
(4 intermediate revisions by one other user not shown)
Line 1: Line 1:
= Forge Update Checker =
+
The '''Version Checker''' is a Forge-provided utility for mods to check for new versions based on an online update JSON file. It is lightweight, toggleable, asynchoronous to the main mod loading, and integrates cleanly with the mods list menu.
  
Forge provides a very lightweight opt-in update-checking framework. All it does is check for updates, then show a flashing icon on the Mods button of the main menu and mod list if any mods have an available update, along with the respective changelogs. It does not download updates automatically.
+
If there are outdated mods according to the version checker, a flashing emerald indicator will be shown on the Mods button on the main menu. The entries for the outdated mods in the mods list screen have the flashing emerald indicator. The information screen for outdated mods will have an <code>Update available:</code> line with the <code>homepage</code> URL from the update JSON file, and a list of mod versions and corresponding text after the mod description, for the mod versions between the most up-to-date and the currently installed version.
 +
<!-- TODO: add images of these -->
  
== Getting Started ==
+
The version checker can be configured through the <code>versionCheck</code> option in the FML config (<tt>config/fml.toml</tt>). This option controls the version checking for all mods, including Forge.
 
 
The first thing you want to do is specify the <code><nowiki>updateJSONURL</nowiki></code> parameter in your <code><nowiki>mods.toml</nowiki></code> file. The value of this parameter should be a valid URL pointing to an update JSON file. This file can be hosted on your own web server, or on GitHub, or wherever you want, as long as it can be reliably reached by all users of your mod.
 
  
 
== Update JSON format ==
 
== Update JSON format ==
 +
The version checker checks the update JSON, specified by the <code>updateJSONURL</code> for the [[Proper Mod Structuring#Mod Properties|mod in the <tt>mods.toml</tt>]]. An example of a JSON file is the [https://files.minecraftforge.net/maven/net/minecraftforge/forge/promotions_slim.json update JSON for Minecraft Forge]. The JSON file must be in the following format:
 +
{{Tree list}}
 +
* '''Root object'''
 +
** <code>homepage</code> (string): A URL, displayed on the mod's information screen on the Mods list screen
 +
** <code>promos</code> (object)
 +
*** <code>'''''<nowiki><minecraft version></nowiki>'''''-latest</code> (string): A version string, for the latest mod version corresponding to the given Minecraft version
 +
*** <code>'''''<nowiki><minecraft version></nowiki>'''''-recommended</code> (string): A version string, for the recommended mod version corresponding to the given Minecraft version
 +
*** ...
 +
** <code>'''''<nowiki><minecraft version></nowiki>'''''</code> (object)
 +
*** <code>'''''<nowiki><mod version></nowiki>'''''</code> (string): Any text, displayed when the the specified mod version in the key is ahead of currently installed version; used as a changelog
 +
*** ...
 +
{{Tree list/end}}
  
The JSON itself has a relatively simple format, given as follows:
+
== Update status ==
 
+
There are 7 possible version checker statuses, according to the <code>VersionChecker.Status</code> enum:
<syntaxhighlight lang="json">
+
* <code>PENDING</code> - The version checker has not or is currently retrieving the version from the update JSON. This is temporary, and will change into one of the other statuses.
{
+
* <code>FAILED</code> - The version checker failed, either to retrieve the update JSON or some other error (such as failure to parse broken JSON).
  "homepage": "<homepage/download page for your mod>",
+
* <code>UP_TO_CODE</code> - The currently installed version is the same as the recommended version for the current Minecraft version.
  "<mcversion>": {
+
* <code>OUTDATED</code> - The currently installed version is either behind the recommended version for the MC version, or ahead of the recommended version, but behind the latest version for the MC version.
    "<modversion>": "<changelog for this version>",
+
* <code>AHEAD</code> - The currently installed version is ahead of the recommended version for the MC version, and there is no more up-to-date latest version for the MC version. <!-- might reword the second part -->
    '' List all versions of your mod for the given Minecraft version, along with their changelogs
+
* <code>BETA</code> - There is no recommended version, and either the currently installed version is up-to-date or ahead of the latest version, or there is no latest version for the MC version.
    ...
+
* <code>BETA_OUTDATED</code> - There is no recommended version, and the currently installed version is behind the latest version for the MC version.
  },
 
  ...
 
  "promos": {
 
    "<mcversion>-latest": "<modversion>",
 
    '' Declare the latest "bleeding-edge" version of your mod for the given Minecraft version
 
    "<mcversion>-recommended": "<modversion>",
 
    '' Declare the latest "stable" version of your mod for the given Minecraft version
 
    ...
 
  }
 
}
 
</syntaxhighlight>
 
 
 
This is fairly self-explanatory, but some notes:
 
 
 
* The link under <code><nowiki>homepage</nowiki></code> is the link the user will be shown when the mod is outdated.
 
* Forge uses an internal algorithm to determine whether one version String of your mod is “newer” than another. Most versioning schemes should be compatible, but see the <code><nowiki>ComparableVersion</nowiki></code> class if you are concerned about whether your scheme is supported. Adherence to [[Semantic Versioning]] is highly recommended.
 
* The changelog string can be separated into lines using <code><nowiki>\n</nowiki></code>. Some prefer to include a abbreviated changelog, then link to an external site that provides a full listing of changes.
 
* Manually inputting data can be chore. You can configure your <code><nowiki>build.gradle</nowiki></code> to automatically update this file when building a release, as Groovy has native JSON parsing support. Doing this is left as an exercise to the reader.
 
* Some examples can be found here for [https://cadiboo.github.io/projects/nocubes/update.json nocubes], [https://github.com/Corail31/tombstone_lite/blob/master/update.json Corail Tombstone] and [https://github.com/Aeltumn/Chisels-and-Bits-2/blob/master/update.json  Chisels & Bits 2].
 
  
== Retrieving Update Check Results ==
+
==<tt>CheckResult</tt>==
 +
The version checker result for a mod can be retrieving using the <code>VersionChecker.getResult(IModInfo)</code> static method which returns a <code>CheckResult</code>. (<code>IModInfo</code> is the information for a specific mod; see <code>ModList#getModContainerById(String)</code> and <code>ModContainer#getModInfo()</code>).
  
You can retrieve the results of the Forge Update Checker using <code><nowiki>VersionChecker.getResult(ModInfo)</nowiki></code>. The returned object has a field <code><nowiki>status</nowiki></code> which indicates the status of the version check. Example values: <code><nowiki>FAILED</nowiki></code> (the version checker couldn’t connect to the URL provided), <code><nowiki>UP_TO_DATE</nowiki></code> (the current version is equal to or newer than the latest stable version), <code><nowiki>OUTDATED</nowiki></code> (there is a new stable version), <code><nowiki>BETA_OUTDATED</nowiki></code> (there is a new unstable version), or <code><nowiki>BETA</nowiki></code> (the current version is equal to or newer than the latest unstable version). The status will be <code><nowiki>PENDING</nowiki></code> if the result requested has not finished yet; in that case, you should try again in a little bit. Otherwise, the returned object will also have the target version and any changelog lines, as specified in <code><nowiki>update.json</nowiki></code>. You can obtain your own <code><nowiki>ModContainer</nowiki></code> to get the <code><nowiki>ModInfo</nowiki></code> of (with <code><nowiki>ModContainer#getModInfo()</nowiki></code>) to pass to this method using <code><nowiki>ModLoadingContext.get().getActiveContainer()</nowiki></code> inside your constructor, <code><nowiki>ModList.get().getModContainerById(<your modId>)</nowiki></code> or <code><nowiki>ModList.get().getModContainerByObject(<your mod instance>)</nowiki></code>; or any other mod’s <code><nowiki>ModContainer</nowiki></code> using <code><nowiki>ModList.get().getModContainerById(<modId>)</nowiki></code>.
+
The <code>CheckResult</code> contains four methods:
 +
* <code>status</code>, the version checker status as a <code>VersionChecker.Status</code> enum value.
 +
* <code>target</code>, the version which caused the <code>OUTDATED</code>, <code>BETA</code> or <code>BETA_OUTDATED</code>
 +
** If the status is <code>OUTDATED</code>, this is the newest recommended or latest version from the JSON.
 +
** If the status is <code>BETA_OUTDATED</code> or <code>BETA</code>, this is the highest newest version from the JSON.
 +
** This may be <code>null</code> if the status is <code>BETA</code>, and there is no recommended or latest version defined in the JSON file.
 +
* <code>changes</code>, an unmodifiable map of mod versions and their corresponding text based on the MC version, where the mod versions are higher than the currently installed version. This information is shown on the mods information screen, as a changelog.
 +
* <code>url</code>, the URL from the <code>homepage</code> string in the update JSON, displayed on the mods information screen.

Latest revision as of 16:48, 11 June 2022

The Version Checker is a Forge-provided utility for mods to check for new versions based on an online update JSON file. It is lightweight, toggleable, asynchoronous to the main mod loading, and integrates cleanly with the mods list menu.

If there are outdated mods according to the version checker, a flashing emerald indicator will be shown on the Mods button on the main menu. The entries for the outdated mods in the mods list screen have the flashing emerald indicator. The information screen for outdated mods will have an Update available: line with the homepage URL from the update JSON file, and a list of mod versions and corresponding text after the mod description, for the mod versions between the most up-to-date and the currently installed version.

The version checker can be configured through the versionCheck option in the FML config (config/fml.toml). This option controls the version checking for all mods, including Forge.

Update JSON format

The version checker checks the update JSON, specified by the updateJSONURL for the mod in the mods.toml. An example of a JSON file is the update JSON for Minecraft Forge. The JSON file must be in the following format:

  • Root object
    • homepage (string): A URL, displayed on the mod's information screen on the Mods list screen
    • promos (object)
      • <minecraft version>-latest (string): A version string, for the latest mod version corresponding to the given Minecraft version
      • <minecraft version>-recommended (string): A version string, for the recommended mod version corresponding to the given Minecraft version
      • ...
    • <minecraft version> (object)
      • <mod version> (string): Any text, displayed when the the specified mod version in the key is ahead of currently installed version; used as a changelog
      • ...

Update status

There are 7 possible version checker statuses, according to the VersionChecker.Status enum:

  • PENDING - The version checker has not or is currently retrieving the version from the update JSON. This is temporary, and will change into one of the other statuses.
  • FAILED - The version checker failed, either to retrieve the update JSON or some other error (such as failure to parse broken JSON).
  • UP_TO_CODE - The currently installed version is the same as the recommended version for the current Minecraft version.
  • OUTDATED - The currently installed version is either behind the recommended version for the MC version, or ahead of the recommended version, but behind the latest version for the MC version.
  • AHEAD - The currently installed version is ahead of the recommended version for the MC version, and there is no more up-to-date latest version for the MC version.
  • BETA - There is no recommended version, and either the currently installed version is up-to-date or ahead of the latest version, or there is no latest version for the MC version.
  • BETA_OUTDATED - There is no recommended version, and the currently installed version is behind the latest version for the MC version.

CheckResult

The version checker result for a mod can be retrieving using the VersionChecker.getResult(IModInfo) static method which returns a CheckResult. (IModInfo is the information for a specific mod; see ModList#getModContainerById(String) and ModContainer#getModInfo()).

The CheckResult contains four methods:

  • status, the version checker status as a VersionChecker.Status enum value.
  • target, the version which caused the OUTDATED, BETA or BETA_OUTDATED
    • If the status is OUTDATED, this is the newest recommended or latest version from the JSON.
    • If the status is BETA_OUTDATED or BETA, this is the highest newest version from the JSON.
    • This may be null if the status is BETA, and there is no recommended or latest version defined in the JSON file.
  • changes, an unmodifiable map of mod versions and their corresponding text based on the MC version, where the mod versions are higher than the currently installed version. This information is shown on the mods information screen, as a changelog.
  • url, the URL from the homepage string in the update JSON, displayed on the mods information screen.