Files
Tenet/build.gradle
2025-06-25 02:25:26 +08:00

870 lines
36 KiB
Groovy

import groovy.json.JsonBuilder
import org.apache.tools.ant.filters.ReplaceTokens
import net.minecraftforge.forge.tasks.checks.CheckATs
import net.minecraftforge.forge.tasks.checks.CheckExcs
import net.minecraftforge.forge.tasks.checks.CheckPatches
import net.minecraftforge.forge.tasks.checks.CheckSAS
import net.minecraftforge.forge.tasks.checks.CheckTask
import java.nio.file.Files
import net.minecraftforge.forge.tasks.*
import static net.minecraftforge.forge.tasks.Util.*
import net.minecraftforge.gradle.common.tasks.ApplyBinPatches
import net.minecraftforge.gradle.common.tasks.CheckJarCompatibility
import net.minecraftforge.gradle.common.tasks.DownloadMavenArtifact
import net.minecraftforge.gradle.common.tasks.ExtractInheritance
import net.minecraftforge.gradle.patcher.tasks.GeneratePatches
import net.minecraftforge.gradle.common.tasks.SignJar
import net.minecraftforge.gradle.patcher.tasks.ReobfuscateJar
import org.gradle.plugins.ide.eclipse.model.SourceFolder
plugins {
id 'org.cadixdev.licenser' version '0.6.1'
id 'com.github.ben-manes.versions' version '0.46.0'
id 'net.minecraftforge.gradleutils' version '[2.2,2.3)'
id 'net.minecraftforge.gradle.patcher' version '[6.0.16,6.2)' apply false
id 'net.minecraftforge.gradle.mcp' version '[6.0.16,6.2)' apply false
id 'eclipse'
id 'de.undercouch.download' version '5.4.0'
}
Util.init() //Init all our extension methods
println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))
ext {
JAR_SIGNER = null
MAPPING_CHANNEL = 'official'
MAPPING_VERSION = '1.16.5'
MC_VERSION = '1.16.5'
MCP_VERSION = '20210115.111550'
ASM_VERSION = '9.6'
SPI_VERSION = '3.2.0'
MOHIST_VERSION = gradleutils.gitInfo.abbreviatedId
}
project(':mcp') {
apply plugin: 'net.minecraftforge.gradle.mcp'
repositories {
mavenLocal()
}
mcp {
config MC_VERSION + '-' + MCP_VERSION
pipeline = 'joined'
}
}
project(':clean') {
evaluationDependsOn(':mcp')
apply plugin: 'eclipse'
apply plugin: 'net.minecraftforge.gradle.patcher'
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
implementation 'net.minecraftforge:forgespi:' + SPI_VERSION
}
patcher {
parent = project(':mcp')
mcVersion = MC_VERSION
patchedSrc = file('src/main/java')
mappings channel: MAPPING_CHANNEL, version: MAPPING_VERSION
runs {
clean_server {
taskName 'clean_server'
main 'net.minecraft.server.Main'
workingDirectory project.file('run')
}
}
}
}
project(':mohist') {
evaluationDependsOn(':clean')
apply plugin: 'java-library'
apply plugin: 'maven-publish'
apply plugin: 'signing'
apply plugin: 'eclipse'
apply plugin: 'net.minecraftforge.gradle.patcher'
java.toolchain.languageVersion = JavaLanguageVersion.of(11)
group = 'com.mohistmc'
sourceSets {
fmllauncher {
java {
srcDirs = ["$rootDir/src/fmllauncher/java"]
}
resources {
srcDirs = ["$rootDir/src/fmllauncher/resources"]
}
}
main {
compileClasspath += sourceSets.fmllauncher.runtimeClasspath
runtimeClasspath += sourceSets.fmllauncher.runtimeClasspath
java {
srcDirs = ["$rootDir/src/main/java"]
}
resources {
srcDirs = [
"$rootDir/src/main/resources",
"$rootDir/src/generated/resources"
]
}
}
userdev {
compileClasspath += sourceSets.main.runtimeClasspath
runtimeClasspath += sourceSets.main.runtimeClasspath
java {
srcDirs = ["$rootDir/src/userdev/java"]
}
resources {
srcDirs = ["$rootDir/src/userdev/resources"]
}
}
}
//Eclipse adds the sourcesets twice, once where we tell it to, once in the projects folder. No idea why. So delete them
eclipse.classpath.file.whenMerged { cls -> cls.entries.removeIf { e -> e instanceof SourceFolder && e.path.startsWith('src/') && !e.path.startsWith('src/main/') } }
repositories {
mavenLocal()
mavenCentral()
maven { url 'https://hub.spigotmc.org/nexus/content/groups/public/' }
maven { url 'https://papermc.io/repo/repository/maven-public/' }
maven { url 'https://repo.aikar.co/content/groups/aikar/' }
maven { url 'https://maven.mohistmc.com/' }
}
ext {
SPEC_VERSION = '36.2' // This is overwritten by git tag, but here so dev time doesnt explode
// The new versioning sceme is <MCVersion>-<ForgeMC>.<RB>.<CommitsSinceRB>
// ForgeMC is a unique identifier for every MC version we have supported.
// Essentially, the same as the old, except dropping the first number, and the builds are no longer unique.
MCP_ARTIFACT = project(':mcp').mcp.config.get()
SPECIAL_SOURCE_MCP = 'net.md-5:SpecialSource:1.8.5'
VERSION_JSON = project(':mcp').file('build/mcp/downloadJson/version.json')
BINPATCH_TOOL = 'net.minecraftforge:binarypatcher:1.0.12:fatjar'
INSTALLER_TOOLS = 'net.minecraftforge:installertools:1.3.0'
}
version = "1.16.5-" + MOHIST_VERSION
String forge_version = "36.2.42"
println('Forge Version: ' + forge_version)
patcher {
excs.from = file("$rootDir/src/main/resources/forge.exc")
parent = project(':clean')
patches = file("$rootDir/patches/minecraft")
patchedSrc = file('src/main/java')
srgPatches = true
accessTransformers.from file("$rootDir/src/main/resources/META-INF/accesstransformer.cfg")
sideAnnotationStrippers.from file("$rootDir/src/main/resources/forge.sas")
runs {
forge_server {
taskName 'forge_server'
main 'net.minecraftforge.userdev.LaunchTesting'
workingDirectory project.file('run')
// Support Forge devs running on Java 8 and up, including 16
jvmArgs '-XX:+IgnoreUnrecognizedVMOptions'
jvmArgs '--add-exports=java.base/sun.security.util=ALL-UNNAMED'
jvmArgs '--add-exports=jdk.naming.dns/com.sun.jndi.dns=java.naming'
jvmArgs '--add-opens=java.base/java.util.jar=ALL-UNNAMED'
environment 'target', 'fmldevserver'
environment 'MC_VERSION', MC_VERSION
environment 'MCP_VERSION', MCP_VERSION
environment 'FORGE_GROUP', project.group
environment 'FORGE_SPEC', SPEC_VERSION
environment 'FORGE_VERSION', forge_version
environment 'LAUNCHER_VERSION', SPEC_VERSION
environment 'MOHIST_VERSION', MOHIST_VERSION
property 'eventbus.checkTypesOnDispatch', 'true'
ideaModule "${rootProject.name}.${project.name}.userdev"
mods {
forge { source sourceSets.main }
}
}
forge_data {
taskName 'forge_data'
main 'net.minecraftforge.userdev.LaunchTesting'
workingDirectory project.file('run')
// Support Forge devs running on Java 8 and up, including 16
jvmArgs '-XX:+IgnoreUnrecognizedVMOptions'
jvmArgs '--add-exports=java.base/sun.security.util=ALL-UNNAMED'
jvmArgs '--add-exports=jdk.naming.dns/com.sun.jndi.dns=java.naming'
jvmArgs '--add-opens=java.base/java.util.jar=ALL-UNNAMED'
environment 'target', 'fmldevdata'
environment 'assetIndex', '{asset_index}'
environment 'assetDirectory', downloadAssets.output
environment 'MC_VERSION', MC_VERSION
environment 'MCP_VERSION', MCP_VERSION
environment 'FORGE_GROUP', project.group
environment 'FORGE_SPEC', SPEC_VERSION
environment 'FORGE_VERSION', forge_version
environment 'LAUNCHER_VERSION', SPEC_VERSION
environment 'MOHIST_VERSION', MOHIST_VERSION
ideaModule "${rootProject.name}.${project.name}.userdev"
mods {
forge { source sourceSets.main }
}
args '--mod', 'forge', '--all', '--output', rootProject.file('src/generated/resources/'), '--validate',
'--existing', sourceSets.main.resources.srcDirs[0]
}
}
}
afterEvaluate {
if (!patcher.srgPatches) {
srg2mcpClean {
dependsOn = []
input = project(':mcp').setupMCP.output
}
userdevJar {
onlyIf = { t -> true }
}
def patches = project.file('build/genPatchesForUserdev/output/')
patches.mkdirs()
def genPatchesForUserdev = tasks.register('genPatchesForUserdev', GeneratePatches){
base = project(':mcp').setupMCP.output
modified = applyRangeMapBase.output
originalPrefix = genPatches.originalPrefix
modifiedPrefix = genPatches.modifiedPrefix
output = patches
autoHeader true
lineEnding = '\n'
}
bakePatches {
dependsOn = []
input = genPatchesForUserdev.get().output
}
}
}
ext {
MANIFESTS = [
'/': [
'Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
'Git-Branch': '1.16.5'
] as LinkedHashMap,
'net/minecraftforge/versions/forge/': [
'Specification-Title': 'Forge',
'Specification-Vendor': 'Forge Development LLC',
'Specification-Version': SPEC_VERSION,
'Implementation-Title': project.group,
'Implementation-Version': forge_version,
'Implementation-Vendor': 'Forge Development LLC'
] as LinkedHashMap,
'net/minecraftforge/versions/mcp/': [
'Specification-Title': 'Minecraft',
'Specification-Vendor': 'Mojang',
'Specification-Version': MC_VERSION,
'Implementation-Title': 'MCP',
'Implementation-Version': MCP_VERSION,
'Implementation-Vendor': 'Forge'
] as LinkedHashMap,
'net/minecraftforge/fml/javafmlmod/': [
'Specification-Title': 'Mod Language Provider',
'Specification-Vendor': 'Forge Development LLC',
'Specification-Version': '1',
'Implementation-Title': 'FML Java Mod',
'Implementation-Version': SPEC_VERSION,
'Implementation-Vendor': 'Forge'
] as LinkedHashMap,
'net/minecraftforge/fml/mclanguageprovider/': [
'Specification-Title': 'Mod Language Provider',
'Specification-Vendor': 'Forge Development LLC',
'Specification-Version': '1',
'Implementation-Title': 'Minecraft Language Mod Provider',
'Implementation-Version': '1',
'Implementation-Vendor': 'Forge'
] as LinkedHashMap,
'net/minecraftforge/fml/loading/': [
'Specification-Title': 'Launcher',
'Specification-Vendor': 'Forge Development LLC',
'Specification-Version': '1',
'Implementation-Title': 'FML Launcher',
'Implementation-Version': SPEC_VERSION,
'Implementation-Vendor': 'Forge'
] as LinkedHashMap,
'net/minecraftforge/fml/userdev/': [
'Specification-Title': 'Forge User Development',
'Specification-Vendor': 'Forge Development LLC',
'Specification-Version': SPEC_VERSION,
'Implementation-Title': project.group,
'Implementation-Version': MOHIST_VERSION,
'Implementation-Vendor': 'Forge Development LLC'
] as LinkedHashMap,
'com/mohistmc/': [
'Specification-Title' : 'Mohist',
'Specification-Vendor' : 'MohistMC',
'Specification-Version': MOHIST_VERSION,
'Implementation-Title' : 'Mohist',
'Implementation-Version': '1.16.5-' + MOHIST_VERSION,
'Implementation-Vendor' : 'MohistMC'
] as LinkedHashMap,
'org/bukkit/craftbukkit/v1_16_R3/': [
'Specification-Title' : MCP_VERSION,
'Specification-Vendor' : 'SpigotMC',
'Specification-Version': '1.16.5',
'Implementation-Title' : 'Spigot',
'Implementation-Version': '7e29f765-296df566-9fb885e8',
'Implementation-Vendor' : 'SpigotMC'
] as LinkedHashMap
]
}
configurations {
installer {
transitive = false //Don't pull all libraries, if we're missing something, add it to the installer list so the installer knows to download it.
}
api.extendsFrom(installer)
fmllauncherImplementation.extendsFrom(installer, implementation)
}
dependencies {
installer 'org.ow2.asm:asm:' + ASM_VERSION
installer 'org.ow2.asm:asm-commons:' + ASM_VERSION
installer 'org.ow2.asm:asm-tree:' + ASM_VERSION
installer 'org.ow2.asm:asm-util:' + ASM_VERSION
installer 'org.ow2.asm:asm-analysis:' + ASM_VERSION
installer 'cpw.mods:modlauncher:mohist-8.1.3'
installer 'cpw.mods:grossjava9hacks:1.3.3'
installer 'net.minecraftforge:accesstransformers:3.0.1'
installer 'org.antlr:antlr4-runtime:4.9.1' //Dep of AccessTransformer
installer 'net.minecraftforge:eventbus:4.0.0'
installer 'net.minecraftforge:forgespi:' + SPI_VERSION
installer 'net.minecraftforge:coremods:4.0.6'
installer 'net.minecraftforge:unsafe:0.2.0'
installer 'com.electronwill.night-config:core:3.6.3'
installer 'com.electronwill.night-config:toml:3.6.3'
installer 'org.jline:jline:3.12.1'
installer 'org.apache.maven:maven-artifact:3.6.3'
installer 'net.jodah:typetools:0.8.3'
installer 'org.apache.logging.log4j:log4j-api:2.17.2'
installer 'org.apache.logging.log4j:log4j-core:2.17.2'
installer 'org.apache.logging.log4j:log4j-slf4j18-impl:2.17.2'
installer 'net.minecrell:terminalconsoleappender:1.2.0'
installer 'net.sf.jopt-simple:jopt-simple:5.0.4'
installer 'org.spongepowered:mixin:0.8.4'
// This is org.openjdk.nashorn:nashorn-core:15.1.1 repackaged so it doesn't crash on JREs < 15.
// See: https://github.com/LexManos/NashornLegacyPackager
installer 'org.openjdk.nashorn:nashorn-core:15.3'
// bukkit
installer 'commons-lang:commons-lang:2.6'
installer 'org.yaml:snakeyaml:1.27'
installer 'org.apache.maven:maven-resolver-provider:3.8.1'
installer 'org.apache.maven.resolver:maven-resolver-connector-basic:1.6.2'
installer 'org.apache.maven.resolver:maven-resolver-transport-http:1.6.2'
installer 'org.jetbrains:annotations:20.1.0'
installer 'org.slf4j:slf4j-api:1.8.0-beta4'
installer 'javax.inject:javax.inject:1'
// craftbukkit
installer 'org.fusesource.jansi:jansi:1.18'
installer 'jline:jline:2.14.6'
installer 'com.googlecode.json-simple:json-simple:1.1.1'
installer 'org.xerial:sqlite-jdbc:3.34.0'
installer 'mysql:mysql-connector-java:5.1.49'
installer 'org.apache.logging.log4j:log4j-iostreams:2.17.1'
installer 'net.md-5:SpecialSource:1.8.5'
// spigot
installer 'net.md-5:bungeecord-chat:1.16-R0.4'
fmllauncherImplementation 'com.google.guava:guava:21.0'
fmllauncherImplementation 'com.google.code.gson:gson:2.10'
fmllauncherImplementation 'org.lwjgl:lwjgl:3.2.2'
fmllauncherImplementation 'org.lwjgl:lwjgl-glfw:3.2.2'
fmllauncherImplementation 'org.lwjgl:lwjgl-opengl:3.2.2'
fmllauncherImplementation 'org.lwjgl:lwjgl-stb:3.2.2'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testImplementation 'org.junit.vintage:junit-vintage-engine:5.+'
testImplementation 'org.opentest4j:opentest4j:1.2.0' // needed for junit 5
testImplementation 'org.hamcrest:hamcrest-all:1.3' // needs advanced matching for list order
}
// We apply the bin patches we just created to make a jar that is JUST our changes
['Client', 'Server', 'Joined'].each { side ->
def gen = tasks.getByName("gen${side}BinPatches")
gen.tool = BINPATCH_TOOL
task "apply${side}BinPatches"(type: net.minecraftforge.gradle.common.tasks.ApplyBinPatches, dependsOn: gen) {
clean = gen.cleanJar
patch = gen.output
tool = BINPATCH_TOOL
}
def srgTask = tasks.getByName(patcher.notchObf ? 'createMcp2Obf' : 'createMcp2Srg')
// Create SRG named Vanilla jars, using the SpecialSource we have in the installer
task "create${side}SRG"(type: net.minecraftforge.gradle.userdev.tasks.RenameJar, dependsOn: srgTask) {
tool = SPECIAL_SOURCE_MCP + ':shaded'
args = ['--stable', '--in-jar', '{input}', '--out-jar', '{output}', '--srg-in', '{mappings}']
mappings = srgTask.output
input = gen.cleanJar
output = file("build/create${name}SRG/output.jar")
}
}
task downloadLibraries(type: DownloadLibraries, dependsOn: ':mcp:setupMCP') {
input = VERSION_JSON
output = rootProject.file('build/libraries/')
}
task extractInheritance(type: ExtractInheritance, dependsOn: [genJoinedBinPatches, downloadLibraries]) {
tool = INSTALLER_TOOLS + ':fatjar'
args.add '--annotations'
input = genJoinedBinPatches.cleanJar
libraries.addAll downloadLibraries.librariesOutput.map { rf -> Files.readAllLines(rf.asFile.toPath()).stream().map(File::new).collect(java.util.stream.Collectors.toList()) }
}
task findFieldInstanceChecks(type: FieldCompareFinder, dependsOn: ['createJoinedSRG']) {
jar = tasks.getByName('createJoinedSRG').output
output = rootProject.file('src/main/resources/coremods/field_to_instanceof.json')
fields {
bows {
cls = 'net/minecraft/item/Items'
name = 'field_151031_f'
replacement = 'net/minecraft/item/BowItem'
}
crossbows {
cls = 'net/minecraft/item/Items'
name = 'field_222114_py'
replacement = 'net/minecraft/item/CrossbowItem'
}
filled_map {
cls = 'net/minecraft/item/Items'
name = 'field_151098_aY'
replacement = 'net/minecraft/item/FilledMapItem'
blacklist 'net/minecraft/client/gui/screen/inventory/CartographyTableScreen', 'func_230450_a_', '(Lcom/mojang/blaze3d/matrix/MatrixStack;FII)V'
blacklist 'net/minecraft/client/renderer/entity/ItemFrameRenderer', 'func_225623_a_', '(Lnet/minecraft/entity/item/ItemFrameEntity;FFLcom/mojang/blaze3d/matrix/MatrixStack;Lnet/minecraft/client/renderer/IRenderTypeBuffer;I)V'
blacklist 'net/minecraft/item/crafting/MapCloningRecipe'
blacklist 'net/minecraft/item/crafting/MapExtendingRecipe'
}
fishing_rod {
cls = 'net/minecraft/item/Items'
name = 'field_151112_aM'
replacement = 'net/minecraft/item/FishingRodItem'
}
shears {
cls = 'net/minecraft/item/Items'
name = 'field_151097_aZ'
replacement = 'net/minecraft/item/ShearsItem'
}
}
}
tasks.register('checkAll') {
dependsOn 'checkLicenses'
group = 'checks'
}
tasks.register('checkAllAndFix') {
dependsOn 'findFieldInstanceChecks', 'checkLicenses'
group = 'checks'
}
CheckTask.registerTask(tasks, 'ATs', CheckATs) {
dependsOn extractInheritance, createSrg2Mcp
ats.from patcher.accessTransformers
inheritance = extractInheritance.output
mappings = createSrg2Mcp.output
}
CheckTask.registerTask(tasks, 'SAS', CheckSAS) {
dependsOn extractInheritance
sass.from patcher.sideAnnotationStrippers
inheritance = extractInheritance.output
}
CheckTask.registerTask(tasks, 'Excs', CheckExcs) {
dependsOn jar
binary = jar.archiveFile.get().asFile
excs.from patcher.excs
}
CheckTask.registerTask(tasks, 'Patches', CheckPatches) {
dependsOn genPatches
patchDir = file("$rootDir/patches")
patchesWithS2SArtifact = [
'minecraft/net/minecraft/client/renderer/ViewFrustum.java.patch',
'minecraft/net/minecraft/data/BlockModelDefinition.java.patch',
]
}
genPatches {
autoHeader true
lineEnding = '\n'
}
def baseForgeVersionProperty = project.objects.property(String)
baseForgeVersionProperty.set(project.provider { getLatestForgeVersion(MC_VERSION) }.map { MC_VERSION + '-' + it })
baseForgeVersionProperty.finalizeValueOnRead()
def jarCompatibilityTaskSetup = { task ->
task.group = 'jar compatibility'
task.onlyIf {
baseForgeVersionProperty.getOrNull() != null
}
}
tasks.register('setupCheckJarCompatibility', SetupCheckJarCompatibility) {
inputVersion = baseForgeVersionProperty
}
tasks.register('applyBaseCompatibilityJarBinPatches', ApplyBinPatches) {
jarCompatibilityTaskSetup(it)
clean = project.tasks.createJoinedSRG.output
patch = project.tasks.named('setupCheckJarCompatibility').flatMap { it.baseBinPatchesOutput }
output = project.layout.buildDirectory.dir(name).map { it.file('output.jar') }
}
tasks.register('mergeBaseForgeJar', MergeJars) {
jarCompatibilityTaskSetup(it)
inputJars.from(project.tasks.named('applyBaseCompatibilityJarBinPatches').flatMap { it.output })
inputJars.from(baseForgeVersionProperty.map { inputVersion ->
def output = project.layout.buildDirectory.dir(name).map { it.file("forge-${inputVersion}-universal.jar") }.get().asFile
project.rootProject.extensions.download.run {
src "https://maven.minecraftforge.net/net/minecraftforge/forge/${inputVersion}/forge-${inputVersion}-universal.jar"
dest output
}
return output
})
}
tasks.register('checkJarCompatibility', CheckJarCompatibility) {
jarCompatibilityTaskSetup(it)
dependsOn 'setupCheckJarCompatibility'
baseJar = project.tasks.named('mergeBaseForgeJar').flatMap { it.output }
baseLibraries.from(project.tasks.named('createJoinedSRG').flatMap { it.output })
inputJar = project.tasks.named('reobfJar').flatMap { it.output }
commonLibraries.from(project.configurations.minecraftImplementation)
commonLibraries.from(project.configurations.installer)
}
task launcherJson(dependsOn: ['signUniversalJar', 'signLauncherJar']) {
inputs.file universalJar.archiveFile
inputs.file { launcherJar.archiveFile }
ext {
output = file('build/version.json')
vanilla = project(':mcp').file('build/mcp/downloadJson/version.json')
timestamp = iso8601Now()
comment = [
"Please do not automate the download and installation of Forge.",
"Our efforts are supported by ads from the download page.",
"If you MUST automate this, please consider supporting the project through https://www.patreon.com/LexManos/"
]
def idx = project.version.indexOf('-')
id = project.version.substring(0, idx) + "-${project.name}" + project.version.substring(idx)
}
inputs.file vanilla
outputs.file output
doLast {
def json_vanilla = vanilla.json()
def json = [
_comment_: comment,
id: id,
time: timestamp,
releaseTime: timestamp,
type: 'release',
mainClass: 'cpw.mods.modlauncher.Launcher',
inheritsFrom: MC_VERSION,
logging: {},
arguments: [
game: ['--launchTarget', 'fmlclient','--fml.mohistVersion', "${MOHIST_VERSION}", '--fml.forgeVersion', forge_version, '--fml.mcVersion', "${MC_VERSION}", '--fml.forgeGroup', "${project.group}", '--fml.mcpVersion', "${MCP_VERSION}"],
// Support running with Java 8 and up, including 16
jvm: [
// Allow these JVM args to not crash Java 8
'-XX:+IgnoreUnrecognizedVMOptions',
// ModLauncher uses sun.security.util.ManifestEntryVerifier and needs access to it
'--add-exports=java.base/sun.security.util=ALL-UNNAMED',
// JDK bug, not fixed properly - https://bugs.openjdk.java.net/browse/JDK-8186019
'--add-exports=jdk.naming.dns/com.sun.jndi.dns=java.naming',
// ModLauncher reflects field 'jv' in java.util.jar.JarVerifier
'--add-opens=java.base/java.util.jar=ALL-UNNAMED'
]
],
libraries: [
[
//Package our launcher jar as the 'main' jar Mojang's launcher loads. It will in turn load Forge's regular jars itself.
name: "${project.group}:${project.name}:${project.version}",
downloads: [
artifact: [
path: "${project.group.replace('.', '/')}/${project.name}/${project.version}/${project.name}-${project.version}.jar",
url: "", //Do not include the URL so that the installer/launcher won't grab it. This is also why we don't have the universal classifier
sha1: launcherJar.archiveFile.get().asFile.sha1(),
size: launcherJar.archiveFile.get().asFile.length()
]
]
]
]
]
def artifacts = getArtifacts(project, project.configurations.installer, false)
artifacts.each { key, lib ->
json.libraries.add(lib)
}
output.text = new JsonBuilder(json).toPrettyString()
}
}
['client', 'server'].each { side ->
['slim', 'extra'].each { type ->
def name = "download${side.capitalize()}${type.capitalize()}"
task "${name}"(type: DownloadMavenArtifact) {
artifact = "net.minecraft:${side}:${MC_VERSION}-${MCP_VERSION}:${type}"
}
}
}
universalJar {
duplicatesStrategy = 'exclude'
doFirst {
MANIFESTS.each{ pkg, values ->
if (pkg == '/') {
manifest.attributes(values += [
'Manifest-Version': MOHIST_VERSION
])
} else {
manifest.attributes(values, pkg)
}
}
}
}
task launcherJar(type: Jar) {
archiveBaseName = 'mohist'
archiveClassifier.set('launcher')
from sourceSets.fmllauncher.output
doFirst {
def classpath = new StringBuilder()
def artifacts = getArtifacts(project, project.configurations.installer, false)
artifacts.each { key, lib ->
classpath += "libraries/${lib.downloads.artifact.path} "
}
classpath += "libraries/net/minecraft/server/${MC_VERSION}-${MCP_VERSION}/server-${MC_VERSION}-${MCP_VERSION}-extra.jar"
MANIFESTS.each{ pkg, values ->
if (pkg == '/') {
manifest.attributes(values += [
'Premain-Class': 'com.mohistmc.util.JarLoader',
'Launcher-Agent-Class': 'com.mohistmc.util.JarLoader',
'Main-Class': 'net.minecraftforge.server.ServerMain',
'Class-Path': classpath.toString(),
'ServerLaunchArgs': [
'--gameDir', '.',
'--launchTarget', 'fmlserver',
'--fml.mohistVersion', "${MOHIST_VERSION}".toString(),
'--fml.forgeVersion', forge_version,
'--fml.mcpVersion', MCP_VERSION,
'--fml.mcVersion', MC_VERSION,
'--fml.forgeGroup', project.group
].join(' ')
])
} else {
manifest.attributes(values, pkg)
}
}
}
}
task downloadInstaller(type: DownloadMavenArtifact) {
artifact = 'net.minecraftforge:installer:2.2.+:fatjar'
changing = true
}
task mohistJar(type: Jar, dependsOn: [genServerBinPatches, 'signUniversalJar']) {
archiveClassifier = 'server'
archiveExtension = 'jar'
archiveBaseName = 'mohist'
archiveVersion = "1.16.5-" + MOHIST_VERSION
destinationDirectory = file('build/libs')
from sourceSets.fmllauncher.output
def classpath = new StringBuilder()
def artifacts = getArtifacts(project, project.configurations.installer, false)
artifacts.each { key, lib ->
classpath += "libraries/${lib.downloads.artifact.path} "
}
doFirst {
MANIFESTS.each{ pkg, values ->
if (pkg == '/') {
manifest.attributes(values += [
'Premain-Class': 'com.mohistmc.util.JarLoader',
'Launcher-Agent-Class': 'com.mohistmc.util.JarLoader',
'Main-Class': 'net.minecraftforge.server.ServerMain',
'Class-Path': classpath.toString(),
'ServerLaunchArgs': [
'--gameDir', '.',
'--launchTarget', 'fmlserver',
'--fml.mohistVersion', MOHIST_VERSION,
'--fml.forgeVersion', forge_version,
'--fml.mcpVersion', MCP_VERSION,
'--fml.mcVersion', MC_VERSION,
'--fml.forgeGroup', project.group
].join(' ')
])
} else {
manifest.attributes(values, pkg)
}
}
}
from(genServerBinPatches.output) {
rename{'data/server.lzma'}
}
from(universalJar) {
into "/data/"
}
from(rootProject.file('server_files/version.txt')) {
filter(ReplaceTokens, tokens: [VERSION: forge_version])
rename { 'versions/forge.txt' }
}
from(rootProject.file('server_files/version.txt')) {
filter(ReplaceTokens, tokens: [VERSION: MCP_VERSION])
rename { 'versions/mcp.txt' }
}
from(rootProject.file('server_files/libraries.txt')) {
filter(ReplaceTokens, tokens: [CLASS_PATH: classpath.toString()])
rename { 'data/libraries.txt' }
}
}
[universalJar, launcherJar, mohistJar].each { t ->
task "sign${t.name.capitalize()}"(type: SignJar, dependsOn: t) {
onlyIf {
JAR_SIGNER != null && t.state.failure == null
}
def jarsigner = JAR_SIGNER == null ? [:] : JAR_SIGNER
alias = 'forge'
storePass = jarsigner.storepass
keyPass = jarsigner.keypass
keyStore = jarsigner.keystore
inputFile = t.archiveFile
outputFile = t.archiveFile
doFirst {
project.logger.lifecycle('Signing: ' + inputFile)
}
}
t.finalizedBy(tasks.getByName("sign${t.name.capitalize()}"))
}
userdevConfig {
def artifacts = getArtifacts(project, project.configurations.installer, true)
artifacts.each { key, lib ->
libraries.add(lib.name)
}
libraries.add("${project.group}:${project.name}:${project.version}:launcher")
runs {
server {
main 'net.minecraftforge.userdev.LaunchTesting'
// Support mod devs running on Java 8 and up, including 16
jvmArgs '-XX:+IgnoreUnrecognizedVMOptions'
jvmArgs '--add-exports=java.base/sun.security.util=ALL-UNNAMED'
jvmArgs '--add-exports=jdk.naming.dns/com.sun.jndi.dns=java.naming'
jvmArgs '--add-opens=java.base/java.util.jar=ALL-UNNAMED'
environment 'target', 'fmluserdevserver'
environment 'MC_VERSION', "${MC_VERSION}"
environment 'FORGE_GROUP', "${project.group}"
environment 'MCP_VERSION', "${MCP_VERSION}"
environment 'MOD_CLASSES', '{source_roots}'
environment 'MCP_MAPPINGS', '{mcp_mappings}'
environment 'FORGE_VERSION', "${forge_version}"
environment 'MOHIST_VERSION', "${MOHIST_VERSION}"
}
data {
main 'net.minecraftforge.userdev.LaunchTesting'
// Support mod devs running on Java 8 and up, including 16
jvmArgs '-XX:+IgnoreUnrecognizedVMOptions'
jvmArgs '--add-exports=java.base/sun.security.util=ALL-UNNAMED'
jvmArgs '--add-exports=jdk.naming.dns/com.sun.jndi.dns=java.naming'
jvmArgs '--add-opens=java.base/java.util.jar=ALL-UNNAMED'
environment 'target', 'fmluserdevdata'
environment 'assetIndex', '{asset_index}'
environment 'assetDirectory', '{assets_root}'
environment 'MC_VERSION', "${MC_VERSION}"
environment 'FORGE_GROUP', "${project.group}"
environment 'MCP_VERSION', "${MCP_VERSION}"
environment 'MOD_CLASSES', '{source_roots}'
environment 'MCP_MAPPINGS', '{mcp_mappings}'
environment 'FORGE_VERSION', "${forge_version}"
environment 'MOHIST_VERSION', "${MOHIST_VERSION}"
}
}
}
task userdevExtras(type:Jar) {
dependsOn classes
from sourceSets.userdev.output
archiveClassifier.set('userdev-temp')
}
task userdevExtrasReobf(type: ReobfuscateJar) {
dependsOn userdevExtras, createMcp2Srg
input = tasks.userdevExtras.archiveFile
classpath.from project.configurations.userdevCompileClasspath
srg = tasks.createMcp2Srg.output
}
userdevJar {
dependsOn tasks.userdevExtrasReobf
from (zipTree(tasks.userdevExtrasReobf.output)) {
into '/inject/'
}
from (sourceSets.userdev.output.resourcesDir) {
into '/inject/'
}
}
extractRangeMap {
dependencies.from jar.archiveFile
sources.from sourceSets.userdev.java.srcDirs
}
applyRangeMap {
sources.from sourceSets.userdev.java.srcDirs
}
tasks.eclipse.dependsOn('genEclipseRuns')
tasks.withType(JavaCompile) {
options.warnings = false
}
}
task setup() {
dependsOn ':clean:extractMapped'
dependsOn ':mohist:extractMapped' //These must be strings so that we can do lazy resolution. Else we need evaluationDependsOnChildren above
}