diff --git a/eco-core/core-nms/modern/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/common/modern/NewEcoFastItemStack.kt b/eco-core/core-nms/modern/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/common/modern/NewEcoFastItemStack.kt index 2a6a9eeb..df72ee2d 100644 --- a/eco-core/core-nms/modern/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/common/modern/NewEcoFastItemStack.kt +++ b/eco-core/core-nms/modern/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/common/modern/NewEcoFastItemStack.kt @@ -17,6 +17,7 @@ import net.kyori.adventure.text.Component import net.kyori.adventure.text.format.Style import net.kyori.adventure.text.format.TextColor import net.kyori.adventure.text.format.TextDecoration +import net.minecraft.core.Holder import net.minecraft.core.component.DataComponentType import net.minecraft.core.component.DataComponents import net.minecraft.core.registries.Registries @@ -47,7 +48,6 @@ private fun Component.unstyled(): Component { open class NewEcoFastItemStack( private val bukkit: ItemStack, - private val registryAccessor: RegistryAccessor ) : ImplementedFIS { // Cast is there because, try as I might, I can't get IntellIJ to recognise half the classes in the dev bundle @Suppress("USELESS_CAST") @@ -83,20 +83,17 @@ open class NewEcoFastItemStack( enchantment: Enchantment, checkStored: Boolean ): Int { - val minecraft = - CraftRegistry.bukkitToMinecraft( - enchantment - ) - - val registry = registryAccessor.getRegistry(Registries.ENCHANTMENT) - val holder = registry.wrapAsHolder(minecraft) + val minecraft = CraftRegistry.bukkitToMinecraftHolder( + enchantment, + Registries.ENCHANTMENT + ) val enchantments = handle.get(DataComponents.ENCHANTMENTS) ?: return 0 - var level = enchantments.getLevel(holder) + var level = enchantments.getLevel(minecraft) if (checkStored) { val storedEnchantments = handle.get(DataComponents.STORED_ENCHANTMENTS) ?: return 0 - level = max(level, storedEnchantments.getLevel(holder)) + level = max(level, storedEnchantments.getLevel(minecraft)) } return level diff --git a/eco-core/core-nms/modern/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/common/modern/RegistryAccessor.kt b/eco-core/core-nms/modern/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/common/modern/RegistryAccessor.kt deleted file mode 100644 index 2dd35116..00000000 --- a/eco-core/core-nms/modern/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/common/modern/RegistryAccessor.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.willfp.eco.internal.spigot.proxy.common.modern - -import net.minecraft.core.Registry -import net.minecraft.resources.ResourceKey - -/** - * Cross-version compat method for accessing registries. - */ -interface RegistryAccessor { - /** - * Get registry by [key] or throw. - */ - fun getRegistry(key: ResourceKey>): Registry -} diff --git a/eco-core/core-nms/v1_21/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_21/FastItemStackFactory.kt b/eco-core/core-nms/v1_21/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_21/FastItemStackFactory.kt index 9a71b2bc..7f10934f 100644 --- a/eco-core/core-nms/v1_21/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_21/FastItemStackFactory.kt +++ b/eco-core/core-nms/v1_21/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_21/FastItemStackFactory.kt @@ -3,7 +3,6 @@ package com.willfp.eco.internal.spigot.proxy.v1_21 import com.willfp.eco.core.fast.FastItemStack import com.willfp.eco.internal.spigot.proxy.FastItemStackFactoryProxy import com.willfp.eco.internal.spigot.proxy.common.modern.NewEcoFastItemStack -import com.willfp.eco.internal.spigot.proxy.common.modern.RegistryAccessor import net.minecraft.core.Registry import net.minecraft.core.component.DataComponents import net.minecraft.core.registries.Registries @@ -19,7 +18,7 @@ class FastItemStackFactory : FastItemStackFactoryProxy { } private class LegacyNewEcoFastItemStack(itemStack: ItemStack) : - NewEcoFastItemStack(itemStack, LegacyRegistryAccessor) { + NewEcoFastItemStack(itemStack) { override fun getCustomModelData(): Int? = handle.get(DataComponents.CUSTOM_MODEL_DATA)?.value @@ -34,12 +33,4 @@ class FastItemStackFactory : FastItemStackFactoryProxy { apply() } } - - private object LegacyRegistryAccessor : RegistryAccessor { - override fun getRegistry(key: ResourceKey>): Registry { - val server = Bukkit.getServer() as CraftServer - val access = server.server.registryAccess() - return access.registryOrThrow(key) - } - } } diff --git a/eco-core/core-nms/v1_21_3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_21_3/FastItemStackFactory.kt b/eco-core/core-nms/v1_21_3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_21_3/FastItemStackFactory.kt index 3071a0d2..bf160982 100644 --- a/eco-core/core-nms/v1_21_3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_21_3/FastItemStackFactory.kt +++ b/eco-core/core-nms/v1_21_3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_21_3/FastItemStackFactory.kt @@ -3,7 +3,6 @@ package com.willfp.eco.internal.spigot.proxy.v1_21_3 import com.willfp.eco.core.fast.FastItemStack import com.willfp.eco.internal.spigot.proxy.FastItemStackFactoryProxy import com.willfp.eco.internal.spigot.proxy.common.modern.NewEcoFastItemStack -import com.willfp.eco.internal.spigot.proxy.common.modern.RegistryAccessor import net.minecraft.core.Registry import net.minecraft.resources.ResourceKey import org.bukkit.Bukkit @@ -12,14 +11,6 @@ import org.bukkit.inventory.ItemStack class FastItemStackFactory : FastItemStackFactoryProxy { override fun create(itemStack: ItemStack): FastItemStack { - return NewEcoFastItemStack(itemStack, ModernRegistryAccessor) - } - - private object ModernRegistryAccessor : RegistryAccessor { - override fun getRegistry(key: ResourceKey>): Registry { - val server = Bukkit.getServer() as CraftServer - val access = server.server.registryAccess() - return access.get(key).get().value() - } + return NewEcoFastItemStack(itemStack) } } diff --git a/eco-core/core-nms/v1_21_4/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_21_4/FastItemStackFactory.kt b/eco-core/core-nms/v1_21_4/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_21_4/FastItemStackFactory.kt index d3192342..4dfec547 100644 --- a/eco-core/core-nms/v1_21_4/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_21_4/FastItemStackFactory.kt +++ b/eco-core/core-nms/v1_21_4/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_21_4/FastItemStackFactory.kt @@ -3,8 +3,8 @@ package com.willfp.eco.internal.spigot.proxy.v1_21_4 import com.willfp.eco.core.fast.FastItemStack import com.willfp.eco.internal.spigot.proxy.FastItemStackFactoryProxy import com.willfp.eco.internal.spigot.proxy.common.modern.NewEcoFastItemStack -import com.willfp.eco.internal.spigot.proxy.common.modern.RegistryAccessor import net.minecraft.core.Registry +import net.minecraft.core.registries.Registries import net.minecraft.resources.ResourceKey import org.bukkit.Bukkit import org.bukkit.craftbukkit.CraftServer @@ -12,14 +12,6 @@ import org.bukkit.inventory.ItemStack class FastItemStackFactory : FastItemStackFactoryProxy { override fun create(itemStack: ItemStack): FastItemStack { - return NewEcoFastItemStack(itemStack, ModernRegistryAccessor) - } - - private object ModernRegistryAccessor : RegistryAccessor { - override fun getRegistry(key: ResourceKey>): Registry { - val server = Bukkit.getServer() as CraftServer - val access = server.server.registryAccess() - return access.get(key).get().value() - } + return NewEcoFastItemStack(itemStack) } }