@@ -34,35 +34,30 @@ 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 /* *
5451 * Iterates over all the enchantments for the given [ItemStack]
5552 */
5653 fun <T > ItemStack.forEachEnchantment (block : (RegistryEntry <Enchantment >, Int ) -> T ) =
57- enchantments.enchantmentEntries.asSequence()
58- .map { block(it.key, it.intValue) }
54+ enchantments.enchantmentEntries.map { block(it.key, it.intValue) }
5955
6056 /* *
6157 * Iterates over all the enchantments of the given [net.minecraft.entity.LivingEntity]'s [EquipmentSlot]
6258 */
6359 fun <T > LivingEntity.forEachSlot (
6460 vararg slots : EquipmentSlot ,
6561 block : (entry: RegistryEntry <Enchantment >, level: Int ) -> T
66- ) =
67- slots.flatMap { getEquippedStack(it).forEachEnchantment(block) }
62+ ) = slots.flatMap { getEquippedStack(it).forEachEnchantment(block) }
6863}
0 commit comments