Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ static ArtifactNamingStrategy createVanilla(String version) {
};
}

static ArtifactNamingStrategy createVanillaPatched(String loaderVersion) {
return artifact -> "vanilla-patched-%s%s.jar".formatted(loaderVersion, artifact.defaultSuffix);
}

static ArtifactNamingStrategy createNeoForge(VersionCapabilitiesInternal versionCapabilities, String loader, String version) {
return (artifact) -> {
if (artifact != WorkflowArtifact.CLIENT_RESOURCES || versionCapabilities.modLocatorRework()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,15 @@ public static ModDevArtifactsWorkflow create(Project project,

Function<WorkflowArtifact, Provider<RegularFile>> artifactPathStrategy = artifact -> artifactsBuildDir.map(dir -> dir.file(artifactNamingStrategy.getFilename(artifact)));

if (moddingDependencies.gameLibrariesContainUniversalJar()) {
task.getPutNeoForgeInTheMcJar().set(false);
}
task.getCompiledArtifact().set(artifactPathStrategy.apply(WorkflowArtifact.COMPILED));
task.getCompiledWithSourcesArtifact().set(artifactPathStrategy.apply(WorkflowArtifact.COMPILED_WITH_SOURCES));
task.getSourcesArtifact().set(artifactPathStrategy.apply(WorkflowArtifact.SOURCES));
task.getResourcesArtifact().set(artifactPathStrategy.apply(WorkflowArtifact.CLIENT_RESOURCES));
if (!moddingDependencies.gameLibrariesContainUniversalJar()) {
task.getResourcesArtifact().set(artifactPathStrategy.apply(WorkflowArtifact.CLIENT_RESOURCES));
}

task.getNeoForgeArtifact().set(moddingDependencies.neoForgeDependencyNotation());
task.getNeoFormArtifact().set(moddingDependencies.neoFormDependencyNotation());
Expand Down Expand Up @@ -183,7 +188,9 @@ public static ModDevArtifactsWorkflow create(Project project,
config.setCanBeConsumed(false);

config.getDependencies().addLater(minecraftClassesDependency);
config.getDependencies().addLater(createArtifacts.map(task -> project.files(task.getResourcesArtifact())).map(dependencyFactory::create));
if (!moddingDependencies.gameLibrariesContainUniversalJar()) {
config.getDependencies().addLater(createArtifacts.map(task -> project.files(task.getResourcesArtifact())).map(dependencyFactory::create));
}
// Technically, the Minecraft dependencies do not strictly need to be on the classpath because they are pulled from the legacy class path.
// However, we do it anyway because this matches production environments, and allows launch proxies such as DevLogin to use Minecraft's libraries.
config.getDependencies().add(moddingDependencies.gameLibrariesDependency());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,21 @@ public void enable(
var versionCapabilities = neoForgeVersion != null ? VersionCapabilitiesInternal.ofNeoForgeVersion(neoForgeVersion)
: VersionCapabilitiesInternal.ofNeoFormVersion(neoFormVersion);

ArtifactNamingStrategy artifactNamingStrategy;
// It's helpful to be able to differentiate the Vanilla jar and the NeoForge jar in classic multiloader setups.
if (neoForge != null) {
artifactNamingStrategy = ArtifactNamingStrategy.createNeoForge(versionCapabilities, "neoforge", neoForgeVersion);
} else {
artifactNamingStrategy = ArtifactNamingStrategy.createVanilla(neoFormVersion);
}

var configurations = project.getConfigurations();

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

ArtifactNamingStrategy artifactNamingStrategy;
// It's helpful to be able to differentiate the Vanilla jar and the NeoForge jar in classic multiloader setups.
if (neoForge == null) {
artifactNamingStrategy = ArtifactNamingStrategy.createVanilla(neoFormVersion);
} else if (dependencies.gameLibrariesContainUniversalJar()) {
artifactNamingStrategy = ArtifactNamingStrategy.createVanillaPatched(neoForgeVersion);
} else {
artifactNamingStrategy = ArtifactNamingStrategy.createNeoForge(versionCapabilities, "neoforge", neoForgeVersion);
}

var artifacts = ModDevArtifactsWorkflow.create(
project,
settings.getEnabledSourceSets(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ private ModDevRunWorkflow(Project project,
spec.setCanBeConsumed(false);

spec.getDependencies().add(gameLibrariesDependency);
addClientResources(project, spec, artifactsWorkflow.createArtifacts());
if (!artifactsWorkflow.dependencies().gameLibrariesContainUniversalJar()) {
addClientResources(project, spec, artifactsWorkflow.createArtifacts());
}
if (!versionCapabilities.modLocatorRework()) {
// Forge expects to find the Forge and client-extra jar on the legacy classpath
// Newer FML versions also search for it on the java.class.path.
Expand Down Expand Up @@ -221,7 +223,9 @@ public void configureTesting(Provider<ModModel> testedMod, Provider<Set<ModModel
},
legacyClassPath -> {
legacyClassPath.getDependencies().add(gameLibrariesDependency);
addClientResources(project, legacyClassPath, artifactsWorkflow.createArtifacts());
if (!artifactsWorkflow.dependencies().gameLibrariesContainUniversalJar()) {
addClientResources(project, legacyClassPath, artifactsWorkflow.createArtifacts());
}
},
artifactsWorkflow.downloadAssets().flatMap(DownloadAssets::getAssetPropertiesFile),
artifactsWorkflow.versionCapabilities());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import java.util.Map;
import net.neoforged.moddevgradle.internal.utils.VersionCapabilitiesInternal;
import org.gradle.api.Project;
import org.gradle.api.artifacts.ModuleDependency;
import org.gradle.api.attributes.LibraryElements;
import org.jetbrains.annotations.Nullable;

public record ModdingDependencies(
Expand All @@ -11,6 +13,8 @@ public record ModdingDependencies(
@Nullable ModuleDependency neoFormDependency,
@Nullable String neoFormDependencyNotation,
ModuleDependency gameLibrariesDependency,
// TODO: terrible name
boolean gameLibrariesContainUniversalJar,
@Nullable ModuleDependency modulePathDependency,
@Nullable ModuleDependency runTypesConfigDependency,
@Nullable ModuleDependency testFixturesDependency) {
Expand All @@ -25,8 +29,16 @@ public static ModdingDependencies create(ModuleDependency neoForge,
.capabilities(caps -> caps.requireCapability("net.neoforged:neoforge-moddev-module-path"))
// TODO: this is ugly; maybe make the configuration transitive in neoforge, or fix the SJH dep.
.exclude(Map.of("group", "org.jetbrains", "module", "annotations"));
var librariesDependency = neoForge.copy()
.capabilities(c -> c.requireCapability("net.neoforged:neoforge-dependencies"));
// TODO: configure based on version
boolean gameLibrariesContainUniversalJar = true;
ModuleDependency librariesDependency;
if (gameLibrariesContainUniversalJar) {
librariesDependency = neoForge.copy()
.capabilities(c -> c.requireCapability("net.neoforged:neoforge-universal-and-dependencies"));
} else {
librariesDependency = neoForge.copy()
.capabilities(c -> c.requireCapability("net.neoforged:neoforge-dependencies"));
}

ModuleDependency testFixturesDependency = null;
if (versionCapabilities.testFixtures()) {
Expand All @@ -40,6 +52,7 @@ public static ModdingDependencies create(ModuleDependency neoForge,
neoForm,
neoFormNotation,
librariesDependency,
gameLibrariesContainUniversalJar,
modulePathDependency,
runTypesDataDependency,
testFixturesDependency);
Expand All @@ -55,6 +68,7 @@ public static ModdingDependencies createVanillaOnly(ModuleDependency neoForm, St
neoForm,
neoFormNotation,
librariesDependency,
true, // TODO: might not work on old NeoForm versions?
null,
null,
null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public CreateMinecraftArtifacts() {
getAnalyzeCacheMisses().convention(false);
getValidateAccessTransformers().convention(false);
getParchmentEnabled().convention(false);
getPutNeoForgeInTheMcJar().convention(true);
}

/**
Expand Down Expand Up @@ -192,6 +193,11 @@ public CreateMinecraftArtifacts() {
@Optional
public abstract RegularFileProperty getResourcesArtifact();

// TODO: better name
// TODO: we should however put the resources in the MC jar
@Input
public abstract Property<Boolean> getPutNeoForgeInTheMcJar();

@Inject
protected abstract Problems getProblems();

Expand Down Expand Up @@ -281,7 +287,7 @@ public void createArtifacts() {
}

// NOTE: When we use NeoForm standalone, the result-ids also change, a.k.a. "Vanilla Mode"
if (getNeoForgeArtifact().isPresent()) {
if (getNeoForgeArtifact().isPresent() && getPutNeoForgeInTheMcJar().get()) {
if (getCompiledArtifact().isPresent()) {
requestedResults.add(new RequestedResult("compiledWithNeoForge", getCompiledArtifact().get().getAsFile()));
}
Expand All @@ -292,14 +298,15 @@ public void createArtifacts() {
requestedResults.add(new RequestedResult("sourcesAndCompiledWithNeoForge", getCompiledWithSourcesArtifact().get().getAsFile()));
}
} else {
boolean withResources = !getPutNeoForgeInTheMcJar().get();
if (getCompiledArtifact().isPresent()) {
requestedResults.add(new RequestedResult("compiled", getCompiledArtifact().get().getAsFile()));
requestedResults.add(new RequestedResult(withResources ? "compiledWithResources" : "compiled", getCompiledArtifact().get().getAsFile()));
}
if (getResourcesArtifact().isPresent()) {
requestedResults.add(new RequestedResult("sources", getSourcesArtifact().get().getAsFile()));
}
if (getCompiledWithSourcesArtifact().isPresent()) {
requestedResults.add(new RequestedResult("sourcesAndCompiled", getCompiledWithSourcesArtifact().get().getAsFile()));
requestedResults.add(new RequestedResult(withResources ? "sourcesAndCompiledWithResources" : "sourcesAndCompiled", getCompiledWithSourcesArtifact().get().getAsFile()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public abstract class NeoFormRuntimeExtension {
public static final String NAME = "neoFormRuntime";

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

@Inject
public NeoFormRuntimeExtension(Project project) {
Expand Down
8 changes: 7 additions & 1 deletion testproject/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ plugins {
id 'maven-publish'
}

allprojects {
repositories {
mavenLocal()
}
}

evaluationDependsOn(":subproject") // Because of the sourceset reference

tasks.named('wrapper') {
Expand Down Expand Up @@ -62,7 +68,7 @@ neoForge {
disableIdeRun()
}
data {
data()
clientData()
}
server {
server()
Expand Down
2 changes: 1 addition & 1 deletion testproject/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
org.gradle.configuration-cache=true

# Dependency versions
neoforge_version=21.0.61-beta
neoforge_version=21.10.49-beta-more-caps
2 changes: 1 addition & 1 deletion testproject/jijtest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ neoForge {

runs {
data {
data()
clientData()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
modLoader = "javafml"
loaderVersion = "[4,)"
license = "CC0"
[[mods]]
modId = "jijtest"
Expand Down
4 changes: 2 additions & 2 deletions testproject/src/main/java/testproject/TestProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
@Mod("testproject")
public class TestProject {
public TestProject() {
System.out.println(DetectedVersion.tryDetectVersion().getName());
System.out.println("Top-Level: " + ((DetectedVersion) DetectedVersion.BUILT_IN).buildTime);
System.out.println(DetectedVersion.tryDetectVersion().id());
System.out.println("Top-Level: " + DetectedVersion.LOGGER.getName());
System.out.println(SubProject.class.getName());

new ApiTest(); // access something from the api source set
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
public net.minecraft.DetectedVersion buildTime
public net.minecraft.DetectedVersion LOGGER
9 changes: 2 additions & 7 deletions testproject/src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
# The overall format is standard TOML format, v0.5.0.
# Note that there are a couple of TOML lists in this file.
# Find more information on toml format here: https://github.com/toml-lang/toml
# The name of the mod loader type to load - for regular FML @Mod mods it should be javafml
modLoader="javafml" #mandatory

# A version range to match for said mod loader - for regular FML @Mod it will be the the FML version. This is currently 47.
loaderVersion="[4,)" #mandatory

# The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties.
# Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here.
Expand Down Expand Up @@ -79,7 +74,7 @@ type="required" #mandatory
# Optional field describing why the dependency is required or why it is incompatible
# reason="..."
# The version range of the dependency
versionRange="[21.0.0-beta,)" #mandatory
versionRange="[21.10.0-beta,)" #mandatory
# An ordering relationship for the dependency.
# BEFORE - This mod is loaded BEFORE the dependency
# AFTER - This mod is loaded AFTER the dependency
Expand All @@ -92,7 +87,7 @@ side="BOTH"
modId="minecraft"
type="required"
# This version range declares a minimum of the current minecraft version up to but not including the next major version
versionRange="[1.21]"
versionRange="[1.21.10]"
ordering="NONE"
side="BOTH"

Expand Down
Loading