Class MenuBase

java.lang.Object
net.minecraft.world.inventory.AbstractContainerMenu
org.moddingx.libx.menu.MenuBase
Direct Known Subclasses:
DefaultMenu, GenericMenu

public abstract class MenuBase extends net.minecraft.world.inventory.AbstractContainerMenu
A base class for menus. Provides some utilities that are useful for any type of menu. When using this it's important to register the player inventory slots through layoutPlayerInventorySlots(int, int) and after all the other slots.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final net.minecraftforge.items.IItemHandler
     

    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
    MenuBase(net.minecraft.world.inventory.MenuType<?> type, int id, net.minecraft.world.entity.player.Inventory inventory)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected int
    addSlotBox(net.minecraftforge.items.IItemHandler handler, int index, int x, int y, int horAmount, int dx, int verAmount, int dy)
    Adds a box of slots to the container
    protected int
    addSlotBox(net.minecraftforge.items.IItemHandler handler, int index, int x, int y, int horAmount, int dx, int verAmount, int dy, com.mojang.datafixers.util.Function4<net.minecraftforge.items.IItemHandler,Integer,Integer,Integer,net.minecraft.world.inventory.Slot> slotFactory)
    Adds a box of slots to the container
    protected int
    addSlotRange(net.minecraftforge.items.IItemHandler handler, int index, int x, int y, int amount, int dx)
    Adds a row of slots to the container
    protected int
    addSlotRange(net.minecraftforge.items.IItemHandler handler, int index, int x, int y, int amount, int dx, com.mojang.datafixers.util.Function4<net.minecraftforge.items.IItemHandler,Integer,Integer,Integer,net.minecraft.world.inventory.Slot> slotFactory)
    Adds a row of slots to the container
    protected void
    layoutPlayerInventorySlots(int leftCol, int topRow)
    Places the player inventory slots into the container.
    protected boolean
    moveItemStackTo(net.minecraft.world.item.ItemStack stack, int startIndex, int endIndex, boolean reverseDirection)
     

    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, quickMoveStack, 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

    • playerInventory

      public final net.minecraftforge.items.IItemHandler playerInventory
  • Constructor Details

    • MenuBase

      protected MenuBase(@Nullable net.minecraft.world.inventory.MenuType<?> type, int id, net.minecraft.world.entity.player.Inventory inventory)
  • Method Details

    • layoutPlayerInventorySlots

      protected void layoutPlayerInventorySlots(int leftCol, int topRow)
      Places the player inventory slots into the container.
      Parameters:
      leftCol - The x coordinate of the top left slot
      topRow - The y coordinate of the top left slot
    • addSlotBox

      protected int addSlotBox(net.minecraftforge.items.IItemHandler handler, int index, int x, int y, int horAmount, int dx, int verAmount, int dy)
      Adds a box of slots to the container
      Parameters:
      handler - The inventory of the slot
      index - The index of the first slot
      x - The x coordinate of the top left slot
      y - The y coordinate of the top left slot
      horAmount - The amount of slots in horizontal direction
      dx - The space between two slots in horizontal direction. Should not be less than 16 or you create overlapping slots. Most of the time this is 18
      verAmount - The amount of slots in vertical direction
      dy - The space between two slots in vertical direction. Should not be less than 16 or you create overlapping slots. Most of the time this is 18
      Returns:
      The next index to be used to create a slot
    • addSlotRange

      protected int addSlotRange(net.minecraftforge.items.IItemHandler handler, int index, int x, int y, int amount, int dx)
      Adds a row of slots to the container
      Parameters:
      handler - The inventory of the slot
      index - The index of the first slot
      x - The x coordinate of the top left slot
      y - The y coordinate of the top left slot
      amount - The amount of slots
      dx - The space between two slots. Should not be less than 16 or you create overlapping slots. Most of the time this is 18
      Returns:
      The next index to be used to create a slot
    • addSlotBox

      protected int addSlotBox(net.minecraftforge.items.IItemHandler handler, int index, int x, int y, int horAmount, int dx, int verAmount, int dy, com.mojang.datafixers.util.Function4<net.minecraftforge.items.IItemHandler,Integer,Integer,Integer,net.minecraft.world.inventory.Slot> slotFactory)
      Adds a box of slots to the container
      Parameters:
      handler - The inventory of the slot
      index - The index of the first slot
      x - The x coordinate of the top left slot
      y - The y coordinate of the top left slot
      horAmount - The amount of slots in horizontal direction
      dx - The space between two slots in horizontal direction. Should not be less than 16 or you create overlapping slots. Most of the time this is 18
      verAmount - The amount of slots in vertical direction
      dy - The space between two slots in vertical direction. Should not be less than 16 or you create overlapping slots. Most of the time this is 18
      slotFactory - A factory to create a slot. This could be SlotItemHandler::new or SlotOutputOnly::new for output slots.
      Returns:
      The next index to be used to create a slot
    • addSlotRange

      protected int addSlotRange(net.minecraftforge.items.IItemHandler handler, int index, int x, int y, int amount, int dx, com.mojang.datafixers.util.Function4<net.minecraftforge.items.IItemHandler,Integer,Integer,Integer,net.minecraft.world.inventory.Slot> slotFactory)
      Adds a row of slots to the container
      Parameters:
      handler - The inventory of the slot
      index - The index of the first slot
      x - The x coordinate of the top left slot
      y - The y coordinate of the top left slot
      amount - The amount of slots
      dx - The space between two slots. Should not be less than 16 or you create overlapping slots. Most of the time this is 18
      slotFactory - A factory to create a slot. This could be SlotItemHandler::new or SlotOutputOnly::new for output slots.
      Returns:
      The next index to be used to create a slot
    • moveItemStackTo

      protected boolean moveItemStackTo(@Nonnull net.minecraft.world.item.ItemStack stack, int startIndex, int endIndex, boolean reverseDirection)
      Overrides:
      moveItemStackTo in class net.minecraft.world.inventory.AbstractContainerMenu