Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public static void register() {
DataComponentAdapter.register(new FoodAdapter());
DataComponentAdapter.register(new GliderAdapter());
DataComponentAdapter.register(new ItemModelAdapter());
DataComponentAdapter.register(new ItemNameAdapter());
DataComponentAdapter.register(new MaxDurabilityAdapter());
DataComponentAdapter.register(new MaxStackSizeAdapter());
DataComponentAdapter.register(new RarityAdapter());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.denizenscript.denizen.paper.datacomponents;

import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.core.ElementTag;
import io.papermc.paper.datacomponent.DataComponentTypes;
import net.kyori.adventure.text.Component;
import com.denizenscript.denizen.paper.PaperModule;
import net.md_5.bungee.api.ChatColor;

public class ItemNameAdapter extends DataComponentAdapter.Valued<ElementTag, Component> {

// <--[property]
// @object ItemTag
// @name item_name
// @input ElementTag
// @description
// Controls the item's item_name component. In effect, this changes its display name.
// Unlike <@link mechanism ItemTag.display>, this name cannot be changed by an anvil, but will be hidden when the display is set, such as with an anvil.
// That is, it will remain under the display name and be shown again if the display is removed.
// See also <@link language Item Components>.
// @mechanism
// Provide no input to reset the item to its default value.
// -->

public ItemNameAdapter() {
super(ElementTag.class, DataComponentTypes.ITEM_NAME, "item_name");
}

@Override
public ElementTag toDenizen(Component value) {
return new ElementTag(PaperModule.stringifyComponent(value));
}

@Override
public Component fromDenizen(ElementTag value, Mechanism mechanism) {
return PaperModule.parseFormattedText(value.toString(), ChatColor.WHITE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
// @group properties
// @description
// Returns the display name of the item, as set by plugin or an anvil.
// Use <@link property ItemTag.item_name> to get the item's item name component, which cannot be changed by an anvil.
// -->
if (attribute.startsWith("display")) {
if (hasDisplayName()) {
Expand All @@ -77,6 +78,7 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
// @group properties
// @description
// Returns whether the item has a custom set display name.
// Use <@link property ItemTag.item_name> for the item's item_display component, which also controls its name.
// -->
if (attribute.startsWith("has_display")) {
return new ElementTag(hasDisplayName())
Expand Down Expand Up @@ -116,6 +118,7 @@ public void adjust(Mechanism mechanism) {
// @description
// Changes the item's display name.
// Give no input to remove the item's display name.
// Use <@link property ItemTag.item_name> to set the item's item name component, which persists through changes to its display, and shows when no display is set.
// @tags
// <ItemTag.display>
// -->
Expand Down