Skip to content

Commit

Permalink
Initial work on Forge 1.12.2 port
Browse files Browse the repository at this point in the history
  • Loading branch information
NeRdTheNed committed Jun 6, 2023
1 parent 904613d commit 48345b2
Show file tree
Hide file tree
Showing 17 changed files with 285 additions and 125 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/draftrelease.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# This workflow will build a Java project with Gradle
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle

name: fabric-1.20 - Draft release
name: forge-1.12.2 - Draft release

on:
push:
# Sequence of patterns matched against refs/tags
tags: 'v*-1.20' # Push events to matching v*-1.20
tags: 'v*-1.12.2.forge' # Push events to matching v*-1.12.2.forge

jobs:
build:
Expand All @@ -15,11 +15,11 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17
java-version: 8
- name: Install advancecomp
run: sudo apt-get install advancecomp
- name: Install strip-nondeterminism
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# This workflow will build a Java project with Gradle
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle

name: fabric-1.20 - Snapshot
name: forge-1.12.2 - Snapshot

on:
push:
branches: fabric-1.20
branches: forge-1.12.2
pull_request:
branches: fabric-1.20
branches: forge-1.12.2

jobs:
build:
Expand All @@ -16,11 +16,11 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17
java-version: 8
- name: Install advancecomp
run: sudo apt-get install advancecomp
- name: Install strip-nondeterminism
Expand All @@ -31,7 +31,7 @@ jobs:
uses: gradle/gradle-build-action@v2
with:
gradle-version: wrapper
cache-read-only: ${{ github.ref != 'refs/heads/fabric-1.20' }}
cache-read-only: ${{ github.ref != 'refs/heads/forge-1.12.2' }}
arguments: build --stacktrace --warning-mode all
- name: Rezip mod .jar files to remove directory entries
run: bash removeDirectoryEntries.sh
Expand Down
195 changes: 147 additions & 48 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,114 @@ buildscript {
repositories {
mavenCentral()
google()
maven {
name = "forge"
url = "https://maven.minecraftforge.net/"
}
maven { url = 'https://repo.spongepowered.org/maven' }
}
dependencies {
// FIXME Replace with a newer version as soon as it releases.
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true
}
classpath 'com.guardsquare:proguard-gradle:7.3.2'
classpath 'org.spongepowered:mixingradle:0.7.+'
}
}

plugins {
// TODO This buildscript currently depends on some implementation details of Loom due to dumb ProGuard stuff
// The version of Loom used will probably be able to be updated without any issues.
id 'fabric-loom' version '1.2-SNAPSHOT'
id 'java-library'
id 'maven-publish'
}

// Defines a Java 17 compatible JDK.
apply plugin: 'java'
apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'org.spongepowered.mixin'

// Defines a Java 8 compatible JDK.
def compiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(17)
languageVersion = JavaLanguageVersion.of(8)
}

// Tells Gradle to use the previously defined Java 17 compatible JDK.
// Tells Gradle to use the previously defined Java 8 compatible JDK.
java {
toolchain {
compiler
}
}

// Tells Gradle to always compile with the previously defined Java 17 compatible JDK.
// Tells Gradle to always compile with the previously defined Java 8 compatible JDK.
tasks.withType(JavaCompile).configureEach {
javaCompiler = compiler
}

archivesBaseName = project.archives_base_name
version = project.mod_version + "-" + project.minecraft_version
group = project.maven_group
def internalVersion = project.mod_version

// Information for ForgeGradle to configure the Minecraft / Forge version.
minecraft {
mappings channel: project.mcp_channel, version: project.mcp_version
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.

// Default run configurations.
runs {
client {
workingDirectory project.file('run')

// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'

// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
}

server {
workingDirectory project.file('run')

// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'

// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
}
}
}

configurations {
// Another list of dependencies to use with ProGaurd, as ForgeGradle isn't happy about resolving it the normal way.
// I'm not happy about it either.
proguardHack
}

dependencies {
//to change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
minecraft "net.minecraftforge:forge:${project.forge_version}"

// Mixins
annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
compileOnly 'org.spongepowered:mixin:0.8.5'
proguardHack 'org.spongepowered:mixin:0.8.5'
}

mixin {
add sourceSets.main, 'punch2prime.refmap.json'
config 'punch2prime.mixins.json'

debug.verbose = true
debug.export = true
}

import groovy.json.JsonSlurper
import groovy.json.JsonOutput
import proguard.gradle.ProGuardTask

processResources {
inputs.property "version", project.version
inputs.property "version", internalVersion
inputs.property "minecraft_version", project.minecraft_version

filesMatching("fabric.mod.json") {
expand "version": project.version
filesMatching('mcmod.info') {
expand 'version': internalVersion, 'mcversion': minecraft_version
}

// Minifies all .json files when building the mod.
Expand Down Expand Up @@ -84,67 +142,108 @@ tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}

// This task creates a .jar file containing the source code of this mod.
tasks.register('sourcesJar', Jar) {
dependsOn(classes)

archiveClassifier = "sources"
from sourceSets.main.allSource
}

// This task creates a .jar file containing a deobfuscated version of this mod, for ProGuard to minimise.
task unmappedJar(type: Jar) {
archiveClassifier = "unmapped"
tasks.register('unmappedJar', Jar) {
archiveClassifier = "dev"
from sourceSets.main.output
}

// TODO depends on loom implementation details I don't understand
task ('proguard', type: proguard.gradle.ProGuardTask) {
dependsOn "unmappedJar"
// This task uses ProGuard to shrink the built .jar's file size and optimise the bytecode. TODO Cleanup.
tasks.register('proguard', ProGuardTask) {
dependsOn(unmappedJar)
verbose

target "17"
target "1.8"

// Workaround for ProGuard seemingly not recognising when the output .jar file doesn't exist
outputs.upToDateWhen { false }
// Use the non-remapped .jar as the input file, because ForgeGradle has a convenient task to map it to obfuscated Minecraft class names for us when we're done optimising it
injars "build/libs/" + rootProject.name + "-" + version + "-dev.jar"
outjars "build/libs/" + rootProject.name + "-" + version + "-proguard-dev.jar"

injars "build/libs/" + archivesBaseName + "-" + version + "-unmapped.jar"
outjars "build/libs/" + archivesBaseName + "-" + version + "-dev" + ".jar"

// Get the Java standard library from the provided toolchain.
libraryjars compiler.get().metadata.installationPath.asFile.absolutePath + "/jmods/java.base.jmod", jarfilter: '!**.jar', filter: '!module-info.class'
// Get the location of rt.jar from the provided toolchain.
// Note to self: probably support building with not outdated versions of Java in the future.
libraryjars compiler.get().metadata.installationPath.asFile.absolutePath + "/lib/rt.jar"
// If rt.jar is not there, try looking inside a JRE folder instead.
libraryjars compiler.get().metadata.installationPath.asFile.absolutePath + "/jre/lib/rt.jar"

// Add relevant Minecraft libraries to ProGuard's list of libraries to obfuscate against.
// TODO this is very janky
libraryjars project.configurations.compileClasspath
libraryjars project.configurations.minecraft

// Add the dependencies to ProGuard's list of libraries to obfuscate against. I'd love a more sane way of doing this.
libraryjars project.configurations.proguardHack

// The rest of the configs are in this file
configuration 'guard.pro'
}

artifacts.add('archives', file(proguard.outputs.files.singleFile)) {
type('jar')
builtBy(proguard)
// TODO rethink probably
tasks.register('optimisedJar', Jar) {
dependsOn(proguard)

from zipTree(proguard.outputs.files.singleFile)
//archiveClassifier = "proguard"

manifest {
attributes([
"MixinConnector": "com.github.NeRdTheNed.Punch2Prime.Connector",
"TweakClass": "org.spongepowered.asm.launch.MixinTweaker",
'ForceLoadAsMod': 'true'
])
}
}

java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
reobf {
optimisedJar {
// This line left intentionally blank?
}
}

tasks.optimisedJar.finalizedBy('reobfOptimisedJar')

jar {
archiveClassifier = "debug" // Contains things like variables with actual names, line numbers etc. Useful for debugging, but these things take up file size, so they have to go.
manifest {
attributes([
"MixinConnector": "com.github.NeRdTheNed.Punch2Prime.Connector",
"TweakClass": "org.spongepowered.asm.launch.MixinTweaker",
'ForceLoadAsMod': 'true'
])
}
}

// TODO depends on loom implementation details I don't understand
remapJar {
// Creates the listed artifacts on building the mod.
artifacts {
archives sourcesJar
archives optimisedJar
}

// TODO this is a bit dumb
tasks.register('deleteProGuardOutput', Delete) {
dependsOn(proguard)
input.fileValue(proguard.outputs.files.singleFile)
//archiveClassifier.set("proguard")

delete proguard.outputs.files.singleFile
}

build.finalizedBy(cleanUnmappedJar)
build.finalizedBy(cleanUnmappedJar, deleteProGuardOutput)

// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
// add all the jars that should be included when publishing to maven
artifact(remapJar) {
builtBy remapJar
artifact(jar) {
builtBy build
}
artifact(sourcesJar) {
builtBy remapSourcesJar
builtBy sourcesJar
}
artifact(optimisedJar) {
builtBy optimisedJar
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/develop/
minecraft_version=1.20-rc1
yarn_mappings=1.20-rc1+build.2
loader_version=0.14.19
# Forge Properties
forge_version=1.12.2-14.23.5.2860
mcp_channel=stable
mcp_version=39-1.12
minecraft_version=1.12.2

# Mod Properties
mod_version = 1.0.2
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 48345b2

Please sign in to comment.