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 | Description |
---|---|---|
static class |
InventoryView.Property |
Represents various extra properties of certain inventory windows.
|
Modifier and Type | Field | Description |
---|---|---|
static int |
OUTSIDE |
Constructor | Description |
---|---|
InventoryView() |
Modifier and Type | Method | 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 Inventory |
getBottomInventory() |
Get the lower inventory involved in this transaction.
|
ItemStack |
getCursor() |
Get the item on the cursor of one of the viewing players.
|
Inventory |
getInventory(int rawSlot) |
Gets the inventory corresponding to the given raw slot ID.
|
ItemStack |
getItem(int slot) |
Gets one item in this inventory view by its raw slot ID.
|
abstract HumanEntity |
getPlayer() |
Get the player viewing.
|
InventoryType.SlotType |
getSlotType(int slot) |
Determine the type of the slot by its raw slot ID.
|
abstract String |
getTitle() |
Get the title of this inventory window.
|
abstract Inventory |
getTopInventory() |
Get the upper inventory involved in this transaction.
|
abstract InventoryType |
getType() |
Determine the type of inventory involved in the transaction.
|
void |
setCursor(ItemStack item) |
Sets the item on the cursor of one of the viewing players.
|
void |
setItem(int slot,
ItemStack item) |
Sets one item in this inventory view by its raw slot ID.
|
boolean |
setProperty(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.
|
public static final int OUTSIDE
@NotNull public abstract Inventory getTopInventory()
@NotNull public abstract Inventory getBottomInventory()
@NotNull public abstract HumanEntity getPlayer()
@NotNull public abstract InventoryType getType()
public void setItem(int slot, @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 ItemStack getItem(int slot)
slot
- The ID as returned by InventoryClickEvent.getRawSlot()public final void setCursor(@Nullable ItemStack item)
item
- The item to put on the cursor, or null to remove the item
on their cursor.@Nullable public final ItemStack getCursor()
@Nullable public final 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 InventoryView.Property prop, int value)
prop
- the window property to updatevalue
- the new value for the window property@NotNull public abstract String getTitle()
Copyright © 2019. All rights reserved.