aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md9
-rw-r--r--build.gradle10
-rw-r--r--gradle.properties4
-rw-r--r--src/main/kotlin/thedarkcolour/kotlinforforge/AutoKotlinEventBusSubscriber.kt2
-rw-r--r--src/main/kotlin/thedarkcolour/kotlinforforge/registry/KtDeferredRegister.kt34
-rw-r--r--src/main/kotlin/thedarkcolour/kotlinforforge/registry/KtRegistryObject.kt46
-rw-r--r--thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0-sources.jarbin6030 -> 7778 bytes
-rw-r--r--thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0-sources.jar.md52
-rw-r--r--thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0-sources.jar.sha12
-rw-r--r--thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.jarbin65480 -> 75364 bytes
-rw-r--r--thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.jar.md52
-rw-r--r--thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.jar.sha12
-rw-r--r--thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.pom6
-rw-r--r--thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.pom.md52
-rw-r--r--thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.pom.sha12
15 files changed, 104 insertions, 19 deletions
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<T : IForgeRegistryEntry<T>>(private val registry: IForgeRegistry<T>, private val modid: String) {
+ private val entries: MutableMap<KtRegistryObject<T>, Supplier<out T>> = LinkedHashMap()
+ val entriesView: Set<KtRegistryObject<T>> = Collections.unmodifiableSet(entries.keys)
+
+ fun register(name: String, supplier: Supplier<out T>): KtRegistryObject<T> {
+ 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<T>) {
+ 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<T : IForgeRegistryEntry<T>>(private val name: ResourceLocation, private val registry: IForgeRegistry<T>) : Supplier<T> {
+ private lateinit var value: T
+
+ constructor(name: String, registry: IForgeRegistry<T>) : this(ResourceLocation(name), registry)
+
+ constructor(name: String, registryType: Supplier<Class<out T>>) : this(ResourceLocation(name), RegistryManager.ACTIVE.getRegistry(registryType.get()) as IForgeRegistry<T>)
+
+ init {
+ ObjectHolderRegistry.addHandler { predicate ->
+ if (predicate.test(registry.registryName)) {
+ value = registry.getValue(name)!!
+ }
+ }
+ }
+
+ override fun get(): T = value
+
+ fun refresh(registry: IForgeRegistry<out T>) {
+ 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
--- a/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0-sources.jar
+++ b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0-sources.jar
Binary files 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
--- a/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.jar
+++ b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.jar
Binary files 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 @@
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
- <version>16.0.3</version>
+ <version>18.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core</artifactId>
- <version>1.3.1</version>
+ <version>1.3.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-jdk8</artifactId>
- <version>1.3.1</version>
+ <version>1.3.2</version>
<scope>compile</scope>
</dependency>
</dependencies>
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