Skip to content

ItemSlot

Since 2.2.1

ItemSlot is a Minecraft item slot that integrates with the vanilla container system. It renders the held ItemStack, shows a hover highlight, and registers itself with the open AbstractContainerMenu for standard click-to-transfer behaviour. It also hooks into JEI, REI, and EMI when those mods are present.

Everything documented on UIElement (layout, styles, events, data bindings, etc.) applies here too.


Usage

// Bind to an item handler
var slot = new ItemSlot();
slot.bind(itemHandler, 0); // IItemHandlerModifiable + slot index
parent.addChild(slot);

// Or bind to a vanilla Slot directly
var slot2 = new ItemSlot(new Slot(inventory, 0, 0, 0));

// Phantom slot (XEI drag-drop support)
slot.xeiPhantom();
itemSlot({
    layout { width(18).height(18) }
}) {
    api { bind(itemHandler, 0) }
}
let slot = new ItemSlot();
slot.bind(itemHandler, 0);
parent.addChild(slot);

XML

<!-- Basic slot (no handler — uses LocalSlot) -->
<item-slot/>

<!-- With an item pre-set for display in the editor -->
<item-slot id="minecraft:diamond" count="1"/>

<!-- Disable XEI recipe lookup -->
<item-slot allow-xei-Lookup="false"/>
XML Attribute Type Description
allow-xei-Lookup boolean Whether clicking the slot triggers XEI (JEI/REI/EMI) recipe lookup. Default: true.
id / count / NBT Item attributes used to pre-fill the slot for editor display only.

Slot Style

hover-overlay

Texture drawn over the slot when the mouse hovers over it.

Default: ColorRectTexture(0x80FFFFFF) (semi-transparent white)

slot.slotStyle(style -> style.hoverOverlay(myTexture));
item-slot {
    hover-overlay: color(#FFFFFF80);
}

slot-overlay

Texture drawn over the slot background (always, or only when empty — see show-slot-overlay-only-empty).

Default: none (empty)

slot.slotStyle(style -> style.slotOverlay(myOverlay));
item-slot {
    slot-overlay: sprite("mymod:textures/gui/slot_icon.png");
}

show-slot-overlay-only-empty

When true, the slot-overlay is drawn only when the slot is empty.

Default: true

slot.slotStyle(style -> style.showSlotOverlayOnlyEmpty(false));
item-slot {
    show-slot-overlay-only-empty: false;
}

show-item-tooltips

Whether hovering the slot shows the standard item tooltip.

Default: true

slot.slotStyle(style -> style.showItemTooltips(false));
item-slot {
    show-item-tooltips: false;
}

is-player-slot

Marks this slot as a player inventory slot (used by the quick-move system).

Default: false

slot.slotStyle(style -> style.isPlayerSlot(true));
item-slot {
    is-player-slot: true;
}

accept-quick-move / quick-move-priority

Whether this slot participates in shift-click quick-move, and its priority when multiple slots compete.

Defaults: true / 0

slot.slotStyle(style -> style.acceptQuickMove(true).quickMovePriority(1));
item-slot {
    accept-quick-move: true;
    quick-move-priority: 1;
}

Value Binding

ItemSlot extends BindableUIElement<ItemStack>:

slot.bind(DataBindingBuilder.itemStack(
    () -> handler.getStackInSlot(0),
    stack -> handler.setStackInSlot(0, stack)
).build());

See Data Bindings for full details.


Fields

Name Type Access Description
slotStyle SlotStyle private (getter) Current slot style.
slot Slot private (getter) The bound Slot.

Methods

Method Returns Description
bind(IItemHandlerModifiable, int) ItemSlot Binds to an item handler at the given slot index.
bind(Slot) ItemSlot Binds to an existing vanilla Slot.
setItem(ItemStack) ItemSlot Sets the displayed item and notifies listeners.
setItem(ItemStack, boolean) ItemSlot Sets the displayed item; second param controls notification.
slotStyle(Consumer<SlotStyle>) ItemSlot Configures style fluently.
xeiPhantom() ItemSlot Enables XEI (JEI/REI/EMI) phantom drag-drop on this slot.
xeiRecipeIngredient(IngredientIO) ItemSlot Marks this slot as a recipe ingredient in XEI recipe views.
xeiRecipeSlot() ItemSlot Marks this slot as a recipe slot with default IngredientIO.NONE.
xeiRecipeSlot(IngredientIO, float) ItemSlot Marks as recipe slot with given I/O type and chance.
getFullTooltipTexts() List<Component> Returns the combined item and custom tooltip lines.