Class Inventory

java.lang.Object
net.minestom.server.inventory.AbstractInventory
net.minestom.server.inventory.Inventory
All Implemented Interfaces:
InventoryClickHandler, Taggable, TagReadable, TagWritable, Viewable
Direct Known Subclasses:
AnvilInventory, BeaconInventory, BrewingStandInventory, EnchantmentTableInventory, FurnaceInventory, VillagerInventory

public non-sealed class Inventory extends AbstractInventory
Represents an inventory which can be viewed by a collection of Player.

You can create one with Inventory(InventoryType, String) or by making your own subclass. It can then be opened using Player.openInventory(Inventory).

  • Constructor Details

    • Inventory

      public Inventory(@NotNull @NotNull InventoryType inventoryType, @NotNull @NotNull Component title)
    • Inventory

      public Inventory(@NotNull @NotNull InventoryType inventoryType, @NotNull @NotNull String title)
  • Method Details

    • getInventoryType

      @NotNull public @NotNull InventoryType getInventoryType()
      Gets the inventory type.
      Returns:
      the inventory type
    • getTitle

      @NotNull public @NotNull Component getTitle()
      Gets the inventory title.
      Returns:
      the inventory title
    • setTitle

      public void setTitle(@NotNull @NotNull Component title)
      Changes the inventory title.
      Parameters:
      title - the new inventory title
    • getWindowId

      public byte getWindowId()
      Description copied from class: AbstractInventory
      Gets this window id.

      This is the id that the client will send to identify the affected inventory, mostly used by packets.

      Specified by:
      getWindowId in class AbstractInventory
      Returns:
      the window id
    • addViewer

      public boolean addViewer(@NotNull @NotNull Player player)
      This will not open the inventory for player, use Player.openInventory(Inventory).
      Specified by:
      addViewer in interface Viewable
      Overrides:
      addViewer in class AbstractInventory
      Parameters:
      player - the viewer to add
      Returns:
      true if the player has successfully been added
    • removeViewer

      public boolean removeViewer(@NotNull @NotNull Player player)
      This will not close the inventory for player, use Player.closeInventory().
      Specified by:
      removeViewer in interface Viewable
      Overrides:
      removeViewer in class AbstractInventory
      Parameters:
      player - the viewer to remove
      Returns:
      true if the player has successfully been removed
    • getCursorItem

      @Deprecated @NotNull public @NotNull ItemStack getCursorItem(@NotNull @NotNull Player player)
      Deprecated.
      normal inventories no longer store cursor items
      Gets the cursor item of a player.
      See Also:
    • setCursorItem

      @Deprecated public void setCursorItem(@NotNull @NotNull Player player, @NotNull @NotNull ItemStack cursorItem)
      Deprecated.
      normal inventories no longer store cursor items
      Changes the cursor item of a player.
      See Also:
    • sendProperty

      protected void sendProperty(@NotNull @NotNull InventoryProperty property, short value)
      Sends a window property to all viewers.
      Parameters:
      property - the property to send
      value - the value of the property
      See Also:
    • leftClick

      public boolean leftClick(@NotNull @NotNull Player player, int slot)
      Description copied from interface: InventoryClickHandler
      Called when a Player left click in the inventory. Can also be to drop the cursor item
      Parameters:
      player - the player who clicked
      slot - the slot number
      Returns:
      true if the click hasn't been cancelled, false otherwise
    • rightClick

      public boolean rightClick(@NotNull @NotNull Player player, int slot)
      Description copied from interface: InventoryClickHandler
      Called when a Player right click in the inventory. Can also be to drop the cursor item
      Parameters:
      player - the player who clicked
      slot - the slot number
      Returns:
      true if the click hasn't been cancelled, false otherwise
    • shiftClick

      public boolean shiftClick(@NotNull @NotNull Player player, int slot)
      Description copied from interface: InventoryClickHandler
      Called when a Player shift click in the inventory
      Parameters:
      player - the player who clicked
      slot - the slot number
      Returns:
      true if the click hasn't been cancelled, false otherwise
    • changeHeld

      public boolean changeHeld(@NotNull @NotNull Player player, int slot, int key)
      Description copied from interface: InventoryClickHandler
      Called when a Player held click in the inventory
      Parameters:
      player - the player who clicked
      slot - the slot number
      key - the held slot (0-8) pressed
      Returns:
      true if the click hasn't been cancelled, false otherwise
    • middleClick

      public boolean middleClick(@NotNull @NotNull Player player, int slot)
    • drop

      public boolean drop(@NotNull @NotNull Player player, boolean all, int slot, int button)
      Description copied from interface: InventoryClickHandler
      Called when a Player press the drop button
      Parameters:
      player - the player who clicked
      all -
      slot - the slot number
      button - -999 if clicking outside, normal if he is not
      Returns:
      true if the drop hasn't been cancelled, false otherwise
    • dragging

      public boolean dragging(@NotNull @NotNull Player player, int slot, int button)
    • doubleClick

      public boolean doubleClick(@NotNull @NotNull Player player, int slot)
      Description copied from interface: InventoryClickHandler
      Called when a Player double click in the inventory
      Parameters:
      player - the player who clicked
      slot - the slot number
      Returns:
      true if the click hasn't been cancelled, false otherwise