Class ItemOrItems

java.lang.Object
johnsmith.enchantmentcore.api.config.data.ItemOrItems

public class ItemOrItems extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    static final com.mojang.serialization.Codec<ItemOrItems>
    Codec for serializing and deserializing ItemOrItems instances to and from strings.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ItemOrItems(net.minecraft.tags.TagKey<net.minecraft.world.item.Item> tag)
    Constructs an ItemOrItems container holding an item TagKey.
    ItemOrItems(net.minecraft.world.item.Item item)
    Constructs an ItemOrItems container holding a single concrete Item.
  • Method Summary

    Modifier and Type
    Method
    Description
    Converts the stored item or tag key into its canonical string representation.
    boolean
     
    @Nullable net.minecraft.world.item.Item
    Retrieves the stored Item instance.
    @Nullable net.minecraft.tags.TagKey<net.minecraft.world.item.Item>
    Retrieves the stored item TagKey.
    int
     
    boolean
    Checks whether this container holds an item TagKey rather than a single Item.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • CODEC

      public static final com.mojang.serialization.Codec<ItemOrItems> CODEC
      Codec for serializing and deserializing ItemOrItems instances to and from strings. Strings prefixed with "#" are parsed as item TagKeys; all other strings are resolved against BuiltInRegistries.ITEM.
  • Constructor Details

    • ItemOrItems

      public ItemOrItems(net.minecraft.world.item.Item item)
      Constructs an ItemOrItems container holding a single concrete Item.
      Parameters:
      item - The target item instance.
    • ItemOrItems

      public ItemOrItems(net.minecraft.tags.TagKey<net.minecraft.world.item.Item> tag)
      Constructs an ItemOrItems container holding an item TagKey.
      Parameters:
      tag - The target item tag key.
  • Method Details

    • isTag

      public boolean isTag()
      Checks whether this container holds an item TagKey rather than a single Item.
      Returns:
      true if this instance represents a tag key, false if it represents a single item.
    • getItem

      @Nullable public @Nullable net.minecraft.world.item.Item getItem()
      Retrieves the stored Item instance.
      Returns:
      The stored Item, or null if isTag() is true.
    • getTag

      @Nullable public @Nullable net.minecraft.tags.TagKey<net.minecraft.world.item.Item> getTag()
      Retrieves the stored item TagKey.
      Returns:
      The stored TagKey, or null if isTag() is false.
    • asString

      public String 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

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object