Class AbstractContainerScreen<T extends AbstractContainerMenu>

All Implemented Interfaces:
ContainerEventHandler, GuiEventListener, Renderable, TabOrderedElement, MenuAccess<T>
Direct Known Subclasses:
AbstractFurnaceScreen, BeaconScreen, BrewingStandScreen, CartographyTableScreen, ContainerScreen, CrafterScreen, CraftingScreen, DispenserScreen, EffectRenderingInventoryScreen, EnchantmentScreen, GrindstoneScreen, HopperScreen, HorseInventoryScreen, ItemCombinerScreen, LoomScreen, MerchantScreen, ShulkerBoxScreen, StonecutterScreen

public abstract class AbstractContainerScreen<T extends AbstractContainerMenu> extends Screen implements MenuAccess<T>
  • Field Details

    • INVENTORY_LOCATION

      public static final ResourceLocation INVENTORY_LOCATION
      The location of the inventory background texture
    • SNAPBACK_SPEED

      private static final float SNAPBACK_SPEED
      See Also:
    • QUICKDROP_DELAY

      private static final int QUICKDROP_DELAY
      See Also:
    • SLOT_ITEM_BLIT_OFFSET

      public static final int SLOT_ITEM_BLIT_OFFSET
      See Also:
    • HOVER_ITEM_BLIT_OFFSET

      private static final int HOVER_ITEM_BLIT_OFFSET
      See Also:
    • imageWidth

      protected int imageWidth
      The X size of the inventory window in pixels.
    • imageHeight

      protected int imageHeight
      The Y size of the inventory window in pixels.
    • titleLabelX

      protected int titleLabelX
    • titleLabelY

      protected int titleLabelY
    • inventoryLabelX

      protected int inventoryLabelX
    • inventoryLabelY

      protected int inventoryLabelY
    • playerInventoryTitle

      protected final Component playerInventoryTitle
    • hoveredSlot

      @Nullable protected Slot hoveredSlot
      Holds the slot currently hovered
    • clickedSlot

      @Nullable private Slot clickedSlot
      Used when touchscreen is enabled
    • snapbackEnd

      @Nullable private Slot snapbackEnd
    • quickdropSlot

      @Nullable private Slot quickdropSlot
    • lastClickSlot

      @Nullable private Slot lastClickSlot
    • leftPos

      protected int leftPos
      Starting X position for the Gui. Inconsistent use for Gui backgrounds.
    • topPos

      protected int topPos
      Starting Y position for the Gui. Inconsistent use for Gui backgrounds.
    • isSplittingStack

      private boolean isSplittingStack
      Used when touchscreen is enabled.
    • draggingItem

      private ItemStack draggingItem
      Used when touchscreen is enabled
    • snapbackStartX

      private int snapbackStartX
    • snapbackStartY

      private int snapbackStartY
    • snapbackTime

      private long snapbackTime
    • snapbackItem

      private ItemStack snapbackItem
      Used when touchscreen is enabled
    • quickdropTime

      private long quickdropTime
    • quickCraftSlots

      protected final Set<Slot> quickCraftSlots
    • isQuickCrafting

      protected boolean isQuickCrafting
    • quickCraftingType

      private int quickCraftingType
    • quickCraftingButton

      private int quickCraftingButton
    • skipNextRelease

      private boolean skipNextRelease
    • quickCraftingRemainder

      private int quickCraftingRemainder
    • lastClickTime

      private long lastClickTime
    • lastClickButton

      private int lastClickButton
    • doubleclick

      private boolean doubleclick
    • lastQuickMoved

      private ItemStack lastQuickMoved
    • slotColor

      protected int slotColor
  • Constructor Details

    • AbstractContainerScreen

      public AbstractContainerScreen(T menu, Inventory playerInventory, Component title)
  • Method Details

    • init

      protected void init()
      Overrides:
      init in class Screen
    • render

      public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick)
      Renders the graphical user interface (GUI) element.
      Specified by:
      render in interface Renderable
      Overrides:
      render in class Screen
      Parameters:
      guiGraphics - the GuiGraphics object used for rendering.
      mouseX - the x-coordinate of the mouse cursor.
      mouseY - the y-coordinate of the mouse cursor.
      partialTick - the partial tick time.
    • renderBackground

      public void renderBackground(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick)
      Overrides:
      renderBackground in class Screen
    • renderSlotHighlight

      public static void renderSlotHighlight(GuiGraphics guiGraphics, int x, int y, int blitOffset)
    • renderSlotHighlight

      public static void renderSlotHighlight(GuiGraphics guiGraphics, int x, int y, int blitOffset, int color)
    • renderSlotHighlight

      protected void renderSlotHighlight(GuiGraphics guiGraphics, Slot slot, int mouseX, int mouseY, float partialTick)
      Renders a highlight for the given slot to indicate the mouse is currently hovering over it.
    • renderTooltip

      protected void renderTooltip(GuiGraphics guiGraphics, int x, int y)
    • getTooltipFromContainerItem

      protected List<Component> getTooltipFromContainerItem(ItemStack stack)
    • renderFloatingItem

      private void renderFloatingItem(GuiGraphics guiGraphics, ItemStack stack, int x, int y, String text)
    • renderLabels

      protected void renderLabels(GuiGraphics guiGraphics, int mouseX, int mouseY)
    • renderBg

      protected abstract void renderBg(GuiGraphics guiGraphics, float partialTick, int mouseX, int mouseY)
    • renderSlot

      protected void renderSlot(GuiGraphics guiGraphics, Slot slot)
    • renderSlotContents

      protected void renderSlotContents(GuiGraphics guiGraphics, ItemStack itemstack, Slot slot, @Nullable String countString)
    • recalculateQuickCraftRemaining

      private void recalculateQuickCraftRemaining()
    • findSlot

      @Nullable private Slot findSlot(double mouseX, double mouseY)
    • mouseClicked

      public boolean mouseClicked(double mouseX, double mouseY, int button)
      Called when a mouse button is clicked within the GUI element.

      Specified by:
      mouseClicked in interface ContainerEventHandler
      Specified by:
      mouseClicked in interface GuiEventListener
      Parameters:
      mouseX - the X coordinate of the mouse.
      mouseY - the Y coordinate of the mouse.
      button - the button that was clicked.
      Returns:
      true if the event is consumed, false otherwise.
    • checkHotbarMouseClicked

      private void checkHotbarMouseClicked(int keyCode)
    • hasClickedOutside

      protected boolean hasClickedOutside(double mouseX, double mouseY, int guiLeft, int guiTop, int mouseButton)
    • mouseDragged

      public boolean mouseDragged(double mouseX, double mouseY, int button, double dragX, double dragY)
      Called when the mouse is dragged within the GUI element.

      Specified by:
      mouseDragged in interface ContainerEventHandler
      Specified by:
      mouseDragged in interface GuiEventListener
      Parameters:
      mouseX - the X coordinate of the mouse.
      mouseY - the Y coordinate of the mouse.
      button - the button that is being dragged.
      dragX - the X distance of the drag.
      dragY - the Y distance of the drag.
      Returns:
      true if the event is consumed, false otherwise.
    • mouseReleased

      public boolean mouseReleased(double mouseX, double mouseY, int button)
      Called when a mouse button is released within the GUI element.

      Specified by:
      mouseReleased in interface ContainerEventHandler
      Specified by:
      mouseReleased in interface GuiEventListener
      Parameters:
      mouseX - the X coordinate of the mouse.
      mouseY - the Y coordinate of the mouse.
      button - the button that was released.
      Returns:
      true if the event is consumed, false otherwise.
    • clearDraggingState

      public void clearDraggingState()
    • isHovering

      private boolean isHovering(Slot slot, double mouseX, double mouseY)
    • isHovering

      protected boolean isHovering(int x, int y, int width, int height, double mouseX, double mouseY)
    • slotClicked

      protected void slotClicked(Slot slot, int slotId, int mouseButton, ClickType type)
      Called when the mouse is clicked over a slot or outside the gui.
    • handleSlotStateChanged

      protected void handleSlotStateChanged(int slotId, int containerId, boolean newState)
    • keyPressed

      public boolean keyPressed(int keyCode, int scanCode, int modifiers)
      Called when a keyboard key is pressed within the GUI element.

      Specified by:
      keyPressed in interface ContainerEventHandler
      Specified by:
      keyPressed in interface GuiEventListener
      Overrides:
      keyPressed in class Screen
      Parameters:
      keyCode - the key code of the pressed key.
      scanCode - the scan code of the pressed key.
      modifiers - the keyboard modifiers.
      Returns:
      true if the event is consumed, false otherwise.
    • checkHotbarKeyPressed

      protected boolean checkHotbarKeyPressed(int keyCode, int scanCode)
    • removed

      public void removed()
      Overrides:
      removed in class Screen
    • isPauseScreen

      public boolean isPauseScreen()
      Overrides:
      isPauseScreen in class Screen
    • tick

      public final void tick()
      Overrides:
      tick in class Screen
    • containerTick

      protected void containerTick()
    • getMenu

      public T getMenu()
      Specified by:
      getMenu in interface MenuAccess<T extends AbstractContainerMenu>
    • getSlotUnderMouse

      @Nullable public @Nullable Slot getSlotUnderMouse()
    • getGuiLeft

      public int getGuiLeft()
    • getGuiTop

      public int getGuiTop()
    • getXSize

      public int getXSize()
    • getYSize

      public int getYSize()
    • getSlotColor

      public int getSlotColor(int index)
    • onClose

      public void onClose()
      Overrides:
      onClose in class Screen