Skip to content

Commit

Permalink
Updated custom name and lore on 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Jun 22, 2024
1 parent 75dd6be commit de04833
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import com.willfp.eco.util.StringUtils
import com.willfp.eco.util.toComponent
import com.willfp.eco.util.toLegacy
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.format.Style
import net.kyori.adventure.text.format.TextColor
import net.kyori.adventure.text.format.TextDecoration
import net.minecraft.core.component.DataComponentType
import net.minecraft.core.component.DataComponents
Expand All @@ -37,6 +39,10 @@ private val unstyledComponent = Component.empty().style {
it.color(null).decoration(TextDecoration.ITALIC, false)
}

private fun Component.unstyled(): Component {
return unstyledComponent.append(this)
}

class NewEcoFastItemStack(
private val bukkit: ItemStack
) : ImplementedFIS {
Expand Down Expand Up @@ -102,7 +108,7 @@ class NewEcoFastItemStack(
handle.set<ItemLore>(DataComponents.LORE, null)
} else {
val components = lore
.map { unstyledComponent.append(it) }
.map { it.unstyled() }
.map { it.toNMS() }

handle.set(
Expand All @@ -126,8 +132,12 @@ class NewEcoFastItemStack(
override fun setDisplayName(name: Component?) {
if (name == null) {
handle.set<net.minecraft.network.chat.Component>(DataComponents.ITEM_NAME, null)
handle.set<net.minecraft.network.chat.Component>(DataComponents.CUSTOM_NAME, null)
} else {
handle.set(DataComponents.ITEM_NAME, unstyledComponent.append(name).toNMS())
handle.set(
DataComponents.CUSTOM_NAME,
name.unstyled().toNMS()
)
}

apply()
Expand Down

0 comments on commit de04833

Please sign in to comment.