Class StorageMenuDefinition
java.lang.Object
net.ixdarklord.coolcatcore.api.menu.StorageMenuDefinition
A menu for the inventory of a block or an item, declared once: where its slots go, what else the screen shows, and
what its buttons do. It makes the
MenuType to register, opens the menu, and keeps it in sync.
// A 9-slot crate, with the number of times it was used shown on the screen.
public static final StorageMenuDefinition CRATE = StorageMenuDefinition.grid(9, 1)
.sync(CRATE_USES)
.button(0, (menu, player) -> menu.getContainer().clearContent())
.build();
public static final RegistryEntry<MenuType<StorageMenu>> CRATE_MENU = MENUS.register("crate", CRATE::createMenuType);
// Server, when the block is used:
CRATE.open(serverPlayer, crateBlockEntity, Component.translatable("container.mymod.crate"));
// Client, while it initialises:
MenuScreenRegistry.register(CRATE_MENU, StorageScreen::new);
Slots follow the container's ContainerLayout (filters, limits, output slots) and move with shift-click; the
menu closes when the block is removed or the player walks away, or when an item's stack leaves its slot (which the
menu locks meanwhile). Slot contents sync as in any vanilla menu; StorageMenuDefinition.Builder.sync(net.ixdarklord.coolcatcore.api.attachment.Attachment<T>) values reach the screen too.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic final recordWhere one container slot shows on the screen (the slot's top-left, inside its 18x18 box). -
Method Summary
Modifier and TypeMethodDescriptionbuilder()An empty definition: place the slots yourself.net.minecraft.world.inventory.MenuType<StorageMenu>The menu type to register inRegistries.MENU, e.g.grid(int columns, int rows) The usual chest-like screen:columnsbyrowsslots (container slots 0 upward), centred, with the player inventory below them.intheight()The screen's height.intintnet.minecraft.world.inventory.MenuType<StorageMenu>menuType()voidopen(net.minecraft.server.level.ServerPlayer player, int inventorySlot, ContainerLayout layout, net.minecraft.network.chat.Component title) Opens the menu on the inventory kept in the stack in one of the player's slots, with the given layout.voidopen(net.minecraft.server.level.ServerPlayer player, int inventorySlot, net.minecraft.network.chat.Component title) Opens the menu on theContainerItemin one of the player's inventory slots.voidopen(net.minecraft.server.level.ServerPlayer player, net.minecraft.world.InteractionHand hand, net.minecraft.network.chat.Component title) Opens the menu on theContainerItemheld in a hand.voidopen(net.minecraft.server.level.ServerPlayer player, net.minecraft.world.level.block.entity.BlockEntity blockEntity, net.minecraft.network.chat.Component title) Opens the menu on a block's inventory: anExtendedContainerBlockEntity's, or any containerHandlerTypes.CONTAINERfinds there (a vanilla chest...).slots()intwidth()The screen's width.
-
Method Details
-
builder
An empty definition: place the slots yourself. The player inventory goes at (8, 84) unless moved. -
grid
The usual chest-like screen:columnsbyrowsslots (container slots 0 upward), centred, with the player inventory below them. -
createMenuType
The menu type to register inRegistries.MENU, e.g.MENUS.register("crate", CRATE::createMenuType). -
open
public void open(net.minecraft.server.level.ServerPlayer player, net.minecraft.world.level.block.entity.BlockEntity blockEntity, net.minecraft.network.chat.Component title) Opens the menu on a block's inventory: anExtendedContainerBlockEntity's, or any containerHandlerTypes.CONTAINERfinds there (a vanilla chest...). -
open
public void open(net.minecraft.server.level.ServerPlayer player, net.minecraft.world.InteractionHand hand, net.minecraft.network.chat.Component title) Opens the menu on theContainerItemheld in a hand. -
open
public void open(net.minecraft.server.level.ServerPlayer player, int inventorySlot, net.minecraft.network.chat.Component title) Opens the menu on theContainerItemin one of the player's inventory slots. -
open
public void open(net.minecraft.server.level.ServerPlayer player, int inventorySlot, ContainerLayout layout, net.minecraft.network.chat.Component title) Opens the menu on the inventory kept in the stack in one of the player's slots, with the given layout. -
slots
-
inventoryX
public int inventoryX() -
inventoryY
public int inventoryY() -
width
public int width()The screen's width. -
height
public int height()The screen's height.
-