mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-11-21 14:55:17 +01:00
Fixed registry unfreezing
This commit is contained in:
parent
0047df4eb6
commit
cd8dd2de57
@ -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 <T> unfreeze(registry: Registry<T>) {
|
||||
frozenField.set(registry, false)
|
||||
unregisteredIntrusiveHoldersField.set(registry, IdentityHashMap<T, Holder.Reference<T>>())
|
||||
}
|
||||
|
||||
override fun unregister(enchant: EcoEnchant) {
|
||||
/*
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user