mirror of
https://github.com/TeamMidnightDust/MidnightControls.git
synced 2025-12-13 15:25:08 +01:00
- Update to 1.19.3 (Tabbing through creative tabs behaves the same as before, that was hard) - Add an option to move the chat input field to the top of the screen for better input on devices using an on-screen keyboard - Add an option to make the left joystick behave like a mouse in every screen - Add a button to more easily access the Advanced Config
270 lines
9.7 KiB
Groovy
270 lines
9.7 KiB
Groovy
plugins {
|
|
id 'fabric-loom' version '1.0-SNAPSHOT'
|
|
id 'java-library'
|
|
id 'maven-publish'
|
|
id 'com.github.johnrengelman.shadow' version '7.0.0'
|
|
id 'com.modrinth.minotaur' version '1.2.+'
|
|
}
|
|
|
|
import com.google.gson.GsonBuilder
|
|
import com.google.gson.JsonObject
|
|
import com.modrinth.minotaur.TaskModrinthUpload
|
|
import com.modrinth.minotaur.request.VersionType
|
|
import com.modrinth.minotaur.responses.ResponseError
|
|
import org.apache.http.client.config.CookieSpecs
|
|
import org.apache.http.client.config.RequestConfig
|
|
import org.apache.http.client.entity.EntityBuilder
|
|
import org.apache.http.client.methods.HttpPatch
|
|
import org.apache.http.entity.ContentType
|
|
import org.apache.http.impl.client.HttpClientBuilder
|
|
import org.apache.http.util.EntityUtils
|
|
|
|
group = project.maven_group
|
|
version = "${project.mod_version}+${getMCVersionString()}"
|
|
archivesBaseName = project.archives_base_name
|
|
|
|
// This field defines the Java version your mod target.
|
|
def targetJavaVersion = 17
|
|
|
|
boolean isMCVersionNonRelease() {
|
|
return project.minecraft_version.matches('^\\d\\dw\\d\\d[a-z]$')
|
|
|| project.minecraft_version.matches('\\d+\\.\\d+-(pre|rc)(\\d+)')
|
|
}
|
|
|
|
String getMCVersionString() {
|
|
if (isMCVersionNonRelease() || project.minecraft_version == "1.19.3") {
|
|
return project.minecraft_version
|
|
}
|
|
def version = project.minecraft_version.split('\\.')
|
|
return version[0] + '.' + version[1]
|
|
}
|
|
|
|
boolean pingUrl(String address) {
|
|
try {
|
|
def conn = (HttpURLConnection) new URL(address).openConnection()
|
|
int responseCode = conn.getResponseCode()
|
|
return (200 <= responseCode && responseCode <= 399)
|
|
} catch (IOException ignored) {
|
|
return false
|
|
}
|
|
}
|
|
|
|
String parseReadme() {
|
|
def excludeRegex = /(?m)<!-- modrinth_exclude\.start -->(.|\n)*?<!-- modrinth_exclude\.end -->/
|
|
def linkRegex = /!\[([A-z_ ]+)]\((images\/[A-z.\/_]+)\)/
|
|
|
|
def readme = (String) file('README.md').text
|
|
readme = readme.replaceAll(excludeRegex, '')
|
|
return readme
|
|
}
|
|
|
|
|
|
repositories {
|
|
mavenLocal()
|
|
mavenCentral()
|
|
maven { url 'https://aperlambda.github.io/maven' }
|
|
maven {
|
|
name 'Gegy'
|
|
url 'https://maven.gegy.dev'
|
|
}
|
|
maven {
|
|
name = "CottonMC"
|
|
url = "https://server.bbkr.space/artifactory/libs-release"
|
|
}
|
|
maven { url "https://maven.terraformersmc.com/releases/" }
|
|
maven { url 'https://maven.kosmx.dev' }
|
|
maven { url 'https://maven.isxander.dev/releases' }
|
|
maven { url 'https://maven.shedaniel.me/' }
|
|
maven { url 'https://jitpack.io' }
|
|
maven { url "https://api.modrinth.com/maven" }
|
|
maven { url 'https://maven.quiltmc.org/repository/release'}
|
|
}
|
|
|
|
configurations {
|
|
shadow
|
|
api.extendsFrom shadow
|
|
}
|
|
|
|
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}"
|
|
|
|
// Fabric API. This is technically optional, but you probably want it anyway.
|
|
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
|
|
|
modImplementation "dev.lambdaurora:spruceui:${project.spruceui_version}"
|
|
include "dev.lambdaurora:spruceui:${project.spruceui_version}"
|
|
api('org.aperlambda:lambdajcommon:1.8.1') {
|
|
exclude group: 'com.google.code.gson'
|
|
exclude group: 'com.google.guava'
|
|
}
|
|
include 'org.aperlambda:lambdajcommon:1.8.1'
|
|
|
|
modCompileOnlyApi "com.terraformersmc:modmenu:${project.modmenu_version}"
|
|
|
|
// Compatibility mods
|
|
|
|
// Ok Zoomer and LibZoomer are temporarily disabled for the time being, as we are currently using Reflection at runtime instead in OkZoomerCompat due to there being two major, completely incompatible API versions.
|
|
// modImplementation("maven.modrinth:ok-zoomer:${project.ok_zoomer_version}")
|
|
// modImplementation "io.github.ennuil:LibZoomer:${project.libzoomer_version}"
|
|
|
|
modCompileOnlyApi "io.github.cottonmc:LibGui:${project.libgui_version}"
|
|
modCompileOnlyApi "org.quiltmc:quilt-json5:1.0.0"
|
|
modCompileOnly "maven.modrinth:sodium:${project.sodium_version}"
|
|
modImplementation "maven.modrinth:emi:${project.emi_version}"
|
|
modCompileOnlyApi "maven.modrinth:emotecraft:${project.emotecraft_version}"
|
|
modCompileOnlyApi "io.github.kosmx:bendy-lib:${project.bendylib_version}"
|
|
modCompileOnlyApi "dev.isxander:yet-another-config-lib:${project.yacl_version}"
|
|
modCompileOnlyApi "maven.modrinth:inventory-tabs-updated:${project.inventorytabs_version}"
|
|
modCompileOnlyApi "maven.modrinth:bedrockify:${project.bedrockify_version}"
|
|
// Required for Inventory Tabs
|
|
modApi("me.shedaniel.cloth:cloth-config-fabric:${project.clothconfig_version}") {
|
|
exclude(group: "net.fabricmc.fabric-api")
|
|
}
|
|
|
|
modImplementation "maven.modrinth:midnightlib:${project.midnightlib_version}"
|
|
include "maven.modrinth:midnightlib:${project.midnightlib_version}"
|
|
|
|
shadow 'com.electronwill.night-config:core:3.6.3'
|
|
shadow 'com.electronwill.night-config:toml:3.6.3'
|
|
apply plugin: 'java-library'
|
|
}
|
|
loom {
|
|
accessWidenerPath = file("src/main/resources/midnightcontrols.accesswidener")
|
|
}
|
|
|
|
java {
|
|
sourceCompatibility = JavaVersion.toVersion(targetJavaVersion)
|
|
targetCompatibility = JavaVersion.toVersion(targetJavaVersion)
|
|
|
|
withSourcesJar()
|
|
}
|
|
|
|
tasks.withType(JavaCompile).configureEach {
|
|
it.options.encoding = 'UTF-8'
|
|
|
|
it.options.release.set(targetJavaVersion)
|
|
}
|
|
|
|
processResources {
|
|
inputs.property 'version', project.version
|
|
|
|
filesMatching('fabric.mod.json') {
|
|
expand 'version': project.version
|
|
}
|
|
}
|
|
|
|
task publishModrinth(type: TaskModrinthUpload) {
|
|
dependsOn(build)
|
|
onlyIf {
|
|
System.getenv('MODRINTH_TOKEN')
|
|
}
|
|
|
|
token = System.getenv('MODRINTH_TOKEN')
|
|
projectId = project.modrinth_id
|
|
versionNumber = version
|
|
versionName = "midnightcontrols ${project.mod_version} (${getMCVersionString()})"
|
|
addGameVersion((String) project.minecraft_version)
|
|
addLoader('fabric')
|
|
versionType = isMCVersionNonRelease() ? VersionType.BETA : VersionType.RELEASE
|
|
|
|
// Changelog fetching
|
|
def changelogText = file('CHANGELOG.md').text
|
|
def regexVersion = ((String) project.mod_version).replaceAll('\\.', /\\./).replaceAll('\\+', '\\+')
|
|
def changelogRegex = ~"###? ${regexVersion}\\n\\n(( *- .+\\n)+)"
|
|
def matcher = changelogText =~ changelogRegex
|
|
|
|
if (matcher.find()) {
|
|
changelog = matcher.group(1)
|
|
|
|
def changelogLines = changelogText.split('\n')
|
|
def linkRefRegex = ~'^\\[([A-z0-9 _\\-/+.]+)]: '
|
|
for (int i = changelogLines.length - 1; i > 0; i--) {
|
|
def line = changelogLines[i]
|
|
if ((line =~ linkRefRegex).find())
|
|
changelog += '\n' + line
|
|
else break
|
|
}
|
|
}
|
|
|
|
// Readme
|
|
doFirst {
|
|
final def client = HttpClientBuilder.create().setDefaultRequestConfig(RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES).build()).build()
|
|
final def patch = new HttpPatch((String) (apiURL + '/v1/mod/' + projectId))
|
|
patch.addHeader("Authorization", token)
|
|
|
|
var json = new JsonObject()
|
|
json.addProperty("body", parseReadme())
|
|
patch.setEntity(EntityBuilder.create()
|
|
.setText(json.toString())
|
|
.setContentType(ContentType.APPLICATION_JSON)
|
|
.build())
|
|
|
|
final def response = client.execute(patch)
|
|
final int status = response.getStatusLine().getStatusCode()
|
|
|
|
final def gson = new GsonBuilder().create()
|
|
if (status == 200) {
|
|
project.getLogger().lifecycle("Successfully updated readme to ${projectId}.")
|
|
} else {
|
|
errorInfo = gson.fromJson(EntityUtils.toString(response.getEntity()), ResponseError.class)
|
|
project.getLogger().error("Upload failed! Status: ${status} Error: ${errorInfo.getError()} Reason: ${errorInfo.getDescription()}")
|
|
throw new GradleException("Upload failed! Status: ${status} Reason: ${errorInfo.getDescription()}")
|
|
}
|
|
}
|
|
}
|
|
|
|
// configure the maven publication
|
|
publishing {
|
|
publications {
|
|
mavenJava(MavenPublication) {
|
|
artifact(sourcesJar) {
|
|
builtBy remapSourcesJar
|
|
}
|
|
|
|
pom {
|
|
name = 'midnightcontrols'
|
|
description = 'Adds better controls, and controller support.'
|
|
}
|
|
|
|
pom.withXml {
|
|
def dependenciesNode = asNode().appendNode('dependencies')
|
|
|
|
configurations.shadow.allDependencies.each {
|
|
def dependencyNode = dependenciesNode.appendNode('dependency')
|
|
|
|
dependencyNode.appendNode('groupId', it.group)
|
|
dependencyNode.appendNode('artifactId', it.name)
|
|
dependencyNode.appendNode('version', it.version)
|
|
dependencyNode.appendNode('scope', 'compile')
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
repositories {
|
|
mavenLocal()
|
|
maven {
|
|
name 'GithubPackages'
|
|
url uri('https://maven.pkg.github.com/LambdAurora/midnightcontrols')
|
|
credentials {
|
|
username = project.findProperty("gpr.user") ?: System.getenv("USERNAME")
|
|
password = project.findProperty("gpr.key") ?: System.getenv("TOKEN")
|
|
}
|
|
}
|
|
def midnightcontrolsMaven = System.getenv('midnightcontrols_MAVEN')
|
|
if (midnightcontrolsMaven) {
|
|
maven {
|
|
name 'midnightcontrolsMaven'
|
|
url uri(midnightcontrolsMaven)
|
|
credentials {
|
|
username = project.findProperty('gpr.user') ?: System.getenv('MAVEN_USERNAME')
|
|
password = project.findProperty('gpr.key') ?: System.getenv('MAVEN_PASSWORD')
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|