Class AbstractContainerMenu

java.lang.Object
net.minecraft.world.inventory.AbstractContainerMenu
Direct Known Subclasses:
BeaconMenu, BrewingStandMenu, CartographyTableMenu, ChestMenu, ContainerTypeTest.TestContainer, CrafterMenu, CreativeModeInventoryScreen.ItemPickerMenu, DispenserMenu, EnchantmentMenu, GrindstoneMenu, HopperMenu, HorseInventoryMenu, ItemCombinerMenu, LecternMenu, LoomMenu, MerchantMenu, RecipeBookMenu, ShulkerBoxMenu, StonecutterMenu

public abstract class AbstractContainerMenu extends Object
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • SLOT_CLICKED_OUTSIDE

      public static final int SLOT_CLICKED_OUTSIDE
      See Also:
    • QUICKCRAFT_TYPE_CHARITABLE

      public static final int QUICKCRAFT_TYPE_CHARITABLE
      See Also:
    • QUICKCRAFT_TYPE_GREEDY

      public static final int QUICKCRAFT_TYPE_GREEDY
      See Also:
    • QUICKCRAFT_TYPE_CLONE

      public static final int QUICKCRAFT_TYPE_CLONE
      See Also:
    • QUICKCRAFT_HEADER_START

      public static final int QUICKCRAFT_HEADER_START
      See Also:
    • QUICKCRAFT_HEADER_CONTINUE

      public static final int QUICKCRAFT_HEADER_CONTINUE
      See Also:
    • QUICKCRAFT_HEADER_END

      public static final int QUICKCRAFT_HEADER_END
      See Also:
    • CARRIED_SLOT_SIZE

      public static final int CARRIED_SLOT_SIZE
      See Also:
    • lastSlots

      private final NonNullList<ItemStack> lastSlots
    • slots

      public final NonNullList<Slot> slots
    • dataSlots

      private final List<DataSlot> dataSlots
    • carried

      private ItemStack carried
    • remoteSlots

      private final NonNullList<ItemStack> remoteSlots
    • remoteDataSlots

      private final it.unimi.dsi.fastutil.ints.IntList remoteDataSlots
    • remoteCarried

      private ItemStack remoteCarried
    • stateId

      private int stateId
    • containerId

      public final int containerId
    • quickcraftType

      private int quickcraftType
    • quickcraftStatus

      private int quickcraftStatus
    • quickcraftSlots

      private final Set<Slot> quickcraftSlots
    • containerListeners

      private final List<ContainerListener> containerListeners
    • synchronizer

      @Nullable private ContainerSynchronizer synchronizer
    • suppressRemoteUpdates

      private boolean suppressRemoteUpdates
  • Constructor Details

    • AbstractContainerMenu

      protected AbstractContainerMenu(@Nullable MenuType<?> pMenuType, int pContainerId)
  • Method Details

    • stillValid

      protected static boolean stillValid(ContainerLevelAccess pAccess, Player pPlayer, Block pTargetBlock)
    • getType

      public MenuType<?> getType()
    • checkContainerSize

      protected static void checkContainerSize(Container pContainer, int pMinSize)
    • checkContainerDataCount

      protected static void checkContainerDataCount(ContainerData pIntArray, int pMinSize)
    • isValidSlotIndex

      public boolean isValidSlotIndex(int pSlotIndex)
    • addSlot

      protected Slot addSlot(Slot pSlot)
      Adds an item slot to this container
    • addDataSlot

      protected DataSlot addDataSlot(DataSlot pIntValue)
    • addDataSlots

      protected void addDataSlots(ContainerData pArray)
    • addSlotListener

      public void addSlotListener(ContainerListener pListener)
    • setSynchronizer

      public void setSynchronizer(ContainerSynchronizer pSynchronizer)
    • sendAllDataToRemote

      public void sendAllDataToRemote()
    • removeSlotListener

      public void removeSlotListener(ContainerListener pListener)
      Remove the given Listener. Method name is for legacy.
    • getItems

      public NonNullList<ItemStack> getItems()
    • broadcastChanges

      public void broadcastChanges()
    • broadcastFullState

      public void broadcastFullState()
    • updateDataSlotListeners

      private void updateDataSlotListeners(int pSlotIndex, int pValue)
    • triggerSlotListeners

      private void triggerSlotListeners(int pSlotIndex, ItemStack pStack, Supplier<ItemStack> pSupplier)
    • synchronizeSlotToRemote

      private void synchronizeSlotToRemote(int pSlotIndex, ItemStack pStack, Supplier<ItemStack> pSupplier)
    • synchronizeDataSlotToRemote

      private void synchronizeDataSlotToRemote(int pSlotIndex, int pValue)
    • synchronizeCarriedToRemote

      private void synchronizeCarriedToRemote()
    • setRemoteSlot

      public void setRemoteSlot(int pSlot, ItemStack pStack)
    • setRemoteSlotNoCopy

      public void setRemoteSlotNoCopy(int pSlot, ItemStack pStack)
    • setRemoteCarried

      public void setRemoteCarried(ItemStack pRemoteCarried)
    • clickMenuButton

      public boolean clickMenuButton(Player pPlayer, int pId)
      Handles the given Button-click on the server, currently only used by enchanting. Name is for legacy.
    • getSlot

      public Slot getSlot(int pSlotId)
    • quickMoveStack

      public abstract ItemStack quickMoveStack(Player pPlayer, int pIndex)
      Handle when the stack in slot index is shift-clicked. Normally this moves the stack between the player inventory and the other inventory(s).
    • clicked

      public void clicked(int pSlotId, int pButton, ClickType pClickType, Player pPlayer)
    • doClick

      private void doClick(int pSlotId, int pButton, ClickType pClickType, Player pPlayer)
    • tryItemClickBehaviourOverride

      private boolean tryItemClickBehaviourOverride(Player pPlayer, ClickAction pAction, Slot pSlot, ItemStack pClickedItem, ItemStack pCarriedItem)
    • createCarriedSlotAccess

      private SlotAccess createCarriedSlotAccess()
    • canTakeItemForPickAll

      public boolean canTakeItemForPickAll(ItemStack pStack, Slot pSlot)
      Called to determine if the current slot is valid for the stack merging (double-click) code. The stack passed in is null for the initial slot that was double-clicked.
    • removed

      public void removed(Player pPlayer)
      Called when the container is closed.
    • clearContainer

      protected void clearContainer(Player pPlayer, Container pContainer)
    • slotsChanged

      public void slotsChanged(Container pContainer)
      Callback for when the crafting matrix is changed.
    • setItem

      public void setItem(int pSlotId, int pStateId, ItemStack pStack)
      Puts an ItemStack in a slot.
    • initializeContents

      public void initializeContents(int pStateId, List<ItemStack> pItems, ItemStack pCarried)
    • setData

      public void setData(int pId, int pData)
    • stillValid

      public abstract boolean stillValid(Player pPlayer)
      Determines whether supplied player can use this container
    • moveItemStackTo

      protected boolean moveItemStackTo(ItemStack pStack, int pStartIndex, int pEndIndex, boolean pReverseDirection)
      Merges provided ItemStack with the first available one in the container/player inventor between minIndex (included) and maxIndex (excluded). Args : stack, minIndex, maxIndex, negativDirection. [!] the Container implementation do not check if the item is valid for the slot
    • getQuickcraftType

      public static int getQuickcraftType(int pEventButton)
      Extracts the drag mode. Args : eventButton. Return (0 : evenly split, 1 : one item by slot, 2 : not used ?)
    • getQuickcraftHeader

      public static int getQuickcraftHeader(int pClickedButton)
      Args : clickedButton, Returns (0 : start drag, 1 : add slot, 2 : end drag)
    • getQuickcraftMask

      public static int getQuickcraftMask(int pQuickCraftingHeader, int pQuickCraftingType)
    • isValidQuickcraftType

      public static boolean isValidQuickcraftType(int pDragMode, Player pPlayer)
    • resetQuickCraft

      protected void resetQuickCraft()
    • canItemQuickReplace

      public static boolean canItemQuickReplace(@Nullable Slot pSlot, ItemStack pStack, boolean pStackSizeMatters)
      Checks if it's possible to add the given itemstack to the given slot.
    • getQuickCraftPlaceCount

      public static int getQuickCraftPlaceCount(Set<Slot> pSlots, int pType, ItemStack pStack)
    • canDragTo

      public boolean canDragTo(Slot pSlot)
      Returns true if the player can "drag-spilt" items into this slot. Returns true by default. Called to check if the slot can be added to a list of Slots to split the held ItemStack across.
    • getRedstoneSignalFromBlockEntity

      public static int getRedstoneSignalFromBlockEntity(@Nullable BlockEntity pBlockEntity)
      Like the version that takes an inventory. If the given BlockEntity is not an Inventory, 0 is returned instead.
    • getRedstoneSignalFromContainer

      public static int getRedstoneSignalFromContainer(@Nullable Container pContainer)
    • setCarried

      public void setCarried(ItemStack pStack)
    • getCarried

      public ItemStack getCarried()
    • suppressRemoteUpdates

      public void suppressRemoteUpdates()
    • resumeRemoteUpdates

      public void resumeRemoteUpdates()
    • transferState

      public void transferState(AbstractContainerMenu pMenu)
    • findSlot

      public OptionalInt findSlot(Container pContainer, int pSlotIndex)
    • getStateId

      public int getStateId()
    • incrementStateId

      public int incrementStateId()