diff --git a/build_forge.gradle b/build_forge.gradle index 4be10a27a6..2dc5af5e7d 100644 --- a/build_forge.gradle +++ b/build_forge.gradle @@ -985,6 +985,15 @@ tasks.register('genAllData') { dependsOn 'forge_data', 'forge_test_data' } +tasks.named('processResources', ProcessResources) { + final Map replaceProperties = Map.of('forge_version', (String) version) + inputs.properties replaceProperties + + filesMatching(['META-INF/mods.toml']) { + expand replaceProperties + [project: project] + } +} + if (project.hasProperty('UPDATE_MAPPINGS')) { extractRangeMap { sources.from sourceSets.test.java.srcDirs diff --git a/fmlloader/src/main/java/net/minecraftforge/fml/loading/StringSubstitutor.java b/fmlloader/src/main/java/net/minecraftforge/fml/loading/StringSubstitutor.java deleted file mode 100644 index 21c3e625f8..0000000000 --- a/fmlloader/src/main/java/net/minecraftforge/fml/loading/StringSubstitutor.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) Forge Development LLC and contributors - * SPDX-License-Identifier: LGPL-2.1-only - */ - -package net.minecraftforge.fml.loading; - -import net.minecraftforge.fml.loading.moddiscovery.ModFile; - -import java.util.Map; - -import org.apache.commons.lang3.text.StrLookup; -import org.apache.commons.lang3.text.StrSubstitutor; - -@SuppressWarnings("deprecation") -public class StringSubstitutor { - private static final Map GLOBALS = Map.of( - "mcVersion", FMLLoader.versionInfo().mcVersion(), - "forgeVersion", FMLLoader.versionInfo().forgeVersion() - ); - - public static String replace(final String in, final ModFile file) { - return new StrSubstitutor(getStringLookup(file)).replace(in); - } - - private static StrLookup getStringLookup(final ModFile file) { - return new StrLookup<>() { - @Override - public String lookup(String key) { - var parts = key.split("\\."); - if (parts.length == 1) - return key; - var pfx = parts[0]; - - if ("global".equals(pfx)) - return GLOBALS.get(parts[1]); - else if ("file".equals(pfx) && file != null) - return String.valueOf(file.getSubstitutionMap().get().get(parts[1])); - - return key; - } - }; - } -} diff --git a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModFile.java b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModFile.java index 6869e1d121..05201fef95 100644 --- a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModFile.java +++ b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModFile.java @@ -5,7 +5,6 @@ package net.minecraftforge.fml.loading.moddiscovery; -import com.google.common.collect.ImmutableMap; import com.mojang.logging.LogUtils; import cpw.mods.jarhandling.SecureJar; import net.minecraftforge.fml.loading.FMLLoader; @@ -39,7 +38,6 @@ import java.util.jar.Manifest; public class ModFile implements IModFile { private static final Logger LOGGER = LogUtils.getLogger(); private final String jarVersion; - private Map fileProperties; private List loaders; private Throwable scanError; private final SecureJar jar; @@ -69,9 +67,10 @@ public class ModFile implements IModFile { } @Override - public Supplier> getSubstitutionMap() { - return () -> ImmutableMap.builder().put("jarVersion", jarVersion).putAll(fileProperties).build(); + public Supplier> getSubstitutionMap() { + return Map::of; } + @Override public Type getType() { return modFileType; @@ -151,7 +150,7 @@ public class ModFile implements IModFile { } public void setFileProperties(Map fileProperties) { - this.fileProperties = fileProperties; + LOGGER.warn(LogMarkers.LOADING, "Setting file properties for the purposes of runtime mods.toml string substitution is no longer supported."); } @Override diff --git a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModFileInfo.java b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModFileInfo.java index f6ea9a2331..8d9488dfad 100644 --- a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModFileInfo.java +++ b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModFileInfo.java @@ -101,7 +101,6 @@ public class ModFileInfo implements IModFileInfo, IConfigurable { this.properties = config.>getConfigElement("properties") .orElse(Collections.emptyMap()); } - this.modFile.setFileProperties(this.properties); final List modConfigs = config.getConfigList("mods"); if (modConfigs == null || modConfigs.isEmpty()) diff --git a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModInfo.java b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModInfo.java index f41741e423..5490093e6e 100644 --- a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModInfo.java +++ b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModInfo.java @@ -6,7 +6,6 @@ package net.minecraftforge.fml.loading.moddiscovery; import com.mojang.logging.LogUtils; -import net.minecraftforge.fml.loading.StringSubstitutor; import net.minecraftforge.fml.loading.StringUtils; import net.minecraftforge.forgespi.language.IConfigurable; import net.minecraftforge.forgespi.language.IModInfo; @@ -74,7 +73,6 @@ public record ModInfo( } ArtifactVersion version = config.getConfigElement("version") - .map(s -> StringSubstitutor.replace(s, owningFile.getFile())) .map(DefaultArtifactVersion::new) .orElse(DEFAULT_VERSION); diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index d863d55ca1..1f6747ac20 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -6,7 +6,7 @@ license="LGPL v2.1" [[mods]] modId="forge" -version="${global.forgeVersion}" +version="${forge_version}" updateJSONURL="https://files.minecraftforge.net/net/minecraftforge/forge/promotions_slim.json" displayURL="https://minecraftforge.net/" displayName="Forge"