diff --git a/src/main/java/net/fabricmc/loader/impl/metadata/V1ModMetadataParser.java b/src/main/java/net/fabricmc/loader/impl/metadata/V1ModMetadataParser.java index 89f421913..4d1d6f717 100644 --- a/src/main/java/net/fabricmc/loader/impl/metadata/V1ModMetadataParser.java +++ b/src/main/java/net/fabricmc/loader/impl/metadata/V1ModMetadataParser.java @@ -18,9 +18,11 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; +import java.util.ListIterator; import java.util.Locale; import java.util.Map; import java.util.SortedMap; @@ -41,7 +43,6 @@ final class V1ModMetadataParser { /** * Reads a {@code fabric.mod.json} file of schema version {@code 1}. * - * @param logger the logger to print warnings to * @param reader the json reader to read the file with * @return the metadata of this file, null if the file could not be parsed * @throws IOException if there was any issue reading the file @@ -59,6 +60,7 @@ static LoaderModMetadata parse(JsonReader reader) throws IOException, ParseMetad // Optional (mod loading) ModEnvironment environment = ModEnvironment.UNIVERSAL; // Default is always universal + String defaultLanguageAdapter = "default"; Map> entrypoints = new HashMap<>(); List jars = new ArrayList<>(); List mixins = new ArrayList<>(); @@ -137,6 +139,13 @@ static LoaderModMetadata parse(JsonReader reader) throws IOException, ParseMetad environment = readEnvironment(reader); break; + case "defaultLanguageAdapter": + if (reader.peek() != JsonToken.STRING) { + throw new ParseMetadataException("default language adapter must be a string key", reader); + } + + defaultLanguageAdapter = reader.nextString(); + break; case "entrypoints": readEntrypoints(warnings, reader, entrypoints); break; @@ -222,6 +231,21 @@ static LoaderModMetadata parse(JsonReader reader) throws IOException, ParseMetad throw new ParseMetadataException.MissingRequired("version"); } + for (Map.Entry> entry : entrypoints.entrySet()) { + List list = entry.getValue(); + ListIterator listItr = list.listIterator(); + + while (listItr.hasNext()) { + EntrypointMetadata m = listItr.next(); + + if (m.getAdapter() == null) { + listItr.set(new V1ModMetadata.EntrypointMetadataImpl(defaultLanguageAdapter, m.getValue())); + } + } + + entry.setValue(Collections.unmodifiableList(list)); + } + ModMetadataParser.logWarningMessages(id, warnings); return new V1ModMetadata(id, version, provides, environment, entrypoints, jars, mixins, accessWidener, depends, recommends, suggests, conflicts, breaks, requires, name, description, authors, contributors, contact, license, icon, languageAdapters, customValues); @@ -279,7 +303,7 @@ private static void readEntrypoints(List warnings, JsonReader read reader.beginArray(); while (reader.hasNext()) { - String adapter = "default"; + String adapter = null; String value = null; // Entrypoints may be specified directly as a string or as an object to allow specification of the language adapter to use.