@@ -34,34 +34,29 @@ object EnchantmentUtils {
3434 get() = getOrDefault(DataComponentTypes .ENCHANTMENTS , ItemEnchantmentsComponent .DEFAULT )
3535
3636 /* *
37- * Returns whether the given [ItemStack] has enchantments
37+ * Returns whether the given [ItemStack] has enchantments, including enchantments on books
3838 */
3939 val ItemStack .hasEnchantments: Boolean
4040 get() = ! getOrDefault(DataComponentTypes .ENCHANTMENTS , ItemEnchantmentsComponent .DEFAULT ).isEmpty
41- || getOrDefault(DataComponentTypes .STORED_ENCHANTMENTS , ItemEnchantmentsComponent .DEFAULT ).isEmpty
41+ || ! getOrDefault(DataComponentTypes .STORED_ENCHANTMENTS , ItemEnchantmentsComponent .DEFAULT ).isEmpty
4242
4343 /* *
4444 * Returns the given enchantment level from a [net.minecraft.item.ItemStack]
4545 */
4646 fun ItemStack.getEnchantment (key : RegistryKey <Enchantment >) =
47- getOrDefault(DataComponentTypes .ENCHANTMENTS , ItemEnchantmentsComponent .DEFAULT )
48- .enchantmentEntries.find { it.key?.matchesKey(key) == true }
49- ?.intValue
50- ? : 0
47+ enchantments.enchantmentEntries.find { it.key?.matchesKey(key) == true }?.intValue ? : 0
5148
5249 /* *
5350 * Iterates over all the enchantments for the given [ItemStack]
5451 */
5552 fun <T > ItemStack.forEachEnchantment (block : (RegistryEntry <Enchantment >, Int ) -> T ) =
56- enchantments.enchantmentEntries.asSequence()
57- .map { block(it.key, it.intValue) }
53+ enchantments.enchantmentEntries.map { block(it.key, it.intValue) }
5854
5955 /* *
6056 * Iterates over all the enchantments of the given [net.minecraft.entity.LivingEntity]'s [EquipmentSlot]
6157 */
6258 fun <T > LivingEntity.forEachSlot (
6359 vararg slots : EquipmentSlot ,
6460 block : (entry: RegistryEntry <Enchantment >, level: Int ) -> T
65- ) =
66- slots.flatMap { getEquippedStack(it).forEachEnchantment(block) }
61+ ) = slots.flatMap { getEquippedStack(it).forEachEnchantment(block) }
6762}
0 commit comments