mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-28 04:07:01 -05:00
Add support for multiple access wideners in Quilt mods
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package dev.architectury.loom.metadata;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -14,9 +15,9 @@ public interface ModMetadataFile {
|
||||
@Nullable String getId();
|
||||
|
||||
/**
|
||||
* {@return the path to the access widener file of this mod, or {@code null} if absent}.
|
||||
* {@return the paths to the access widener file of this mod, or an empty set if absent}.
|
||||
*/
|
||||
@Nullable String getAccessWidener();
|
||||
Set<String> getAccessWideners();
|
||||
|
||||
/**
|
||||
* {@return the injected interface data in this mod metadata file}.
|
||||
|
||||
@@ -6,8 +6,10 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
@@ -18,6 +20,7 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.fabricmc.loom.LoomGradlePlugin;
|
||||
import net.fabricmc.loom.configuration.ifaceinject.InterfaceInjectionProcessor;
|
||||
import net.fabricmc.loom.util.function.CollectionUtil;
|
||||
|
||||
public final class QuiltModJson implements JsonBackedModMetadataFile {
|
||||
public static final String FILE_NAME = "quilt.mod.json";
|
||||
@@ -68,22 +71,16 @@ public final class QuiltModJson implements JsonBackedModMetadataFile {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String getAccessWidener() {
|
||||
public Set<String> getAccessWideners() {
|
||||
if (json.has(ACCESS_WIDENER_KEY)) {
|
||||
if (json.get(ACCESS_WIDENER_KEY).isJsonArray()) {
|
||||
JsonArray array = json.get(ACCESS_WIDENER_KEY).getAsJsonArray();
|
||||
|
||||
// TODO (1.1): Support multiple access wideners in Quilt mods
|
||||
if (array.size() != 1) {
|
||||
throw new UnsupportedOperationException("Loom does not support multiple access wideners in one mod!");
|
||||
}
|
||||
|
||||
return array.get(0).getAsString();
|
||||
return CollectionUtil.mapTo(array, new LinkedHashSet<>(), JsonElement::getAsString);
|
||||
} else {
|
||||
return json.get(ACCESS_WIDENER_KEY).getAsString();
|
||||
return Set.of(json.get(ACCESS_WIDENER_KEY).getAsString());
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
return Set.of();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,8 @@ package net.fabricmc.loom.util.fmj;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
@@ -77,7 +79,8 @@ public final class ModMetadataFabricModJson extends FabricModJson {
|
||||
|
||||
@Override
|
||||
public Map<String, ModEnvironment> getClassTweakers() {
|
||||
@Nullable String accessWidener = modMetadata.getAccessWidener();
|
||||
return accessWidener != null ? Map.of(accessWidener, ModEnvironment.UNIVERSAL) : Map.of();
|
||||
return modMetadata.getAccessWideners()
|
||||
.stream()
|
||||
.collect(Collectors.toMap(Function.identity(), path -> ModEnvironment.UNIVERSAL));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,13 +83,26 @@ public final class CollectionUtil {
|
||||
* @return a mutable list with the transformed entries
|
||||
*/
|
||||
public static <A, B> List<B> map(Iterable<? extends A> collection, Function<? super A, ? extends B> transform) {
|
||||
ArrayList<B> result = new ArrayList<>();
|
||||
return mapTo(collection, new ArrayList<>(), transform);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the collection with a function, storing the results in a target collection.
|
||||
*
|
||||
* @param collection the source collection
|
||||
* @param target the target collection
|
||||
* @param transform the transformation function
|
||||
* @param <A> the source type
|
||||
* @param <B> the target type
|
||||
* @param <C> the target collection type
|
||||
* @return the target collection
|
||||
*/
|
||||
public static <A, B, C extends Collection<B>> C mapTo(Iterable<? extends A> collection, C target, Function<? super A, ? extends B> transform) {
|
||||
for (A a : collection) {
|
||||
result.add(transform.apply(a));
|
||||
target.add(transform.apply(a));
|
||||
}
|
||||
|
||||
return result;
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user