Skip to content

Commit

Permalink
refactor: make serializer-package depend on nms and move hideTooltip …
Browse files Browse the repository at this point in the history
…method to Nms-package
  • Loading branch information
Boy0000 committed May 12, 2024
1 parent 43d1af1 commit 1bc5354
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
18 changes: 18 additions & 0 deletions idofront-nms/src/main/kotlin/com/mineinabyss/idofront/nms/Items.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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

return CraftItemStack.asCraftCopy(this).apply {
handle.set(DataComponents.ATTRIBUTE_MODIFIERS, (handle.get(DataComponents.ATTRIBUTE_MODIFIERS) ?: handle.item.defaultAttributeModifiers).withTooltip(false))
}
}
1 change: 1 addition & 0 deletions idofront-serializers/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies {
implementation(project(":idofront-logging"))
implementation(project(":idofront-text-components"))
implementation(project(":idofront-di"))
implementation(project(":idofront-nms"))

testImplementation(libs.kotlinx.serialization.json)
testImplementation(libs.kotlinx.serialization.kaml)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
package com.mineinabyss.idofront.serialization

import com.mineinabyss.idofront.di.DI
import com.mineinabyss.idofront.items.hideAttributeTooltipWithItemFlagSet
import com.mineinabyss.idofront.messaging.idofrontLogger
import com.mineinabyss.idofront.nms.hideAttributeTooltipWithItemFlagSet
import com.mineinabyss.idofront.plugin.Plugins
import dev.lone.itemsadder.api.CustomStack
import io.lumine.mythiccrucible.MythicCrucible
Expand Down
2 changes: 1 addition & 1 deletion idofront-util/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
plugins {
id("com.mineinabyss.conventions.kotlin.jvm")
id("com.mineinabyss.conventions.papermc")
id("com.mineinabyss.conventions.nms")
//id("com.mineinabyss.conventions.nms")
id("com.mineinabyss.conventions.publication")
alias(libs.plugins.kotlinx.serialization)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.mineinabyss.idofront.items

import net.minecraft.core.component.DataComponents
import org.bukkit.craftbukkit.inventory.CraftItemStack
import org.bukkit.inventory.ItemFlag
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.ItemMeta

Expand All @@ -24,15 +21,3 @@ inline fun <reified T : ItemMeta> ItemStack.editItemMeta(apply: T.() -> Unit): I
itemMeta = meta
return this
}

/**
* 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

return CraftItemStack.asCraftCopy(this).apply {
handle.set(DataComponents.ATTRIBUTE_MODIFIERS, (handle.get(DataComponents.ATTRIBUTE_MODIFIERS) ?: handle.item.defaultAttributeModifiers).withTooltip(false))
}
}

0 comments on commit 1bc5354

Please sign in to comment.