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

java.lang.Object
net.xun.armory.api.item.ItemSet<P,T>
Type Parameters:
P - the piece type used to identify individual items in the set
T - the common item type represented by this set
Direct Known Subclasses:
ArmorSet, ToolSet

public class ItemSet<P extends PieceType,T extends net.minecraft.world.item.Item> extends Object
A generic container for a collection of related Item instances, where each item is identified by a piece type.

An ItemSet associates each PieceType with a lazily initialized item reference and an item factory used during registration. Items are not created until their corresponding supplier is resolved, allowing item sets to be declared before the actual registry instances are available.

Each piece is assigned a registry name derived from the set name and the piece's registry suffix. These names can be used to generate registration entries and to bind the resulting registered item instances back to the set.

This class is intended to serve as a common abstraction for specialized item-set implementations such as ToolSet and ArmorSet.

Since:
2.0.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final String
    The base name of this item set, used for generating registry IDs.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    ItemSet(String setName, Collection<P> pieceTypes, BiFunction<P,net.minecraft.world.item.Item.Properties,T> factory)
    Constructs an item set with the specified name, piece types, and item factory.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    bind(String registryName, Supplier<T> supplier)
    Binds a supplier to the lazy reference associated with a registry name.
    get(P piece)
    Returns the lazy reference associated with the specified piece.
    Resolves and returns all items belonging to this set.
    Returns the piece types belonging to this set.
    Map<net.minecraft.resources.ResourceLocation,Function<net.minecraft.world.item.Item.Properties,T>>
    Generates the registry entries for all pieces in this set.
    Returns the base name used to generate registry names for this set.

    Methods inherited from class java.lang.Object

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

    • setName

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

    • ItemSet

      protected ItemSet(String setName, Collection<P> pieceTypes, BiFunction<P,net.minecraft.world.item.Item.Properties,T> factory)
      Constructs an item set with the specified name, piece types, and item factory.

      Each supplied piece is registered internally with a lazy reference and a factory capable of creating the corresponding item from Item.Properties. The supplied collection is copied into the internal data structures, so subsequent modifications to the collection do not affect this set.

      Parameters:
      setName - the base name used to generate registry names
      pieceTypes - the piece types belonging to this set; must not be empty
      factory - the factory used to create an item for each piece
      Throws:
      NullPointerException - if setName, pieceTypes, factory, or a piece is null
      IllegalArgumentException - if pieceTypes is empty
  • Method Details

    • getPiecesForRegistration

      public Map<net.minecraft.resources.ResourceLocation,Function<net.minecraft.world.item.Item.Properties,T>> getPiecesForRegistration(String modId)
      Generates the registry entries for all pieces in this set.

      Each entry maps a ResourceLocation constructed from the supplied namespace and the piece's generated registry name to a factory accepting Item.Properties. The returned factories create the actual item instances when invoked by the registry system.

      The registry names are generated when the set is constructed and therefore remain consistent across registration and later item access.

      Parameters:
      modId - the namespace used for the generated resource locations
      Returns:
      an insertion-ordered map containing one registration entry for each piece in this set
      Throws:
      NullPointerException - if modId is null
      IllegalArgumentException - if modId is not a valid resource location namespace
      See Also:
      • ResourceLocation.fromNamespaceAndPath(String, String)
    • bind

      public void bind(String registryName, Supplier<T> supplier)
      Binds a supplier to the lazy reference associated with a registry name.

      This method is intended for use by the registration layer after an item instance has been registered. The supplied value is subsequently resolved when the corresponding piece is accessed through get(P) or getAll().

      Parameters:
      registryName - the registry name of the piece to bind
      supplier - the supplier used to resolve the registered item
      Throws:
      NullPointerException - if supplier is null
      IllegalArgumentException - if registryName does not identify a piece in this set
      See Also:
    • get

      public Supplier<T> get(P piece)
      Returns the lazy reference associated with the specified piece.

      The returned reference implements Supplier, allowing the item to be resolved when required rather than requiring the item instance to be created at the time the set itself is constructed.

      Parameters:
      piece - the piece whose item reference should be returned
      Returns:
      the lazy reference for the specified piece
      Throws:
      NullPointerException - if piece is null
      IllegalArgumentException - if piece is not part of this set
    • getAll

      public Collection<T> getAll()
      Resolves and returns all items belonging to this set.

      Calling this method causes every item's lazy reference to be resolved. Consequently, this method should generally be used when the complete set of item instances is required rather than when only an individual piece is needed.

      The returned collection follows the insertion order of the pieces supplied when this set was constructed.

      Returns:
      an unmodifiable list containing every item in this set
    • getPieces

      public Set<P> getPieces()
      Returns the piece types belonging to this set.

      The returned set is backed by the set's internal piece map and cannot be modified through the returned view.

      Returns:
      an unmodifiable set of the pieces in this set
    • getSetName

      public String getSetName()
      Returns the base name used to generate registry names for this set.
      Returns:
      the set's base registry name