Interface InventoryView

All Known Subinterfaces:
AnvilView, BeaconView, BrewingStandView, CrafterView, EnchantmentView, FurnaceView, LecternView, LoomView, MerchantView, StonecutterView

public interface InventoryView
Represents a view linking two inventories and a single player (whose inventory may or may not be one of the two).
  • Field Details

  • Method Details

    • getTopInventory

      @NotNull @NotNull Inventory getTopInventory()
      Get the upper inventory involved in this transaction.
      Returns:
      the inventory
    • getBottomInventory

      @NotNull @NotNull Inventory getBottomInventory()
      Get the lower inventory involved in this transaction.
      Returns:
      the inventory
    • getPlayer

      Get the player viewing.
      Returns:
      the player
    • getType

      Determine the type of inventory involved in the transaction. This indicates the window style being shown. It will never return PLAYER, since that is common to all windows.
      Returns:
      the inventory type
    • setItem

      void setItem(int slot, @Nullable @Nullable ItemStack item)
      Sets one item in this inventory view by its raw slot ID.

      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.

      Parameters:
      slot - The ID as returned by InventoryClickEvent.getRawSlot()
      item - The new item to put in the slot, or null to clear it.
    • getItem

      @Nullable @Nullable ItemStack getItem(int slot)
      Gets one item in this inventory view by its raw slot ID.
      Parameters:
      slot - The ID as returned by InventoryClickEvent.getRawSlot()
      Returns:
      The item currently in the slot.
    • setCursor

      void setCursor(@Nullable @Nullable ItemStack item)
      Sets the item on the cursor of one of the viewing players.
      Parameters:
      item - The item to put on the cursor, or null to remove the item on their cursor.
    • getCursor

      Get the item on the cursor of one of the viewing players.
      Returns:
      The item on the player's cursor, or an empty stack if they aren't holding one.
    • getInventory

      @Nullable @Nullable Inventory getInventory(int rawSlot)
      Gets the inventory corresponding to the given raw slot ID. If the slot ID is 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.
      Parameters:
      rawSlot - The raw slot ID.
      Returns:
      corresponding inventory, or null
    • convertSlot

      int convertSlot(int rawSlot)
      Converts a raw slot ID into its local slot ID into whichever of the two inventories the slot points to.

      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().

      Parameters:
      rawSlot - The raw slot ID.
      Returns:
      The converted slot ID.
    • getSlotType

      @NotNull InventoryType.SlotType getSlotType(int slot)
      Determine the type of the slot by its raw slot ID.

      If the type of the slot is unknown, then InventoryType.SlotType.CONTAINER will be returned.

      Parameters:
      slot - The raw slot ID
      Returns:
      the slot type
    • close

      void close()
      Closes the inventory view.
    • countSlots

      int countSlots()
      Check the total number of slots in this view, combining the upper and lower inventories.

      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.

      Returns:
      The total size
    • setProperty

      boolean setProperty(@NotNull @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.
      Parameters:
      prop - the window property to update
      value - the new value for the window property
      Returns:
      true if the property was updated successfully, false if the property is not supported by that inventory
    • title

      @NotNull default Component title()
      Get the title of this inventory window.
      Returns:
      The title.
    • getTitle

      Deprecated.
      in favour of title()
      Get the title of this inventory window.
      Returns:
      The title.
    • getOriginalTitle

      @NotNull @Deprecated(since="1.21.1") @NotNull String getOriginalTitle()
      Deprecated.
      changing the title is not supported
      Get the original title of this inventory window, before any changes were made using setTitle(String).
      Returns:
      the original title
    • setTitle

      @Deprecated(since="1.21.1") void setTitle(@NotNull @NotNull String title)
      Deprecated.
      changing the title is not supported. This method has poorly defined and broken behaviors. It should not be used.
      Sets the title of this inventory window to the specified title if the inventory window supports it.

      Note if the inventory does not support titles that can be changed (ie, it is not creatable or viewed by a player), then this method will throw an exception.

      Parameters:
      title - The new title.