mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-13 16:54:22 +00:00
Try and be a bit nicer about handling bad [feature] definitions (#9606)
* Try and be a bit nicer about handling bad [feature] definitions - they're single square bracket defined and require strings for feature bound values. * Some more tweaks to the feature system to output useful and well formatted error messages when bounds fail. Requires SPI 7.0.1 and the language string "fml.modloading.feature.missing" has changed. * Use immutable lists where possible and generally tidy things a bit
This commit is contained in:
12 files changed
+105
-60
No files matched your search
@@ -50,6 +50,8 @@ public class ForgeI18n {
|
||||
customFactories.put("exc", (name, formatString, locale) -> new CustomReadOnlyFormat((stringBuffer, objectToParse) -> parseException(formatString, stringBuffer, objectToParse)));
|
||||
// {0,vr} -> transform VersionRange into cleartext string using fml.messages.version.restriction.* strings
|
||||
customFactories.put("vr", (name, formatString, locale) -> new CustomReadOnlyFormat(MavenVersionStringHelper::parseVersionRange));
|
||||
// {0,featurebound} -> transform feature bound to cleartext string
|
||||
customFactories.put("featurebound", (name, formatString, locale) -> new CustomReadOnlyFormat(MavenVersionStringHelper::parseFeatureBoundValue));
|
||||
// {0,i18n,fml.message} -> pass object to i18n string 'fml.message'
|
||||
customFactories.put("i18n", (name, formatString, locale) -> new CustomReadOnlyFormat((stringBuffer, o) -> stringBuffer.append(ForgeI18n.parseMessage(formatString, o))));
|
||||
// {0,ornull,fml.absent} -> append String value of o, or i18n string 'fml.absent' (message format transforms nulls into the string literal "null")
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
package net.minecraftforge.common.util;
|
||||
|
||||
import net.minecraftforge.common.ForgeI18n;
|
||||
import net.minecraftforge.forgespi.locating.ForgeFeature;
|
||||
import org.apache.maven.artifact.versioning.ArtifactVersion;
|
||||
import org.apache.maven.artifact.versioning.Restriction;
|
||||
import org.apache.maven.artifact.versioning.VersionRange;
|
||||
@@ -80,4 +81,17 @@ public class MavenVersionStringHelper {
|
||||
public static void parseVersionRange(final StringBuffer stringBuffer, final Object range) {
|
||||
stringBuffer.append(versionRangeToString((VersionRange) range));
|
||||
}
|
||||
|
||||
public static void parseFeatureBoundValue(final StringBuffer stringBuffer, final Object range) {
|
||||
if (range instanceof ForgeFeature.Bound bound) {
|
||||
stringBuffer.append(bound.featureName());
|
||||
if (bound.bound() instanceof Boolean b) {
|
||||
stringBuffer.append("=").append(b);
|
||||
} else if (bound.bound() instanceof VersionRange vr) {
|
||||
stringBuffer.append(" ").append(versionRangeToString(vr));
|
||||
} else {
|
||||
stringBuffer.append("=\"").append(bound.featureBound()).append("\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user