more fixes for run configs + asset downloading
Some checks failed
Publish to snapshot maven / build (push) Failing after 17s
Some checks failed
Publish to snapshot maven / build (push) Failing after 17s
This commit is contained in:
parent
b111afe9a5
commit
efff2e71d3
|
@ -1,6 +1,7 @@
|
|||
package org.ecorous.esnesnon.gradle
|
||||
|
||||
import net.fabricmc.fernflower.api.IFabricJavadocProvider
|
||||
import org.ecorous.esnesnon.gradle.run.AssetDownloader
|
||||
import org.ecorous.esnesnon.gradle.run.RunConfigGenerator
|
||||
import org.ecorous.esnesnon.gradle.vineflower.ParchmentJavadocProvider
|
||||
import org.ecorous.esnesnon.nonsense_remapper.provider.ParchmentProvider
|
||||
|
@ -106,6 +107,12 @@ class NonsenseGradlePlugin : Plugin<Project> {
|
|||
}
|
||||
}
|
||||
|
||||
project.task("downloadAssets").apply {
|
||||
doFirst {
|
||||
AssetDownloader.download()
|
||||
}
|
||||
}
|
||||
|
||||
// TODO mod relocation/renaming: decide on mod file extension
|
||||
/*project.tasks.getByName("jar").actions.addLast {
|
||||
it.outputs.files.forEach {file ->
|
||||
|
|
|
@ -73,11 +73,15 @@ object VersionChecker {
|
|||
return fetchVersionData(version).downloads.client
|
||||
}
|
||||
|
||||
fun downloadAssetIndex(version: String, path: Path) {
|
||||
val url = fetchVersionData(version).assetIndex.url
|
||||
CachingHttpClient.get(URI.create(url)).use {
|
||||
Files.copy(it, path)
|
||||
fun downloadAssetIndex(version: String, path: Path): String {
|
||||
val index = fetchVersionData(version).assetIndex
|
||||
val dest = path.resolve(index.id+".json")
|
||||
if (dest.notExists()) {
|
||||
CachingHttpClient.getUncached(URI.create(index.url)).use {
|
||||
Files.copy(it, dest)
|
||||
}
|
||||
}
|
||||
return index.id
|
||||
}
|
||||
|
||||
private fun rawDownload(url: String): ByteArray {
|
||||
|
|
|
@ -15,9 +15,9 @@ object CachingHttpClient {
|
|||
|
||||
fun downloadTo(uri: URI, path: Path) {
|
||||
if (path.notExists()) {
|
||||
path.createParentDirectories()
|
||||
Files.copy(getUncached(uri), path)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun get(uri: URI): InputStream {
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package org.ecorous.esnesnon.gradle.run
|
||||
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.JsonObject
|
||||
import org.ecorous.esnesnon.gradle.NonsenseGradlePlugin
|
||||
import org.ecorous.esnesnon.gradle.VersionChecker
|
||||
import org.ecorous.esnesnon.gradle.common.CachingHttpClient
|
||||
import java.net.URI
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.createDirectories
|
||||
import kotlin.io.path.reader
|
||||
|
||||
object AssetDownloader {
|
||||
private const val ASSETS_URL = "https://resources.download.minecraft.net"
|
||||
|
||||
fun download() {
|
||||
val version = NonsenseGradlePlugin.minecraftVersion
|
||||
val path = NonsenseGradlePlugin.nonsenseCacheDir.resolve("assets")
|
||||
val id = VersionChecker.downloadAssetIndex(version, path.resolve("indexes"))
|
||||
|
||||
val index = Gson().fromJson(
|
||||
path.resolve("indexes").resolve("$id.json").reader(StandardCharsets.UTF_8),
|
||||
JsonObject::class.java
|
||||
)
|
||||
val objectsPath = path.resolve("objects")
|
||||
objectsPath.createDirectories()
|
||||
val entries = index.getAsJsonObject("objects").entrySet()
|
||||
println("Downloading ${entries.size} assets...")
|
||||
entries.forEach {
|
||||
val hash = it.value.asJsonObject.get("hash").asString
|
||||
/*val size = it.value.asJsonObject.get("size").asInt
|
||||
val name = it.key*/
|
||||
// TODO asset downloading for versions <=1.7 (legacy)
|
||||
get(objectsPath, hash)
|
||||
}
|
||||
}
|
||||
|
||||
private fun get(localDir: Path, hash: String) {
|
||||
val shortHash = hash.substring(0, 2)
|
||||
val path = localDir.resolve("$shortHash/$hash")
|
||||
CachingHttpClient.downloadTo(URI.create("$ASSETS_URL/$shortHash/$hash"), path)
|
||||
}
|
||||
}
|
|
@ -8,11 +8,12 @@ import org.ecorous.esnesnon.gradle.run.adapter.IdeaAdapter
|
|||
import org.gradle.api.Project
|
||||
import java.nio.file.Files
|
||||
import kotlin.io.path.absolute
|
||||
import kotlin.io.path.createDirectories
|
||||
import kotlin.io.path.createParentDirectories
|
||||
import kotlin.io.path.notExists
|
||||
|
||||
object RunConfigGenerator {
|
||||
private const val LOG4J_CONFIG_PATH = ".gradle/nonsense/log4j.xml"
|
||||
private const val LOG4J_CONFIG_PATH = ".gradle/nonsense-gradle/log4j.xml"
|
||||
private const val ASSET_DIR = "assets"
|
||||
private val ADAPTERS = arrayOf(EclipseAdapter(), IdeaAdapter())
|
||||
|
||||
|
@ -26,11 +27,11 @@ object RunConfigGenerator {
|
|||
}
|
||||
|
||||
val assetPath = NonsenseGradlePlugin.nonsenseCacheDir.resolve(ASSET_DIR).absolute()
|
||||
val assetIndexPath = assetPath.resolve("indexes").resolve(NonsenseGradlePlugin.minecraftVersion + ".json")
|
||||
val assetIndexPath = assetPath.resolve("indexes")
|
||||
if (assetIndexPath.notExists()) {
|
||||
assetIndexPath.createParentDirectories()
|
||||
VersionChecker.downloadAssetIndex(NonsenseGradlePlugin.minecraftVersion, assetIndexPath)
|
||||
assetIndexPath.createDirectories()
|
||||
}
|
||||
val indexId = VersionChecker.downloadAssetIndex(NonsenseGradlePlugin.minecraftVersion, assetIndexPath)
|
||||
|
||||
val runConfigPath = project.rootDir.resolve(".idea").resolve("runConfigurations")
|
||||
runConfigPath.mkdirs()
|
||||
|
@ -43,16 +44,17 @@ object RunConfigGenerator {
|
|||
adapter.generate(
|
||||
project,
|
||||
"Minecraft ${env.pascalName}",
|
||||
"org.ecorous.esnesnon.nonsense.loader.impl.launch.client.Nonsense${env.pascalName}",
|
||||
"org.ecorous.esnesnon.nonsense.loader.impl.launch.${env.id}.Nonsense${env.pascalName}",
|
||||
arrayOf(
|
||||
"-Dnonsense.development=true",
|
||||
"-Dnonsense.plugin.minecraft.gameJar=${NonsenseGradlePlugin.remappedGameJarPath}",
|
||||
"-Dlog4j.configurationFile=$assetPath"
|
||||
"-Dlog4j.configurationFile=$log4jPath"
|
||||
),
|
||||
arrayOf(
|
||||
"--assetDir", assetPath.toString(),
|
||||
"--assetsDir", assetPath.toString(),
|
||||
"--version", "Nonsense",
|
||||
"--assetIndex", assetIndexPath.toString()
|
||||
"--assetIndex", indexId,
|
||||
"--accessToken", "0"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue