Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default adapter for all entrypoints of a mod #453

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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<String, List<EntrypointMetadata>> entrypoints = new HashMap<>();
List<NestedJarEntry> jars = new ArrayList<>();
List<V1ModMetadata.MixinEntry> mixins = new ArrayList<>();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -222,6 +231,21 @@ static LoaderModMetadata parse(JsonReader reader) throws IOException, ParseMetad
throw new ParseMetadataException.MissingRequired("version");
}

for (Map.Entry<String, List<EntrypointMetadata>> entry : entrypoints.entrySet()) {
List<EntrypointMetadata> list = entry.getValue();
ListIterator<EntrypointMetadata> 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);
Expand Down Expand Up @@ -279,7 +303,7 @@ private static void readEntrypoints(List<ParseWarning> 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.
Expand Down