Class Inventory
java.lang.Object
net.minecraft.world.entity.player.Inventory
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int[]
final NonNullList
<ItemStack> private final List
<NonNullList<ItemStack>> static final int[]
static final int
final NonNullList
<ItemStack> static final int
final NonNullList
<ItemStack> final Player
static final int
int
private static final int
static final int
private int
Fields inherited from interface net.minecraft.world.Container
DEFAULT_DISTANCE_BUFFER
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Adds the stack to the specified slot in the player's inventory.boolean
Adds the stack to the first empty slot in the player's inventory.private int
addResource
(int pSlot, ItemStack pStack) 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.void
int
clearOrCountMatchingItems
(Predicate<ItemStack> pStackPredicate, int pMaxCount, Container pInventory) boolean
boolean
boolean
Returnstrue
if the specifiedItemStack
exists in the inventory.void
dropAll()
void
fillStackedContents
(StackedContents pStackedContent) int
findSlotMatchingItem
(ItemStack pStack) Finds the stack or an equivalent one in the main inventoryint
findSlotMatchingUnusedItem
(ItemStack pStack) getArmor
(int pSlot) int
float
getDestroySpeed
(BlockState pState) int
getItem
(int pIndex) Returns the stack in the given slot.getName()
static int
int
getSlotWithRemainingSpace
(ItemStack pStack) Stores a stack in the player's inventory.int
int
private boolean
hasRemainingSpaceForItem
(ItemStack pDestination, ItemStack pOrigin) boolean
isEmpty()
static boolean
isHotbarSlot
(int pIndex) void
Reads from the given tag list and fills the slots in the inventory with the correct items.void
pickSlot
(int pIndex) void
placeItemBackInInventory
(ItemStack pStack) void
placeItemBackInInventory
(ItemStack pStack, boolean pSendPacket) removeFromSelected
(boolean pRemoveStack) removeItem
(int pIndex, int pCount) Removes up to a specified number of items from an inventory slot and returns them in a new stack.void
removeItem
(ItemStack pStack) removeItemNoUpdate
(int pIndex) Removes a stack from the given slot and returns it.void
replaceWith
(Inventory pPlayerInventory) Copy the ItemStack contents from another InventoryPlayer instanceWrites the inventory out as a list of compound tags.void
void
Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).void
setPickedItem
(ItemStack pStack) boolean
stillValid
(Player pPlayer) Don't rename this method to canInteractWith due to conflicts with Containervoid
swapPaint
(double pDirection) Change the selected item in the hotbar after a mouse scroll.void
tick()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.minecraft.world.Container
canPlaceItem, canTakeItem, countItem, getMaxStackSize, getMaxStackSize, hasAnyMatching, hasAnyOf, startOpen, stopOpen
Methods inherited from interface net.minecraft.world.Nameable
getCustomName, getDisplayName, hasCustomName
-
Field Details
-
POP_TIME_DURATION
public static final int POP_TIME_DURATION- See Also:
-
INVENTORY_SIZE
public static final int INVENTORY_SIZE- See Also:
-
SELECTION_SIZE
private static final int SELECTION_SIZE- See Also:
-
SLOT_OFFHAND
public static final int SLOT_OFFHAND- See Also:
-
NOT_FOUND_INDEX
public static final int NOT_FOUND_INDEX- See Also:
-
ALL_ARMOR_SLOTS
public static final int[] ALL_ARMOR_SLOTS -
HELMET_SLOT_ONLY
public static final int[] HELMET_SLOT_ONLY -
items
-
armor
-
offhand
-
compartments
-
selected
public int selected -
player
-
timesChanged
private int timesChanged
-
-
Constructor Details
-
Inventory
-
-
Method Details
-
getSelected
-
getSelectionSize
public static int getSelectionSize() -
hasRemainingSpaceForItem
-
getFreeSlot
public int getFreeSlot() -
setPickedItem
-
pickSlot
public void pickSlot(int pIndex) -
isHotbarSlot
public static boolean isHotbarSlot(int pIndex) -
findSlotMatchingItem
Finds the stack or an equivalent one in the main inventory -
findSlotMatchingUnusedItem
-
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 ifdirection
is positive, or to the right if negative. -
clearOrCountMatchingItems
-
addResource
This function stores as many items of an ItemStack as possible in a matching slot and returns the quantity of left over items. -
addResource
-
getSlotWithRemainingSpace
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
Adds the stack to the first empty slot in the player's inventory. Returnsfalse
if it's not possible to place the entire stack in the inventory. -
add
Adds the stack to the specified slot in the player's inventory. Returnsfalse
if it's not possible to place the entire stack in the inventory. -
placeItemBackInInventory
-
placeItemBackInInventory
-
removeItem
Removes up to a specified number of items from an inventory slot and returns them in a new stack.- Specified by:
removeItem
in interfaceContainer
-
removeItem
-
removeItemNoUpdate
Removes a stack from the given slot and returns it.- Specified by:
removeItemNoUpdate
in interfaceContainer
-
setItem
Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections). -
getDestroySpeed
-
save
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
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 interfaceContainer
-
isEmpty
public boolean isEmpty() -
getItem
Returns the stack in the given slot. -
getName
-
getArmor
- 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 interfaceContainer
-
getTimesChanged
public int getTimesChanged() -
stillValid
Don't rename this method to canInteractWith due to conflicts with Container- Specified by:
stillValid
in interfaceContainer
-
contains
Returnstrue
if the specifiedItemStack
exists in the inventory. -
contains
-
contains
-
replaceWith
Copy the ItemStack contents from another InventoryPlayer instance -
clearContent
public void clearContent()- Specified by:
clearContent
in interfaceClearable
-
fillStackedContents
-
removeFromSelected
- Parameters:
pRemoveStack
- Whether to remove the entire stack of items. Iffalse
, removes a single item.
-