Class ItemSet<P extends Enum<P>,T extends net.minecraft.world.item.Item>
- Type Parameters:
P- the enum type representing individual pieces in the setT- the type of item managed by this set, must extendItem
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionRetrieves a supplier for a specific piece in this item set.getAll()Retrieves all items in this set, forcing initialization if not already created.getPiecesForRegistration(String modId) Generates a registration map for all items in this set.Gets the base name of this item set.
-
Field Details
-
Constructor Details
-
ItemSet
Constructs a new item set with the specified configuration.This constructor initializes the item set by:
- Creating an
EnumMapfor the piece enum class - Iterating through all enum constants of the piece type
- Creating a
LazyReferencefor each piece using the factory - 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, nevernullpieceEnumClass- the class object for the piece enum type, used to discover all possible pieces, nevernullfactory- the factory responsible for creating individual item pieces, nevernull- Throws:
NullPointerException- if any parameter isnullIllegalArgumentException- if the piece enum class has no constants
- Creating an
-
-
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
ResourceLocationtoSupplierpairs 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 bemymod:diamond_sword.- Parameters:
modId- the namespace (mod ID) for all generated resource locations, nevernull- 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- ifmodIdisnullIllegalArgumentException- ifmodIdis not a valid namespace- See Also:
-
get
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- ifpieceisnullIllegalArgumentException- ifpieceis not part of this set
-
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
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
-