Skip to content

Commit

Permalink
Add ModPlatform as a param to getMixinConfigs
Browse files Browse the repository at this point in the history
  • Loading branch information
shedaniel committed Nov 13, 2023
1 parent 05f38c5 commit 7f95869
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import net.fabricmc.loom.LoomGradlePlugin;
import net.fabricmc.loom.configuration.ifaceinject.InterfaceInjectionProcessor;
import net.fabricmc.loom.util.ModPlatform;

public final class ArchitecturyCommonJson implements JsonBackedModMetadataFile, SingleIdModMetadataFile {
public static final String FILE_NAME = "architectury.common.json";
Expand Down Expand Up @@ -108,7 +109,7 @@ public String getFileName() {
}

@Override
public List<String> getMixinConfigs() {
public List<String> getMixinConfigs(@Nullable ModPlatform platform) {
return List.of();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.VisibleForTesting;

import net.fabricmc.loom.util.ModPlatform;
import net.fabricmc.loom.configuration.ifaceinject.InterfaceInjectionProcessor;

/**
Expand Down Expand Up @@ -42,7 +43,7 @@ public String getFileName() {
}

@Override
public List<String> getMixinConfigs() {
public List<String> getMixinConfigs(@Nullable ModPlatform platform) {
return List.of();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.jetbrains.annotations.Nullable;

import net.fabricmc.loom.configuration.ifaceinject.InterfaceInjectionProcessor;
import net.fabricmc.loom.util.ModPlatform;
import net.fabricmc.loom.util.function.CollectionUtil;

/**
Expand Down Expand Up @@ -48,5 +49,5 @@ public interface ModMetadataFile {
/**
* {@return a list of the mixin configs declared in this mod metadata file}.
*/
List<String> getMixinConfigs();
List<String> getMixinConfigs(@Nullable ModPlatform platform);
}
18 changes: 17 additions & 1 deletion src/main/java/dev/architectury/loom/metadata/ModsToml.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
import com.electronwill.nightconfig.core.Config;
import com.electronwill.nightconfig.core.io.ParsingException;
import com.electronwill.nightconfig.toml.TomlParser;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.jetbrains.annotations.Nullable;

import net.fabricmc.loom.configuration.ifaceinject.InterfaceInjectionProcessor;
import net.fabricmc.loom.util.ExceptionUtil;
import net.fabricmc.loom.util.ModPlatform;

public final class ModsToml implements ModMetadataFile {
public static final String FILE_PATH = "META-INF/mods.toml";
Expand Down Expand Up @@ -83,7 +85,21 @@ public String getFileName() {
}

@Override
public List<String> getMixinConfigs() {
public List<String> getMixinConfigs(@Nullable ModPlatform platform) {
if (platform == ModPlatform.NEOFORGE) {
Optional<List<Config>> mixins = config.getOptional("mixins");
if (mixins.isEmpty()) return List.of();

final ImmutableList.Builder<String> configs = ImmutableList.builder();

for (final Config mixin : mixins.get()) {
final Optional<String> config = mixin.getOptional("config");
config.ifPresent(configs::add);
}

return configs.build();
}

return List.of();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import net.fabricmc.loom.LoomGradlePlugin;
import net.fabricmc.loom.configuration.ifaceinject.InterfaceInjectionProcessor;
import net.fabricmc.loom.util.ModPlatform;
import net.fabricmc.loom.util.function.CollectionUtil;

public final class QuiltModJson implements JsonBackedModMetadataFile, SingleIdModMetadataFile {
Expand Down Expand Up @@ -107,7 +108,7 @@ public List<InterfaceInjectionProcessor.InjectedInterface> getInjectedInterfaces
}

@Override
public List<String> getMixinConfigs() {
public List<String> getMixinConfigs(@Nullable ModPlatform platform) {
// RFC 0002: The `mixin` field:
// Type: Array/String
// Required: False
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/fabricmc/loom/task/RemapJarTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ private void setupLegacyMixinRefmapRemapping(RemapParams params) {
final FabricModJson fabricModJson = FabricModJsonFactory.createFromZipNullable(getInputFile().getAsFile().get().toPath());

if (fabricModJson != null) {
allMixinConfigs.addAll(fabricModJson.getMixinConfigurations());
allMixinConfigs.addAll(fabricModJson.getMixinConfigurations(extension.getPlatform().get()));
}

if (getReadMixinConfigsFromManifest().get()) {
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/net/fabricmc/loom/util/fmj/FabricModJson.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import net.fabricmc.loom.util.ModPlatform;

import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.VisibleForTesting;

Expand All @@ -53,7 +56,11 @@ public String getId() {
@Nullable
public abstract JsonElement getCustom(String key);

public abstract List<String> getMixinConfigurations();
public final List<String> getMixinConfigurations() {
return getMixinConfigurations(null);
}

public abstract List<String> getMixinConfigurations(@Nullable ModPlatform platform);

public abstract Map<String, ModEnvironment> getClassTweakers();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import com.google.gson.JsonPrimitive;
import org.jetbrains.annotations.Nullable;

import net.fabricmc.loom.util.ModPlatform;

@Deprecated
public final class FabricModJsonV0 extends FabricModJson {
FabricModJsonV0(JsonObject jsonObject, FabricModJsonSource source) {
Expand All @@ -53,7 +55,7 @@ public JsonElement getCustom(String key) {
}

@Override
public List<String> getMixinConfigurations() {
public List<String> getMixinConfigurations(@Nullable ModPlatform platform) {
final JsonObject mixinsObject = jsonObject.getAsJsonObject("mixins");

if (mixinsObject == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import com.google.gson.JsonPrimitive;
import org.jetbrains.annotations.Nullable;

import net.fabricmc.loom.util.ModPlatform;

public final class FabricModJsonV1 extends FabricModJson {
FabricModJsonV1(JsonObject jsonObject, FabricModJsonSource source) {
super(jsonObject, source);
Expand Down Expand Up @@ -69,7 +71,7 @@ static JsonElement getCustom(JsonObject jsonObject, String key) {
}

@Override
public List<String> getMixinConfigurations() {
public List<String> getMixinConfigurations(@Nullable ModPlatform platform) {
final JsonArray mixinArray = jsonObject.getAsJsonArray("mixins");

if (mixinArray == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

import net.fabricmc.loom.util.ModPlatform;
import net.fabricmc.loom.util.Pair;

@ApiStatus.Experimental
Expand All @@ -56,7 +57,7 @@ public JsonElement getCustom(String key) {
}

@Override
public List<String> getMixinConfigurations() {
public List<String> getMixinConfigurations(@Nullable ModPlatform platform) {
if (!jsonObject.has("mixins")) {
return Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.gradle.api.tasks.SourceSet;
import org.jetbrains.annotations.Nullable;

import net.fabricmc.loom.util.ModPlatform;
import net.fabricmc.loom.util.gradle.SourceSetHelper;

public final class ModMetadataFabricModJson extends FabricModJson {
Expand Down Expand Up @@ -115,8 +116,8 @@ public int getVersion() {
}

@Override
public List<String> getMixinConfigurations() {
return modMetadata.getMixinConfigs();
public List<String> getMixinConfigurations(@Nullable ModPlatform platform) {
return modMetadata.getMixinConfigs(platform);
}

@Override
Expand Down

0 comments on commit 7f95869

Please sign in to comment.