Registration fixes and improvements

This commit is contained in:
Will FP
2023-12-07 16:57:58 +00:00
parent c7a1bb21b7
commit 942d76f989
7 changed files with 24 additions and 11 deletions

View File

@@ -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) {

View File

@@ -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)
}

View File

@@ -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

View File

@@ -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)
}
}
/**

View File

@@ -24,6 +24,8 @@ abstract class EcoEnchantBase(
final override val config by lazy { _config ?: loadConfig()!! }
override lateinit var enchantment: Enchantment
private val levels = mutableMapOf<Int, EcoEnchantLevel>()
private val conflictIds = config.getStrings("conflicts").toSet()

View File

@@ -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"
}

View File

@@ -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