mirror of
https://github.com/FabricMC/fabric.git
synced 2024-11-30 03:26:07 -05:00
9ff28f4026
A common source of crashes on modded Minecraft servers comes from modders accidently calling client only code from the client, this PR is another large step towards elimitating that. This PR has been months in the making and years in the planning, requiring major changes to Loom & Loader. In recent Minecraft versions Mojang has made it easier than ever to cleanly split the jar, going against the status-quo of merging the client and server into one jar. From the start we have designed Fabric to have a very clear split between client and common (client & server) code. Fabric has always encoraged keeping client only code seprate from the server, this can be seen at a fundamental level with the entrypoints in Loader. Fabric API's have all been designed with this mind. This PR provides a compile safety net around Fabric API using client only code on the server. Even though there are almost 400 changed files, minimal changes beyond moving the files were required to achieve this in Fabric API, thanks to the effort of all contributors in the past. These changes should not affect modders or players in anyway, a single "universal" jar is still produced. Im happy to awnswer any questions.
75 lines
2.1 KiB
Groovy
75 lines
2.1 KiB
Groovy
import groovy.json.JsonSlurper
|
|
|
|
/*
|
|
* This buildscript contains tasks related to the validation of each module in fabric api.
|
|
*
|
|
* Right now this task verifies each Fabric API module has a module lifecycle specified.
|
|
* More functionality will probably be added in the future.
|
|
*/
|
|
|
|
subprojects {
|
|
if (it.name == "deprecated") return
|
|
|
|
// Create the task
|
|
task validateModules(type: ValidateModuleTask)
|
|
}
|
|
|
|
/**
|
|
* Verifies that each module has the required custom values for module lifecycle in it's FMJ.
|
|
*
|
|
* <p>Example:
|
|
* <pre>{@code
|
|
* "custom": {
|
|
* "fabric-api:module-lifecycle": "stable"
|
|
* }
|
|
* }</pre>
|
|
*/
|
|
class ValidateModuleTask extends DefaultTask {
|
|
ValidateModuleTask() {
|
|
group = "verification"
|
|
|
|
// Hook up validation to check task
|
|
project.tasks.check.dependsOn(this)
|
|
}
|
|
|
|
@TaskAction
|
|
void validate() {
|
|
def clientOnlyMod = false
|
|
def file = (project.file("src/main/resources/fabric.mod.json") as File)
|
|
|
|
if (!file.exists()) {
|
|
file = (project.file("src/client/resources/fabric.mod.json") as File)
|
|
clientOnlyMod = true
|
|
}
|
|
|
|
def json = new JsonSlurper().parse(file) as Map<String, Map<String, String>>
|
|
|
|
if (json.custom == null) {
|
|
throw new GradleException("Module ${project} does not have a custom value containing module lifecycle!")
|
|
}
|
|
|
|
def moduleLifecycle = json.custom.get("fabric-api:module-lifecycle")
|
|
|
|
if (moduleLifecycle == null) {
|
|
throw new GradleException("Module ${project} does not have module lifecycle in custom values!")
|
|
}
|
|
|
|
if (!moduleLifecycle instanceof String) {
|
|
throw new GradleException("Module ${project} has an invalid module lifecycle value. The value must be a string but read a ${moduleLifecycle.class}")
|
|
}
|
|
|
|
// Validate the lifecycle value
|
|
switch (moduleLifecycle) {
|
|
case "stable":
|
|
case "experimental":
|
|
break
|
|
case "deprecated":
|
|
if (!project.path.startsWith(":deprecated")) {
|
|
throw new GradleException("Deprecated module ${project} must be in the deprecated sub directory.")
|
|
}
|
|
break
|
|
default:
|
|
throw new GradleException("Module ${project} has an invalid module lifecycle ${json.custom.get('fabric-api:module-lifecycle')}")
|
|
}
|
|
}
|
|
}
|