Class Inventory

java.lang.Object
net.minecraft.world.entity.player.Inventory
All Implemented Interfaces:
Clearable, Container, Nameable

public class Inventory extends Object implements Container, Nameable
  • Field Details

  • Constructor Details

    • Inventory

      public Inventory(Player pPlayer)
  • Method Details

    • getSelected

      public ItemStack getSelected()
    • getSelectionSize

      public static int getSelectionSize()
    • hasRemainingSpaceForItem

      private boolean hasRemainingSpaceForItem(ItemStack pDestination, ItemStack pOrigin)
    • getFreeSlot

      public int getFreeSlot()
    • setPickedItem

      public void setPickedItem(ItemStack pStack)
    • pickSlot

      public void pickSlot(int pIndex)
    • isHotbarSlot

      public static boolean isHotbarSlot(int pIndex)
    • findSlotMatchingItem

      public int findSlotMatchingItem(ItemStack pStack)
      Finds the stack or an equivalent one in the main inventory
    • findSlotMatchingUnusedItem

      public int findSlotMatchingUnusedItem(ItemStack pStack)
    • getSuitableHotbarSlot

      public int getSuitableHotbarSlot()
    • swapPaint

      public void swapPaint(double pDirection)
      Change the selected item in the hotbar after a mouse scroll. Select the slot to the left if direction is positive, or to the right if negative.
    • clearOrCountMatchingItems

      public int clearOrCountMatchingItems(Predicate<ItemStack> pStackPredicate, int pMaxCount, Container pInventory)
    • addResource

      private int addResource(ItemStack pStack)
      This function stores as many items of an ItemStack as possible in a matching slot and returns the quantity of left over items.
    • addResource

      private int addResource(int pSlot, ItemStack pStack)
    • getSlotWithRemainingSpace

      public int getSlotWithRemainingSpace(ItemStack pStack)
      Stores a stack in the player's inventory. It first tries to place it in the selected slot in the player's hotbar, then the offhand slot, then any available/empty slot in the player's inventory.
    • tick

      public void tick()
    • add

      public boolean add(ItemStack pStack)
      Adds the stack to the first empty slot in the player's inventory. Returns false if it's not possible to place the entire stack in the inventory.
    • add

      public boolean add(int pSlot, ItemStack pStack)
      Adds the stack to the specified slot in the player's inventory. Returns false if it's not possible to place the entire stack in the inventory.
    • placeItemBackInInventory

      public void placeItemBackInInventory(ItemStack pStack)
    • placeItemBackInInventory

      public void placeItemBackInInventory(ItemStack pStack, boolean pSendPacket)
    • removeItem

      public ItemStack removeItem(int pIndex, int pCount)
      Removes up to a specified number of items from an inventory slot and returns them in a new stack.
      Specified by:
      removeItem in interface Container
    • removeItem

      public void removeItem(ItemStack pStack)
    • removeItemNoUpdate

      public ItemStack removeItemNoUpdate(int pIndex)
      Removes a stack from the given slot and returns it.
      Specified by:
      removeItemNoUpdate in interface Container
    • setItem

      public void setItem(int pIndex, ItemStack pStack)
      Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
      Specified by:
      setItem in interface Container
    • getDestroySpeed

      public float getDestroySpeed(BlockState pState)
    • save

      public ListTag save(ListTag pListTag)
      Writes the inventory out as a list of compound tags. This is where the slot indices are used (+100 for armor, +80 for crafting).
    • load

      public void load(ListTag pListTag)
      Reads from the given tag list and fills the slots in the inventory with the correct items.
    • getContainerSize

      public int getContainerSize()
      Specified by:
      getContainerSize in interface Container
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Container
    • getItem

      public ItemStack getItem(int pIndex)
      Returns the stack in the given slot.
      Specified by:
      getItem in interface Container
    • getName

      public Component getName()
      Specified by:
      getName in interface Nameable
    • getArmor

      public ItemStack getArmor(int pSlot)
      Returns:
      a player armor item (as an ItemStack) contained in specified armor slot
    • dropAll

      public void dropAll()
    • setChanged

      public void setChanged()
      Specified by:
      setChanged in interface Container
    • getTimesChanged

      public int getTimesChanged()
    • stillValid

      public boolean stillValid(Player pPlayer)
      Don't rename this method to canInteractWith due to conflicts with Container
      Specified by:
      stillValid in interface Container
    • contains

      public boolean contains(ItemStack pStack)
      Returns true if the specified ItemStack exists in the inventory.
    • contains

      public boolean contains(TagKey<Item> pTag)
    • contains

      public boolean contains(Predicate<ItemStack> pPredicate)
    • replaceWith

      public void replaceWith(Inventory pPlayerInventory)
      Copy the ItemStack contents from another InventoryPlayer instance
    • clearContent

      public void clearContent()
      Specified by:
      clearContent in interface Clearable
    • fillStackedContents

      public void fillStackedContents(StackedContents pStackedContent)
    • removeFromSelected

      public ItemStack removeFromSelected(boolean pRemoveStack)
      Parameters:
      pRemoveStack - Whether to remove the entire stack of items. If false, removes a single item.