Skip to content

Commit

Permalink
Set both resources and classes directory to the same directory
Browse files Browse the repository at this point in the history
  • Loading branch information
shedaniel committed Dec 8, 2023
1 parent 827c0e9 commit 5106db2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,17 @@ public void run() {
}
}
}

if (extension.isForge() && extension.getForgeProvider().getVersion().getForgeMajorVersion() >= 49) {
// Merge all source set resources and classes into the same directory
// This is required for Forge 1.20.3+ to work properly
// This is really a hack in itself, thank you Forge
getProject().getExtensions().getByType(JavaPluginExtension.class).getSourceSets().forEach(sourceSet -> {
var dir = getProject().getLayout().getBuildDirectory().dir("sourcesSets/%s".formatted(sourceSet.getName()));
sourceSet.getOutput().setResourcesDir(dir);
sourceSet.getJava().getDestinationDirectory().set(dir);
});
}
});

finalizedBy("idea", "genIdeaWorkspace");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,15 @@ public static final class ForgeVersion {
private final String combined;
private final String minecraftVersion;
private final String forgeVersion;
private final int forgeMajorVersion;

public ForgeVersion(String combined) {
this.combined = combined;

if (combined == null) {
this.minecraftVersion = "NO_VERSION";
this.forgeVersion = "NO_VERSION";
this.forgeMajorVersion = -1;
return;
}

Expand All @@ -105,6 +107,20 @@ public ForgeVersion(String combined) {
this.minecraftVersion = "NO_VERSION";
this.forgeVersion = combined;
}

int major;

try {
if (this.forgeVersion.contains(".")) {
major = Integer.parseInt(this.forgeVersion.substring(0, this.forgeVersion.indexOf('.')));
} else {
major = Integer.parseInt(this.forgeVersion);
}
} catch (NumberFormatException e) {
major = -1;
}

this.forgeMajorVersion = major;
}

public String getCombined() {
Expand All @@ -118,5 +134,9 @@ public String getMinecraftVersion() {
public String getForgeVersion() {
return forgeVersion;
}

public int getForgeMajorVersion() {
return forgeMajorVersion;
}
}
}

0 comments on commit 5106db2

Please sign in to comment.