diff --git a/eco-core/core-nms/v1_20_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R3/ModernEnchantmentRegisterer.kt b/eco-core/core-nms/v1_20_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R3/ModernEnchantmentRegisterer.kt index 365f34fd..336c3a50 100644 --- a/eco-core/core-nms/v1_20_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R3/ModernEnchantmentRegisterer.kt +++ b/eco-core/core-nms/v1_20_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R3/ModernEnchantmentRegisterer.kt @@ -2,6 +2,7 @@ package com.willfp.ecoenchants.proxy.v1_20_R3 import com.willfp.ecoenchants.enchant.EcoEnchant import com.willfp.ecoenchants.enchant.EcoEnchants +import com.willfp.ecoenchants.enchant.impl.EcoEnchantBase import com.willfp.ecoenchants.enchant.registration.modern.ModernEnchantmentRegistererProxy import com.willfp.ecoenchants.proxy.v1_20_R3.registration.DelegatedCraftEnchantment import com.willfp.ecoenchants.proxy.v1_20_R3.registration.ModifiedVanillaCraftEnchantment @@ -41,7 +42,7 @@ class ModernEnchantmentRegisterer : ModernEnchantmentRegistererProxy { if (enchant == null) { ModifiedVanillaCraftEnchantment(key, registry) } else { - DelegatedCraftEnchantment(enchant, registry) + enchant as Enchantment } } } @@ -54,13 +55,11 @@ class ModernEnchantmentRegisterer : ModernEnchantmentRegistererProxy { // Unfreeze registry frozenField.set(BuiltInRegistries.ENCHANTMENT, false) - Registry.register( - BuiltInRegistries.ENCHANTMENT, enchant.id, VanillaEcoEnchantsEnchantment( - enchant.id - ) - ) + val nms = VanillaEcoEnchantsEnchantment(enchant.id) - return org.bukkit.Registry.ENCHANTMENT.get(enchant.enchantmentKey)!! + Registry.register(BuiltInRegistries.ENCHANTMENT, enchant.id, nms) + + return DelegatedCraftEnchantment(enchant, nms) } override fun unregister(enchant: EcoEnchant) { diff --git a/eco-core/core-nms/v1_20_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R3/registration/DelegatedCraftEnchantment.kt b/eco-core/core-nms/v1_20_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R3/registration/DelegatedCraftEnchantment.kt index 2a1725ab..8a0634a2 100644 --- a/eco-core/core-nms/v1_20_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R3/registration/DelegatedCraftEnchantment.kt +++ b/eco-core/core-nms/v1_20_R3/src/main/kotlin/com/willfp/ecoenchants/proxy/v1_20_R3/registration/DelegatedCraftEnchantment.kt @@ -17,6 +17,10 @@ class DelegatedCraftEnchantment( private val enchant: EcoEnchant, nmsEnchantment: Enchantment ) : CraftEnchantment(enchant.enchantmentKey, nmsEnchantment), EcoEnchant by enchant { + init { + enchant.enchantment = this + } + override fun canEnchantItem(item: ItemStack): Boolean { return enchant.canEnchantItem(item) } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/EcoEnchant.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/EcoEnchant.kt index d6a08bc1..9d4cfd43 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/EcoEnchant.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/EcoEnchant.kt @@ -16,8 +16,7 @@ interface EcoEnchant : KRegistrable, EcoEnchantLike { /** * The enchantment. */ - override val enchantment: Enchantment - get() = this as Enchantment + override var enchantment: Enchantment /** * If this enchantment conflicts with all other enchantments. @@ -79,7 +78,7 @@ interface EcoEnchant : KRegistrable, EcoEnchantLike { } if (other is EcoEnchant) { - return other.conflictsWithDirectly(this as Enchantment) + return other.conflictsWithDirectly(this.enchantment) } return false diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/EcoEnchantLike.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/EcoEnchantLike.kt index e6f1d771..1b564285 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/EcoEnchantLike.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/EcoEnchantLike.kt @@ -77,7 +77,11 @@ interface EcoEnchantLike { return true } - return enchantment.canEnchantItem(item) + return if (this is EcoEnchant) { + this.targets.any { it.matches(item) } + } else { + enchantment.canEnchantItem(item) + } } /** diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/impl/EcoEnchantBase.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/impl/EcoEnchantBase.kt index 0f448c0a..7cf7446d 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/impl/EcoEnchantBase.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/impl/EcoEnchantBase.kt @@ -24,6 +24,8 @@ abstract class EcoEnchantBase( final override val config by lazy { _config ?: loadConfig()!! } + override lateinit var enchantment: Enchantment + private val levels = mutableMapOf() private val conflictIds = config.getStrings("conflicts").toSet() diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/registration/legacy/LegacyDelegatedEnchantment.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/registration/legacy/LegacyDelegatedEnchantment.kt index 5535cd62..aad89a1b 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/registration/legacy/LegacyDelegatedEnchantment.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/registration/legacy/LegacyDelegatedEnchantment.kt @@ -16,6 +16,10 @@ import org.bukkit.inventory.ItemStack class LegacyDelegatedEnchantment( private val enchant: EcoEnchant ) : Enchantment(enchant.enchantmentKey), EcoEnchant by enchant { + init { + enchant.enchantment = this + } + override fun translationKey(): String { return "ecoenchants:enchantment.$id" } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/registration/legacy/LegacyEnchantmentRegisterer.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/registration/legacy/LegacyEnchantmentRegisterer.kt index 44529cba..3052c9ac 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/registration/legacy/LegacyEnchantmentRegisterer.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/registration/legacy/LegacyEnchantmentRegisterer.kt @@ -1,6 +1,7 @@ package com.willfp.ecoenchants.enchant.registration.legacy import com.willfp.ecoenchants.enchant.EcoEnchant +import com.willfp.ecoenchants.enchant.impl.EcoEnchantBase import com.willfp.ecoenchants.enchant.registration.EnchantmentRegisterer import org.bukkit.NamespacedKey import org.bukkit.enchantments.Enchantment