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,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.
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.

// @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());
Copy link
Member

Choose a reason for hiding this comment

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

Plain text

}

@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
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
// @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
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);
}
}