From 88d27da569789b80844418af4d941c7a93299311 Mon Sep 17 00:00:00 2001 From: thedarkcolour <30441001+thedarkcolour@users.noreply.github.com> Date: Thu, 19 Dec 2019 15:07:01 -0800 Subject: Update 1.0.0 --- README.md | 16 +++++ build.gradle | 55 +-------------- .../thedarkcolour/kotlinforforge/KotlinForForge.kt | 2 - .../kotlinforforge/KotlinLanguageProvider.kt | 2 - .../thedarkcolour/kotlinforforge/forge/Forge.kt | 43 ++++++++---- .../kotlinforforge/webgenerator/WebGenerator.kt | 68 ++++++++++++++++++ src/main/resources/META-INF/mods.toml | 2 +- .../1.0.0/kotlinforforge-1.0.0-sources.jar | Bin 6807 -> 8142 bytes .../1.0.0/kotlinforforge-1.0.0-sources.jar.md5 | 2 +- .../1.0.0/kotlinforforge-1.0.0-sources.jar.sha1 | 2 +- .../kotlinforforge/1.0.0/kotlinforforge-1.0.0.jar | Bin 78066 -> 81103 bytes .../1.0.0/kotlinforforge-1.0.0.jar.md5 | 1 + .../1.0.0/kotlinforforge-1.0.0.jar.sha1 | 2 +- webgenerator/WebGenerator.kt | 76 --------------------- 14 files changed, 121 insertions(+), 150 deletions(-) create mode 100644 src/main/kotlin/thedarkcolour/kotlinforforge/webgenerator/WebGenerator.kt delete mode 100644 webgenerator/WebGenerator.kt diff --git a/README.md b/README.md index cec9159..4d47218 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,16 @@ Makes Kotlin forge-friendly by doing the following: To implement in your project, add the following to your build.gradle: ```groovy +buildscript { + // ... + dependencies { + // Check the mod file for the Kotlin version + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61" + } +} + +apply plugin: 'kotlin' + repositories { maven { name = 'kotlinforforge' @@ -18,6 +28,12 @@ dependencies { // Uses the latest version of KotlinForForge implementation 'thedarkcolour:kotlinforforge:1+' } + +compileKotlin { + kotlinOptions { + jvmTarget = '1.8' + } +} ``` Then, add the following to your mods.toml file: ```toml diff --git a/build.gradle b/build.gradle index 26760ab..363c8c3 100644 --- a/build.gradle +++ b/build.gradle @@ -15,14 +15,10 @@ plugins { } apply plugin: 'net.minecraftforge.gradle' -// Only edit below this line, the above code adds and enables the necessary things for Forge to be setup. -apply plugin: 'maven-publish' -apply plugin: 'eclipse' -apply plugin: 'idea' apply plugin: 'kotlin' version = '1.0.0' -group = 'thedarkcolour.kotlinforforge' // http://maven.apache.org/guides/mini/guide-naming-conventions.html +group = 'thedarkcolour.kotlinforforge' archivesBaseName = 'kotlinforforge' sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' @@ -37,51 +33,27 @@ minecraft { 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' - - mods { - examplemod { - source sourceSets.main - } - } } 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' - - mods { - examplemod { - source sourceSets.main - } - } } data { 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' args '--mod', 'examplemod', '--all', '--output', file('src/generated/resources/') - - mods { - examplemod { - source sourceSets.main - } - } } } } @@ -127,7 +99,7 @@ jar { attributes([ "Specification-Title": "Mod Language Provider", "Specification-Vendor": "Forge", - "Specification-Version": "1", // We are version 1 of ourselves + "Specification-Version": "1", "Implementation-Title": project.name, "Implementation-Version": "${version}", "Implementation-Vendor" :"thedarkcolour", @@ -136,29 +108,6 @@ jar { } } -// Example configuration to allow publishing using the maven-publish task -// we define a custom artifact that is sourced from the reobfJar output task -// and then declare that to be published -// Note you'll need to add a repository hereI -def reobfFile = file("$buildDir/reobfJar/output.jar") -def reobfArtifact = artifacts.add('default', reobfFile) { - type 'jar' - builtBy 'reobfJar' -} - -publishing { - publications { - mavenJava(MavenPublication) { - artifact reobfArtifact - } - } - repositories { - maven { - url "file:///${project.projectDir}/mcmodsrepo" - } - } -} - compileKotlin { kotlinOptions { freeCompilerArgs = ["-Xinline-classes"] diff --git a/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinForForge.kt b/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinForForge.kt index 4b07205..f6139bc 100644 --- a/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinForForge.kt +++ b/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinForForge.kt @@ -1,10 +1,8 @@ package thedarkcolour.kotlinforforge import net.minecraftforge.fml.common.Mod -import net.minecraftforge.registries.DeferredRegister import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.Logger -import thedarkcolour.kotlinforforge.forge.MOD_BUS /** * Set 'modLoader' in mods.toml to "kotlinforforge" and loaderVersion to "[1,)". diff --git a/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinLanguageProvider.kt b/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinLanguageProvider.kt index 378b999..7d68f7e 100644 --- a/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinLanguageProvider.kt +++ b/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinLanguageProvider.kt @@ -6,9 +6,7 @@ import net.minecraftforge.forgespi.language.ILifecycleEvent import net.minecraftforge.forgespi.language.IModInfo import net.minecraftforge.forgespi.language.IModLanguageProvider import net.minecraftforge.forgespi.language.ModFileScanData -import java.util.function.BinaryOperator import java.util.function.Consumer -import java.util.function.Function import java.util.function.Supplier import java.util.stream.Collectors diff --git a/src/main/kotlin/thedarkcolour/kotlinforforge/forge/Forge.kt b/src/main/kotlin/thedarkcolour/kotlinforforge/forge/Forge.kt index 297afe4..73cab7e 100644 --- a/src/main/kotlin/thedarkcolour/kotlinforforge/forge/Forge.kt +++ b/src/main/kotlin/thedarkcolour/kotlinforforge/forge/Forge.kt @@ -1,8 +1,11 @@ package thedarkcolour.kotlinforforge.forge import net.minecraftforge.api.distmarker.Dist +import net.minecraftforge.common.ForgeConfigSpec import net.minecraftforge.common.MinecraftForge import net.minecraftforge.eventbus.api.IEventBus +import net.minecraftforge.fml.ModLoadingContext +import net.minecraftforge.fml.config.ModConfig import net.minecraftforge.fml.loading.FMLEnvironment import thedarkcolour.kotlinforforge.KotlinModLoadingContext @@ -38,6 +41,9 @@ val MOD_BUS: IEventBus val MOD_CONTEXT: KotlinModLoadingContext inline get() = KotlinModLoadingContext.get() +val LOADING_CONTEXT: ModLoadingContext + inline get() = ModLoadingContext.get() + /** @since 1.0.0 * The current [Dist] of this environment. */ @@ -45,37 +51,48 @@ val DIST: Dist = FMLEnvironment.dist /** @since 1.0.0 * An alternative to [net.minecraftforge.fml.DistExecutor.callWhenOn] - * that uses Kotlin functions instead of Java functional interfaces. + * that inlines the callable. */ -fun callWhenOn(dist: Dist, toRun: () -> () -> T): T? { - if (DIST == dist) { +inline fun callWhenOn(dist: Dist, toRun: () -> T): T? { + return if (DIST == dist) { try { - return toRun()() + toRun() } catch (e: Exception) { throw RuntimeException(e) } + } else { + null } - - return null } /** @since 1.0.0 - * An alternative to [net.minecraftforge.fml.DistExecutor.callWhenOn] + * An alternative to [net.minecraftforge.fml.DistExecutor.runWhenOn] * that uses Kotlin functions instead of Java functional interfaces. */ -fun runWhenOn(dist: Dist, toRun: () -> () -> Unit) { +inline fun runWhenOn(dist: Dist, toRun: () -> Unit) { if (DIST == dist) { - toRun()() + toRun() } } /** @since 1.0.0 * An alternative to [net.minecraftforge.fml.DistExecutor.runForDist] - * that uses Kotlin functions instead of Java functional interfaces. + * that inlines the method call. */ -fun runForDist(clientTarget: () -> () -> T, serverTarget: () -> () -> T): T { +inline fun runForDist(clientTarget: () -> T, serverTarget: () -> T): T { return when (DIST) { - Dist.CLIENT -> clientTarget()() - Dist.DEDICATED_SERVER -> serverTarget()() + Dist.CLIENT -> clientTarget() + Dist.DEDICATED_SERVER -> serverTarget() + } +} + +/** @since 1.0.0 + * Registers a config. + */ +fun registerConfig(type: ModConfig.Type, spec: ForgeConfigSpec, fileName: String? = null) { + if (fileName == null) { + LOADING_CONTEXT.registerConfig(type, spec) + } else { + LOADING_CONTEXT.registerConfig(type, spec, fileName) } } \ No newline at end of file diff --git a/src/main/kotlin/thedarkcolour/kotlinforforge/webgenerator/WebGenerator.kt b/src/main/kotlin/thedarkcolour/kotlinforforge/webgenerator/WebGenerator.kt new file mode 100644 index 0000000..fb0dc56 --- /dev/null +++ b/src/main/kotlin/thedarkcolour/kotlinforforge/webgenerator/WebGenerator.kt @@ -0,0 +1,68 @@ +@file:JvmName("WebGenerator") + +package thedarkcolour.kotlinforforge.webgenerator + +import org.apache.commons.io.FileUtils +import org.jsoup.Jsoup +import org.jsoup.nodes.Attribute +import org.jsoup.nodes.Attributes +import org.jsoup.nodes.Document +import org.jsoup.nodes.Element +import org.jsoup.parser.Tag +import java.io.File +import java.nio.charset.Charset + +fun main() = run() + +fun run() { + // val v = Files.newDirectoryStream(File("C:\\Things\\mods\\thedarkcolour.kotlinforforge\\thedarkcolour\\thedarkcolour.kotlinforforge").toPath()) + // val mavenMetadata = File("C:\\Things\\mods\\thedarkcolour.kotlinforforge\\thedarkcolour\\thedarkcolour.kotlinforforge\\maven-metadata.xml") + + //val webHtml = Jsoup.parse(File("..\\KotlinForForge\\thedarkcolour\\thedarkcolour.kotlinforforge\\web.html"), null).childNodes()[0] + //webHtml.childNodes()[2].childNodes()[5].childNodes().filterIsInstance().forEach(::println) + + val thedarkcolour = File("C:\\Things\\mods\\KotlinForForge\\thedarkcolour") + + val web = File("C:\\Things\\mods\\KotlinForForge\\thedarkcolour\\web.html") + val webHtml = Jsoup.parse(web, "UTF-8") + + for (file in thedarkcolour.listFiles()!!) { + if (file.isDirectory) { + val pre = webHtml.getElementsByAttributeValue("href", "../index.html") + .parents() + .first() + val attr = Attributes().put(Attribute("href", file.absolutePath.replace("${thedarkcolour.absolutePath}\\", "") + "/web.html")) + + if (pre.getElementsByAttributeValue("href", attr.get("href")).isEmpty()) { + pre.appendChild(Element(Tag.valueOf("a"), webHtml.baseUri(), attr)) + + val innerWeb = File("${file.absolutePath}\\web.html") + innerWeb.createNewFile() + } + } + } + + FileUtils.writeStringToFile(web, webHtml.outerHtml(), Charset.defaultCharset()) + + /* + +

Index of /thedarkcolour.kotlinforforge/

+
+
../
+    1.0.0
+    maven-metadata.xml
+    maven-metadata.xml.md5
+    maven-metadata.xml.sha1
+    
+
+ + */ +} + +fun getPre(doc: Document): Element { + return doc.getElementsByAttributeValue("href", "../web.html") + .parents() + .first() ?: doc.getElementsByAttributeValue("href", "../index.html") + .parents() + .first() +} \ No newline at end of file diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index e79af5b..0aa5be1 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -22,7 +22,7 @@ Kotlin for Forge. Allows mods to use the Kotlin programming language. [[dependencies.kotlinforforge]] modId="minecraft" mandatory=true - versionRange="[1.14.4]" + versionRange="[1.14,1.16)" ordering="NONE" side="BOTH" diff --git a/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0-sources.jar b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0-sources.jar index 8c61a66..eb5e82e 100644 Binary files a/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0-sources.jar and b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0-sources.jar differ diff --git a/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0-sources.jar.md5 b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0-sources.jar.md5 index b440f7b..70de8fc 100644 --- a/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0-sources.jar.md5 +++ b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0-sources.jar.md5 @@ -1 +1 @@ -cda2255791958f5288c24161b2826b1d \ No newline at end of file +896142079761595540d2f1fa85073333 \ No newline at end of file diff --git a/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0-sources.jar.sha1 b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0-sources.jar.sha1 index 01e1999..2b4a8ba 100644 --- a/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0-sources.jar.sha1 +++ b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0-sources.jar.sha1 @@ -1 +1 @@ -2207a49e93eb065bc7f0442fdf6160d9f4e94c4d \ No newline at end of file +54f989a11ca7c4deb65b220df847cfa609409ae8 \ No newline at end of file diff --git a/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.jar b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.jar index 331ba80..9ccf5d2 100644 Binary files a/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.jar and b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.jar differ diff --git a/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.jar.md5 b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.jar.md5 index e69de29..8f70740 100644 --- a/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.jar.md5 +++ b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.jar.md5 @@ -0,0 +1 @@ +58d767d557b954d4385c9f67415aba8d \ No newline at end of file diff --git a/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.jar.sha1 b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.jar.sha1 index b6ea805..690420a 100644 --- a/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.jar.sha1 +++ b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.jar.sha1 @@ -1 +1 @@ -F91033F841208DBDCFF5EB46C8A4B1CCDFC49E66 \ No newline at end of file +51f2fd0551bf0aadd9052af5537073c3cd94f10c \ No newline at end of file diff --git a/webgenerator/WebGenerator.kt b/webgenerator/WebGenerator.kt deleted file mode 100644 index 29150f0..0000000 --- a/webgenerator/WebGenerator.kt +++ /dev/null @@ -1,76 +0,0 @@ -@file:JvmName("WebGenerator") - -package thedarkcolour.kotlinforforge.webgenerator - -import org.apache.commons.io.FileUtils -import org.jsoup.Jsoup -import org.jsoup.nodes.Attribute -import org.jsoup.nodes.Attributes -import org.jsoup.nodes.Document -import org.jsoup.nodes.Element -import org.jsoup.parser.Tag -import java.io.File -import java.nio.charset.Charset - -fun main() = run() - -fun run() { - // val v = Files.newDirectoryStream(File("C:\\Things\\mods\\thedarkcolour.kotlinforforge\\thedarkcolour\\thedarkcolour.kotlinforforge").toPath()) - // val mavenMetadata = File("C:\\Things\\mods\\thedarkcolour.kotlinforforge\\thedarkcolour\\thedarkcolour.kotlinforforge\\maven-metadata.xml") - - //val webHtml = Jsoup.parse(File("..\\KotlinForForge\\thedarkcolour\\thedarkcolour.kotlinforforge\\web.html"), null).childNodes()[0] - //webHtml.childNodes()[2].childNodes()[5].childNodes().filterIsInstance().forEach(::println) - - val thedarkcolour = File("C:\\Things\\mods\\KotlinForForge\\thedarkcolour") - - val web = File("C:\\Things\\mods\\KotlinForForge\\thedarkcolour\\web.html") - val webHtml = Jsoup.parse(web, "UTF-8") - - for (file in thedarkcolour.listFiles()!!) { - if (file.isDirectory) { - val pre = webHtml.getElementsByAttributeValue("href", "../index.html") - .parents() - .first() - val attr = Attributes().put(Attribute("href", file.absolutePath.replace("${thedarkcolour.absolutePath}\\", "") + "/web.html")) - - if (pre.getElementsByAttributeValue("href", attr.get("href")).isEmpty()) { - pre.appendChild(Element(Tag.valueOf("a"), webHtml.baseUri(), attr)) - - val innerWeb = File("${file.absolutePath}\\web.html") - innerWeb.createNewFile() - } - //webHtml.allElements.find { - // it.tagName() == "body" - //}!!.allElements.find { - // it.tagName() == "pre" - //}!!.allElements.find { - // print(it.attr("href")) - // it.className() == "" - //}//.appendChild((Element(Tag.valueOf("a"), "hi"))) - } - } - - FileUtils.writeStringToFile(web, webHtml.outerHtml(), Charset.defaultCharset()) - - /* - -

Index of /thedarkcolour.kotlinforforge/

-
-
../
-    1.0.0
-    maven-metadata.xml
-    maven-metadata.xml.md5
-    maven-metadata.xml.sha1
-    
-
- - */ -} - -fun getPre(doc: Document): Element { - return doc.getElementsByAttributeValue("href", "../web.html") - .parents() - .first() ?: doc.getElementsByAttributeValue("href", "../index.html") - .parents() - .first() -} \ No newline at end of file -- cgit