Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog], and this project adheres to [Semantic Versioning].

## Unreleased
- /

- added option for disable loading the test mod in recipe viewer run configs
- fixed recipe viewer run configs not loading the test source set and not executing compile tasks

## [1.2.0] - 2025-04-17

Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,14 @@ Possible values are:
- `full` - load the full mod into the compile time classpath
- `none` - don't load anything into the compile time classpath

*Run Config* refers to whether a run configuration should be created for the recipe viewer.
*Run Config* refers to whether a run configuration should be created for the recipe viewer. If *Run Config* is enabled,
the option *Test Mod* defines whether the test mod should be loaded in that run configuration.

### Defaults:

Mode: `none`<br>
Run Config: `false`<br>
Test Mod: `true`<br>
Minecraft Version: same as project<br>
Maven Repository: default for the respective recipe viewer

Expand All @@ -365,6 +367,7 @@ almostgradle.setup {
runConfig = true
mode = LoadingMode.FULL
version = "x.x.x"
testMod = false
}
jei {
runConfig = false
Expand All @@ -391,6 +394,7 @@ almostgradle.recipeViewers.emi.maven = https://modmaven.dev
almostgradle.recipeViewers.rei.runConfig = true
almostgradle.recipeViewers.rei.mode = FULL
almostgradle.recipeViewers.rei.version = x.x.x
almostgradle.recipeViewers.rei.testMod = false

almostgradle.recipeViewers.jei.runConfig = true
almostgradle.recipeViewers.jei.mode = API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public RecipeViewerOptions(Project project, ModDependency mod) {
.map(s -> s.equals("true"))
.orElse(false));
getMinecraftVersion().convention(providers.gradleProperty(propPrefix + ".minecraftVersion"));
getTestMod().convention(providers
.gradleProperty(propPrefix + ".testMod")
.map(s -> s.equals("true"))
.orElse(true));
}

public abstract Property<String> getMavenRepository();
Expand All @@ -47,6 +51,8 @@ public RecipeViewerOptions(Project project, ModDependency mod) {

public abstract Property<String> getMinecraftVersion();

public abstract Property<Boolean> getTestMod();

public Provider<ModuleDependency> getDependency() {
var almostGradle = project.getExtensions().getByType(AlmostGradleExtension.class);
var mcv = getMinecraftVersion().orElse(almostGradle.getMinecraftVersion()).get();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.almostreliable.almostgradle.dependency;

import com.almostreliable.almostgradle.AlmostGradleExtension;
import com.almostreliable.almostgradle.Utils;
import net.neoforged.moddevgradle.dsl.ModModel;
import net.neoforged.moddevgradle.dsl.NeoForgeExtension;
import org.gradle.api.Action;
import org.gradle.api.Project;
Expand All @@ -11,6 +13,8 @@
import org.gradle.api.tasks.Internal;

import javax.inject.Inject;
import java.util.HashSet;
import java.util.Set;

public abstract class RecipeViewers {

Expand Down Expand Up @@ -73,6 +77,7 @@ private void createRun(RecipeViewerOptions settings, ModDependency mod) {
Utils.log(project, "\t* Version", settings.getVersion().get());
Utils.log(project, "\t* Mode", settings.getMode().get().toString());
Utils.log(project, "\t* Run Config Enabled", settings.getRunConfig().get());
Utils.log(project, "\t* Test Mod Enabled", settings.getTestMod().get());
Utils.log(project, "\t* Minecraft Version", settings.getMinecraftVersion().orElse("NOT_DEFINED").get());
Utils.log(project, "\t* Repository", settings.getMavenRepository().get());

Expand All @@ -86,20 +91,41 @@ private void createRun(RecipeViewerOptions settings, ModDependency mod) {

var neoForge = this.project.getExtensions().getByType(NeoForgeExtension.class);
var java = this.project.getExtensions().getByType(JavaPluginExtension.class);
var almostGradle = this.project.getExtensions().getByType(AlmostGradleExtension.class);
var mainMod = neoForge.getMods().maybeCreate(almostGradle.getModId());
var mainSourceSet = java.getSourceSets().getByName("main");

var dep = settings.getDependency();
var apiDep = settings.getApiDependency();

if (settings.getRunConfig().isPresent() && settings.getRunConfig().get()) {
var sourceSet = java.getSourceSets().create(mod.id() + "Run");
sourceSet.setCompileClasspath(sourceSet.getCompileClasspath().plus(mainSourceSet.getCompileClasspath()));
sourceSet.setRuntimeClasspath(sourceSet.getRuntimeClasspath().plus(mainSourceSet.getRuntimeClasspath()));

var compileClasspath = sourceSet.getCompileClasspath()
.plus(mainSourceSet.getCompileClasspath());
var runtimeClasspath = sourceSet.getRuntimeClasspath()
.plus(mainSourceSet.getRuntimeClasspath());

Set<ModModel> loadedMods = new HashSet<>();
loadedMods.add(mainMod);

if (almostGradle.getTestMod().get() && settings.getTestMod().get()) {
var testMod = neoForge.getMods().maybeCreate(AlmostGradleExtension.TESTMOD_ID);
var testSourceSet = java.getSourceSets().getByName("test");

compileClasspath = compileClasspath.plus(testSourceSet.getCompileClasspath());
runtimeClasspath = runtimeClasspath.plus(testSourceSet.getRuntimeClasspath());
loadedMods.add(testMod);
}

sourceSet.setCompileClasspath(compileClasspath);
sourceSet.setRuntimeClasspath(runtimeClasspath);

neoForge.getRuns().create(sourceSet.getName(), (run) -> {
run.getIdeName().set("RecipeViewer (" + mod.id().toUpperCase() + ")");
run.client();
run.getSourceSet().set(sourceSet);
run.getLoadedMods().set(loadedMods);
});

var config = Utils.createLocalRuntime(project,
Expand Down