GuiUtil interface provides simple and handy utility functions for working with Minecraft’s GUI system, including screen management and GUI scale detection.
Accessing GuiUtil
Screen Management
openScreen
Queues a new screen for opening synchronously, avoiding potential mouse glitches.- Kotlin
- Java
screen: GuiScreen?- The screen to open, ornullto close the current screen
- Ensures GUI displays synchronously
- Prevents mouse glitches that can occur with direct screen opening
- Thread-safe screen transitions
openedScreen
Returns the currently opened GUI screen.GuiScreen? - The currently open screen, or null if no screen is open
GUI Scale
getGuiScale
Retrieves the current GUI scale setting.step: Int- Optional step parameter for GUI scale calculation (default behavior when not specified)
Int - -1 for automatic/current Minecraft GUI scale, or a positive integer indicating the GUI scale level
Method Reference
Common Use Cases
Opening Custom GUIs
Checking Current Screen
Scale-Aware Rendering
Conditional GUI Opening
Thread-Safe GUI Opening
Notes
- Always use
GuiUtil.open()instead of directly settingMinecraft.currentScreento avoid mouse glitches - The API handles synchronization automatically, making it safe to call from any thread
- Passing
nulltoopenScreen()will close the current GUI - The GUI scale value of
-1indicates automatic/default Minecraft scaling