Record Class ItemStack
java.lang.Object
java.lang.Record
fr.fidorial.item.ItemStack
- Record Components:
id- the item identifier, e.g.minecraft:diamond_swordcount- how many;0or less means emptycomponents- the patch over the item's defaults
- All Implemented Interfaces:
DataComponentHolder, HoverEventSource<HoverEvent.ShowItem>, Translatable
public record ItemStack(Key id, int count, DataComponentMap components)
extends Record
implements DataComponentHolder, Translatable, HoverEventSource<HoverEvent.ShowItem>
An item identifier, a count, and a patch over that item's default components.
- Since:
- 0.1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilds a stack a component at a time. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionItemStack(Key id, int count, DataComponentMap components) Creates an instance of aItemStackrecord class. -
Method Summary
Modifier and TypeMethodDescriptionstatic ItemStack.BuilderReturns the value of thecomponentsrecord component.intcount()Returns the value of thecountrecord component.edit(Consumer<DataComponentEditor> editor) Reads an editor, hands it toeditor, and returns the resulting stack.editor()Hands back an editor over this stack's components.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.id()Returns the value of theidrecord component.booleanisEmpty()booleanWhether two stacks would merge into one slot — same item, same components, count ignored.static ItemStackstatic ItemStackplus(int delta) reset(DataComponentType<?> type) toString()Returns a string representation of this record class.<T> ItemStackwith(DataComponentType<T> type, T value) withComponents(DataComponentEditor editor) withCount(int newCount) without(DataComponentType<?> type) Removes the item's default for a component.Methods inherited from interface DataComponentHolder
get, getOrDefault, hasMethods inherited from interface HoverEventSource
asHoverEvent
-
Field Details
-
EMPTY
The absence of an item. Slots hold this rather thannull.
-
-
Constructor Details
-
ItemStack
Creates an instance of aItemStackrecord class.- Parameters:
id- the value for theidrecord componentcount- the value for thecountrecord componentcomponents- the value for thecomponentsrecord component
-
ItemStack
- Parameters:
id- the item identifiercount- how many
-
-
Method Details
-
of
-
of
-
builder
- Parameters:
key- the item identifier- Returns:
- a builder for a stack of one
-
toBuilder
- Returns:
- a builder pre-populated with this stack
-
editor
Hands back an editor over this stack's components. Changing it does not change this stack; feed it back throughwithComponents(DataComponentEditor)when you are done, or useedit(Consumer)to do both at once.- Returns:
- a fresh editor
- Since:
- 0.1.0
-
withComponents
- Parameters:
editor- the editor whose components to take- Returns:
- a new stack carrying those components, or this one when nothing changed
- Since:
- 0.1.0
-
edit
Reads an editor, hands it toeditor, and returns the resulting stack.- Parameters:
editor- given an editor over this stack's components- Returns:
- a new stack, or this one when nothing changed
- Since:
- 0.1.0
-
with
- Type Parameters:
T- the component's value type- Parameters:
type- the component to setvalue- the value- Returns:
- a new stack
-
without
Removes the item's default for a component. SeeDataComponentMap.without(DataComponentType)for why this differs fromreset(DataComponentType).- Parameters:
type- the component to remove- Returns:
- a new stack
-
reset
- Parameters:
type- the component to stop patching- Returns:
- a new stack
-
isEmpty
public boolean isEmpty()- Returns:
truewhen this stack holds nothing
-
isSimilar
-
withCount
- Parameters:
newCount- the new count- Returns:
- a new stack, or this one when the count is unchanged
-
plus
- Parameters:
delta- how much to add to the count; may be negative- Returns:
- a new stack, clamped at
0
-
asHoverEvent
- Specified by:
asHoverEventin interfaceHoverEventSource<HoverEvent.ShowItem>
-
translationKey
- Specified by:
translationKeyin interfaceTranslatable
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
id
-
count
-
components
Returns the value of thecomponentsrecord component.- Specified by:
componentsin interfaceDataComponentHolder- Returns:
- the value of the
componentsrecord component
-