Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 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 @@ -5,5 +5,9 @@ public class ComponentAdaptersRegistry {
public static void register() {
DataComponentAdapter.register(new FoodAdapter());
DataComponentAdapter.register(new GliderAdapter());
DataComponentAdapter.register(new ItemModelAdapter());
DataComponentAdapter.register(new MaxDurabilityAdapter());
DataComponentAdapter.register(new MaxStackSizeAdapter());
DataComponentAdapter.register(new RarityAdapter());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.denizenscript.denizen.paper.datacomponents;

import com.denizenscript.denizen.utilities.Utilities;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.core.ElementTag;
import io.papermc.paper.datacomponent.DataComponentTypes;
import net.kyori.adventure.key.Key;

public class ItemModelAdapter extends DataComponentAdapter.Valued<ElementTag, Key> {

// <--[property]
// @object ItemTag
// @name item_model
// @input ElementTag
// @description
// Controls an item's model <@link language Item Components> in namespaced key format.
// The default namespace is "minecraft", so for example an input of "stone" becomes "minecraft:stone", and will set the item model to a stone block.
Comment thread
tal5 marked this conversation as resolved.
// @mechanism
// Provide no input to reset the item to its default value.
// -->

public ItemModelAdapter() {
super(ElementTag.class, DataComponentTypes.ITEM_MODEL, "item_model");
}

@Override
public ElementTag toDenizen(Key value) {
return new ElementTag(value.toString());
Copy link
Copy Markdown
Contributor

@davight davight Feb 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iirc should use Utilities#namespacedKeyToString, and then mark it as plain element

}

@Override
public Key fromDenizen(ElementTag value, Mechanism mechanism) {
return Utilities.parseNamespacedKey(value.asString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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;

public class MaxDurabilityAdapter extends DataComponentAdapter.Valued<ElementTag, Integer> {

// <--[property]
// @object ItemTag
// @name max_durability
// @input ElementTag(Number)
// @description
// Controls an item's max durability <@link language Item Components>.
// @mechanism
// Provide no input to reset the item to its default value.
// -->

public MaxDurabilityAdapter() {
super(ElementTag.class, DataComponentTypes.MAX_DAMAGE, "max_durability");
}

@Override
public ElementTag toDenizen(Integer value) {
return new ElementTag(value);
}

@Override
public Integer fromDenizen(ElementTag value, Mechanism mechanism) {
return value.asInt();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These still need input checking, can probably just tern on requireInteger to return asInt or null.

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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;

public class MaxStackSizeAdapter extends DataComponentAdapter.Valued<ElementTag, Integer> {

// <--[property]
// @object ItemTag
// @name max_stack_size
// @input ElementTag(Number)
// @description
// Controls an item's max stack size <@link language Item Components>.
// @mechanism
// Provide no input to reset the item to its default value.
// -->

public MaxStackSizeAdapter() {
super(ElementTag.class, DataComponentTypes.MAX_STACK_SIZE, "max_stack_size");
}

@Override
public ElementTag toDenizen(Integer value) {
return new ElementTag(value);
}

@Override
public Integer fromDenizen(ElementTag value, Mechanism mechanism) {
return value.asInt();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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 org.bukkit.inventory.ItemRarity;

public class RarityAdapter extends DataComponentAdapter.Valued<ElementTag, ItemRarity> {

// <--[property]
// @object ItemTag
// @name rarity
Comment thread
tal5 marked this conversation as resolved.
// @input ElementTag
// @description
// Controls an item's rarity <@link language Item Components>.
// See https://jd.papermc.io/paper/1.21.11/org/bukkit/inventory/ItemRarity.html for valid rarity values.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<@link>? Also remove the version so that it automatically uses the latest one

// @mechanism
// Provide no input to reset the item to its default value.
// -->

public RarityAdapter() {
super(ElementTag.class, DataComponentTypes.RARITY, "rarity");
}

@Override
public ElementTag toDenizen(ItemRarity value) {
return new ElementTag(value);
}

@Override
public ItemRarity fromDenizen(ElementTag value, Mechanism mechanism) {
return value.asEnum(ItemRarity.class);
}
}