Fixed registry unfreezing on 1.21.3

This commit is contained in:
Will FP 2024-11-04 17:21:28 +00:00
parent a455915c5c
commit 6b8f49d2e1

View File

@ -18,6 +18,7 @@ import org.bukkit.craftbukkit.CraftRegistry
import org.bukkit.craftbukkit.CraftServer
import org.bukkit.craftbukkit.util.CraftNamespacedKey
import org.bukkit.enchantments.Enchantment
import java.lang.reflect.Modifier
import java.util.IdentityHashMap
import java.util.function.BiFunction
@ -34,6 +35,11 @@ class ModernEnchantmentRegisterer : ModernEnchantmentRegistererProxy {
.filter { it.type.isPrimitive }[0]
.apply { isAccessible = true }
private val allTags = MappedRegistry::class.java
.declaredFields
.filter { it.type.name.contains("TagSet") }[0]
.apply { isAccessible = true }
private val unregisteredIntrusiveHoldersField = MappedRegistry::class.java
.declaredFields
.last { it.type == Map::class.java }
@ -81,6 +87,21 @@ class ModernEnchantmentRegisterer : ModernEnchantmentRegistererProxy {
IdentityHashMap<net.minecraft.world.item.enchantment.Enchantment,
Holder.Reference<net.minecraft.world.item.enchantment.Enchantment>>()
)
/*
Creating an unbound tag set requires using reflection because the inner class is
package-private, so we just find the method manually.
*/
val unboundTagSet = MappedRegistry::class.java
.declaredClasses[0]
.declaredMethods
.filter { Modifier.isStatic(it.modifiers) }
.filter { it.parameterCount == 0 }[0]
.apply { isAccessible = true }
.invoke(null)
allTags.set(enchantmentRegistry, unboundTagSet)
}
override fun register(enchant: EcoEnchantBase): Enchantment {