mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-30 13:05:27 -05:00
Add way to add new launch arguments, because this can change without regenerating the run configs.
This commit is contained in:
@@ -55,6 +55,7 @@ import net.fabricmc.loom.api.decompilers.LoomDecompiler;
|
||||
import net.fabricmc.loom.configuration.LoomDependencyManager;
|
||||
import net.fabricmc.loom.configuration.ide.RunConfig;
|
||||
import net.fabricmc.loom.configuration.ide.RunConfigSettings;
|
||||
import net.fabricmc.loom.configuration.launch.LaunchProviderSettings;
|
||||
import net.fabricmc.loom.configuration.processors.JarProcessor;
|
||||
import net.fabricmc.loom.configuration.processors.JarProcessorManager;
|
||||
import net.fabricmc.loom.configuration.providers.MinecraftProvider;
|
||||
@@ -112,6 +113,7 @@ public class LoomGradleExtension {
|
||||
public final List<Consumer<RunConfig>> settingsPostEdit = new ArrayList<>();
|
||||
|
||||
private NamedDomainObjectContainer<RunConfigSettings> runConfigs;
|
||||
private NamedDomainObjectContainer<LaunchProviderSettings> launchConfigs;
|
||||
|
||||
/**
|
||||
* Loom will generate a new genSources task (with a new name, based off of {@link LoomDecompiler#name()})
|
||||
@@ -137,6 +139,7 @@ public class LoomGradleExtension {
|
||||
}
|
||||
|
||||
public Mercury getOrCreateSrcMercuryCache(int id, Supplier<Mercury> factory) {
|
||||
if (id == -1) return factory.get();
|
||||
return srcMercuryCache[id] != null ? srcMercuryCache[id] : (srcMercuryCache[id] = factory.get());
|
||||
}
|
||||
|
||||
@@ -216,6 +219,8 @@ public class LoomGradleExtension {
|
||||
this.forge = new LazyBool(() -> Boolean.parseBoolean(Objects.toString(project.findProperty(FORGE_PROPERTY))));
|
||||
this.runConfigs = project.container(RunConfigSettings.class,
|
||||
baseName -> new RunConfigSettings(project, baseName));
|
||||
this.launchConfigs = project.container(LaunchProviderSettings.class,
|
||||
baseName -> new LaunchProviderSettings(project, baseName));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -495,8 +500,18 @@ public class LoomGradleExtension {
|
||||
action.execute(runConfigs);
|
||||
}
|
||||
|
||||
@ApiStatus.Experimental
|
||||
public void launches(Action<NamedDomainObjectContainer<LaunchProviderSettings>> action) {
|
||||
action.execute(launchConfigs);
|
||||
}
|
||||
|
||||
@ApiStatus.Experimental
|
||||
public NamedDomainObjectContainer<RunConfigSettings> getRunConfigs() {
|
||||
return runConfigs;
|
||||
}
|
||||
|
||||
@ApiStatus.Experimental
|
||||
public NamedDomainObjectContainer<LaunchProviderSettings> getLaunchConfigs() {
|
||||
return launchConfigs;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package net.fabricmc.loom.configuration.launch;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gradle.api.Named;
|
||||
import org.gradle.api.Project;
|
||||
|
||||
public class LaunchProviderSettings implements Named {
|
||||
private final String name;
|
||||
private List<Map.Entry<String, String>> properties = new ArrayList<>();
|
||||
private List<String> arguments = new ArrayList<>();
|
||||
|
||||
public LaunchProviderSettings(Project project, String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void arg(String argument) {
|
||||
this.arguments.add(argument);
|
||||
}
|
||||
|
||||
public void arg(String... arguments) {
|
||||
this.arguments.addAll(Arrays.asList(arguments));
|
||||
}
|
||||
|
||||
public void arg(Collection<String> arguments) {
|
||||
this.arguments.addAll(arguments);
|
||||
}
|
||||
|
||||
public void property(String key, String value) {
|
||||
this.properties.add(new AbstractMap.SimpleEntry<>(key, value));
|
||||
}
|
||||
|
||||
public void properties(Map<String, String> arguments) {
|
||||
this.properties.addAll(arguments.entrySet());
|
||||
}
|
||||
|
||||
public List<Map.Entry<String, String>> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public List<String> getArguments() {
|
||||
return arguments;
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,7 @@ import org.gradle.api.plugins.JavaPlugin;
|
||||
|
||||
import net.fabricmc.loom.configuration.DependencyProvider;
|
||||
import net.fabricmc.loom.configuration.RemappedConfigurationEntry;
|
||||
import net.fabricmc.loom.configuration.launch.LaunchProviderSettings;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
|
||||
public class LaunchProvider extends DependencyProvider {
|
||||
@@ -116,6 +117,16 @@ public class LaunchProvider extends DependencyProvider {
|
||||
}
|
||||
}
|
||||
|
||||
for (LaunchProviderSettings settings : getExtension().getLaunchConfigs()) {
|
||||
for (String argument : settings.getArguments()) {
|
||||
launchConfig.argument(settings.getName(), argument);
|
||||
}
|
||||
|
||||
for (Map.Entry<String, String> property : settings.getProperties()) {
|
||||
launchConfig.property(settings.getName(), property.getKey(), property.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
//Enable ansi by default for idea and vscode
|
||||
if (new File(getProject().getRootDir(), ".vscode").exists()
|
||||
|| new File(getProject().getRootDir(), ".idea").exists()
|
||||
|
||||
Reference in New Issue
Block a user