Skip to content

Commit 83cbe16

Browse files
committed
Put resources into the MC jar
1 parent de3cd19 commit 83cbe16

File tree

7 files changed

+32
-16
lines changed

7 files changed

+32
-16
lines changed

src/main/java/net/neoforged/moddevgradle/internal/ArtifactNamingStrategy.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ static ArtifactNamingStrategy createVanilla(String version) {
1212
};
1313
}
1414

15+
static ArtifactNamingStrategy createVanillaPatched(String loaderVersion) {
16+
return artifact -> "vanilla-patched-%s%s.jar".formatted(loaderVersion, artifact.defaultSuffix);
17+
}
18+
1519
static ArtifactNamingStrategy createNeoForge(VersionCapabilitiesInternal versionCapabilities, String loader, String version) {
1620
return (artifact) -> {
1721
if (artifact != WorkflowArtifact.CLIENT_RESOURCES || versionCapabilities.modLocatorRework()) {

src/main/java/net/neoforged/moddevgradle/internal/ModDevArtifactsWorkflow.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ public static ModDevArtifactsWorkflow create(Project project,
147147
task.getCompiledArtifact().set(artifactPathStrategy.apply(WorkflowArtifact.COMPILED));
148148
task.getCompiledWithSourcesArtifact().set(artifactPathStrategy.apply(WorkflowArtifact.COMPILED_WITH_SOURCES));
149149
task.getSourcesArtifact().set(artifactPathStrategy.apply(WorkflowArtifact.SOURCES));
150-
task.getResourcesArtifact().set(artifactPathStrategy.apply(WorkflowArtifact.CLIENT_RESOURCES));
150+
if (!moddingDependencies.gameLibrariesContainUniversalJar()) {
151+
task.getResourcesArtifact().set(artifactPathStrategy.apply(WorkflowArtifact.CLIENT_RESOURCES));
152+
}
151153

152154
task.getNeoForgeArtifact().set(moddingDependencies.neoForgeDependencyNotation());
153155
task.getNeoFormArtifact().set(moddingDependencies.neoFormDependencyNotation());
@@ -186,7 +188,9 @@ public static ModDevArtifactsWorkflow create(Project project,
186188
config.setCanBeConsumed(false);
187189

188190
config.getDependencies().addLater(minecraftClassesDependency);
189-
config.getDependencies().addLater(createArtifacts.map(task -> project.files(task.getResourcesArtifact())).map(dependencyFactory::create));
191+
if (!moddingDependencies.gameLibrariesContainUniversalJar()) {
192+
config.getDependencies().addLater(createArtifacts.map(task -> project.files(task.getResourcesArtifact())).map(dependencyFactory::create));
193+
}
190194
// Technically, the Minecraft dependencies do not strictly need to be on the classpath because they are pulled from the legacy class path.
191195
// However, we do it anyway because this matches production environments, and allows launch proxies such as DevLogin to use Minecraft's libraries.
192196
config.getDependencies().add(moddingDependencies.gameLibrariesDependency());

src/main/java/net/neoforged/moddevgradle/internal/ModDevPlugin.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,21 @@ public void enable(
7373
var versionCapabilities = neoForgeVersion != null ? VersionCapabilitiesInternal.ofNeoForgeVersion(neoForgeVersion)
7474
: VersionCapabilitiesInternal.ofNeoFormVersion(neoFormVersion);
7575

76-
ArtifactNamingStrategy artifactNamingStrategy;
77-
// It's helpful to be able to differentiate the Vanilla jar and the NeoForge jar in classic multiloader setups.
78-
if (neoForge != null) {
79-
artifactNamingStrategy = ArtifactNamingStrategy.createNeoForge(versionCapabilities, "neoforge", neoForgeVersion);
80-
} else {
81-
artifactNamingStrategy = ArtifactNamingStrategy.createVanilla(neoFormVersion);
82-
}
83-
8476
var configurations = project.getConfigurations();
8577

8678
var dependencies = neoForge != null ? ModdingDependencies.create(neoForge, neoForgeNotation, neoForm, neoFormNotation, versionCapabilities)
8779
: ModdingDependencies.createVanillaOnly(neoForm, neoFormNotation);
8880

81+
ArtifactNamingStrategy artifactNamingStrategy;
82+
// It's helpful to be able to differentiate the Vanilla jar and the NeoForge jar in classic multiloader setups.
83+
if (neoForge == null) {
84+
artifactNamingStrategy = ArtifactNamingStrategy.createVanilla(neoFormVersion);
85+
} else if (dependencies.gameLibrariesContainUniversalJar()) {
86+
artifactNamingStrategy = ArtifactNamingStrategy.createVanillaPatched(neoForgeVersion);
87+
} else {
88+
artifactNamingStrategy = ArtifactNamingStrategy.createNeoForge(versionCapabilities, "neoforge", neoForgeVersion);
89+
}
90+
8991
var artifacts = ModDevArtifactsWorkflow.create(
9092
project,
9193
settings.getEnabledSourceSets(),

src/main/java/net/neoforged/moddevgradle/internal/ModDevRunWorkflow.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ private ModDevRunWorkflow(Project project,
104104
spec.setCanBeConsumed(false);
105105

106106
spec.getDependencies().add(gameLibrariesDependency);
107-
addClientResources(project, spec, artifactsWorkflow.createArtifacts());
107+
if (!artifactsWorkflow.dependencies().gameLibrariesContainUniversalJar()) {
108+
addClientResources(project, spec, artifactsWorkflow.createArtifacts());
109+
}
108110
if (!versionCapabilities.modLocatorRework()) {
109111
// Forge expects to find the Forge and client-extra jar on the legacy classpath
110112
// Newer FML versions also search for it on the java.class.path.
@@ -221,7 +223,9 @@ public void configureTesting(Provider<ModModel> testedMod, Provider<Set<ModModel
221223
},
222224
legacyClassPath -> {
223225
legacyClassPath.getDependencies().add(gameLibrariesDependency);
224-
addClientResources(project, legacyClassPath, artifactsWorkflow.createArtifacts());
226+
if (!artifactsWorkflow.dependencies().gameLibrariesContainUniversalJar()) {
227+
addClientResources(project, legacyClassPath, artifactsWorkflow.createArtifacts());
228+
}
225229
},
226230
artifactsWorkflow.downloadAssets().flatMap(DownloadAssets::getAssetPropertiesFile),
227231
artifactsWorkflow.versionCapabilities());

src/main/java/net/neoforged/moddevgradle/internal/ModdingDependencies.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public record ModdingDependencies(
1313
@Nullable ModuleDependency neoFormDependency,
1414
@Nullable String neoFormDependencyNotation,
1515
ModuleDependency gameLibrariesDependency,
16+
// TODO: terrible name
1617
boolean gameLibrariesContainUniversalJar,
1718
@Nullable ModuleDependency modulePathDependency,
1819
@Nullable ModuleDependency runTypesConfigDependency,
@@ -67,7 +68,7 @@ public static ModdingDependencies createVanillaOnly(ModuleDependency neoForm, St
6768
neoForm,
6869
neoFormNotation,
6970
librariesDependency,
70-
false,
71+
true, // TODO: might not work on old NeoForm versions?
7172
null,
7273
null,
7374
null);

src/main/java/net/neoforged/nfrtgradle/CreateMinecraftArtifacts.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,14 +298,15 @@ public void createArtifacts() {
298298
requestedResults.add(new RequestedResult("sourcesAndCompiledWithNeoForge", getCompiledWithSourcesArtifact().get().getAsFile()));
299299
}
300300
} else {
301+
boolean withResources = !getPutNeoForgeInTheMcJar().get();
301302
if (getCompiledArtifact().isPresent()) {
302-
requestedResults.add(new RequestedResult("compiled", getCompiledArtifact().get().getAsFile()));
303+
requestedResults.add(new RequestedResult(withResources ? "compiledWithResources" : "compiled", getCompiledArtifact().get().getAsFile()));
303304
}
304305
if (getResourcesArtifact().isPresent()) {
305306
requestedResults.add(new RequestedResult("sources", getSourcesArtifact().get().getAsFile()));
306307
}
307308
if (getCompiledWithSourcesArtifact().isPresent()) {
308-
requestedResults.add(new RequestedResult("sourcesAndCompiled", getCompiledWithSourcesArtifact().get().getAsFile()));
309+
requestedResults.add(new RequestedResult(withResources ? "sourcesAndCompiledWithResources" : "sourcesAndCompiled", getCompiledWithSourcesArtifact().get().getAsFile()));
309310
}
310311
}
311312

src/main/java/net/neoforged/nfrtgradle/NeoFormRuntimeExtension.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
public abstract class NeoFormRuntimeExtension {
1313
public static final String NAME = "neoFormRuntime";
1414

15-
private static final String DEFAULT_NFRT_VERSION = "1.0.43";
15+
private static final String DEFAULT_NFRT_VERSION = "1.0.44-mc-resources-in-jar";
1616

1717
@Inject
1818
public NeoFormRuntimeExtension(Project project) {

0 commit comments

Comments
 (0)