Class SlotReference<T>
java.lang.Object
net.ixdarklord.coolcatcore.api.utils.SlotReference<T>
- Type Parameters:
T- The type of the inventory owner (e.g.,PlayerorContainer).
- Direct Known Subclasses:
SlotReference.Container,SlotReference.Player
Represents a reference to a specific slot within an inventory or container.
A SlotReference provides direct access to an ItemStack stored in a slot,
allowing retrieval, modification, and clearing operations.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classASlotReferenceimplementation for generic containers (e.g., chests, furnaces).static classASlotReferenceimplementation for player inventories. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SlotReference<?> A static empty slot reference used as a placeholder for invalid or unavailable slots.protected final intprotected final T -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanclear()Clears the slot by setting its contents toItemStack.EMPTY.abstract @NotNull net.minecraft.world.item.ItemStackget()Retrieves theItemStackcurrently stored in this slot.intgetIndex()Returns the slot index within the container or inventory.getOwner()Returns the inventory owner associated with this slot.abstract booleanset(net.minecraft.world.item.ItemStack stack) Replaces the item in this slot.
-
Field Details
-
EMPTY
A static empty slot reference used as a placeholder for invalid or unavailable slots.Always returns
ItemStack.EMPTYand does not permit modifications. -
owner
-
index
protected final int index
-
-
Constructor Details
-
SlotReference
Creates a newSlotReferenceinstance.- Parameters:
owner- the inventory owner managing this slot, ornullif invalidindex- the index of the slot within the inventory
-
-
Method Details
-
getOwner
Returns the inventory owner associated with this slot.- Returns:
- the owner, or
nullif this reference is invalid
-
getIndex
public int getIndex()Returns the slot index within the container or inventory.- Returns:
- the slot index
-
get
@NotNull public abstract @NotNull net.minecraft.world.item.ItemStack get()Retrieves theItemStackcurrently stored in this slot.- Returns:
- the stored item, or
ItemStack.EMPTYif the slot is empty - Throws:
IllegalStateException- if the owner isnull
-
set
public abstract boolean set(net.minecraft.world.item.ItemStack stack) Replaces the item in this slot.- Parameters:
stack- the newItemStackto place- Returns:
trueif the item was successfully set,falseif unchanged- Throws:
IllegalStateException- if the owner isnull
-
clear
public boolean clear()Clears the slot by setting its contents toItemStack.EMPTY.- Returns:
trueif an item was removed,falseif already empty- Throws:
IllegalStateException- if the owner isnull
-