public class WItemSlot extends WWidget
Item slot widgets can contain multiple visual slots themselves. For example, a slot widget might be 5x3 with 15 visual slots in total.
Item slots are handled with so-called peers in the background.
They are instances of ValidatedSlot that handle the interactions
between the player and the widget.
setFilter(Predicate). For example:
// Only sand in this slot!
slot.setFilter(stack -> stack.getItem() == Items.SAND);
WItemSlot.ChangeListener that can handle changes
to item stacks in slots. For example:
slot.addChangeListener((slot, inventory, index, stack) -> {
if (stack.isEmpty() || stack.getCount() < stack.getMaxCount()) {
System.out.println("I'm not full yet!");
}
});
| Modifier and Type | Class and Description |
|---|---|
static interface |
WItemSlot.ChangeListener
A listener for changes in an item slot.
|
| Constructor and Description |
|---|
WItemSlot(net.minecraft.inventory.Inventory inventory,
int startIndex,
int slotsWide,
int slotsHigh,
boolean big) |
| Modifier and Type | Method and Description |
|---|---|
void |
addChangeListener(WItemSlot.ChangeListener listener)
Adds a change listener to this slot.
|
void |
addPainters()
Adds the default background painters to this widget and all children.
|
boolean |
canFocus()
Tests whether this widget can have the focus in the GUI.
|
protected ValidatedSlot |
createSlotPeer(net.minecraft.inventory.Inventory inventory,
int index,
int x,
int y)
Creates a slot peer for this slot widget.
|
@Nullable WWidget |
cycleFocus(boolean lookForwards)
Cycles the focus inside this widget.
|
@Nullable BackgroundPainter |
getBackgroundPainter()
Gets this slot widget's background painter.
|
java.util.function.Predicate<net.minecraft.item.ItemStack> |
getFilter()
Gets the item filter of this item slot.
|
int |
getFocusedSlot()
Gets the currently focused slot index.
|
int |
getHeight() |
int |
getWidth() |
boolean |
isBigSlot() |
boolean |
isInsertingAllowed()
Returns whether items can be inserted into this slot.
|
boolean |
isModifiable()
Returns true if the contents of this
WItemSlot can be modified by players. |
boolean |
isTakingAllowed()
Returns whether items can be taken from this slot.
|
static WItemSlot |
of(net.minecraft.inventory.Inventory inventory,
int index) |
static WItemSlot |
of(net.minecraft.inventory.Inventory inventory,
int startIndex,
int slotsWide,
int slotsHigh) |
static WItemSlot |
ofPlayerStorage(net.minecraft.inventory.Inventory inventory)
Creates a 9x3 slot widget from the "main" part of a player inventory.
|
void |
onHidden()
Notifies this widget that it won't be drawn and
hides any visible peers of itself and its children.
|
void |
onKeyPressed(int ch,
int key,
int modifiers)
Notifies this widget that a key has been pressed.
|
void |
onShown()
Notifies this widget that it is visible and
shows any hidden peers of itself and its children.
|
static WItemSlot |
outputOf(net.minecraft.inventory.Inventory inventory,
int index) |
void |
paint(net.minecraft.client.util.math.MatrixStack matrices,
int x,
int y,
int mouseX,
int mouseY)
Paints this widget.
|
void |
setBackgroundPainter(@Nullable BackgroundPainter painter)
Sets this item slot's background painter.
|
WItemSlot |
setFilter(java.util.function.Predicate<net.minecraft.item.ItemStack> filter)
Sets the item filter of this item slot.
|
WItemSlot |
setInsertingAllowed(boolean insertingAllowed)
Sets whether inserting items into this slot is allowed.
|
WItemSlot |
setModifiable(boolean modifiable) |
WItemSlot |
setTakingAllowed(boolean takingAllowed)
Sets whether taking items from this slot is allowed.
|
void |
validate(GuiDescription host)
Creates component peers, lays out children, and initializes animation data for this Widget and all its children.
|
addTooltip, canResize, createPeers, getAbsoluteX, getAbsoluteY, getHost, getParent, getX, getY, hit, isActivationKey, isFocused, isWithinBounds, onCharTyped, onClick, onFocusGained, onFocusLost, onKeyReleased, onMouseDown, onMouseDrag, onMouseMove, onMouseScroll, onMouseUp, releaseFocus, renderTooltip, requestFocus, setHost, setLocation, setParent, setSize, tickpublic WItemSlot(net.minecraft.inventory.Inventory inventory,
int startIndex,
int slotsWide,
int slotsHigh,
boolean big)
public static WItemSlot of(net.minecraft.inventory.Inventory inventory, int index)
public static WItemSlot of(net.minecraft.inventory.Inventory inventory, int startIndex, int slotsWide, int slotsHigh)
public static WItemSlot outputOf(net.minecraft.inventory.Inventory inventory, int index)
public static WItemSlot ofPlayerStorage(net.minecraft.inventory.Inventory inventory)
inventory - the player inventoryWPlayerInvPanelpublic boolean canFocus()
WWidgetpublic boolean isBigSlot()
public boolean isModifiable()
WItemSlot can be modified by players.public WItemSlot setModifiable(boolean modifiable)
public boolean isInsertingAllowed()
public WItemSlot setInsertingAllowed(boolean insertingAllowed)
insertingAllowed - true if items can be inserted, false otherwisepublic boolean isTakingAllowed()
public WItemSlot setTakingAllowed(boolean takingAllowed)
takingAllowed - true if items can be taken, false otherwisepublic int getFocusedSlot()
public void validate(GuiDescription host)
WWidget@Environment(value=CLIENT)
public void onKeyPressed(int ch,
int key,
int modifiers)
WWidgetonKeyPressed in class WWidgetkey - the GLFW scancode of the keyprotected ValidatedSlot createSlotPeer(net.minecraft.inventory.Inventory inventory, int index, int x, int y)
inventory - the slot inventoryindex - the index in the inventoryx - the X coordinatey - the Y coordinate@Nullable @Environment(value=CLIENT) public @Nullable BackgroundPainter getBackgroundPainter()
@Environment(value=CLIENT)
public void setBackgroundPainter(@Nullable
@Nullable BackgroundPainter painter)
painter - the new painterpublic java.util.function.Predicate<net.minecraft.item.ItemStack> getFilter()
public WItemSlot setFilter(java.util.function.Predicate<net.minecraft.item.ItemStack> filter)
filter - the new item filter@Environment(value=CLIENT)
public void paint(net.minecraft.client.util.math.MatrixStack matrices,
int x,
int y,
int mouseX,
int mouseY)
WWidget@Nullable public @Nullable WWidget cycleFocus(boolean lookForwards)
WWidgetIf this widget is not focusable, returns null.
cycleFocus in class WWidgetlookForwards - whether this should cycle forwards (true) or backwards (false)public void addChangeListener(WItemSlot.ChangeListener listener)
listener - the added listenerjava.lang.NullPointerException - if the listener is nullpublic void onShown()
WWidgetpublic void onHidden()
WWidgetThe default implementation releases this widget's focus if it is focused. Overriding implementations might want to do this as well.
@Environment(value=CLIENT) public void addPainters()
WWidgetAlways called before GuiDescription.addPainters() to allow users to modify painters.
addPainters in class WWidget