Class ItemOrItems
java.lang.Object
johnsmith.enchantmentcore.api.config.data.ItemOrItems
Immutable sum-type data container representing either a single registered
Item or an
item TagKey (prefixed with "#" when serialized).
Used by Enchantment Core's configurable item set properties and GUI selection screens to allow users and datapacks to mix individual items and item tags seamlessly within a single list.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final com.mojang.serialization.Codec<ItemOrItems> Codec for serializing and deserializingItemOrItemsinstances to and from strings. -
Constructor Summary
ConstructorsConstructorDescriptionItemOrItems(net.minecraft.tags.TagKey<net.minecraft.world.item.Item> tag) Constructs anItemOrItemscontainer holding an itemTagKey.ItemOrItems(net.minecraft.world.item.Item item) Constructs anItemOrItemscontainer holding a single concreteItem. -
Method Summary
Modifier and TypeMethodDescriptionasString()Converts the stored item or tag key into its canonical string representation.boolean@Nullable net.minecraft.world.item.ItemgetItem()Retrieves the storedIteminstance.@Nullable net.minecraft.tags.TagKey<net.minecraft.world.item.Item> getTag()Retrieves the stored itemTagKey.inthashCode()booleanisTag()Checks whether this container holds an itemTagKeyrather than a singleItem.
-
Field Details
-
CODEC
Codec for serializing and deserializingItemOrItemsinstances to and from strings. Strings prefixed with"#"are parsed as itemTagKeys; all other strings are resolved againstBuiltInRegistries.ITEM.
-
-
Constructor Details
-
ItemOrItems
public ItemOrItems(net.minecraft.world.item.Item item) Constructs anItemOrItemscontainer holding a single concreteItem.- Parameters:
item- The target item instance.
-
ItemOrItems
public ItemOrItems(net.minecraft.tags.TagKey<net.minecraft.world.item.Item> tag) Constructs anItemOrItemscontainer holding an itemTagKey.- Parameters:
tag- The target item tag key.
-
-
Method Details
-
isTag
public boolean isTag()Checks whether this container holds an itemTagKeyrather than a singleItem.- Returns:
trueif this instance represents a tag key,falseif it represents a single item.
-
getItem
@Nullable public @Nullable net.minecraft.world.item.Item getItem()Retrieves the storedIteminstance.- Returns:
- The stored
Item, ornullifisTag()istrue.
-
getTag
@Nullable public @Nullable net.minecraft.tags.TagKey<net.minecraft.world.item.Item> getTag()Retrieves the stored itemTagKey.- Returns:
- The stored
TagKey, ornullifisTag()isfalse.
-
asString
Converts the stored item or tag key into its canonical string representation.Tag keys are formatted with a leading
"#"(e.g.,"#minecraft:enchantable/sword"), while single items are formatted as their registry resource location (e.g.,"minecraft:trident").- Returns:
- The string representation of this entry, defaulting to
"minecraft:air"if the item is unregistered.
-
equals
-
hashCode
-