Package net.minecraft.inventory
Class SimpleInventory
java.lang.Object
net.minecraft.inventory.SimpleInventory
- All Implemented Interfaces:
Inventory,RecipeInputProvider,Clearable
- Direct Known Subclasses:
ComposterBlock.ComposterInventory,ComposterBlock.DummyInventory,ComposterBlock.FullComposterInventory,EnderChestInventory
A generic implementation of
Inventory. This is used in a number of
places, mostly:
- To store the input of a
ScreenHandlerwhile it is open. The inventory is stored as a field, and the screen handler will have a slot backed by that inventory. - When defining the clientside constructor for a
ScreenHandlersubclass. The contents of the inventory will then be automatically synced from the serverside screen handler, which queries the original inventory. - For entities and block entities which do not interact with hoppers and therefore
do not need to implement
Inventorythemselves.
Changes to the inventory can be listened to either by subclassing this and
overriding markDirty(), or by using addListener(net.minecraft.inventory.InventoryChangedListener).
- Mappings:
Namespace Name named net/minecraft/inventory/SimpleInventoryintermediary net/minecraft/class_1277official bra
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final DefaultedList<ItemStack> private @Nullable List<InventoryChangedListener> private final intFields inherited from interface net.minecraft.inventory.Inventory
DEFAULT_MAX_INTERACTION_RANGE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(InventoryChangedListener listener) Adds alistenerfor inventory modifications.Addsstackto this inventory as much as possible.private voidaddToExistingSlot(ItemStack stack) private voidaddToNewSlot(ItemStack stack) booleanReturns whetherstackcan be inserted into this inventory.booleancanPlayerUse(PlayerEntity player) Returns whetherplayercan use this inventory.voidclear()Clears this inventory and returns all the non-empty stacks in a list.getStack(int slot) Returns the stack currently stored atslot.booleanisEmpty()Returns whether the inventory consists entirely of empty item stacks.voidMarks the inventory as modified.voidprovideRecipeInputs(RecipeMatcher finder) voidreadNbtList(NbtList list, RegistryWrapper.WrapperLookup registries) Reads the item stacks fromnbtList.removeItem(Item item, int count) Searches this inventory for the specified item and removes the given amount from this inventory.voidremoveListener(InventoryChangedListener listener) Removes alistenerpreviously added by#addListener.removeStack(int slot) Removes the stack currently stored atslot.removeStack(int slot, int amount) Removes a specific number of items fromslot.voidSets the stack stored atslottostack.intsize()Returns the size of the inventory.toNbtList(RegistryWrapper.WrapperLookup registries) Returns an NBT list of non-empty item stacks.toString()private voidMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface net.minecraft.inventory.Inventory
canTransferTo, containsAny, containsAny, count, getMaxCount, getMaxCountPerStack, isValid, onClose, onOpen
-
Field Details
-
size
private final int size- Mappings:
Namespace Name Mixin selector named sizeLnet/minecraft/inventory/SimpleInventory;size:Iintermediary field_5831Lnet/minecraft/class_1277;field_5831:Iofficial bLbra;b:I
-
heldStacks
- Mappings:
Namespace Name Mixin selector named heldStacksLnet/minecraft/inventory/SimpleInventory;heldStacks:Lnet/minecraft/util/collection/DefaultedList;intermediary field_5828Lnet/minecraft/class_1277;field_5828:Lnet/minecraft/class_2371;official cLbra;c:Ljv;
-
listeners
- Mappings:
Namespace Name Mixin selector named listenersLnet/minecraft/inventory/SimpleInventory;listeners:Ljava/util/List;intermediary field_5829Lnet/minecraft/class_1277;field_5829:Ljava/util/List;official dLbra;d:Ljava/util/List;
-
-
Constructor Details
-
SimpleInventory
public SimpleInventory(int size) - Mappings:
Namespace Name Mixin selector named <init>Lnet/minecraft/inventory/SimpleInventory;<init>(I)Vintermediary <init>Lnet/minecraft/class_1277;<init>(I)Vofficial <init>Lbra;<init>(I)V
-
SimpleInventory
- Mappings:
Namespace Name Mixin selector named <init>Lnet/minecraft/inventory/SimpleInventory;<init>([Lnet/minecraft/item/ItemStack;)Vintermediary <init>Lnet/minecraft/class_1277;<init>([Lnet/minecraft/class_1799;)Vofficial <init>Lbra;<init>([Lcuq;)V
-
-
Method Details
-
addListener
Adds alistenerfor inventory modifications. If a listener is added multiple times, it will also be triggered multiple times.- Mappings:
Namespace Name Mixin selector named addListenerLnet/minecraft/inventory/SimpleInventory;addListener(Lnet/minecraft/inventory/InventoryChangedListener;)Vintermediary method_5489Lnet/minecraft/class_1277;method_5489(Lnet/minecraft/class_1265;)Vofficial aLbra;a(Lbqm;)V
-
removeListener
Removes alistenerpreviously added by#addListener. Does nothing when the listener was not found.- Mappings:
Namespace Name Mixin selector named removeListenerLnet/minecraft/inventory/SimpleInventory;removeListener(Lnet/minecraft/inventory/InventoryChangedListener;)Vintermediary method_5488Lnet/minecraft/class_1277;method_5488(Lnet/minecraft/class_1265;)Vofficial bLbra;b(Lbqm;)V
-
getStack
Returns the stack currently stored atslot.If the slot is empty, or is outside the bounds of this inventory, this returns
ItemStack.EMPTY.- Specified by:
getStackin interfaceInventory- Returns:
- the stack currently stored at
slot - Mappings:
Namespace Name Mixin selector named getStackLnet/minecraft/inventory/Inventory;getStack(I)Lnet/minecraft/item/ItemStack;intermediary method_5438Lnet/minecraft/class_1263;method_5438(I)Lnet/minecraft/class_1799;official aLbqk;a(I)Lcuq;
-
clearToList
Clears this inventory and returns all the non-empty stacks in a list.- Returns:
- the non-empty stacks previously in the inventory
- Mappings:
Namespace Name Mixin selector named clearToListLnet/minecraft/inventory/SimpleInventory;clearToList()Ljava/util/List;intermediary method_24514Lnet/minecraft/class_1277;method_24514()Ljava/util/List;official fLbra;f()Ljava/util/List;
-
removeStack
Removes a specific number of items fromslot.- Specified by:
removeStackin interfaceInventory- Returns:
- the removed items as a stack
- Mappings:
Namespace Name Mixin selector named removeStackLnet/minecraft/inventory/Inventory;removeStack(II)Lnet/minecraft/item/ItemStack;intermediary method_5434Lnet/minecraft/class_1263;method_5434(II)Lnet/minecraft/class_1799;official aLbqk;a(II)Lcuq;
-
removeItem
Searches this inventory for the specified item and removes the given amount from this inventory.- Returns:
- the stack of removed items
- Mappings:
Namespace Name Mixin selector named removeItemLnet/minecraft/inventory/SimpleInventory;removeItem(Lnet/minecraft/item/Item;I)Lnet/minecraft/item/ItemStack;intermediary method_20631Lnet/minecraft/class_1277;method_20631(Lnet/minecraft/class_1792;I)Lnet/minecraft/class_1799;official aLbra;a(Lcul;I)Lcuq;
-
addStack
Addsstackto this inventory as much as possible. It is possible that the item stack gets inserted into a non-empty slot or spread across several slots, if it can combine with other stack(s) in this inventory.- Returns:
- the leftover part of the stack, or
ItemStack#EMPTYif the entire stack fit inside the inventory - Mappings:
Namespace Name Mixin selector named addStackLnet/minecraft/inventory/SimpleInventory;addStack(Lnet/minecraft/item/ItemStack;)Lnet/minecraft/item/ItemStack;intermediary method_5491Lnet/minecraft/class_1277;method_5491(Lnet/minecraft/class_1799;)Lnet/minecraft/class_1799;official bLbra;b(Lcuq;)Lcuq;
-
canInsert
Returns whetherstackcan be inserted into this inventory.- Returns:
- whether
stackcan be inserted into this inventory - Mappings:
Namespace Name Mixin selector named canInsertLnet/minecraft/inventory/SimpleInventory;canInsert(Lnet/minecraft/item/ItemStack;)Zintermediary method_27070Lnet/minecraft/class_1277;method_27070(Lnet/minecraft/class_1799;)Zofficial cLbra;c(Lcuq;)Z
-
removeStack
Removes the stack currently stored atslot.- Specified by:
removeStackin interfaceInventory- Returns:
- the stack previously stored at the indicated slot
- Mappings:
Namespace Name Mixin selector named removeStackLnet/minecraft/inventory/Inventory;removeStack(I)Lnet/minecraft/item/ItemStack;intermediary method_5441Lnet/minecraft/class_1263;method_5441(I)Lnet/minecraft/class_1799;official bLbqk;b(I)Lcuq;
-
setStack
Sets the stack stored atslottostack. -
size
public int size()Returns the size of the inventory.The inventory should support the slot ID from
0tosize() - 1. This should remain constant throughout the inventory's lifetime. -
isEmpty
public boolean isEmpty()Returns whether the inventory consists entirely of empty item stacks.- Specified by:
isEmptyin interfaceInventory- Returns:
- whether the inventory consists entirely of empty item stacks
- Mappings:
Namespace Name Mixin selector named isEmptyLnet/minecraft/inventory/Inventory;isEmpty()Zintermediary method_5442Lnet/minecraft/class_1263;method_5442()Zofficial cLbqk;c()Z
-
markDirty
public void markDirty()Marks the inventory as modified. Implementations should call this method every time the inventory is changed in any way.- Specified by:
markDirtyin interfaceInventory- See Also:
- API Note:
- Implementations should mark the inventory for synchronization or
saving in this method. Since this is called frequently, it is not recommended to
synchronize or save the inventory directly in this method. If this inventory is
implemented in a block entity, then it should always call
super.markDirty();to ensure the block entity gets saved. - Mappings:
Namespace Name Mixin selector named markDirtyLnet/minecraft/inventory/Inventory;markDirty()Vintermediary method_5431Lnet/minecraft/class_1263;method_5431()Vofficial eLbqk;e()V
-
canPlayerUse
Returns whetherplayercan use this inventory.This is called by
ScreenHandler.canUse(net.minecraft.screen.ScreenHandlerContext, net.minecraft.entity.player.PlayerEntity, net.minecraft.block.Block).- Specified by:
canPlayerUsein interfaceInventory- Returns:
- whether
playercan use this inventory - See Also:
- API Note:
- Implementations should check the distance between the inventory
holder and
player. For convenience, this interface offers two methods used by block entities to implement this check. - Mappings:
Namespace Name Mixin selector named canPlayerUseLnet/minecraft/inventory/Inventory;canPlayerUse(Lnet/minecraft/entity/player/PlayerEntity;)Zintermediary method_5443Lnet/minecraft/class_1263;method_5443(Lnet/minecraft/class_1657;)Zofficial aLbqk;a(Lcmx;)Z
-
clear
public void clear() -
provideRecipeInputs
- Specified by:
provideRecipeInputsin interfaceRecipeInputProvider- Mappings:
Namespace Name Mixin selector named provideRecipeInputsLnet/minecraft/recipe/RecipeInputProvider;provideRecipeInputs(Lnet/minecraft/recipe/RecipeMatcher;)Vintermediary method_7683Lnet/minecraft/class_1737;method_7683(Lnet/minecraft/class_1662;)Vofficial aLcrv;a(Lcnb;)V
-
toString
-
addToNewSlot
- Mappings:
Namespace Name Mixin selector named addToNewSlotLnet/minecraft/inventory/SimpleInventory;addToNewSlot(Lnet/minecraft/item/ItemStack;)Vintermediary method_20633Lnet/minecraft/class_1277;method_20633(Lnet/minecraft/class_1799;)Vofficial dLbra;d(Lcuq;)V
-
addToExistingSlot
- Mappings:
Namespace Name Mixin selector named addToExistingSlotLnet/minecraft/inventory/SimpleInventory;addToExistingSlot(Lnet/minecraft/item/ItemStack;)Vintermediary method_20634Lnet/minecraft/class_1277;method_20634(Lnet/minecraft/class_1799;)Vofficial eLbra;e(Lcuq;)V
-
transfer
- Mappings:
Namespace Name Mixin selector named transferLnet/minecraft/inventory/SimpleInventory;transfer(Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ItemStack;)Vintermediary method_20632Lnet/minecraft/class_1277;method_20632(Lnet/minecraft/class_1799;Lnet/minecraft/class_1799;)Vofficial aLbra;a(Lcuq;Lcuq;)V
-
readNbtList
Reads the item stacks fromnbtList.- See Also:
- Mappings:
Namespace Name Mixin selector named readNbtListLnet/minecraft/inventory/SimpleInventory;readNbtList(Lnet/minecraft/nbt/NbtList;Lnet/minecraft/registry/RegistryWrapper$WrapperLookup;)Vintermediary method_7659Lnet/minecraft/class_1277;method_7659(Lnet/minecraft/class_2499;Lnet/minecraft/class_7225$class_7874;)Vofficial aLbra;a(Luh;Ljo$a;)V
-
toNbtList
Returns an NBT list of non-empty item stacks.Unlike
Inventories.writeNbt(NbtCompound, DefaultedList, boolean, RegistryWrapper.WrapperLookup), this does not serialize the slots.- Returns:
- an NBT list of non-empty item stacks
- See Also:
- Mappings:
Namespace Name Mixin selector named toNbtListLnet/minecraft/inventory/SimpleInventory;toNbtList(Lnet/minecraft/registry/RegistryWrapper$WrapperLookup;)Lnet/minecraft/nbt/NbtList;intermediary method_7660Lnet/minecraft/class_1277;method_7660(Lnet/minecraft/class_7225$class_7874;)Lnet/minecraft/class_2499;official aLbra;a(Ljo$a;)Luh;
-
getHeldStacks
- Mappings:
Namespace Name Mixin selector named getHeldStacksLnet/minecraft/inventory/SimpleInventory;getHeldStacks()Lnet/minecraft/util/collection/DefaultedList;intermediary method_54454Lnet/minecraft/class_1277;method_54454()Lnet/minecraft/class_2371;official gLbra;g()Ljv;
-