Class ModularGuiContainerMenu

java.lang.Object
net.minecraft.world.inventory.AbstractContainerMenu
codechicken.lib.inventory.container.modular.ModularGuiContainerMenu

public abstract class ModularGuiContainerMenu extends net.minecraft.world.inventory.AbstractContainerMenu
The base abstract ContainerMenu for all modular gui containers.

Created by brandon3055 on 08/09/2023

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final List<DataSync<?>>
     
    final net.minecraft.world.entity.player.Inventory
     
    final Map<net.minecraft.world.inventory.Slot,SlotGroup>
     
     
    final Map<Integer,List<net.minecraft.world.inventory.Slot>>
     

    Fields inherited from class net.minecraft.world.inventory.AbstractContainerMenu

    CARRIED_SLOT_SIZE, containerId, QUICKCRAFT_HEADER_CONTINUE, QUICKCRAFT_HEADER_END, QUICKCRAFT_HEADER_START, QUICKCRAFT_TYPE_CHARITABLE, QUICKCRAFT_TYPE_CLONE, QUICKCRAFT_TYPE_GREEDY, SLOT_CLICKED_OUTSIDE, slots
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    ModularGuiContainerMenu(@Nullable net.minecraft.world.inventory.MenuType<?> menuType, int containerId, net.minecraft.world.entity.player.Inventory inventory)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    static boolean
    canStacksMerge(net.minecraft.world.item.ItemStack stack1, net.minecraft.world.item.ItemStack stack2)
    Determines if two @link ItemStack match and can be merged into a single slot
    protected SlotGroup
    createSlotGroup(int zoneId, int... quickMoveTo)
    Creates and returns a new slot group for this container.
    void
    handlePacketFromClient(net.minecraft.world.entity.player.Player player, int packetId, MCDataInput packet)
    Override this in your container menu implementation in order to receive packets sent via sendPacketToServer(int, Consumer)
    static void
    handlePacketFromClient(net.minecraft.world.entity.player.Player player, MCDataInput packet)
     
    void
    handlePacketFromServer(net.minecraft.world.entity.player.Player player, int packetId, MCDataInput packet)
    Override this in your container menu implementation in order to receive packets sent via sendPacketToServer(int, Consumer)
    static void
    handlePacketFromServer(net.minecraft.world.entity.player.Player player, MCDataInput packet)
     
    void
    mapSlot(net.minecraft.world.inventory.Slot slot, SlotGroup slotGroup)
     
    protected boolean
    moveItemStackTo(net.minecraft.world.item.ItemStack stack, List<net.minecraft.world.inventory.Slot> targets, boolean reverse)
     
    protected SlotGroup
    Convenience method to create a slot group for player slots.
    net.minecraft.world.item.ItemStack
    quickMoveStack(@NotNull net.minecraft.world.entity.player.Player player, int slotIndex)
    Transfers to the next zone in order, and will loop around to the lowest zone.
    protected SlotGroup
    Convenience method to create a slot group for the 'other side' of the inventory So the Block/tile or whatever this inventory is attached to.
    void
    sendPacketToClient(int packetId, Consumer<MCDataOutput> packetWriter)
    Send a packet to the client side container.
    void
    sendPacketToServer(int packetId, Consumer<MCDataOutput> packetWriter)
    Send a packet to the server side container.

    Methods inherited from class net.minecraft.world.inventory.AbstractContainerMenu

    addDataSlot, addDataSlots, addSlot, addSlotListener, broadcastFullState, canDragTo, canItemQuickReplace, canTakeItemForPickAll, checkContainerDataCount, checkContainerSize, clearContainer, clicked, clickMenuButton, findSlot, getCarried, getItems, getQuickcraftHeader, getQuickcraftMask, getQuickCraftPlaceCount, getQuickcraftType, getRedstoneSignalFromBlockEntity, getRedstoneSignalFromContainer, getSlot, getStateId, getType, incrementStateId, initializeContents, isValidQuickcraftType, isValidSlotIndex, moveItemStackTo, removed, removeSlotListener, resetQuickCraft, resumeRemoteUpdates, sendAllDataToRemote, setCarried, setData, setItem, setRemoteCarried, setRemoteSlot, setRemoteSlotNoCopy, setSynchronizer, slotsChanged, stillValid, stillValid, suppressRemoteUpdates, transferState

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • inventory

      public final net.minecraft.world.entity.player.Inventory inventory
    • slotGroups

      public final List<SlotGroup> slotGroups
    • slotGroupMap

      public final Map<net.minecraft.world.inventory.Slot,SlotGroup> slotGroupMap
    • zonedSlots

      public final Map<Integer,List<net.minecraft.world.inventory.Slot>> zonedSlots
    • dataSyncs

      public final List<DataSync<?>> dataSyncs
  • Constructor Details

    • ModularGuiContainerMenu

      protected ModularGuiContainerMenu(@Nullable @Nullable net.minecraft.world.inventory.MenuType<?> menuType, int containerId, net.minecraft.world.entity.player.Inventory inventory)
  • Method Details

    • createSlotGroup

      protected SlotGroup createSlotGroup(int zoneId, int... quickMoveTo)
      Creates and returns a new slot group for this container. You can then add your inventory slots to this slot group, similar to how you would normally add slots to the container. With one big exception! You do not need to worry about setting slot positions! (Just use 0, 0)

      Make sure to save your slot groups to accessible fields in your container menu class. You will need to pass these to appropriate GuiSlots / GuiSlots.singleSlot(GuiParent, ContainerScreenAccess, SlotGroup, int) elements. The gui elements will handle positioning and rendering the slots.

      As far as splitting a containers slots into multiple groups, Typically the players main inventory and hot bar would be added as two separate groups. How you handle the containers slots is up to you, For something like a machine with several spread out slots, you can still add all the slots to a single group, then pass each individual slot from the group to a single GuiSlots.singleSlot(GuiParent, ContainerScreenAccess, SlotGroup, int) element.

      Parameters:
      zoneId - Used for quick-move (shift click) operations. Each group has a zone id, and you can specify which zones a group can quick-move to. Multiple groups can have the same zone id. Quick move work though the groups in a zone in the order the groups here added.
      quickMoveTo - List of zones this group can quick-move to.
    • playerSlotGroup

      protected SlotGroup playerSlotGroup()
      Convenience method to create a slot group for player slots. Configured to quick-move to remoteSlotGroup() groups.
      See Also:
    • remoteSlotGroup

      protected SlotGroup remoteSlotGroup()
      Convenience method to create a slot group for the 'other side' of the inventory So the Block/tile or whatever this inventory is attached to. Configured to quick-move to playerSlotGroup() groups.
      See Also:
    • sendPacketToClient

      public void sendPacketToClient(int packetId, Consumer<MCDataOutput> packetWriter)
      Send a packet to the client side container.
      Parameters:
      packetId - message id, Can be any value from 0 to 254, 255 is used by the DataSync system.
      packetWriter - Use this callback to write your data to the packet.
    • sendPacketToServer

      public void sendPacketToServer(int packetId, Consumer<MCDataOutput> packetWriter)
      Send a packet to the server side container.
      Parameters:
      packetId - message id, Can be any value from 0 to 255
      packetWriter - Use this callback to write your data to the packet.
    • handlePacketFromClient

      public static void handlePacketFromClient(net.minecraft.world.entity.player.Player player, MCDataInput packet)
    • handlePacketFromClient

      public void handlePacketFromClient(net.minecraft.world.entity.player.Player player, int packetId, MCDataInput packet)
      Override this in your container menu implementation in order to receive packets sent via sendPacketToServer(int, Consumer)
    • handlePacketFromServer

      public static void handlePacketFromServer(net.minecraft.world.entity.player.Player player, MCDataInput packet)
    • handlePacketFromServer

      public void handlePacketFromServer(net.minecraft.world.entity.player.Player player, int packetId, MCDataInput packet)
      Override this in your container menu implementation in order to receive packets sent via sendPacketToServer(int, Consumer)

      Don't forget to call super if you plan on using the DataSync system.

    • canStacksMerge

      public static boolean canStacksMerge(net.minecraft.world.item.ItemStack stack1, net.minecraft.world.item.ItemStack stack2)
      Determines if two @link ItemStack match and can be merged into a single slot
    • quickMoveStack

      public net.minecraft.world.item.ItemStack quickMoveStack(@NotNull @NotNull net.minecraft.world.entity.player.Player player, int slotIndex)
      Transfers to the next zone in order, and will loop around to the lowest zone. TODO, Would be nice to have better control over quick-move Maybe just the ability to specify which zones each group quick-moves to...
      Specified by:
      quickMoveStack in class net.minecraft.world.inventory.AbstractContainerMenu
    • moveItemStackTo

      protected boolean moveItemStackTo(net.minecraft.world.item.ItemStack stack, List<net.minecraft.world.inventory.Slot> targets, boolean reverse)
    • mapSlot

      public void mapSlot(net.minecraft.world.inventory.Slot slot, SlotGroup slotGroup)
    • broadcastChanges

      public void broadcastChanges()
      Overrides:
      broadcastChanges in class net.minecraft.world.inventory.AbstractContainerMenu