diff options
author | thedarkcolour <30441001+thedarkcolour@users.noreply.github.com> | 2019-12-19 15:07:01 -0800 |
---|---|---|
committer | thedarkcolour <30441001+thedarkcolour@users.noreply.github.com> | 2019-12-19 15:07:01 -0800 |
commit | 88d27da569789b80844418af4d941c7a93299311 (patch) | |
tree | c221062b2e3c7179525dfacdf4aec7ab71677549 /src/main | |
parent | 359d108e282e8bbfa5e87b2e6099f89ac706240e (diff) | |
download | KotlinForForge-88d27da569789b80844418af4d941c7a93299311.tar.gz KotlinForForge-88d27da569789b80844418af4d941c7a93299311.tar.bz2 KotlinForForge-88d27da569789b80844418af4d941c7a93299311.zip |
Update 1.0.0
Diffstat (limited to 'src/main')
5 files changed, 99 insertions, 18 deletions
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 <T> callWhenOn(dist: Dist, toRun: () -> () -> T): T? { - if (DIST == dist) { +inline fun <T> 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 <T> runForDist(clientTarget: () -> () -> T, serverTarget: () -> () -> T): T { +inline fun <T> 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<Element>().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()) + + /* + <body> + <h1>Index of /thedarkcolour.kotlinforforge/</h1> + <hr> + <pre><a href="../web.html">../</a> + <a href="1.0.0/web.html">1.0.0</a> + <a href="maven-metadata.xml">maven-metadata.xml</a> + <a href="maven-metadata.xml.md5">maven-metadata.xml.md5</a> + <a href="maven-metadata.xml.sha1">maven-metadata.xml.sha1</a> + </pre> + <hr> + </body> + */ +} + +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" |