Class Screen

All Implemented Interfaces:
Drawable, Element, ParentElement, TickableElement
Direct Known Subclasses:
AbstractCommandBlockScreen, AddServerScreen, AdvancementsScreen, BackupPromptScreen, BookEditScreen, BookScreen, ChatScreen, ConfirmScreen, ConnectScreen, CreateWorldScreen, CreditsScreen, CustomizeBuffetLevelScreen, CustomizeFlatLevelScreen, DatapackFailureScreen, DeathScreen, DemoScreen, DialogScreen, DirectConnectScreen, DisconnectedScreen, DownloadingTerrainScreen, EditGameRulesScreen, EditWorldScreen, FatalErrorScreen, GameMenuScreen, GameModeSelectionScreen, GameOptionsScreen, HandledScreen, JigsawBlockScreen, LevelLoadingScreen, MultiplayerScreen, MultiplayerWarningScreen, NoticeScreen, OpenToLanScreen, OptimizeWorldScreen, OptionsScreen, OutOfMemoryScreen, PackScreen, PresetsScreen, ProgressScreen, RealmsScreen, SaveLevelScreen, SelectWorldScreen, SignEditScreen, SocialInteractionsScreen, StatsScreen, StructureBlockScreen, TitleScreen

@Environment(CLIENT)
public abstract class Screen
extends AbstractParentElement
implements TickableElement, Drawable
  • Field Details

    • LOGGER

      private static final Logger LOGGER
    • ALLOWED_PROTOCOLS

      private static final Set<String> ALLOWED_PROTOCOLS
    • title

      protected final Text title
    • children

      protected final List<Element> children
    • client

      @Nullable protected MinecraftClient client
    • itemRenderer

      protected ItemRenderer itemRenderer
    • width

      public int width
    • height

      public int height
    • buttons

      protected final List<AbstractButtonWidget> buttons
    • passEvents

      public boolean passEvents
    • textRenderer

      protected TextRenderer textRenderer
  • Constructor Details

    • Screen

      protected Screen​(Text title)
  • Method Details

    • getTitle

      public Text getTitle()
    • getNarrationMessage

      public String getNarrationMessage()
    • render

      public void render​(MatrixStack matrices, int mouseX, int mouseY, float delta)
      Specified by:
      render in interface Drawable
    • keyPressed

      public boolean keyPressed​(int keyCode, int scanCode, int modifiers)
      Callback for when a key down event has been captured. The key code is identified by the constants in GLFW class.
      Specified by:
      keyPressed in interface Element
      Specified by:
      keyPressed in interface ParentElement
      Parameters:
      keyCode - the named key code of the event as described in the GLFW class
      scanCode - the unique/platform-specific scan code of the keyboard input
      modifiers - a GLFW bitfield describing the modifier keys that are held down (see {@linkplain https://www.glfw.org/docs/3.3/group__mods.html GLFW Modifier key flags})
      Returns:
      true to indicate that the event handling is successful/valid
      See Also:
      Keyboard.onKey(long, int, int, int, int), GLFW.GLFW_KEY_Q, GLFWKeyCallbackI.invoke(long, int, int, int, int)
    • shouldCloseOnEsc

      public boolean shouldCloseOnEsc()
      Checks whether this screen should be closed when the escape key is pressed.
    • onClose

      public void onClose()
    • addButton

      protected <T extends AbstractButtonWidget> T addButton​(T button)
      Adds a button to this screen. This method should be preferred over addChild(Element) since buttons are automatically rendered when added to a screen.
    • addChild

      protected <T extends Element> T addChild​(T child)
      Adds a child element to this screen. If the child element is an AbstractButtonWidget, you should use addButton(AbstractButtonWidget) instead.

      Adding a child element to a screen does not guarantee the widget is rendered or ticked.

      See Also:
      addButton(AbstractButtonWidget)
    • renderTooltip

      protected void renderTooltip​(MatrixStack matrices, ItemStack stack, int x, int y)
    • getTooltipFromItem

      public List<Text> getTooltipFromItem​(ItemStack stack)
    • renderTooltip

      public void renderTooltip​(MatrixStack matrices, Text text, int x, int y)
    • renderTooltip

      public void renderTooltip​(MatrixStack matrices, List<Text> lines, int x, int y)
    • renderOrderedTooltip

      public void renderOrderedTooltip​(MatrixStack matrices, List<? extends OrderedText> lines, int x, int y)
    • renderTextHoverEffect

      protected void renderTextHoverEffect​(MatrixStack matrices, @Nullable Style style, int x, int y)
    • insertText

      protected void insertText​(String text, boolean override)
    • handleTextClick

      public boolean handleTextClick​(@Nullable Style style)
    • sendMessage

      public void sendMessage​(String message)
    • sendMessage

      public void sendMessage​(String message, boolean toHud)
    • init

      public void init​(MinecraftClient client, int width, int height)
    • children

      public List<? extends Element> children()
      Gets a list of all child GUI elements.
      Specified by:
      children in interface ParentElement
    • init

      protected void init()
      Called when a screen should be initialized.

      This method is called when this screen is opened or resized.

    • tick

      public void tick()
      Specified by:
      tick in interface TickableElement
    • removed

      public void removed()
    • renderBackground

      public void renderBackground​(MatrixStack matrices)
      Renders the background of this screen.

      If the client is in a world, renders the translucent background gradient. Otherwise renders the background texture.

    • renderBackground

      public void renderBackground​(MatrixStack matrices, int vOffset)
      Renders the background of this screen.

      If the client is in a world, renders the translucent background gradient. Otherwise renders the background texture.

      Parameters:
      vOffset - an offset applied to the V coordinate of the background texture
    • renderBackgroundTexture

      public void renderBackgroundTexture​(int vOffset)
      Renders the fullscreen background texture of this screen.
      Parameters:
      vOffset - an offset applied to the V coordinate of the background texture
    • isPauseScreen

      public boolean isPauseScreen()
    • confirmLink

      private void confirmLink​(boolean open)
    • openLink

      private void openLink​(URI link)
    • hasControlDown

      public static boolean hasControlDown()
    • hasShiftDown

      public static boolean hasShiftDown()
    • hasAltDown

      public static boolean hasAltDown()
    • isCut

      public static boolean isCut​(int code)
    • isPaste

      public static boolean isPaste​(int code)
    • isCopy

      public static boolean isCopy​(int code)
    • isSelectAll

      public static boolean isSelectAll​(int code)
    • resize

      public void resize​(MinecraftClient client, int width, int height)
    • wrapScreenError

      public static void wrapScreenError​(Runnable task, String errorTitle, String screenName)
    • isValidCharacterForName

      protected boolean isValidCharacterForName​(String name, char character, int cursorPos)
    • isMouseOver

      public boolean isMouseOver​(double mouseX, double mouseY)
      Checks if the mouse position is within the bound of the element.
      Specified by:
      isMouseOver in interface Element
      Parameters:
      mouseX - the X coordinate of the mouse
      mouseY - the Y coordinate of the mouse
      Returns:
      true if the mouse is within the bound of the element, otherwise false
    • filesDragged

      public void filesDragged​(List<Path> paths)