Skip to content

Commit

Permalink
Add the ability to install and run a production client and server as …
Browse files Browse the repository at this point in the history
…well as moddev for testing FML. (#177)
  • Loading branch information
shartte authored Aug 10, 2024
1 parent 6a1f952 commit 2d3fba1
Show file tree
Hide file tree
Showing 19 changed files with 1,223 additions and 32 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@

The mod loader used by [NeoForge](https://github.com/neoforged/NeoForge).

## Testing

The `tests` subproject provides several tasks to test FML in various usage scenarios without having to include
it in a NeoForge working directory.

The Gradle property `test_neoforge_version` controls, which NeoForge version is used for these tests.

### Production Client

Run the `:tests:runProductionClient` task to start FML in an environment resembling a client launched through the
Vanilla launcher.

### Production Server

Run the `:tests:runProductionServer` task to start FML in an environment resembling a server launched through one of
the NeoForge provided startup scripts.

### Mod-Development

Run the `:tests:runClient` or `:tests:runServer` tasks to start FML in an environment resembling a mod development
environment.

## Extension Points

### Mod File Candidate Locators
Expand Down
16 changes: 0 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
plugins {
id 'com.github.ben-manes.versions' version '0.39.0'
id 'org.javamodularity.moduleplugin' version '1.8.7'
id 'net.neoforged.licenser' version '0.7.2' apply false
id 'com.diffplug.spotless' version '6.25.0' apply false
id 'net.neoforged.gradleutils' version "${gradleutils_version}"
Expand All @@ -26,7 +25,6 @@ allprojects {
apply plugin: 'signing'

apply plugin: 'com.github.ben-manes.versions'
apply plugin: 'org.javamodularity.moduleplugin'
apply plugin: 'net.neoforged.licenser'
apply plugin: 'com.diffplug.spotless'
apply plugin: 'net.neoforged.gradleutils'
Expand All @@ -41,20 +39,6 @@ allprojects {

spotlessUtils.configure(spotless)

repositories {
mavenCentral()

maven {
name = 'NeoForged'
url = 'https://maven.neoforged.net/releases'
}

maven {
name = 'Minecraft'
url = 'https://libraries.minecraft.net'
}
}

dependencyUpdates.rejectVersionIf { isNonStable(it.candidate.version) }

java {
Expand Down
17 changes: 17 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
plugins {
id 'java'
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}

dependencies {
implementation "com.google.code.gson:gson:2.10.1"
}

repositories {
gradlePluginPortal()
}
45 changes: 45 additions & 0 deletions buildSrc/src/main/java/fmlbuild/AttributesPlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package fmlbuild;

import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.attributes.Attribute;
import org.gradle.api.attributes.AttributeDisambiguationRule;
import org.gradle.api.attributes.MultipleCandidatesDetails;

/**
* Adds the attributes used by NeoForge, NeoForm and Minecraft Gradle module metadata.
*/
public class AttributesPlugin implements Plugin<Project> {
private static final Attribute<String> ATTRIBUTE_DISTRIBUTION = Attribute.of("net.neoforged.distribution", String.class);
private static final Attribute<String> ATTRIBUTE_OPERATING_SYSTEM = Attribute.of("net.neoforged.operatingsystem", String.class);

@Override
public void apply(Project project) {
project.getDependencies().attributesSchema(attributesSchema -> {
attributesSchema.attribute(ATTRIBUTE_DISTRIBUTION).getDisambiguationRules().add(DistributionDisambiguation.class);
attributesSchema.attribute(ATTRIBUTE_OPERATING_SYSTEM).getDisambiguationRules().add(OperatingSystemDisambiguation.class);
});
}
}

// The production server configuration has to be given the attribute to get server dependencies
abstract class DistributionDisambiguation implements AttributeDisambiguationRule<String> {
@Override
public void execute(MultipleCandidatesDetails<String> details) {
details.closestMatch("client");
}
}

/**
* This disambiguation rule will select native dependencies based on the operating system Gradle is currently running on.
*/
abstract class OperatingSystemDisambiguation implements AttributeDisambiguationRule<String> {
@Override
public void execute(MultipleCandidatesDetails<String> details) {
details.closestMatch(switch (OperatingSystem.current()) {
case LINUX -> "linux";
case MACOS -> "osx";
case WINDOWS -> "windows";
});
}
}
Loading

0 comments on commit 2d3fba1

Please sign in to comment.