Package net.neoforged.neoforge.items
Class StackCopySlot
java.lang.Object
net.minecraft.world.inventory.Slot
net.neoforged.neoforge.items.StackCopySlot
- Direct Known Subclasses:
ItemHandlerCopySlot
public abstract class StackCopySlot
extends net.minecraft.world.inventory.Slot
Slot to handle immutable itemstack storages (Ex:
ComponentItemHandler
).
For an implementation for use with an IItemHandler
see ItemHandlerCopySlot
.
Vanilla MC code modifies the stack returned by `getStack()` directly, but it
calls setChanged()
when that happens, so we just cache the returned stack,
and set it when setChanged()
is called.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate @Nullable net.minecraft.world.item.ItemStack
private static final net.minecraft.world.Container
Fields inherited from class net.minecraft.world.inventory.Slot
container, index, x, y
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal net.minecraft.world.item.ItemStack
getItem()
protected abstract net.minecraft.world.item.ItemStack
Gets the itemstack from the storage.final net.minecraft.world.item.ItemStack
remove
(int amount) final void
set
(net.minecraft.world.item.ItemStack stack) final void
protected abstract void
setStackCopy
(net.minecraft.world.item.ItemStack stack) Sets the itemstack from the storage.Methods inherited from class net.minecraft.world.inventory.Slot
allowModification, checkTakeAchievements, getContainerSlot, getMaxStackSize, getMaxStackSize, getNoItemIcon, getSlotIndex, hasItem, isActive, isFake, isHighlightable, isSameInventory, mayPickup, mayPlace, onQuickCraft, onQuickCraft, onSwapCraft, onTake, safeInsert, safeInsert, safeTake, setBackground, setByPlayer, setByPlayer, tryRemove
-
Field Details
-
emptyInventory
private static final net.minecraft.world.Container emptyInventory -
cachedReturnedStack
@Nullable private @Nullable net.minecraft.world.item.ItemStack cachedReturnedStack
-
-
Constructor Details
-
StackCopySlot
public StackCopySlot(int x, int y)
-
-
Method Details
-
getStackCopy
protected abstract net.minecraft.world.item.ItemStack getStackCopy()Gets the itemstack from the storage.- Returns:
- the stack in this slot
-
setStackCopy
protected abstract void setStackCopy(net.minecraft.world.item.ItemStack stack) Sets the itemstack from the storage.- Parameters:
stack
- the stack to put into this slot
-
getItem
public final net.minecraft.world.item.ItemStack getItem()- Overrides:
getItem
in classnet.minecraft.world.inventory.Slot
-
set
public final void set(net.minecraft.world.item.ItemStack stack) - Overrides:
set
in classnet.minecraft.world.inventory.Slot
-
setChanged
public final void setChanged()- Overrides:
setChanged
in classnet.minecraft.world.inventory.Slot
-
remove
public final net.minecraft.world.item.ItemStack remove(int amount) - Overrides:
remove
in classnet.minecraft.world.inventory.Slot
-