From cd8dd2de573dc88738f4a4ef3e695841495e4a5f Mon Sep 17 00:00:00 2001 From: Will FP Date: Sat, 9 Dec 2023 14:43:03 +0000 Subject: [PATCH] Fixed registry unfreezing --- .../proxy/v1_20_R3/ModernEnchantmentRegisterer.kt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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 c40e4c49..59a537ef 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 @@ -6,6 +6,7 @@ import com.willfp.ecoenchants.enchant.registration.modern.ModernEnchantmentRegis import com.willfp.ecoenchants.proxy.v1_20_R3.registration.EcoEnchantsCraftEnchantment import com.willfp.ecoenchants.proxy.v1_20_R3.registration.ModifiedVanillaCraftEnchantment import com.willfp.ecoenchants.proxy.v1_20_R3.registration.VanillaEcoEnchantsEnchantment +import net.minecraft.core.Holder import net.minecraft.core.MappedRegistry import net.minecraft.core.Registry import net.minecraft.core.registries.BuiltInRegistries @@ -16,6 +17,7 @@ import org.bukkit.craftbukkit.v1_20_R3.CraftRegistry import org.bukkit.craftbukkit.v1_20_R3.CraftServer import org.bukkit.craftbukkit.v1_20_R3.util.CraftNamespacedKey import org.bukkit.enchantments.Enchantment +import java.util.IdentityHashMap class ModernEnchantmentRegisterer : ModernEnchantmentRegistererProxy { private val frozenField = MappedRegistry::class.java @@ -23,6 +25,11 @@ class ModernEnchantmentRegisterer : ModernEnchantmentRegistererProxy { .filter { it.type.isPrimitive }[0] .apply { isAccessible = true } + private val unregisteredIntrusiveHoldersField = MappedRegistry::class.java + .declaredFields + .last { it.type == Map::class.java } + .apply { isAccessible = true } + @Suppress("UNCHECKED_CAST") private val registries = CraftServer::class.java .getDeclaredField("registries") @@ -65,7 +72,7 @@ class ModernEnchantmentRegisterer : ModernEnchantmentRegistererProxy { } // Unfreeze registry - frozenField.set(BuiltInRegistries.ENCHANTMENT, false) + unfreeze(BuiltInRegistries.ENCHANTMENT) val nms = VanillaEcoEnchantsEnchantment(enchant.id) @@ -74,6 +81,11 @@ class ModernEnchantmentRegisterer : ModernEnchantmentRegistererProxy { return EcoEnchantsCraftEnchantment(enchant, nms) } + private fun unfreeze(registry: Registry) { + frozenField.set(registry, false) + unregisteredIntrusiveHoldersField.set(registry, IdentityHashMap>()) + } + override fun unregister(enchant: EcoEnchant) { /*