-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: check for adding empty attributes with hiding them in lore
- Loading branch information
Showing
2 changed files
with
7 additions
and
8 deletions.
There are no files selected for viewing
12 changes: 5 additions & 7 deletions
12
idofront-nms/src/main/kotlin/com/mineinabyss/idofront/nms/Items.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
package com.mineinabyss.idofront.nms | ||
|
||
import net.minecraft.core.component.DataComponents | ||
import org.bukkit.craftbukkit.inventory.CraftItemStack | ||
import org.bukkit.inventory.ItemFlag | ||
import org.bukkit.inventory.ItemStack | ||
|
||
/** | ||
* In 1.20.5, HIDE_ATTIRBUTES ItemFlag has funky behaviour as the component holds the show_in_tooltip property | ||
* This method properly hides the Attributes from the tooltip if an item has the flag set | ||
*/ | ||
fun ItemStack.hideAttributeTooltipWithItemFlagSet(): ItemStack { | ||
if (!hasItemFlag(ItemFlag.HIDE_ATTRIBUTES)) return this | ||
fun ItemStack.hideAttributeTooltipWithItemFlagSet() = editMeta { meta -> | ||
if (!hasItemFlag(ItemFlag.HIDE_ATTRIBUTES)) return@editMeta | ||
if (meta.attributeModifiers?.isEmpty == false) return@editMeta | ||
if (type.defaultAttributeModifiers != meta.attributeModifiers) return@editMeta | ||
|
||
return CraftItemStack.asCraftCopy(this).apply { | ||
handle.set(DataComponents.ATTRIBUTE_MODIFIERS, (handle.get(DataComponents.ATTRIBUTE_MODIFIERS) ?: handle.item.defaultAttributeModifiers).withTooltip(false)) | ||
} | ||
meta.attributeModifiers = type.defaultAttributeModifiers | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters