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 --- .../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 +- 5 files changed, 99 insertions(+), 18 deletions(-) create mode 100644 src/main/kotlin/thedarkcolour/kotlinforforge/webgenerator/WebGenerator.kt (limited to 'src/main') 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" -- cgit