Class SlotContainer
java.lang.Object
net.ixdarklord.coolcatcore.api.container.SlotContainer
- All Implemented Interfaces:
Trackable,net.minecraft.world.Clearable,net.minecraft.world.Container
An inventory following a
ContainerLayout. It's a vanilla Container, so menus, hoppers and
Containers work with it as they are; use createSlot(int, int, int) for menu slots that respect
the layout's filters, limits and roles.
Stored as a
, its changes save and sync on their
own. invalid reference
AttachmentItemContainers binds one to an item stack.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from interface net.minecraft.world.Container
DEFAULT_DISTANCE_BUFFER -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddListener(SlotContainer.Listener listener) Callslistenerafter a slot changes (slot-1: several at once).booleancanExtractFrom(int slot, @Nullable net.minecraft.core.Direction side) Whether automation may take from the slot through a face (null: any face).booleancanInsertFrom(int slot, net.minecraft.world.item.ItemStack stack, @Nullable net.minecraft.core.Direction side) Whether automation may put the item in through a face (null: any face).booleancanPlaceItem(int slot, net.minecraft.world.item.ItemStack stack) Whether automation without a face (a hopper under a plain container) may put the item in.booleancanPlayerPlace(int slot, net.minecraft.world.item.ItemStack stack) Whether a player may put the item in through a menu.booleancanTakeItem(net.minecraft.world.Container into, int slot, net.minecraft.world.item.ItemStack stack) voidintThe comparator signal the contents give (0 to 15).List<net.minecraft.world.item.ItemStack> Copies of the stacks, in order.intnet.minecraft.world.inventory.SlotcreateSlot(int slot, int x, int y) A menu slot that respects the layout's filters, limits and roles.voiddropContents(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos) Spills the contents at a position and empties the container.net.minecraft.world.item.ItemStackextract(int slot, int amount, boolean simulate) Takes up toamountfrom one slot, for the holder's own code.net.minecraft.world.item.ItemStackTakes up toamountof the first item matchingfilter, gathered from every slot holding it.voidfromContents(net.minecraft.world.item.component.ItemContainerContents contents) intnet.minecraft.world.item.ItemStackgetItem(int slot) List<net.minecraft.world.item.ItemStack> getItems()The slots, in order.intintgetSlotLimit(int slot, net.minecraft.world.item.ItemStack stack) How many of the item the slot holds.net.minecraft.world.item.ItemStackinsert(int slot, net.minecraft.world.item.ItemStack stack, boolean simulate) Puts as much ofstackas fits into one slot, for the holder's own code: filters and limits apply, roles don't.net.minecraft.world.item.ItemStackinsert(net.minecraft.world.item.ItemStack stack, boolean simulate) Puts as much ofstackas fits anywhere, topping up matching stacks before filling empty slots.booleanisEmpty()booleanisItemValid(int slot, net.minecraft.world.item.ItemStack stack) Whether the slot's filter takes the item, whoever puts it in.layout()protected voidonChanged(int slot) Called after a slot changes (slot-1: several at once).net.minecraft.world.item.ItemStackremoveItem(int slot, int count) net.minecraft.world.item.ItemStackremoveItemNoUpdate(int slot) voidremoveListener(SlotContainer.Listener listener) voidvoidsetChangeListener(@Nullable Runnable listener) Called by the holder storing this value; calllistenerafter every change.voidsetItem(int slot, net.minecraft.world.item.ItemStack stack) voidReplaces the contents; slots paststacks' end are emptied.setValidator(Predicate<net.minecraft.world.entity.player.Player> validator) Who may keep a menu on this container open; everyone by default.booleanstillValid(net.minecraft.world.entity.player.Player player) net.minecraft.world.item.component.ItemContainerContentsThe contents as an item component (the first 256 slots).Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.minecraft.world.Container
countItem, getMaxStackSize, hasAnyMatching, hasAnyOf, startOpen, stopOpen
-
Constructor Details
-
SlotContainer
-
-
Method Details
-
layout
-
getContainerSize
public int getContainerSize()- Specified by:
getContainerSizein interfacenet.minecraft.world.Container
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfacenet.minecraft.world.Container
-
getItem
public net.minecraft.world.item.ItemStack getItem(int slot) - Specified by:
getItemin interfacenet.minecraft.world.Container
-
removeItem
public net.minecraft.world.item.ItemStack removeItem(int slot, int count) - Specified by:
removeItemin interfacenet.minecraft.world.Container
-
removeItemNoUpdate
public net.minecraft.world.item.ItemStack removeItemNoUpdate(int slot) - Specified by:
removeItemNoUpdatein interfacenet.minecraft.world.Container
-
setItem
public void setItem(int slot, net.minecraft.world.item.ItemStack stack) - Specified by:
setItemin interfacenet.minecraft.world.Container
-
getMaxStackSize
public int getMaxStackSize()- Specified by:
getMaxStackSizein interfacenet.minecraft.world.Container
-
setChanged
public void setChanged()- Specified by:
setChangedin interfacenet.minecraft.world.Container
-
stillValid
public boolean stillValid(net.minecraft.world.entity.player.Player player) - Specified by:
stillValidin interfacenet.minecraft.world.Container
-
canPlaceItem
public boolean canPlaceItem(int slot, net.minecraft.world.item.ItemStack stack) Whether automation without a face (a hopper under a plain container) may put the item in.- Specified by:
canPlaceItemin interfacenet.minecraft.world.Container
-
canTakeItem
public boolean canTakeItem(net.minecraft.world.Container into, int slot, net.minecraft.world.item.ItemStack stack) - Specified by:
canTakeItemin interfacenet.minecraft.world.Container
-
clearContent
public void clearContent()- Specified by:
clearContentin interfacenet.minecraft.world.Clearable
-
isItemValid
public boolean isItemValid(int slot, net.minecraft.world.item.ItemStack stack) Whether the slot's filter takes the item, whoever puts it in. -
canPlayerPlace
public boolean canPlayerPlace(int slot, net.minecraft.world.item.ItemStack stack) Whether a player may put the item in through a menu. -
canInsertFrom
public boolean canInsertFrom(int slot, net.minecraft.world.item.ItemStack stack, @Nullable @Nullable net.minecraft.core.Direction side) Whether automation may put the item in through a face (null: any face). -
canExtractFrom
public boolean canExtractFrom(int slot, @Nullable @Nullable net.minecraft.core.Direction side) Whether automation may take from the slot through a face (null: any face). -
getSlotLimit
public int getSlotLimit(int slot, net.minecraft.world.item.ItemStack stack) How many of the item the slot holds. -
insert
public net.minecraft.world.item.ItemStack insert(int slot, net.minecraft.world.item.ItemStack stack, boolean simulate) Puts as much ofstackas fits into one slot, for the holder's own code: filters and limits apply, roles don't.stackisn't changed.- Returns:
- what didn't fit
-
insert
public net.minecraft.world.item.ItemStack insert(net.minecraft.world.item.ItemStack stack, boolean simulate) Puts as much ofstackas fits anywhere, topping up matching stacks before filling empty slots. -
extract
public net.minecraft.world.item.ItemStack extract(int slot, int amount, boolean simulate) Takes up toamountfrom one slot, for the holder's own code. -
extract
public net.minecraft.world.item.ItemStack extract(Predicate<net.minecraft.world.item.ItemStack> filter, int amount, boolean simulate) Takes up toamountof the first item matchingfilter, gathered from every slot holding it. -
count
-
getItems
The slots, in order. Read-only; don't change the stacks in it either. -
copyItems
Copies of the stacks, in order. -
setItems
Replaces the contents; slots paststacks' end are emptied. -
toContents
public net.minecraft.world.item.component.ItemContainerContents toContents()The contents as an item component (the first 256 slots). -
fromContents
public void fromContents(net.minecraft.world.item.component.ItemContainerContents contents) -
dropContents
public void dropContents(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos) Spills the contents at a position and empties the container. -
comparatorSignal
public int comparatorSignal()The comparator signal the contents give (0 to 15). -
createSlot
public net.minecraft.world.inventory.Slot createSlot(int slot, int x, int y) A menu slot that respects the layout's filters, limits and roles. -
addListener
Callslistenerafter a slot changes (slot-1: several at once). -
removeListener
-
setValidator
Who may keep a menu on this container open; everyone by default. -
setChangeListener
Description copied from interface:TrackableCalled by the holder storing this value; calllistenerafter every change.nullunbinds.- Specified by:
setChangeListenerin interfaceTrackable
-
onChanged
protected void onChanged(int slot) Called after a slot changes (slot-1: several at once).
-