public abstract class InventoryView extends Object
Note: If you implement this interface but fail to satisfy the expected contracts of certain methods, there's no guarantee that the game will work as it should.
Modifier and Type | Class and Description |
---|---|
static class |
InventoryView.Property
Represents various extra properties of certain inventory windows.
|
Modifier and Type | Field and Description |
---|---|
static int |
OUTSIDE |
Constructor and Description |
---|
InventoryView() |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the inventory view.
|
int |
convertSlot(int rawSlot)
Converts a raw slot ID into its local slot ID into whichever of the two
inventories the slot points to.
|
int |
countSlots()
Check the total number of slots in this view, combining the upper and
lower inventories.
|
abstract @NotNull Inventory |
getBottomInventory()
Get the lower inventory involved in this transaction.
|
@Nullable ItemStack |
getCursor()
Get the item on the cursor of one of the viewing players.
|
@Nullable Inventory |
getInventory(int rawSlot)
Gets the inventory corresponding to the given raw slot ID.
|
@Nullable ItemStack |
getItem(int slot)
Gets one item in this inventory view by its raw slot ID.
|
abstract @NotNull HumanEntity |
getPlayer()
Get the player viewing.
|
InventoryType.SlotType |
getSlotType(int slot)
Determine the type of the slot by its raw slot ID.
|
abstract @NotNull String |
getTitle()
Deprecated.
in favour of
title() |
abstract @NotNull Inventory |
getTopInventory()
Get the upper inventory involved in this transaction.
|
abstract @NotNull InventoryType |
getType()
Determine the type of inventory involved in the transaction.
|
void |
setCursor(@Nullable ItemStack item)
Sets the item on the cursor of one of the viewing players.
|
void |
setItem(int slot,
@Nullable ItemStack item)
Sets one item in this inventory view by its raw slot ID.
|
boolean |
setProperty(@NotNull InventoryView.Property prop,
int value)
Sets an extra property of this inventory if supported by that
inventory, for example the state of a progress bar.
|
net.kyori.adventure.text.Component |
title()
Get the title of this inventory window.
|
public static final int OUTSIDE
@NotNull public abstract @NotNull Inventory getTopInventory()
@NotNull public abstract @NotNull Inventory getBottomInventory()
@NotNull public abstract @NotNull HumanEntity getPlayer()
@NotNull public abstract @NotNull InventoryType getType()
public void setItem(int slot, @Nullable @Nullable ItemStack item)
Note: If slot ID -999 is chosen, it may be expected that the item is dropped on the ground. This is not required behaviour, however.
slot
- The ID as returned by InventoryClickEvent.getRawSlot()item
- The new item to put in the slot, or null to clear it.@Nullable public @Nullable ItemStack getItem(int slot)
slot
- The ID as returned by InventoryClickEvent.getRawSlot()public final void setCursor(@Nullable @Nullable ItemStack item)
item
- The item to put on the cursor, or null to remove the item
on their cursor.@Nullable public final @Nullable ItemStack getCursor()
@Nullable public final @Nullable Inventory getInventory(int rawSlot)
OUTSIDE
null will be returned, otherwise
behaviour for illegal and negative slot IDs is undefined.
May be used with convertSlot(int)
to directly index an
underlying inventory.rawSlot
- The raw slot ID.public final int convertSlot(int rawSlot)
If the raw slot refers to the upper inventory, it will be returned unchanged and thus be suitable for getTopInventory().getItem(); if it refers to the lower inventory, the output will differ from the input and be suitable for getBottomInventory().getItem().
rawSlot
- The raw slot ID.@NotNull public final InventoryType.SlotType getSlotType(int slot)
If the type of the slot is unknown, then
InventoryType.SlotType#CONTAINER
will be returned.
slot
- The raw slot IDpublic final void close()
public final int countSlots()
Note though that it's possible for this to be greater than the sum of the two inventories if for example some slots are not being used.
public final boolean setProperty(@NotNull @NotNull InventoryView.Property prop, int value)
prop
- the window property to updatevalue
- the new value for the window property@NotNull public net.kyori.adventure.text.Component title()
null
. @Deprecated @NotNull public abstract @NotNull String getTitle()
title()
Copyright © 2021. All rights reserved.