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 @@ -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,36 @@
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.
Copy link
Member

Choose a reason for hiding this comment

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

Might be useful to say something about resource pack usage? Can be used with your own namespace to display models from a custom resource pack or something, idk.
But more importantly, I'd add a note to custom_model_data saying to usually prefer this now.

// This can also be used to display item models from your own custom resource packs.
// @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.asMinimalString(), true);
}

@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 mechanism.requireInteger() ? value.asInt() : 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 mechanism.requireInteger() ? value.asInt() : null;
}
}
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
// @input ElementTag
// @description
// Controls an item's rarity <@link language Item Components>.
// See <@link url https://jd.papermc.io/paper/org/bukkit/inventory/ItemRarity.html> for valid rarity values.
// @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 mechanism.requireEnum(ItemRarity.class) ? value.asEnum(ItemRarity.class) : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class ItemCustomModel extends ItemProperty<ElementTag> {
// @description
// Controls the custom model data ID number of the item.
// Use with no input to remove the custom model data.
// Prefer <@link property ItemTag.item_model> on MC 1.21+.
// See also <@link tag ItemTag.has_custom_model_data>
// -->
public static boolean describes(ItemTag item) {
Expand Down Expand Up @@ -56,6 +57,7 @@ public static void register() {
// @group properties
// @description
// Returns whether the item has a custom model data ID number set on it.
// Prefer <@link property ItemTag.item_model> on MC 1.21+.
// See also <@link tag ItemTag.custom_model_data>.
// -->
PropertyParser.registerTag(ItemCustomModel.class, ElementTag.class, "has_custom_model_data", (attribute, prop) -> {
Expand Down