Skip to content

Commit

Permalink
Use correct sourceset
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Jan 22, 2025
1 parent 7bb8b80 commit 9265437
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,26 @@ abstract class FabricApiAbstractSourceSet {

protected abstract String getSourceSetName();

protected void configureSourceSet(Property<String> modId, boolean isClient) {
protected SourceSet configureSourceSet(Property<String> modId, boolean isClient) {
final LoomGradleExtension extension = LoomGradleExtension.get(getProject());
final SourceSet mainSourceSet = SourceSetHelper.getMainSourceSet(getProject());

final boolean isClientAndSplit = extension.areEnvironmentSourceSetsSplit() && isClient;

SourceSetContainer sourceSets = SourceSetHelper.getSourceSets(getProject());

// Create the new datagen sourceset, depend on the main or client sourceset.
SourceSet dataGenSourceSet = sourceSets.create(getSourceSetName(), sourceSet -> {
dependsOn(sourceSet, mainSourceSet);
// Create the new sourceset, depend on the main or client sourceset.
SourceSet sourceSet = sourceSets.create(getSourceSetName(), ss -> {
dependsOn(ss, mainSourceSet);

if (isClientAndSplit) {
dependsOn(sourceSet, SourceSetHelper.getSourceSetByName(MinecraftSourceSets.Split.CLIENT_ONLY_SOURCE_SET_NAME, getProject()));
dependsOn(ss, SourceSetHelper.getSourceSetByName(MinecraftSourceSets.Split.CLIENT_ONLY_SOURCE_SET_NAME, getProject()));
}
});

modId.convention(getProject().provider(() -> {
try {
final FabricModJson fabricModJson = FabricModJsonFactory.createFromSourceSetsNullable(getProject(), dataGenSourceSet);
final FabricModJson fabricModJson = FabricModJsonFactory.createFromSourceSetsNullable(getProject(), sourceSet);

if (fabricModJson == null) {
throw new RuntimeException("Could not find a fabric.mod.json file in the data source set or a value for DataGenerationSettings.getModId()");
Expand All @@ -83,6 +83,8 @@ protected void configureSourceSet(Property<String> modId, boolean isClient) {
});

extension.createRemapConfigurations(sourceSets.getByName(getSourceSetName()));

return sourceSet;
}

private static void extendsFrom(Project project, String name, String extendsFrom) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ protected String getSourceSetName() {
void configureTests(Action<GameTestSettings> action) {
final LoomGradleExtension extension = LoomGradleExtension.get(getProject());
final TaskContainer tasks = getProject().getTasks();
final SourceSet mainSourceSet = SourceSetHelper.getMainSourceSet(getProject());

GameTestSettings settings = getProject().getObjects().newInstance(GameTestSettings.class);
settings.getCreateSourceSet().convention(false);
Expand All @@ -77,8 +76,12 @@ void configureTests(Action<GameTestSettings> action) {

action.execute(settings);

final SourceSet testSourceSet;

if (settings.getCreateSourceSet().get()) {
configureSourceSet(settings.getModId(), true);
testSourceSet = configureSourceSet(settings.getModId(), true);
} else {
testSourceSet = SourceSetHelper.getMainSourceSet(getProject());
}

Consumer<RunConfigSettings> configureBase = run -> {
Expand All @@ -100,7 +103,7 @@ void configureTests(Action<GameTestSettings> action) {

if (settings.getEnableClientGameTests().get()) {
// Not ideal as there may be multiple resources directories, if this isnt correct the mod will need to override this.
final File resourcesDir = mainSourceSet.getResources().getFiles().stream().findAny().orElse(null);
final File resourcesDir = testSourceSet.getResources().getFiles().stream().findAny().orElse(null);

RunConfigSettings clientGameTest = extension.getRunConfigs().create("clientGameTest", run -> {
run.inherit(extension.getRunConfigs().getByName("client"));
Expand Down

0 comments on commit 9265437

Please sign in to comment.