Class ItemResource
java.lang.Object
net.neoforged.neoforge.transfer.item.ItemResource
- All Implemented Interfaces:
DataComponentGetter, DataComponentHolder, TypedInstance<Item>, IDataComponentHolderExtension, DataComponentHolderResource<Item>, RegisteredResource<Item>, Resource
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final com.mojang.serialization.Codec<ItemResource> Codec for an item resource.static final ItemResourceThe empty resource instance of aItemResourceprivate final ItemStackA wrappedItemStackwhich must never be modified or exposed.private static final org.slf4j.Loggerstatic final com.mojang.serialization.Codec<ItemResource> Codec for an item resource.static final StreamCodec<RegistryFriendlyByteBuf, ItemResource> Stream codec for an item resource. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanPatches currently applied to the resource's data component holder.Returns the hover name of theItemStack.getItem()intinthashCode()booleanReturns true if the item instance matches the backing instance value.booleanChecks if the resource's data component holder has no patches applied to it.booleanisEmpty()Returnstrueif this represents an empty resource.booleanmatches(@Nullable ItemStackTemplate template) Returns true if this resource matches the item and components of the passed template.booleanReturns true if this resource matches the item and components of the passed stack.static ItemResourceNote: This cannot be called before your item is registeredstatic ItemResourceof(Holder<Item> holder, DataComponentPatch patch) Note: This cannot be called before your item is registeredstatic ItemResourceof(@Nullable ItemStackTemplate template) Creates an ItemResource using the default or copy of the passed in item stack.static ItemResourceCreates an ItemResource using the default or copy of the passed in item stack.static ItemResourceNote: This cannot be called before your item is registeredstatic ItemResourceof(ItemLike item, DataComponentPatch patch) Note: This cannot be called before your item is registeredbooleanTests anItemStackpredicate with the inner stack.toStack()Creates anItemStackwith a count of 1.toStack(int count) Creates anItemStackof the specified count.toString()value()Returns the backing instance of the resource.<D> ItemResourcewith(Supplier<? extends DataComponentType<D>> type, D data) Returns a resource with the data component set to the given value.<D> ItemResourcewith(DataComponentType<D> type, D data) Returns a resource with the data component set to the given value.Returns an instance of the resource with the desired patch applied on top of the existing one.without(Supplier<? extends DataComponentType<?>> type) Returns a resource without the data component, i.e. with the data component explicitly removed.without(DataComponentType<?> type) Returns a resource without the data component, i.e. with the data component explicitly removed.Methods inherited from interface DataComponentGetter
get, getOrDefault, getTyped, hasMethods inherited from interface DataComponentHolder
get, getAllOfType, getOrDefault, hasMethods inherited from interface IDataComponentHolderExtension
addToTooltip, addToTooltipMethods inherited from interface RegisteredResource
is
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
EMPTY
The empty resource instance of aItemResource -
CODEC
Codec for an item resource. Does not accept empty resources. -
OPTIONAL_CODEC
Codec for an item resource. Same format asCODEC, and also accepts empty resources. -
STREAM_CODEC
Stream codec for an item resource. Accepts empty resources. -
innerStack
-
-
Constructor Details
-
ItemResource
-
-
Method Details
-
of
Creates an ItemResource using the default or copy of the passed in item stack. Note the count is lost.- Parameters:
stack- stack to copy with a size of 1- Returns:
- If there were no patches on the stack's data components, the item's default resource will be returned, otherwise a new instance with the copied stack.
-
of
Creates an ItemResource using the default or copy of the passed in item stack. Note the count is lost.- Parameters:
template- stack to copy with a size of 1- Returns:
- If null was given, an empty resource is returned. If there were no patches on the stack's data components, the item's default resource will be returned, otherwise a new instance with the copied stack.
-
of
Note: This cannot be called before your item is registered- Throws:
IllegalStateException- If the backing registry is unavailable or not yet ready.NullPointerException- If the underlying Holder has not been populated (the target object is not registered).
-
of
Note: This cannot be called before your item is registered- Parameters:
item- Item to create the resource with.patch- Data components that should be on the resource instance.- Returns:
- a new
ItemResource. If the item is empty, thenEMPTYwill be returned; If the patch matches the default values the default instance of that item will be provided. - Throws:
IllegalStateException- If the backing registry is unavailable or not yet ready.NullPointerException- If the underlying Holder has not been populated (the target object is not registered).
-
of
Note: This cannot be called before your item is registered- Throws:
IllegalStateException- If the backing registry is unavailable or not yet ready.NullPointerException- If the underlying Holder has not been populated (the target object is not registered).
-
of
Note: This cannot be called before your item is registered- Parameters:
holder- Item holder to create the resource with.patch- Data components that should be on the resource instance.- Returns:
- a new
ItemResource. If the item is empty, thenEMPTYwill be returned; If the patch matches the default values the default instance of that item will be provided. - Throws:
IllegalStateException- If the backing registry is unavailable or not yet ready.NullPointerException- If the underlying Holder has not been populated (the target object is not registered).
-
value
Description copied from interface:RegisteredResourceReturns the backing instance of the resource.- Specified by:
valuein interfaceRegisteredResource<Item>- Returns:
- the backing instance of the resource
-
getItem
-
typeHolder
- Specified by:
typeHolderin interfaceTypedInstance<Item>
-
isEmpty
-
matches
Returns true if this resource matches the item and components of the passed stack.- Parameters:
stack- the item stack to check- Returns:
- true if this resource matches the item and components of the passed stack
-
matches
Returns true if this resource matches the item and components of the passed template.- Parameters:
template- the item stack template to check- Returns:
- true if this resource matches the item and components of the passed template
-
is
Returns true if the item instance matches the backing instance value.- Parameters:
item- the item to check- Returns:
- true if the item instance matches the backing instance value
-
test
-
isComponentsPatchEmpty
public boolean isComponentsPatchEmpty()Description copied from interface:DataComponentHolderResourceChecks if the resource's data component holder has no patches applied to it. Equivalent to checking if thepatchis empty, but more efficient.- Specified by:
isComponentsPatchEmptyin interfaceDataComponentHolderResource<Item>
-
withMergedPatch
Description copied from interface:DataComponentHolderResourceReturns an instance of the resource with the desired patch applied on top of the existing one.- Specified by:
withMergedPatchin interfaceDataComponentHolderResource<Item>- Parameters:
patch- The patch added to the new resource instance.- Returns:
- an instance of the resource with the desired patch applied on top of the existing one
-
with
Description copied from interface:DataComponentHolderResourceReturns a resource with the data component set to the given value.- Specified by:
within interfaceDataComponentHolderResource<Item>- Type Parameters:
D- the type of data component- Parameters:
type- the type of data componentdata- the data to set- Returns:
- a resource with the data component set to the given value
-
with
Description copied from interface:DataComponentHolderResourceReturns a resource with the data component set to the given value.- Specified by:
within interfaceDataComponentHolderResource<Item>- Type Parameters:
D- the type of data component- Parameters:
type- the supplier for the type of data componentdata- the data to set- Returns:
- a resource with the data component set to the given value
-
without
Description copied from interface:DataComponentHolderResourceReturns a resource without the data component, i.e. with the data component explicitly removed.- Specified by:
withoutin interfaceDataComponentHolderResource<Item>- Parameters:
type- the type of data component- Returns:
- a resource without the data component, i.e. with the data component explicitly removed
-
without
Description copied from interface:DataComponentHolderResourceReturns a resource without the data component, i.e. with the data component explicitly removed.- Specified by:
withoutin interfaceDataComponentHolderResource<Item>- Parameters:
type- the supplier for the type of data component- Returns:
- a resource without the data component, i.e. with the data component explicitly removed
-
getComponents
- Specified by:
getComponentsin interfaceDataComponentHolder
-
getComponentsPatch
Description copied from interface:DataComponentHolderResourcePatches currently applied to the resource's data component holder.- Specified by:
getComponentsPatchin interfaceDataComponentHolderResource<Item>
-
toStack
Creates anItemStackof the specified count.- Parameters:
count- The amount of the item the stack should have. Must be non-negative.- Throws:
IllegalArgumentException- when count is negative.
-
toStack
-
getMaxStackSize
public int getMaxStackSize()- See Also:
-
getHoverName
-
equals
-
hashCode
-
toString
-