Class Inventory

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

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

  • Constructor Details

  • Method Details

    • getSelectedSlot

      public int getSelectedSlot()
    • setSelectedSlot

      public void setSelectedSlot(int pSlot)
    • getSelectedItem

      public ItemStack getSelectedItem()
    • setSelectedItem

      public ItemStack setSelectedItem(ItemStack pStack)
    • getSelectionSize

      public static int getSelectionSize()
    • getNonEquipmentItems

      public NonNullList<ItemStack> getNonEquipmentItems()
    • hasRemainingSpaceForItem

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

      public int getFreeSlot()
    • addAndPickItem

      public void addAndPickItem(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
    • isUsableForCrafting

      public static boolean isUsableForCrafting(ItemStack pStack)
    • findSlotMatchingCraftingIngredient

      public int findSlotMatchingCraftingIngredient(Holder<Item> pItem, ItemStack pStack)
    • getSuitableHotbarSlot

      public int getSuitableHotbarSlot()
    • 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)
    • createInventoryUpdatePacket

      public ClientboundSetPlayerInventoryPacket createInventoryUpdatePacket(int pSlot)
    • 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
    • save

      public void save(ValueOutput.TypedOutputList<ItemStackWithSlot> pOutput)
    • load

      public void load(ValueInput.TypedInputList<ItemStackWithSlot> pInput)
    • 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
    • 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(StackedItemContents pContents)
    • removeFromSelected

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