Class CreatedSlot
Slot to everything outside it. It keeps its place
in the hierarchy (panel, group, index) in final fields and belongs to a
CreatedSlotGroup.
It behaves like a vanilla slot. Every override calls super, so
vanilla's behavior and other mods' mixins still apply. It is also presented like
one: its position is vanilla's own Slot.x/y, vanilla's slot pass draws it,
and vanilla's getHoveredSlot finds it (see ContainerScreenLayers in
MenuKit). A third party's extractSlot mixin, or any code that walks
menu.slots and reads x/y, treats a created slot and a vanilla slot
the same because they go through the same calls. The overrides:
mayPlace: false when inert; in aSHULKER_STORAGEgroup, false for an item that can't go inside a container item, as vanilla'sShulkerBoxSlot; otherwise supermayPickup: false when inert, otherwise supergetItem: EMPTY when inert, otherwise superisActive: false when the panel is hidden, otherwise super
Each group is its own container
Every slot group on a menu has its ownContainer, stable
for the menu's life: all of a group's slots share it, no two groups share one (even
over the same storage), and none is shared with the menu's own slots. Vanilla and
other mods that tell containers apart by slot.container (sorting,
shift-click, move-all) treat each group as its own container. A menu's own
shift-click routing stops before every slot SlotKit appended, so a group takes a
shift-click only through its own route. SlotGroupCategories.groups(menu) is
the public way to ask which group a slot is in. Since 2.1.0.
A mod that mixes into Slot.mayPlace to add a global filter sees its
filter run on created slots through the super.mayPlace call, and the most
restrictive answer wins. A mod iterating slots sees inert created slots as empty,
which is a valid state for any slot.
Hierarchy: Screen, then Panel, then CreatedSlotGroup, then CreatedSlot.
-
Field Summary
Fields inherited from class net.minecraft.world.inventory.Slot
container, index, x, y -
Constructor Summary
ConstructorsConstructorDescriptionCreatedSlot(net.minecraft.world.Container container, int containerIndex, int x, int y, CreatedSlotGroup group, MenuPanel panel, String groupId, int localIndex) -
Method Summary
Modifier and TypeMethodDescriptionvoidactiveCount(IntSupplier count) Library use: ties the slot to its group's active count.address()This slot's createdAddress, the same in every menu.getGroup()The CreatedSlotGroup this slot belongs to.net.minecraft.world.item.ItemStackgetItem()Returns the item in this slot, orItemStack.EMPTYwhen the panel is inert, so a hidden panel's storage is never exposed.intIndex within the group (0-based).net.minecraft.resources.IdentifierThe group'sSlotSpec.emptyIconoutline when declared, drawn by vanilla on an empty slot.groupId()Group this slot belongs to within its panel.voidLibrary use: the panel is always shown on the server, and hidden only by the client's reveal.booleanisActive()Whether this slot is active (visible and usable).booleanisInert()True when this slot's panel is hidden, or the slot is past its group's active count.booleanmayPickup(net.minecraft.world.entity.player.Player player) Whether items can be taken.booleanmayPlace(net.minecraft.world.item.ItemStack stack) Whether this stack can be placed here.static @Nullable CreatedSlotof(net.minecraft.world.inventory.Slot slot) The created slotslotis, ornullfor any other slot.panelId()Panel this slot belongs to.voidset(net.minecraft.world.item.ItemStack stack) Writes the stack, unless the slot is inert on both sides.Methods inherited from class net.minecraft.world.inventory.Slot
allowModification, checkTakeAchievements, getContainerSlot, getMaxStackSize, getMaxStackSize, hasItem, isFake, isHighlightable, onQuickCraft, onQuickCraft, onSwapCraft, onTake, remove, safeClone, safeInsert, safeInsert, safeTake, setByPlayer, setByPlayer, setChanged, tryRemove
-
Constructor Details
-
Method Details
-
getNoItemIcon
public net.minecraft.resources.Identifier getNoItemIcon()The group'sSlotSpec.emptyIconoutline when declared, drawn by vanilla on an empty slot.- Overrides:
getNoItemIconin classnet.minecraft.world.inventory.Slot
-
of
The created slotslotis, ornullfor any other slot. Sees through creative's slot wrapper, so it works for a slot taken from any screen's menu. -
panelId
Panel this slot belongs to. -
groupId
Group this slot belongs to within its panel. -
getLocalIndex
public int getLocalIndex()Index within the group (0-based). -
getGroup
The CreatedSlotGroup this slot belongs to. -
address
-
isInert
public boolean isInert()True when this slot's panel is hidden, or the slot is past its group's active count. To the outside world an inert slot looks like no slot at all: getItem returns EMPTY, mayPlace returns false, and shift-click skips it. set does nothing, unless only this client's reveal hides the slot (seeset(ItemStack)).Public for third parties that want to check directly rather than rely on those methods.
-
activeCount
Library use: ties the slot to its group's active count. -
mayPlace
public boolean mayPlace(net.minecraft.world.item.ItemStack stack) Whether this stack can be placed here. An inert slot refuses. Otherwise this is vanilla's own answer, which SlotKit's slot gate (SKSlotGateMixin) has already checked against this slot's address. Calls super, so a mixin onSlot.mayPlacestill runs.A
SHULKER_STORAGEgroup holds a shulker box's contents, so it keeps vanilla'sShulkerBoxSlotrule: nothing that can't go inside a container item (a shulker box). Clicks, number keys, drags and shift-clicks all ask here.- Overrides:
mayPlacein classnet.minecraft.world.inventory.Slot
-
mayPickup
public boolean mayPickup(net.minecraft.world.entity.player.Player player) Whether items can be taken. Inert refuses; the slot gate and Curse of Binding are checked in SlotKit's mixin.- Overrides:
mayPickupin classnet.minecraft.world.inventory.Slot
-
getItem
public net.minecraft.world.item.ItemStack getItem()Returns the item in this slot, orItemStack.EMPTYwhen the panel is inert, so a hidden panel's storage is never exposed.isActive(),mayPlace(ItemStack)andmayPickup(Player)returning false block interaction but not reading. Without this override, anything that readsslot.getItem()on a hidden slot (vanilla'sbroadcastChangessyncing to the client, other mods' mixins onSlot.getItem, consumer code walkingmenu.slots) would see the real contents. That would leak per-player state kept in hidden-panel storage (lock state, private inventories, sort state) to the client and to any mod hook.Returning EMPTY while inert prevents that. When the panel becomes visible,
broadcastChangessees the change and sends the real contents to the client. The backingStoragestill holds the real items, and consumer code that owns the panel can read it directly.Inert means hidden from the world for both interaction and reading. Both are needed for the library's inertness guarantee, which SlotKit's validator tests.
- Overrides:
getItemin classnet.minecraft.world.inventory.Slot
-
set
public void set(net.minecraft.world.item.ItemStack stack) Writes the stack, unless the slot is inert on both sides. A slot inert on both sides reads as EMPTY there, so a write to it is the world catching up with that EMPTY (the server syncing it to the client, a creative client sending it back), not a real change. Taking it would wipe the items the slot's storage still holds.A slot hidden only by this client's reveal is different: the server shows it and syncs its real contents, so the client keeps them, and they're there the moment the slot is revealed (and for anything reading the storage meanwhile, a HUD). It still reads as EMPTY while hidden. The server never resends what it already sent, so dropping the write would leave the client empty for good. Creative's echo of that EMPTY back to the server is stopped on the client (
SKCreativeHiddenSlotMixin).- Overrides:
setin classnet.minecraft.world.inventory.Slot
-
isActive
public boolean isActive()Whether this slot is active (visible and usable).When false, vanilla skips the slot for rendering and hover detection. Together with
getItem()returning EMPTY while inert, this hides the slot from the world entirely.- Overrides:
isActivein classnet.minecraft.world.inventory.Slot
-