dimensions: fix id generation

This commit is contained in:
Bixilon 2022-05-16 14:38:17 +02:00
parent 4d9d23ae80
commit 052dd62bf7
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4

View File

@ -141,14 +141,20 @@ object DimensionGenerator : Generator(
dimensionRegistry?.get(null)?.let {
check(it is Registry<*>)
val registryGetKeyMethod = Registry::class.java.getDeclaredMethod("getId", Object::class.java)
val dimensionTypeGetIdMethod = try {
val idMethod1 = try {
DimensionType::class.java.getDeclaredMethod("getRawId")
} catch (exception: Throwable) {
null
}
val idMethod2 = try {
it::class.java.getDeclaredMethod("getRawId", Object::class.java)
} catch (exception: Throwable) {
null
}
for (entry in it) {
check(entry is DimensionType)
types.add(Triple(registryGetKeyMethod.invoke(it, entry) as Identifier, dimensionTypeGetIdMethod.invoke(it, entry) as Int, entry))
val id1 = idMethod1?.invoke(entry) ?: idMethod2?.invoke(it, entry) ?: throw IllegalStateException("Can not get dimension id for $entry")
types.add(Triple(registryGetKeyMethod.invoke(it, entry) as Identifier, id1 as Int, entry))
}
}
} catch (exception: Exception) {