Class StackCopySlot
java.lang.Object
net.minecraft.world.inventory.Slot
net.neoforged.neoforge.world.inventory.StackCopySlot
- Direct Known Subclasses:
ItemHandlerCopySlot, ResourceHandlerSlot
Slot to handle immutable itemstack storages (Ex:
ItemAccessItemHandler).
For an implementation for use with a ResourceHandler see ResourceHandlerSlot.
Vanilla MC code modifies the stack returned by getItem() directly, but it
calls setChanged() when that happens, so we just cache the returned stack,
and set it when setChanged() is called.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidClears the current cached return stack to prevent asetChanged()call from potentially overriding the contents of this slot.final ItemStackgetItem()protected abstract ItemStackGets the itemstack from the storage.remove(int amount) final voidfinal voidprotected abstract voidsetStackCopy(ItemStack stack) Sets the itemstack from the storage.Methods inherited from class Slot
allowModification, checkTakeAchievements, getContainerSlot, getMaxStackSize, getMaxStackSize, getNoItemIcon, getSlotIndex, hasItem, isActive, isFake, isHighlightable, isSameInventory, mayPickup, mayPlace, onQuickCraft, onQuickCraft, onSwapCraft, onTake, safeClone, safeInsert, safeInsert, safeTake, setBackground, setByPlayer, setByPlayer, tryRemove
-
Field Details
-
emptyInventory
-
cachedReturnedStack
-
-
Constructor Details
-
StackCopySlot
public StackCopySlot(int slot, int x, int y) - Parameters:
slot- The slot in the underlying container, whatever it may be; zero if not applicable.
-
-
Method Details
-
getStackCopy
Gets the itemstack from the storage.- Returns:
- the stack in this slot
-
setStackCopy
Sets the itemstack from the storage.- Parameters:
stack- the stack to put into this slot
-
getItem
-
set
-
setChanged
public final void setChanged()- Overrides:
setChangedin classSlot
-
remove
-
clearCachedReturnStack
protected void clearCachedReturnStack()Clears the current cached return stack to prevent asetChanged()call from potentially overriding the contents of this slot. This is useful when the slot's backing inventory may have been modified directly.
-