Class ItemSet<P extends Enum<P>,T extends net.minecraft.world.item.Item>

java.lang.Object
net.xun.armory.api.item.ItemSet<P,T>
Type Parameters:
P - the enum type representing individual pieces in the set
T - the type of item managed by this set, must extend Item
Direct Known Subclasses:
ArmorSet, ToolSet

public class ItemSet<P extends Enum<P>,T extends net.minecraft.world.item.Item> extends Object
Base class for managing sets of related items with lazy initialization.

This class provides a foundation for creating and managing item sets (such as armor sets or tool sets) where each piece is represented by an enum constant and lazily initialized upon first access. It handles the creation, caching, and registration of individual item pieces within a cohesive set.

Since:
2.0.0
See Also:
  • Field Details

    • setName

      protected final String setName
      The base name of this item set, used for generating registry IDs.
    • pieces

      protected final Map<P extends Enum<P>,LazyReference<T extends net.minecraft.world.item.Item>> pieces
      Map storing lazy references to each item piece in the set.
  • Constructor Details

    • ItemSet

      protected ItemSet(String setName, Class<P> pieceEnumClass, ItemPieceFactory<P,T> factory)
      Constructs a new item set with the specified configuration.

      This constructor initializes the item set by:

      1. Creating an EnumMap for the piece enum class
      2. Iterating through all enum constants of the piece type
      3. Creating a LazyReference for each piece using the factory
      4. Generating appropriate names for each piece
      Parameters:
      setName - the base name for all items in this set (e.g., "diamond"), used to generate registry IDs, never null
      pieceEnumClass - the class object for the piece enum type, used to discover all possible pieces, never null
      factory - the factory responsible for creating individual item pieces, never null
      Throws:
      NullPointerException - if any parameter is null
      IllegalArgumentException - if the piece enum class has no constants
  • Method Details

    • getPiecesForRegistration

      public Map<net.minecraft.resources.ResourceLocation,Supplier<T>> getPiecesForRegistration(String modId)
      Generates a registration map for all items in this set.

      This method creates a map of ResourceLocation to Supplier pairs suitable for registration with Minecraft's registry system. Each entry corresponds to one piece in the item set.

      Generated Resource Locations: Follow the pattern modId:setName_pieceSuffix. For example, with mod ID "mymod", base name "diamond", and piece suffix "_sword", the resulting ResourceLocation would be mymod:diamond_sword.

      Parameters:
      modId - the namespace (mod ID) for all generated resource locations, never null
      Returns:
      a map of registry entries where keys are resource locations and values are suppliers providing the registered items, never null, never empty
      Throws:
      NullPointerException - if modId is null
      IllegalArgumentException - if modId is not a valid namespace
      See Also:
      • ResourceLocation.fromNamespaceAndPath(String, String)
    • get

      public Supplier<T> get(P piece)
      Retrieves a supplier for a specific piece in this item set.

      The returned supplier will lazily create the item upon first invocation and cache the result for subsequent calls.

      Parameters:
      piece - the piece to retrieve, must be a valid enum constant for this item set
      Returns:
      a supplier providing the requested item piece, never null
      Throws:
      NullPointerException - if piece is null
      IllegalArgumentException - if piece is not part of this set
    • getAll

      public Collection<T> getAll()
      Retrieves all items in this set, forcing initialization if not already created.

      This method triggers the creation of all items in the set (if not already initialized) and returns them as a collection. The collection iteration order follows the natural order of the piece enum.

      Performance Note: This method may cause initialization of all items in the set, which could be expensive if items are resource-intensive to create.

      Returns:
      an unmodifiable collection containing all items in this set, in enum constant order, never null, never empty
    • getSetName

      public String getSetName()
      Gets the base name of this item set.

      This is the name used during construction and forms the basis for all generated registry IDs within the set.

      Returns:
      the base name of this item set, never null