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

public class SimpleInventory extends Object implements Inventory, RecipeInputProvider
A generic implementation of Inventory. This is used in a number of places, mostly:
  • To store the input of a ScreenHandler while 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 ScreenHandler subclass. 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 Inventory themselves.

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/SimpleInventory
intermediary net/minecraft/class_1277
official bqq
  • Field Details

    • size

      private final int size
      Mappings:
      Namespace Name Mixin selector
      named size Lnet/minecraft/inventory/SimpleInventory;size:I
      intermediary field_5831 Lnet/minecraft/class_1277;field_5831:I
      official b Lbqq;b:I
    • heldStacks

      private final DefaultedList<ItemStack> heldStacks
      Mappings:
      Namespace Name Mixin selector
      named heldStacks Lnet/minecraft/inventory/SimpleInventory;heldStacks:Lnet/minecraft/util/collection/DefaultedList;
      intermediary field_5828 Lnet/minecraft/class_1277;field_5828:Lnet/minecraft/class_2371;
      official c Lbqq;c:Ljs;
    • listeners

      Mappings:
      Namespace Name Mixin selector
      named listeners Lnet/minecraft/inventory/SimpleInventory;listeners:Ljava/util/List;
      intermediary field_5829 Lnet/minecraft/class_1277;field_5829:Ljava/util/List;
      official d Lbqq;d:Ljava/util/List;
  • Constructor Details

    • SimpleInventory

      public SimpleInventory(int size)
      Mappings:
      Namespace Name Mixin selector
      named <init> Lnet/minecraft/inventory/SimpleInventory;<init>(I)V
      intermediary <init> Lnet/minecraft/class_1277;<init>(I)V
      official <init> Lbqq;<init>(I)V
    • SimpleInventory

      public SimpleInventory(ItemStack[] items)
      Mappings:
      Namespace Name Mixin selector
      named <init> Lnet/minecraft/inventory/SimpleInventory;<init>([Lnet/minecraft/item/ItemStack;)V
      intermediary <init> Lnet/minecraft/class_1277;<init>([Lnet/minecraft/class_1799;)V
      official <init> Lbqq;<init>([Lcud;)V
  • Method Details

    • addListener

      public void addListener(InventoryChangedListener listener)
      Adds a listener for inventory modifications. If a listener is added multiple times, it will also be triggered multiple times.
      Mappings:
      Namespace Name Mixin selector
      named addListener Lnet/minecraft/inventory/SimpleInventory;addListener(Lnet/minecraft/inventory/InventoryChangedListener;)V
      intermediary method_5489 Lnet/minecraft/class_1277;method_5489(Lnet/minecraft/class_1265;)V
      official a Lbqq;a(Lbqc;)V
    • removeListener

      public void removeListener(InventoryChangedListener listener)
      Removes a listener previously added by #addListener. Does nothing when the listener was not found.
      Mappings:
      Namespace Name Mixin selector
      named removeListener Lnet/minecraft/inventory/SimpleInventory;removeListener(Lnet/minecraft/inventory/InventoryChangedListener;)V
      intermediary method_5488 Lnet/minecraft/class_1277;method_5488(Lnet/minecraft/class_1265;)V
      official b Lbqq;b(Lbqc;)V
    • getStack

      public ItemStack getStack(int slot)
      Returns the stack currently stored at slot.

      If the slot is empty, or is outside the bounds of this inventory, this returns ItemStack.EMPTY.

      Specified by:
      getStack in interface Inventory
      Returns:
      the stack currently stored at slot
      Mappings:
      Namespace Name Mixin selector
      named getStack Lnet/minecraft/inventory/Inventory;getStack(I)Lnet/minecraft/item/ItemStack;
      intermediary method_5438 Lnet/minecraft/class_1263;method_5438(I)Lnet/minecraft/class_1799;
      official a Lbqa;a(I)Lcud;
    • clearToList

      public List<ItemStack> 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 clearToList Lnet/minecraft/inventory/SimpleInventory;clearToList()Ljava/util/List;
      intermediary method_24514 Lnet/minecraft/class_1277;method_24514()Ljava/util/List;
      official f Lbqq;f()Ljava/util/List;
    • removeStack

      public ItemStack removeStack(int slot, int amount)
      Removes a specific number of items from slot.
      Specified by:
      removeStack in interface Inventory
      Returns:
      the removed items as a stack
      Mappings:
      Namespace Name Mixin selector
      named removeStack Lnet/minecraft/inventory/Inventory;removeStack(II)Lnet/minecraft/item/ItemStack;
      intermediary method_5434 Lnet/minecraft/class_1263;method_5434(II)Lnet/minecraft/class_1799;
      official a Lbqa;a(II)Lcud;
    • removeItem

      public ItemStack removeItem(Item item, int count)
      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 removeItem Lnet/minecraft/inventory/SimpleInventory;removeItem(Lnet/minecraft/item/Item;I)Lnet/minecraft/item/ItemStack;
      intermediary method_20631 Lnet/minecraft/class_1277;method_20631(Lnet/minecraft/class_1792;I)Lnet/minecraft/class_1799;
      official a Lbqq;a(Lcty;I)Lcud;
    • addStack

      public ItemStack addStack(ItemStack stack)
      Adds stack to 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#EMPTY if the entire stack fit inside the inventory
      Mappings:
      Namespace Name Mixin selector
      named addStack Lnet/minecraft/inventory/SimpleInventory;addStack(Lnet/minecraft/item/ItemStack;)Lnet/minecraft/item/ItemStack;
      intermediary method_5491 Lnet/minecraft/class_1277;method_5491(Lnet/minecraft/class_1799;)Lnet/minecraft/class_1799;
      official b Lbqq;b(Lcud;)Lcud;
    • canInsert

      public boolean canInsert(ItemStack stack)
      Returns whether stack can be inserted into this inventory.
      Returns:
      whether stack can be inserted into this inventory
      Mappings:
      Namespace Name Mixin selector
      named canInsert Lnet/minecraft/inventory/SimpleInventory;canInsert(Lnet/minecraft/item/ItemStack;)Z
      intermediary method_27070 Lnet/minecraft/class_1277;method_27070(Lnet/minecraft/class_1799;)Z
      official c Lbqq;c(Lcud;)Z
    • removeStack

      public ItemStack removeStack(int slot)
      Removes the stack currently stored at slot.
      Specified by:
      removeStack in interface Inventory
      Returns:
      the stack previously stored at the indicated slot
      Mappings:
      Namespace Name Mixin selector
      named removeStack Lnet/minecraft/inventory/Inventory;removeStack(I)Lnet/minecraft/item/ItemStack;
      intermediary method_5441 Lnet/minecraft/class_1263;method_5441(I)Lnet/minecraft/class_1799;
      official b Lbqa;b(I)Lcud;
    • setStack

      public void setStack(int slot, ItemStack stack)
      Sets the stack stored at slot to stack.
      Specified by:
      setStack in interface Inventory
      Mappings:
      Namespace Name Mixin selector
      named setStack Lnet/minecraft/inventory/Inventory;setStack(ILnet/minecraft/item/ItemStack;)V
      intermediary method_5447 Lnet/minecraft/class_1263;method_5447(ILnet/minecraft/class_1799;)V
      official a Lbqa;a(ILcud;)V
    • size

      public int size()
      Returns the size of the inventory.

      The inventory should support the slot ID from 0 to size() - 1. This should remain constant throughout the inventory's lifetime.

      Specified by:
      size in interface Inventory
      Returns:
      the size of the inventory
      Mappings:
      Namespace Name Mixin selector
      named size Lnet/minecraft/inventory/Inventory;size()I
      intermediary method_5439 Lnet/minecraft/class_1263;method_5439()I
      official b Lbqa;b()I
    • isEmpty

      public boolean isEmpty()
      Returns whether the inventory consists entirely of empty item stacks.
      Specified by:
      isEmpty in interface Inventory
      Returns:
      whether the inventory consists entirely of empty item stacks
      Mappings:
      Namespace Name Mixin selector
      named isEmpty Lnet/minecraft/inventory/Inventory;isEmpty()Z
      intermediary method_5442 Lnet/minecraft/class_1263;method_5442()Z
      official c Lbqa;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:
      markDirty in interface Inventory
      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 markDirty Lnet/minecraft/inventory/Inventory;markDirty()V
      intermediary method_5431 Lnet/minecraft/class_1263;method_5431()V
      official e Lbqa;e()V
    • canPlayerUse

      public boolean canPlayerUse(PlayerEntity player)
      Specified by:
      canPlayerUse in interface Inventory
      Returns:
      whether player can 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 canPlayerUse Lnet/minecraft/inventory/Inventory;canPlayerUse(Lnet/minecraft/entity/player/PlayerEntity;)Z
      intermediary method_5443 Lnet/minecraft/class_1263;method_5443(Lnet/minecraft/class_1657;)Z
      official a Lbqa;a(Lcml;)Z
    • clear

      public void clear()
      Specified by:
      clear in interface Clearable
      Mappings:
      Namespace Name Mixin selector
      named clear Lnet/minecraft/util/Clearable;clear()V
      intermediary method_5448 Lnet/minecraft/class_3829;method_5448()V
      official a Lbpy;a()V
    • provideRecipeInputs

      public void provideRecipeInputs(RecipeMatcher finder)
      Specified by:
      provideRecipeInputs in interface RecipeInputProvider
      Mappings:
      Namespace Name Mixin selector
      named provideRecipeInputs Lnet/minecraft/recipe/RecipeInputProvider;provideRecipeInputs(Lnet/minecraft/recipe/RecipeMatcher;)V
      intermediary method_7683 Lnet/minecraft/class_1737;method_7683(Lnet/minecraft/class_1662;)V
      official a Lcrj;a(Lcmp;)V
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • addToNewSlot

      private void addToNewSlot(ItemStack stack)
      Mappings:
      Namespace Name Mixin selector
      named addToNewSlot Lnet/minecraft/inventory/SimpleInventory;addToNewSlot(Lnet/minecraft/item/ItemStack;)V
      intermediary method_20633 Lnet/minecraft/class_1277;method_20633(Lnet/minecraft/class_1799;)V
      official d Lbqq;d(Lcud;)V
    • addToExistingSlot

      private void addToExistingSlot(ItemStack stack)
      Mappings:
      Namespace Name Mixin selector
      named addToExistingSlot Lnet/minecraft/inventory/SimpleInventory;addToExistingSlot(Lnet/minecraft/item/ItemStack;)V
      intermediary method_20634 Lnet/minecraft/class_1277;method_20634(Lnet/minecraft/class_1799;)V
      official e Lbqq;e(Lcud;)V
    • transfer

      private void transfer(ItemStack source, ItemStack target)
      Mappings:
      Namespace Name Mixin selector
      named transfer Lnet/minecraft/inventory/SimpleInventory;transfer(Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ItemStack;)V
      intermediary method_20632 Lnet/minecraft/class_1277;method_20632(Lnet/minecraft/class_1799;Lnet/minecraft/class_1799;)V
      official a Lbqq;a(Lcud;Lcud;)V
    • readNbtList

      public void readNbtList(NbtList list, RegistryWrapper.WrapperLookup registries)
      Reads the item stacks from nbtList.
      See Also:
      Mappings:
      Namespace Name Mixin selector
      named readNbtList Lnet/minecraft/inventory/SimpleInventory;readNbtList(Lnet/minecraft/nbt/NbtList;Lnet/minecraft/registry/RegistryWrapper$WrapperLookup;)V
      intermediary method_7659 Lnet/minecraft/class_1277;method_7659(Lnet/minecraft/class_2499;Lnet/minecraft/class_7225$class_7874;)V
      official a Lbqq;a(Lud;Ljl$a;)V
    • toNbtList

      public NbtList toNbtList(RegistryWrapper.WrapperLookup registries)
      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 toNbtList Lnet/minecraft/inventory/SimpleInventory;toNbtList(Lnet/minecraft/registry/RegistryWrapper$WrapperLookup;)Lnet/minecraft/nbt/NbtList;
      intermediary method_7660 Lnet/minecraft/class_1277;method_7660(Lnet/minecraft/class_7225$class_7874;)Lnet/minecraft/class_2499;
      official a Lbqq;a(Ljl$a;)Lud;
    • getHeldStacks

      public DefaultedList<ItemStack> getHeldStacks()
      Mappings:
      Namespace Name Mixin selector
      named getHeldStacks Lnet/minecraft/inventory/SimpleInventory;getHeldStacks()Lnet/minecraft/util/collection/DefaultedList;
      intermediary method_54454 Lnet/minecraft/class_1277;method_54454()Lnet/minecraft/class_2371;
      official g Lbqq;g()Ljs;