Skip to content

Commit

Permalink
NeoForge-1.21.4 init
Browse files Browse the repository at this point in the history
  • Loading branch information
Mgazul committed Dec 7, 2024
1 parent d211b8d commit 39f7813
Show file tree
Hide file tree
Showing 62 changed files with 4,919 additions and 457 deletions.
48 changes: 15 additions & 33 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,59 +1,41 @@
plugins {
id 'net.neoforged.gradleutils' version '3.0.0-alpha.13' apply false
id 'net.neoforged.gradleutils' version '3.0.0' apply false
id 'com.diffplug.spotless' version '6.22.0' apply false
id 'net.neoforged.licenser' version '0.7.2'
id 'net.neoforged.licenser' version '0.7.5'
id 'neoforge.formatting-conventions'
}

apply plugin: 'net.neoforged.gradleutils'

ext.isPreReleaseVersion = project.minecraft_version.contains('w') || project.minecraft_version.contains('-')

if (isPreReleaseVersion) {
project.version = "${project.neoforge_snapshot_next_stable}.0-alpha.${project.minecraft_version}.${(new Date()).format('yyyyMMdd.HHmmss', TimeZone.getTimeZone('UTC'))}"
} else {
gradleutils.version {
minecraftVersion project.minecraft_version
versionPrefix = null // Reset version prefix, which is set by prev. line
tags {
label = 'beta'
cleanMarkerLabel = 'stable'
}
branches {
suffixBranch = true
}
}

project.version = project.neoforge_version
}
project.version = '1.21.4-dev'

// Print version, generally useful to know - also appears on CI
System.out.println("NeoForge version ${project.version}")

allprojects {
version rootProject.version
group 'net.neoforged'
repositories {
maven { url = 'https://hub.spigotmc.org/nexus/content/groups/public/' }
maven { url = 'https://maven.mohistmc.com/' }
maven { url = 'https://maven.izzel.io/releases' }
mavenLocal()
}

apply plugin: 'java'

tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
options.compilerArgs << '-Xlint:-dep-ann' << '-Xlint:-removal' << '-Xdiags:verbose'
}
}

subprojects {
apply plugin: 'java'

java.toolchain.languageVersion.set(JavaLanguageVersion.of(project.java_version))
}

repositories {
mavenCentral()
// Remove src/ sources from the root project. They are used in the neoforge subproject.
sourceSets {
main {
java {
srcDirs = []
}
resources {
srcDirs = []
}
}
}

// Put licenser here otherwise it tries to license all source sets including decompiled MC sources
Expand Down
81 changes: 81 additions & 0 deletions buildSrc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# NeoForge Development Gradle Plugin

## NeoForge Project Structure

Before understanding the `buildSrc` plugin, one should understand the structure of the NeoForge Gradle project it is
applied to.

The project consists of a project tree with the following structure:

| Folder Path | Gradle Project Path | Applied Plugins | Description |
|------------------------------------------------------------------------|----------------------|:------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`/build.gradle`](../build.gradle) | `:` | &mdash; | The root project. Since this project is reused for Kits, the root project name is based on the checkout folder, which actually can lead to issues if it is called `NeoForge`. |
| [`/projects/neoforge/build.gradle`](../projects/neoforge/build.gradle) | `:neoforge` | [NeoDevPlugin](#neodevplugin) | The core NeoForge project, which produces the artifacts that will be published. |
| [`/projects/base/build.gradle`](../projects/base/build.gradle) | `:base` | [NeoDevBasePlugin](#neodevbaseplugin) | A utility project that contains the Minecraft sources without any NeoForge additions. Can be used to quickly compare what NeoForge has changed. |
| [`/tests/build.gradle`](../tests/build.gradle) | `:tests` | [NeoDevExtraPlugin](#neodevextraplugin) | Contains the game and unit tests for NeoForge. |
| [`/testframework/build.gradle`](../testframework/build.gradle) | `:testframework` | [MinecraftDependenciesPlugin](#minecraftdependenciesplugin) | A library providing support classes around writing game tests. |
| [`/coremods/build.gradle`](../coremods/build.gradle) | `:neoforge-coremods` | &mdash; | Java Bytecode transformers that are embedded into NeoForge as a nested Jar file. |
|

## Plugins

### NeoDevBasePlugin

Sources: [NeoDevBasePlugin.java](src/main/java/net/neoforged/neodev/NeoDevBasePlugin.java)

Implicitly applies: [MinecraftDependenciesPlugin](#minecraftdependenciesplugin).

Sets up a `setup` task that reuses code from [NeoDevPlugin](#neodevplugin) to decompile Minecraft and place the
decompiled sources in `projects/base/src/main/java`.

### NeoDevPlugin

Sources: [NeoDevPlugin.java](src/main/java/net/neoforged/neodev/NeoDevPlugin.java)

Implicitly applies: [MinecraftDependenciesPlugin](#minecraftdependenciesplugin).

This is the primary of this repository and is used to configure the `neoforge` subproject.

#### Setup

It creates a `setup` task that performs the following actions via various subtasks:

- Decompile Minecraft using the [NeoForm Runtime](https://github.com/neoforged/neoformruntime) and Minecraft version specific [NeoForm data](https://github.com/neoforged/NeoForm).
- Applies [Access Transformers](../src/main/resources/META-INF/accesstransformer.cfg) to Minecraft sources.
- Applies [NeoForge patches](../patches) to Minecraft sources. Any rejects are saved to the `/rejects` folder in the repository for manual inspection. During updates to new versions, the task can be run with `-Pupdating=true` to apply patches more leniently.
- Unpacks the patched sources to `projects/neoforge/src/main/java`.

#### Config Generation

The plugin creates and configures the tasks to create various configuration files used downstream to develop
mods with this version of NeoForge ([CreateUserDevConfig](src/main/java/net/neoforged/neodev/CreateUserDevConfig.java)), or install it ([CreateInstallerProfile](src/main/java/net/neoforged/neodev/installer/CreateInstallerProfile.java) and [CreateLauncherProfile](src/main/java/net/neoforged/neodev/installer/CreateLauncherProfile.java)).

A separate userdev profile is created for use by other subprojects in this repository.
The only difference is that it uses the FML launch types ending in `dev` rather than `userdev`.

#### Patch Generation

NeoForge injects its hooks into Minecraft by patching the decompiled source code.
Changes are made locally to the decompiled and patched source.
Since that source cannot be published, patches need to be generated before checking in.
The plugin configures the necessary task to do this
([GenerateSourcePatches](src/main/java/net/neoforged/neodev/GenerateSourcePatches.java)).

The source patches are only used during development of NeoForge itself and development of mods that use Gradle plugins implementing the decompile/patch/recompile pipeline.
For use by the installer intended for players as well as Gradle plugins wanting to replicate the production artifacts more closely, binary patches are generated using the ([GenerateBinaryPatches](src/main/java/net/neoforged/neodev/GenerateBinaryPatches.java)) task.

### NeoDevExtraPlugin

Sources: [NeoDevExtraPlugin.java](src/main/java/net/neoforged/neodev/NeoDevExtraPlugin.java)

This plugin can be applied to obtain a dependency on the `neoforge` project to depend on NeoForge including Minecraft
itself. Besides wiring up the dependency, it also creates run configurations based on the run-types defined in the
`neoforge` project.

### MinecraftDependenciesPlugin

This plugin is reused from [ModDevGradle](https://github.com/neoforged/ModDevGradle/).

It sets up repositories and attributes such that
the [libraries that Minecraft itself depends upon](https://github.com/neoforged/GradleMinecraftDependencies) can be
used.
25 changes: 25 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
plugins {
id 'java-gradle-plugin'
id 'groovy-gradle-plugin'
}

repositories {
gradlePluginPortal()
mavenCentral()
maven {
name = "NeoForged"
url = "https://maven.neoforged.net/releases"
content {
includeGroup "codechicken"
includeGroup "net.neoforged"
}
}
}

dependencies {
// buildSrc is an includedbuild of the parent directory (gradle.parent)
// ../settings.gradle sets these version properties accordingly
implementation "net.neoforged:moddev-gradle:${gradle.parent.ext.moddevgradle_plugin_version}"

implementation "com.google.code.gson:gson:${gradle.parent.ext.gson_version}"
implementation "io.codechicken:DiffPatch:${gradle.parent.ext.diffpatch_version}"

implementation "org.ow2.asm:asm:${gradle.parent.ext.asm_version}"
}
Empty file added buildSrc/settings.gradle
Empty file.
54 changes: 50 additions & 4 deletions buildSrc/src/main/groovy/neoforge.formatting-conventions.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import java.util.regex.Matcher

final generatePackageInfos = tasks.register('generatePackageInfos', Task) {
doLast {
fileTree('src/main/java').each { javaFile ->
project.plugins.apply('com.diffplug.spotless')

abstract class GeneratePackageInfos extends DefaultTask {
@InputFiles
@PathSensitive(PathSensitivity.RELATIVE)
abstract ConfigurableFileCollection getFiles();

@TaskAction
void generatePackageInfos() {
getFiles().each { javaFile ->
def packageInfoFile = new File(javaFile.parent, 'package-info.java')
if (!packageInfoFile.exists()) {
def pkgName = javaFile.toString().replaceAll(Matcher.quoteReplacement(File.separator), '/')
Expand All @@ -25,20 +32,59 @@ final generatePackageInfos = tasks.register('generatePackageInfos', Task) {
}
}
}
final generatePackageInfos = tasks.register('generatePackageInfos', GeneratePackageInfos) {
it.files.from fileTree("src/main/java")
}

spotless {
java {
endWithNewline()
indentWithSpaces()
removeUnusedImports()
toggleOffOn()
// Pin version to 4.31 because of a Spotless bug https://github.com/diffplug/spotless/issues/1992
eclipse('4.31').configFile rootProject.file('codeformat/formatter-config.xml')
importOrder()

// courtesy of diffplug/spotless#240
// https://github.com/diffplug/spotless/issues/240#issuecomment-385206606
custom 'noWildcardImports', { String fileContents ->
if (fileContents.contains('*;\n')) {
throw new GradleException('No wildcard imports are allowed!')
}
}

custom 'noNotNull', { String fileContents ->
if (fileContents.contains('@NotNull') || fileContents.contains('@Nonnull')) {
throw new GradleException('@NotNull and @Nonnull are disallowed.')
}
}

custom 'jetbrainsNullable', { String fileContents ->
fileContents.replace('javax.annotation.Nullable', 'org.jetbrains.annotations.Nullable')
}
bumpThisNumberIfACustomStepChanges(3)
}
}

tasks.named('licenseFormat').configure {
mustRunAfter generatePackageInfos
}
tasks.named('spotlessApply').configure {
mustRunAfter generatePackageInfos
mustRunAfter tasks.named('licenseFormat')
}

tasks.register('applyAllFormatting', Task) {
dependsOn generatePackageInfos
dependsOn tasks.named('licenseFormat')
dependsOn tasks.named('spotlessApply')
group = 'verification'
}


tasks.register('checkFormatting', Task) {
dependsOn 'licenseCheck'
dependsOn 'spotlessCheck'
group = 'verification'
}

Expand Down
13 changes: 13 additions & 0 deletions buildSrc/src/main/groovy/neoforge.versioning.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
project.plugins.apply('net.neoforged.gradleutils')

project.gradleutils.version {
minecraftVersion project.rootProject.minecraft_version
versionPrefix = null // Reset version prefix, which is set by prev. line
tags {
label = 'beta'
cleanMarkerLabel = 'stable'
}
branches {
suffixBranch = true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package net.neoforged.neodev;

import net.neoforged.neodev.utils.FileUtils;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Classpath;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.InputFiles;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.JavaExec;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction;

import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;

/**
* Runs <a href="https://github.com/neoforged/JavaSourceTransformer">JavaSourceTransformer</a> to apply
* access transformers to the Minecraft source code for extending the access level of existing classes/methods/etc.
* <p>
* Note that at runtime, FML also applies access transformers.
*/
abstract class ApplyAccessTransformer extends JavaExec {
@InputFile
public abstract RegularFileProperty getInputJar();

@InputFiles
public abstract ConfigurableFileCollection getAccessTransformers();

@Input
public abstract Property<Boolean> getValidate();

@OutputFile
public abstract RegularFileProperty getOutputJar();

// Used to give JST more information about the classes.
@Classpath
public abstract ConfigurableFileCollection getLibraries();

@Internal
public abstract RegularFileProperty getLibrariesFile();

@Inject
public ApplyAccessTransformer() {}

@Override
@TaskAction
public void exec() {
try {
FileUtils.writeLinesSafe(
getLibrariesFile().getAsFile().get().toPath(),
getLibraries().getFiles().stream().map(File::getAbsolutePath).toList(),
StandardCharsets.UTF_8);
} catch (IOException exception) {
throw new UncheckedIOException("Failed to write libraries for JST.", exception);
}

var args = new ArrayList<>(Arrays.asList(
"--enable-accesstransformers",
"--access-transformer-validation", getValidate().get() ? "error" : "log",
"--libraries-list", getLibrariesFile().getAsFile().get().getAbsolutePath()
));

for (var file : getAccessTransformers().getFiles()) {
args.addAll(Arrays.asList(
"--access-transformer", file.getAbsolutePath()
));
}

args.addAll(Arrays.asList(
getInputJar().getAsFile().get().getAbsolutePath(),
getOutputJar().getAsFile().get().getAbsolutePath()));

args(args);

super.exec();
}
}
Loading

0 comments on commit 39f7813

Please sign in to comment.