Class ModularGuiContainerMenu
Created by brandon3055 on 08/09/2023
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal net.minecraft.world.entity.player.InventoryFields 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
ConstructorsModifierConstructorDescriptionprotectedModularGuiContainerMenu(@Nullable net.minecraft.world.inventory.MenuType<?> menuType, int containerId, net.minecraft.world.entity.player.Inventory inventory) -
Method Summary
Modifier and TypeMethodDescriptionvoidstatic booleancanStacksMerge(net.minecraft.world.item.ItemStack stack1, net.minecraft.world.item.ItemStack stack2) Determines if two @linkItemStackmatch and can be merged into a single slotprotected SlotGroupcreateSlotGroup(int zoneId, int... quickMoveTo) Creates and returns a new slot group for this container.voidhandlePacketFromClient(net.minecraft.world.entity.player.Player player, int packetId, MCDataInput packet) Override this in your container menu implementation in order to receive packets sent viasendPacketToServer(int, Consumer)static voidhandlePacketFromClient(net.minecraft.world.entity.player.Player player, MCDataInput packet) voidhandlePacketFromServer(net.minecraft.world.entity.player.Player player, int packetId, MCDataInput packet) Override this in your container menu implementation in order to receive packets sent viasendPacketToServer(int, Consumer)static voidhandlePacketFromServer(net.minecraft.world.entity.player.Player player, MCDataInput packet) voidprotected booleanmoveItemStackTo(net.minecraft.world.item.ItemStack stack, List<net.minecraft.world.inventory.Slot> targets, boolean reverse) protected SlotGroupConvenience method to create a slot group for player slots.net.minecraft.world.item.ItemStackquickMoveStack(@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 SlotGroupConvenience method to create a slot group for the 'other side' of the inventory So the Block/tile or whatever this inventory is attached to.voidsendPacketToClient(int packetId, Consumer<MCDataOutput> packetWriter) Send a packet to the client side container.voidsendPacketToServer(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
-
Field Details
-
inventory
public final net.minecraft.world.entity.player.Inventory inventory -
slotGroups
-
slotGroupMap
-
zonedSlots
-
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
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
Convenience method to create a slot group for player slots. Configured to quick-move toremoteSlotGroup()groups.- See Also:
-
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 toplayerSlotGroup()groups.- See Also:
-
sendPacketToClient
Send a packet to the client side container.- Parameters:
packetId- message id, Can be any value from 0 to 254, 255 is used by theDataSyncsystem.packetWriter- Use this callback to write your data to the packet.
-
sendPacketToServer
Send a packet to the server side container.- Parameters:
packetId- message id, Can be any value from 0 to 255packetWriter- 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 viasendPacketToServer(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 viasendPacketToServer(int, Consumer)Don't forget to call super if you plan on using the
DataSyncsystem. -
canStacksMerge
public static boolean canStacksMerge(net.minecraft.world.item.ItemStack stack1, net.minecraft.world.item.ItemStack stack2) Determines if two @linkItemStackmatch 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:
quickMoveStackin classnet.minecraft.world.inventory.AbstractContainerMenu
-
moveItemStackTo
protected boolean moveItemStackTo(net.minecraft.world.item.ItemStack stack, List<net.minecraft.world.inventory.Slot> targets, boolean reverse) -
mapSlot
-
broadcastChanges
public void broadcastChanges()- Overrides:
broadcastChangesin classnet.minecraft.world.inventory.AbstractContainerMenu
-