mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 20:05:02 -04:00
make enchantments not injectable by default
This commit is contained in:
parent
a51cb655c8
commit
ceec8a39cf
@ -15,6 +15,7 @@ package de.bixilon.minosoft.data.registries.enchantment
|
|||||||
import de.bixilon.minosoft.data.registries.registries.registry.RegistryItem
|
import de.bixilon.minosoft.data.registries.registries.registry.RegistryItem
|
||||||
|
|
||||||
abstract class Enchantment : RegistryItem() {
|
abstract class Enchantment : RegistryItem() {
|
||||||
|
override val injectable: Boolean get() = false
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return resourceLocation.full
|
return resourceLocation.full
|
||||||
|
@ -20,6 +20,7 @@ import de.bixilon.minosoft.data.registries.registries.registry.codec.ResourceLoc
|
|||||||
class PixLyzerEnchantment(
|
class PixLyzerEnchantment(
|
||||||
override val resourceLocation: ResourceLocation,
|
override val resourceLocation: ResourceLocation,
|
||||||
) : Enchantment() {
|
) : Enchantment() {
|
||||||
|
override val injectable: Boolean get() = true
|
||||||
|
|
||||||
companion object : ResourceLocationCodec<Enchantment> {
|
companion object : ResourceLocationCodec<Enchantment> {
|
||||||
override fun deserialize(registries: Registries?, resourceLocation: ResourceLocation, data: Map<String, Any>): Enchantment {
|
override fun deserialize(registries: Registries?, resourceLocation: ResourceLocation, data: Map<String, Any>): Enchantment {
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.data.registries.registries.registry
|
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.kutil.reflection.ReflectionUtil.forceSet
|
||||||
import de.bixilon.minosoft.data.registries.ResourceLocationAble
|
import de.bixilon.minosoft.data.registries.ResourceLocationAble
|
||||||
import de.bixilon.minosoft.data.registries.registries.Registries
|
import de.bixilon.minosoft.data.registries.registries.Registries
|
||||||
@ -20,9 +21,13 @@ import kotlin.reflect.KProperty
|
|||||||
import kotlin.reflect.jvm.javaField
|
import kotlin.reflect.jvm.javaField
|
||||||
|
|
||||||
abstract class RegistryItem : ResourceLocationAble {
|
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?) {
|
fun KProperty<RegistryItem?>.inject(vararg keys: Any?) {
|
||||||
|
if (!injectable) {
|
||||||
|
throw IllegalStateException("Not injectable")
|
||||||
|
}
|
||||||
val keyList: MutableList<Any> = mutableListOf()
|
val keyList: MutableList<Any> = mutableListOf()
|
||||||
for (key in keys) {
|
for (key in keys) {
|
||||||
key ?: continue
|
key ?: continue
|
||||||
@ -35,6 +40,9 @@ abstract class RegistryItem : ResourceLocationAble {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun inject(registries: Registries) {
|
fun inject(registries: Registries) {
|
||||||
|
if (!injectable) {
|
||||||
|
return
|
||||||
|
}
|
||||||
for ((field, keys) in injects) {
|
for ((field, keys) in injects) {
|
||||||
val javaField = field.javaField ?: continue
|
val javaField = field.javaField ?: continue
|
||||||
var value: Any? = null
|
var value: Any? = null
|
||||||
|
Loading…
x
Reference in New Issue
Block a user