Fixed data driven enchantments not working

This commit is contained in:
Auxilor 2024-06-28 15:38:38 +01:00
parent b64bb71d60
commit 78a4732fdf

View File

@ -61,26 +61,16 @@ class ModernEnchantmentRegisterer : ModernEnchantmentRegistererProxy {
.getDeclaredField("cache") .getDeclaredField("cache")
.apply { isAccessible = true } .apply { isAccessible = true }
@Suppress("UNCHECKED_CAST")
private val vanillaEnchantments = Enchantments::class.java
.declaredFields
.asSequence()
.filter { it.type == ResourceKey::class.java }
.map { it.get(null) as ResourceKey<net.minecraft.world.item.enchantment.Enchantment> }
.map { it.location() }
.map { CraftNamespacedKey.fromMinecraft(it) }
.toSet()
override fun replaceRegistry() { override fun replaceRegistry() {
val newRegistryMTB = val newRegistryMTB =
BiFunction<NamespacedKey, net.minecraft.world.item.enchantment.Enchantment, Enchantment> { key, registry -> BiFunction<NamespacedKey, net.minecraft.world.item.enchantment.Enchantment, Enchantment> { key, registry ->
val isVanilla = vanillaEnchantments.contains(key)
val eco = EcoEnchants.getByID(key.key) val eco = EcoEnchants.getByID(key.key)
val registered = enchantmentRegistry.containsKey(CraftNamespacedKey.toMinecraft(key))
if (isVanilla) { if (eco != null) {
ModifiedVanillaCraftEnchantment(key, registry)
} else if (eco != null) {
eco as Enchantment eco as Enchantment
} else if (registered) {
ModifiedVanillaCraftEnchantment(key, registry)
} else { } else {
null null
} }