mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-11-21 14:55:17 +01:00
Fixed registry unfreezing on 1.21.3
This commit is contained in:
parent
a455915c5c
commit
6b8f49d2e1
@ -18,6 +18,7 @@ import org.bukkit.craftbukkit.CraftRegistry
|
|||||||
import org.bukkit.craftbukkit.CraftServer
|
import org.bukkit.craftbukkit.CraftServer
|
||||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey
|
import org.bukkit.craftbukkit.util.CraftNamespacedKey
|
||||||
import org.bukkit.enchantments.Enchantment
|
import org.bukkit.enchantments.Enchantment
|
||||||
|
import java.lang.reflect.Modifier
|
||||||
import java.util.IdentityHashMap
|
import java.util.IdentityHashMap
|
||||||
import java.util.function.BiFunction
|
import java.util.function.BiFunction
|
||||||
|
|
||||||
@ -34,6 +35,11 @@ class ModernEnchantmentRegisterer : ModernEnchantmentRegistererProxy {
|
|||||||
.filter { it.type.isPrimitive }[0]
|
.filter { it.type.isPrimitive }[0]
|
||||||
.apply { isAccessible = true }
|
.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
|
private val unregisteredIntrusiveHoldersField = MappedRegistry::class.java
|
||||||
.declaredFields
|
.declaredFields
|
||||||
.last { it.type == Map::class.java }
|
.last { it.type == Map::class.java }
|
||||||
@ -81,6 +87,21 @@ class ModernEnchantmentRegisterer : ModernEnchantmentRegistererProxy {
|
|||||||
IdentityHashMap<net.minecraft.world.item.enchantment.Enchantment,
|
IdentityHashMap<net.minecraft.world.item.enchantment.Enchantment,
|
||||||
Holder.Reference<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 {
|
override fun register(enchant: EcoEnchantBase): Enchantment {
|
||||||
|
Loading…
Reference in New Issue
Block a user