Version getters
This commit is contained in:
parent
5cef3a03eb
commit
c6a527714e
2 changed files with 21 additions and 1 deletions
|
@ -33,7 +33,7 @@ public class DataFixerAPI {
|
||||||
Collection<ModContainer> mods = FabricLoader.getInstance().getAllMods();
|
Collection<ModContainer> mods = FabricLoader.getInstance().getAllMods();
|
||||||
for (ModContainer mod: mods) {
|
for (ModContainer mod: mods) {
|
||||||
String name = mod.getMetadata().getId();
|
String name = mod.getMetadata().getId();
|
||||||
int preVersion = getModVersion(WorldDataAPI.getRootTag(name).getString("version"));
|
int preVersion = WorldDataAPI.getIntModVersion(name);
|
||||||
int version = getModVersion(mod.getMetadata().getVersion().toString());
|
int version = getModVersion(mod.getMetadata().getVersion().toString());
|
||||||
if (version > preVersion) {
|
if (version > preVersion) {
|
||||||
int fixVersion = FIX_VERSIONS.getOrDefault(name, version);
|
int fixVersion = FIX_VERSIONS.getOrDefault(name, version);
|
||||||
|
|
|
@ -93,6 +93,10 @@ public class WorldDataAPI {
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forces mod cache file to be saved.
|
||||||
|
* @param modID {@link String} mod ID.
|
||||||
|
*/
|
||||||
public static void saveFile(String modID) {
|
public static void saveFile(String modID) {
|
||||||
try {
|
try {
|
||||||
NbtIo.writeCompressed(getRootTag(modID), new File(dataDir, modID + ".nbt"));
|
NbtIo.writeCompressed(getRootTag(modID), new File(dataDir, modID + ".nbt"));
|
||||||
|
@ -101,4 +105,20 @@ public class WorldDataAPI {
|
||||||
BCLib.LOGGER.error("World data saving failed", e);
|
BCLib.LOGGER.error("World data saving failed", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get stored mod version (only for mods with registered cache).
|
||||||
|
* @return {@link String} mod version.
|
||||||
|
*/
|
||||||
|
public static String getModVersion(String modID) {
|
||||||
|
return getRootTag(modID).getString("version");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get stored mod version as integer (only for mods with registered cache).
|
||||||
|
* @return {@code int} mod version.
|
||||||
|
*/
|
||||||
|
public static int getIntModVersion(String modID) {
|
||||||
|
return DataFixerAPI.getModVersion(getModVersion(modID));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue