Class GenericMenu

java.lang.Object
net.minecraft.world.inventory.AbstractContainerMenu
org.moddingx.libx.menu.MenuBase
org.moddingx.libx.menu.GenericMenu

public class GenericMenu extends MenuBase
A common menu with a variable amount of slots. You should not use this with more than 154 slots. To show a menu to a player, call open on the logical server. As there's no way to synchronise the item validator method from the modifiable item handler, you should register the validator during setup. The slot validation method in your item handler will be ignored by this.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final int
     
    final int
     
    final int
     
     
    static final net.minecraft.world.inventory.MenuType<GenericMenu>
     
    final int
     

    Fields inherited from class org.moddingx.libx.menu.MenuBase

    playerInventory

    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
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    open(net.minecraft.server.level.ServerPlayer player, net.minecraftforge.items.IItemHandlerModifiable inventory, net.minecraft.network.chat.Component name, net.minecraft.resources.ResourceLocation validatorId)
    Opens a menu for a player.
    net.minecraft.world.item.ItemStack
    quickMoveStack(net.minecraft.world.entity.player.Player player, int index)
     
    static void
    registerSlotValidator(net.minecraft.resources.ResourceLocation validatorId, BiPredicate<Integer,net.minecraft.world.item.ItemStack> validator)
    Registers a slot validator.
    boolean
    stillValid(net.minecraft.world.entity.player.Player player)
     

    Methods inherited from class org.moddingx.libx.menu.MenuBase

    addSlotBox, addSlotBox, addSlotRange, addSlotRange, layoutPlayerInventorySlots, moveItemStackTo

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

    addDataSlot, addDataSlots, addSlot, addSlotListener, broadcastChanges, 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, removed, removeSlotListener, resetQuickCraft, resumeRemoteUpdates, sendAllDataToRemote, setCarried, setData, setItem, setRemoteCarried, setRemoteSlot, setRemoteSlotNoCopy, setSynchronizer, slotsChanged, stillValid, suppressRemoteUpdates, transferState

    Methods inherited from class java.lang.Object

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

    • TYPE

      public static final net.minecraft.world.inventory.MenuType<GenericMenu> TYPE
    • width

      public final int width
    • height

      public final int height
    • invX

      public final int invX
    • invY

      public final int invY
    • slotList

      public final List<Pair<Integer,Integer>> slotList
  • Method Details

    • stillValid

      public boolean stillValid(@Nonnull net.minecraft.world.entity.player.Player player)
      Specified by:
      stillValid in class net.minecraft.world.inventory.AbstractContainerMenu
    • quickMoveStack

      @Nonnull public net.minecraft.world.item.ItemStack quickMoveStack(@Nonnull net.minecraft.world.entity.player.Player player, int index)
      Specified by:
      quickMoveStack in class net.minecraft.world.inventory.AbstractContainerMenu
    • open

      public static void open(net.minecraft.server.level.ServerPlayer player, net.minecraftforge.items.IItemHandlerModifiable inventory, net.minecraft.network.chat.Component name, @Nullable net.minecraft.resources.ResourceLocation validatorId)
      Opens a menu for a player.
      Parameters:
      player - The player that should see the menu.
      inventory - The inventory of the menu. The slot amount of this determines how big the container is. This should not have more than 154 slots.
      name - The name of the menu.
      validatorId - The id of the slot validator registered with registerSlotValidator. null disables slot validation. This will override the item handlers slot validation, so null means no slot validation even if the item handler has that feature.
    • registerSlotValidator

      public static void registerSlotValidator(net.minecraft.resources.ResourceLocation validatorId, BiPredicate<Integer,net.minecraft.world.item.ItemStack> validator)
      Registers a slot validator. This is required as the item handler can not be synced to the client, so the slot validation method of the item handler can not be used. This should be called during setup.