From 6faaac2257eb87c1060118e8445dd9cd1b38c9cb Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 20 Jun 2024 23:13:52 +0100 Subject: [PATCH] Fixed 1.20.6+ getEnchants --- .../spigot/proxy/v1_20_6/FastItemStackFactory.kt | 10 ++++++++++ .../spigot/proxy/v1_21/FastItemStackFactory.kt | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/eco-core/core-nms/v1_20_6/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_20_6/FastItemStackFactory.kt b/eco-core/core-nms/v1_20_6/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_20_6/FastItemStackFactory.kt index 709c4e6a1..18daaf60b 100644 --- a/eco-core/core-nms/v1_20_6/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_20_6/FastItemStackFactory.kt +++ b/eco-core/core-nms/v1_20_6/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_20_6/FastItemStackFactory.kt @@ -62,6 +62,16 @@ class FastItemStackFactory : FastItemStackFactoryProxy { map[bukkit] = level } + if (checkStored) { + val stored = handle.get(DataComponents.ENCHANTMENTS) ?: return map + + for ((enchantment, level) in stored.entrySet()) { + val bukkit = CraftEnchantment.minecraftToBukkit(enchantment.value()) + + map[bukkit] = max(map.getOrDefault(bukkit, 0), level) + } + } + return map } 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 e56fbd2d1..a194fec81 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 @@ -69,6 +69,16 @@ class FastItemStackFactory : FastItemStackFactoryProxy { map[bukkit] = level } + if (checkStored) { + val stored = handle.get(DataComponents.ENCHANTMENTS) ?: return map + + for ((enchantment, level) in stored.entrySet()) { + val bukkit = CraftEnchantment.minecraftToBukkit(enchantment.value()) + + map[bukkit] = max(map.getOrDefault(bukkit, 0), level) + } + } + return map }