make enchantments not injectable by default

This commit is contained in:
Bixilon 2022-12-08 00:28:39 +01:00
parent a51cb655c8
commit ceec8a39cf
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 11 additions and 1 deletions

View File

@ -15,6 +15,7 @@ package de.bixilon.minosoft.data.registries.enchantment
import de.bixilon.minosoft.data.registries.registries.registry.RegistryItem
abstract class Enchantment : RegistryItem() {
override val injectable: Boolean get() = false
override fun toString(): String {
return resourceLocation.full

View File

@ -20,6 +20,7 @@ import de.bixilon.minosoft.data.registries.registries.registry.codec.ResourceLoc
class PixLyzerEnchantment(
override val resourceLocation: ResourceLocation,
) : Enchantment() {
override val injectable: Boolean get() = true
companion object : ResourceLocationCodec<Enchantment> {
override fun deserialize(registries: Registries?, resourceLocation: ResourceLocation, data: Map<String, Any>): Enchantment {

View File

@ -13,6 +13,7 @@
package de.bixilon.minosoft.data.registries.registries.registry
import de.bixilon.kutil.cast.CastUtil.unsafeNull
import de.bixilon.kutil.reflection.ReflectionUtil.forceSet
import de.bixilon.minosoft.data.registries.ResourceLocationAble
import de.bixilon.minosoft.data.registries.registries.Registries
@ -20,9 +21,13 @@ import kotlin.reflect.KProperty
import kotlin.reflect.jvm.javaField
abstract class RegistryItem : ResourceLocationAble {
private val injects: MutableMap<KProperty<RegistryItem?>, List<Any>> = mutableMapOf()
open val injectable: Boolean get() = true
private val injects: MutableMap<KProperty<RegistryItem?>, List<Any>> = if (injectable) mutableMapOf() else unsafeNull()
fun KProperty<RegistryItem?>.inject(vararg keys: Any?) {
if (!injectable) {
throw IllegalStateException("Not injectable")
}
val keyList: MutableList<Any> = mutableListOf()
for (key in keys) {
key ?: continue
@ -35,6 +40,9 @@ abstract class RegistryItem : ResourceLocationAble {
}
fun inject(registries: Registries) {
if (!injectable) {
return
}
for ((field, keys) in injects) {
val javaField = field.javaField ?: continue
var value: Any? = null