From bf11f1cb96cfeb98a21025459f24f235ff06cd42 Mon Sep 17 00:00:00 2001 From: thedarkcolour <30441001+thedarkcolour@users.noreply.github.com> Date: Mon, 11 Nov 2019 14:47:37 -0800 Subject: Adding files --- README.md | 9 ++-- build.gradle | 10 +++-- gradle.properties | 4 +- .../kotlinforforge/AutoKotlinEventBusSubscriber.kt | 2 +- .../kotlinforforge/registry/KtDeferredRegister.kt | 34 +++++++++++++++ .../kotlinforforge/registry/KtRegistryObject.kt | 46 +++++++++++++++++++++ .../1.0.0/kotlinforforge-1.0.0-sources.jar | Bin 6030 -> 7778 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 65480 -> 75364 bytes .../1.0.0/kotlinforforge-1.0.0.jar.md5 | 2 +- .../1.0.0/kotlinforforge-1.0.0.jar.sha1 | 2 +- .../kotlinforforge/1.0.0/kotlinforforge-1.0.0.pom | 6 +-- .../1.0.0/kotlinforforge-1.0.0.pom.md5 | 2 +- .../1.0.0/kotlinforforge-1.0.0.pom.sha1 | 2 +- 15 files changed, 104 insertions(+), 19 deletions(-) create mode 100644 src/main/kotlin/thedarkcolour/kotlinforforge/registry/KtDeferredRegister.kt create mode 100644 src/main/kotlin/thedarkcolour/kotlinforforge/registry/KtRegistryObject.kt diff --git a/README.md b/README.md index 7a84c65..76776cf 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ -I am no longer working on this because Kottle exists. - - # KotlinForForge -Makes Kotlin forge-friendly. +Makes Kotlin forge-friendly by doing the following: +- Provides the Kotlin libraries. +- Provides `KotlinLanguageProvider` to allow usage of object declarations as @Mod targets. +- Provides `AutoKotlinEventBusSubscriber` to allow usage of object declarations as @Mod.EventBusSubscriber targets. +- Provides `KtDeferredRegister` as an alternative to `DeferredRegister` that returns non-null values To implement in your project, add the following to your build.gradle: ```groovy diff --git a/build.gradle b/build.gradle index bcca42e..09aac4c 100644 --- a/build.gradle +++ b/build.gradle @@ -117,14 +117,18 @@ shadowJar { jar { manifest { attributes([ - "Specification-Title": "kotlinforforge", - "Specification-Vendor": "thedarkcolour", + "FMLModType": "LANGPROVIDER" + ]) + + attributes([ + "Specification-Title": "Mod Language Provider", + "Specification-Vendor": "Forge", "Specification-Version": "1", // We are version 1 of ourselves "Implementation-Title": project.name, "Implementation-Version": "${version}", "Implementation-Vendor" :"thedarkcolour", "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") - ]) + ], "thedarkcolour/kotlinforforge/") } } diff --git a/gradle.properties b/gradle.properties index 4a0ea15..9031548 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,5 +3,5 @@ org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false kotlin_version=1.3.50 -coroutines_version = 1.3.1 -annotations_version = 16.0.3 \ No newline at end of file +coroutines_version = 1.3.2 +annotations_version = 18.0.0 \ No newline at end of file diff --git a/src/main/kotlin/thedarkcolour/kotlinforforge/AutoKotlinEventBusSubscriber.kt b/src/main/kotlin/thedarkcolour/kotlinforforge/AutoKotlinEventBusSubscriber.kt index e36f9ce..46cdc4d 100644 --- a/src/main/kotlin/thedarkcolour/kotlinforforge/AutoKotlinEventBusSubscriber.kt +++ b/src/main/kotlin/thedarkcolour/kotlinforforge/AutoKotlinEventBusSubscriber.kt @@ -17,7 +17,7 @@ import java.util.stream.Collectors * Handles [net.minecraftforge.fml.common.Mod.EventBusSubscriber] */ @Suppress("unused") -object AutoKotlinEventBusSubscriber { +internal object AutoKotlinEventBusSubscriber { private val EVENT_BUS_SUBSCRIBER: Type = Type.getType(Mod.EventBusSubscriber::class.java) /** diff --git a/src/main/kotlin/thedarkcolour/kotlinforforge/registry/KtDeferredRegister.kt b/src/main/kotlin/thedarkcolour/kotlinforforge/registry/KtDeferredRegister.kt new file mode 100644 index 0000000..dedfb27 --- /dev/null +++ b/src/main/kotlin/thedarkcolour/kotlinforforge/registry/KtDeferredRegister.kt @@ -0,0 +1,34 @@ +package thedarkcolour.kotlinforforge.registry + +import net.minecraft.util.ResourceLocation +import net.minecraftforge.event.RegistryEvent +import net.minecraftforge.eventbus.api.IEventBus +import net.minecraftforge.registries.IForgeRegistry +import net.minecraftforge.registries.IForgeRegistryEntry +import java.util.* +import java.util.function.Supplier +import kotlin.collections.LinkedHashMap + +/** + * @see [net.minecraftforge.registries.DeferredRegister] for example use + */ +class KtDeferredRegister>(private val registry: IForgeRegistry, private val modid: String) { + private val entries: MutableMap, Supplier> = LinkedHashMap() + val entriesView: Set> = Collections.unmodifiableSet(entries.keys) + + fun register(name: String, supplier: Supplier): KtRegistryObject { + val key = ResourceLocation(modid, name) + val obj = KtRegistryObject(key, registry) + require(entries.putIfAbsent(obj, Supplier { supplier.get().setRegistryName(key) }) == null) { "Duplicate registration $name" } + return obj + } + + fun register(bus: IEventBus) = bus.addListener(::addEntries) + + private fun addEntries(event: RegistryEvent.Register) { + for (entry in entries.entries) { + registry.register(entry.value.get()) + entry.key.refresh(registry) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/thedarkcolour/kotlinforforge/registry/KtRegistryObject.kt b/src/main/kotlin/thedarkcolour/kotlinforforge/registry/KtRegistryObject.kt new file mode 100644 index 0000000..0b44705 --- /dev/null +++ b/src/main/kotlin/thedarkcolour/kotlinforforge/registry/KtRegistryObject.kt @@ -0,0 +1,46 @@ +package thedarkcolour.kotlinforforge.registry + +import net.minecraft.util.ResourceLocation +import net.minecraftforge.registries.IForgeRegistry +import net.minecraftforge.registries.IForgeRegistryEntry +import net.minecraftforge.registries.ObjectHolderRegistry +import net.minecraftforge.registries.RegistryManager +import java.util.function.Supplier + +/** + * An alternative to DeferredRegistry that enforces non-nullability. + */ +open class KtRegistryObject>(private val name: ResourceLocation, private val registry: IForgeRegistry) : Supplier { + private lateinit var value: T + + constructor(name: String, registry: IForgeRegistry) : this(ResourceLocation(name), registry) + + constructor(name: String, registryType: Supplier>) : this(ResourceLocation(name), RegistryManager.ACTIVE.getRegistry(registryType.get()) as IForgeRegistry) + + init { + ObjectHolderRegistry.addHandler { predicate -> + if (predicate.test(registry.registryName)) { + value = registry.getValue(name)!! + } + } + } + + override fun get(): T = value + + fun refresh(registry: IForgeRegistry) { + value = registry.getValue(name)!! + } + + override fun equals(other: Any?): Boolean { + return when (other) { + other === this -> true + other?.javaClass != javaClass -> false + (other as KtRegistryObject<*>).name != name -> false + else -> true + } + } + + override fun hashCode(): Int { + return name.hashCode() + } +} \ No newline at end of file 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 fdb0c44..d02a1fe 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 e48a186..22a5ee6 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 @@ -0fca7a1ebe5aa4bd373846697413708f \ No newline at end of file +f2ca40ef2c37abc659e03263b6276804 \ 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 027bd4c..0b5e05d 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 @@ -fb64405967002751f7cc7da0877a7f0e1c4fdda7 \ No newline at end of file +4dd281d62e40171dfa445bb085c1e50727167481 \ 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 d48167a..e692f59 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 6cc63d3..755979c 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 @@ -1 +1 @@ -51c46fc8b03b372f5a8e06776d065c3d \ No newline at end of file +1d2fc2245fcf14f42203a88eee685d4b \ 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 54e4e7c..9b0db5b 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 @@ -849ca5988926423671abd3a052285cc050b9e3f4 \ No newline at end of file +8dbf8625f2d90ebfbae8e0f8cbacb3a3672332b8 \ No newline at end of file diff --git a/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.pom b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.pom index f76b5f0..529c114 100644 --- a/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.pom +++ b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.pom @@ -33,19 +33,19 @@ org.jetbrains annotations - 16.0.3 + 18.0.0 compile org.jetbrains.kotlinx kotlinx-coroutines-core - 1.3.1 + 1.3.2 compile org.jetbrains.kotlinx kotlinx-coroutines-jdk8 - 1.3.1 + 1.3.2 compile diff --git a/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.pom.md5 b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.pom.md5 index 99a6664..38a3cbb 100644 --- a/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.pom.md5 +++ b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.pom.md5 @@ -1 +1 @@ -e27987735a4086178bbb3759c8f9fde8 \ No newline at end of file +df82316577ed12142a1a0f505df5adbd \ No newline at end of file diff --git a/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.pom.sha1 b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.pom.sha1 index 04c31d6..99b0c4e 100644 --- a/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.pom.sha1 +++ b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.pom.sha1 @@ -1 +1 @@ -9e66fcb9607e4e8be3496531519e2f6a4f67ead8 \ No newline at end of file +b4e6bd7ecc9c586686e6a8df09bf53c7822ed601 \ No newline at end of file -- cgit