Class MinecraftClient

All Implemented Interfaces:
AutoCloseable, Executor, WindowEventHandler, SnooperListener, MessageListener<Runnable>

@Environment(CLIENT)
public class MinecraftClient
extends ReentrantThreadExecutor<Runnable>
implements SnooperListener, WindowEventHandler
Represents a logical Minecraft client. The logical Minecraft client is responsible for rendering, sound playback and control input. The Minecraft client also manages connections to a logical server which may be the client's IntegratedServer or a remote server. The Minecraft client instance may be obtained using getInstance().

Rendering on a Minecraft client is split into several facilities. The primary entrypoint for rendering is GameRenderer.render(float, long, boolean).

Rendering facilities
Thing to render Rendering facility
World WorldRenderer
Blocks and Fluids BlockRenderManager
Entities EntityRenderDispatcher
Block entities BlockEntityRenderDispatcher
Items ItemRenderer
Items held in hand HeldItemRenderer
Text TextRenderer
Game hud (health bar, hunger bar) InGameHud
See Also:
IntegratedServer, GameRenderer
  • Field Details

    • instance

      private static MinecraftClient instance
    • LOGGER

      private static final Logger LOGGER
    • IS_SYSTEM_MAC

      public static final boolean IS_SYSTEM_MAC
    • DEFAULT_FONT_ID

      public static final Identifier DEFAULT_FONT_ID
    • UNICODE_FONT_ID

      public static final Identifier UNICODE_FONT_ID
    • ALT_TEXT_RENDERER_ID

      public static final Identifier ALT_TEXT_RENDERER_ID
    • COMPLETED_UNIT_FUTURE

      private static final CompletableFuture<Unit> COMPLETED_UNIT_FUTURE
    • field_26841

      private static final Text field_26841
    • memoryReservedForCrash

      public static byte[] memoryReservedForCrash
    • currentFps

      private static int currentFps
    • resourcePackDir

      private final File resourcePackDir
    • sessionPropertyMap

      private final com.mojang.authlib.properties.PropertyMap sessionPropertyMap
    • textureManager

      private final TextureManager textureManager
    • dataFixer

      private final com.mojang.datafixers.DataFixer dataFixer
    • windowProvider

      private final WindowProvider windowProvider
    • window

      private final Window window
    • renderTickCounter

      private final RenderTickCounter renderTickCounter
    • snooper

      private final Snooper snooper
    • bufferBuilders

      private final BufferBuilderStorage bufferBuilders
    • worldRenderer

      public final WorldRenderer worldRenderer
    • entityRenderDispatcher

      private final EntityRenderDispatcher entityRenderDispatcher
    • itemRenderer

      private final ItemRenderer itemRenderer
    • heldItemRenderer

      private final HeldItemRenderer heldItemRenderer
    • particleManager

      public final ParticleManager particleManager
    • searchManager

      private final SearchManager searchManager
    • session

      private final Session session
    • textRenderer

      public final TextRenderer textRenderer
    • gameRenderer

      public final GameRenderer gameRenderer
    • debugRenderer

      public final DebugRenderer debugRenderer
    • worldGenProgressTracker

      private final AtomicReference<WorldGenerationProgressTracker> worldGenProgressTracker
    • inGameHud

      public final InGameHud inGameHud
    • options

      public final GameOptions options
    • creativeHotbarStorage

      private final HotbarStorage creativeHotbarStorage
    • mouse

      public final Mouse mouse
    • keyboard

      public final Keyboard keyboard
    • runDirectory

      public final File runDirectory
      The directory that stores options, worlds, resource packs, logs, etc.
    • gameVersion

      private final String gameVersion
    • versionType

      private final String versionType
    • netProxy

      private final Proxy netProxy
    • levelStorage

      private final LevelStorage levelStorage
    • metricsData

      public final MetricsData metricsData
    • is64Bit

      private final boolean is64Bit
    • isDemo

      private final boolean isDemo
    • multiplayerEnabled

      private final boolean multiplayerEnabled
    • onlineChatEnabled

      private final boolean onlineChatEnabled
    • resourceManager

      private final ReloadableResourceManager resourceManager
    • builtinPackProvider

      private final ClientBuiltinResourcePackProvider builtinPackProvider
    • resourcePackManager

      private final ResourcePackManager resourcePackManager
    • languageManager

      private final LanguageManager languageManager
    • blockColors

      private final BlockColors blockColors
    • itemColors

      private final ItemColors itemColors
    • framebuffer

      private final Framebuffer framebuffer
    • soundManager

      private final SoundManager soundManager
    • musicTracker

      private final MusicTracker musicTracker
    • fontManager

      private final FontManager fontManager
    • splashTextLoader

      private final SplashTextResourceSupplier splashTextLoader
    • videoWarningManager

      private final VideoWarningManager videoWarningManager
    • sessionService

      private final com.mojang.authlib.minecraft.MinecraftSessionService sessionService
    • field_26902

      private final com.mojang.authlib.minecraft.SocialInteractionsService field_26902
    • skinProvider

      private final PlayerSkinProvider skinProvider
    • bakedModelManager

      private final BakedModelManager bakedModelManager
    • blockRenderManager

      private final BlockRenderManager blockRenderManager
    • paintingManager

      private final PaintingManager paintingManager
    • statusEffectSpriteManager

      private final StatusEffectSpriteManager statusEffectSpriteManager
    • toastManager

      private final ToastManager toastManager
    • game

      private final MinecraftClientGame game
    • tutorialManager

      private final TutorialManager tutorialManager
    • socialInteractionsManager

      private final SocialInteractionsManager socialInteractionsManager
    • interactionManager

      @Nullable public ClientPlayerInteractionManager interactionManager
    • world

      @Nullable public ClientWorld world
      Represents the world the client is currently viewing. This field is not null when in game.
    • player

      Represents the client's own player. This field is not null when in game.
    • server

      @Nullable private IntegratedServer server
    • currentServerEntry

      @Nullable private ServerInfo currentServerEntry
    • integratedServerConnection

      @Nullable private ClientConnection integratedServerConnection
      The client connection to the integrated server. This is only used when connecting to the integrated server.
      See Also:
      ConnectScreen
    • integratedServerRunning

      private boolean integratedServerRunning
    • cameraEntity

      @Nullable public Entity cameraEntity
    • targetedEntity

      @Nullable public Entity targetedEntity
    • crosshairTarget

      @Nullable public HitResult crosshairTarget
    • itemUseCooldown

      private int itemUseCooldown
      The cooldown for using items when the item use button is held down.
    • attackCooldown

      protected int attackCooldown
    • paused

      private boolean paused
    • pausedTickDelta

      private float pausedTickDelta
    • lastMetricsSampleTime

      private long lastMetricsSampleTime
    • nextDebugInfoUpdateTime

      private long nextDebugInfoUpdateTime
    • fpsCounter

      private int fpsCounter
    • skipGameRender

      public boolean skipGameRender
    • currentScreen

      @Nullable public Screen currentScreen
      The Minecraft client's currently open screen. This field should only be used to get the current screen. For changing the screen use openScreen(Screen)
      See Also:
      openScreen(Screen)
    • overlay

      @Nullable public Overlay overlay
    • connectedToRealms

      private boolean connectedToRealms
    • thread

      private Thread thread
    • running

      private volatile boolean running
    • crashReport

      @Nullable private CrashReport crashReport
    • fpsDebugString

      public String fpsDebugString
    • debugChunkInfo

      public boolean debugChunkInfo
    • debugChunkOcclusion

      public boolean debugChunkOcclusion
    • chunkCullingEnabled

      public boolean chunkCullingEnabled
    • windowFocused

      private boolean windowFocused
    • renderTaskQueue

      private final Queue<Runnable> renderTaskQueue
    • resourceReloadFuture

      @Nullable private CompletableFuture<Void> resourceReloadFuture
    • field_26843

      @Nullable private TutorialToast field_26843
    • profiler

      private Profiler profiler
    • trackingTick

      private int trackingTick
    • tickTimeTracker

      private final TickTimeTracker tickTimeTracker
    • tickProfilerResult

      @Nullable private ProfileResult tickProfilerResult
    • openProfilerSection

      private String openProfilerSection
  • Constructor Details

    • MinecraftClient

      public MinecraftClient​(RunArgs args)
  • Method Details

    • updateWindowTitle

      public void updateWindowTitle()
    • getWindowTitle

      private String getWindowTitle()
    • method_31382

      private com.mojang.authlib.minecraft.SocialInteractionsService method_31382​(com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService yggdrasilAuthenticationService, RunArgs runArgs)
    • isModded

      public boolean isModded()
      Checks if this client is modded.

      This checks the client's brand and if the MinecraftClient's class is still signed.

    • handleResourceReloadException

      private void handleResourceReloadException​(Throwable exception)
    • method_31186

      public void method_31186​(Throwable throwable, @Nullable Text text)
    • run

      public void run()
    • initFont

      void initFont​(boolean forcesUnicode)
    • initializeSearchableContainers

      private void initializeSearchableContainers()
    • handleGlErrorByDisableVsync

      private void handleGlErrorByDisableVsync​(int error, long description)
    • checkIs64Bit

      private static boolean checkIs64Bit()
    • getFramebuffer

      public Framebuffer getFramebuffer()
    • getGameVersion

      public String getGameVersion()
    • getVersionType

      public String getVersionType()
    • setCrashReport

      public void setCrashReport​(CrashReport report)
    • printCrashReport

      public static void printCrashReport​(CrashReport report)
    • forcesUnicodeFont

      public boolean forcesUnicodeFont()
    • reloadResources

      public CompletableFuture<Void> reloadResources()
    • checkGameData

      private void checkGameData()
    • getLevelStorage

      public LevelStorage getLevelStorage()
    • openChatScreen

      private void openChatScreen​(String text)
    • openScreen

      public void openScreen​(@Nullable Screen screen)
      Opens a new screen, changing the current screen if needed.

      If the screen being opened is null and the client is not in game, the title screen will be opened. If the currently opened screen is null and player is dead then the death screen will be opened. Otherwise the currently open screen will be closed.

    • setOverlay

      public void setOverlay​(@Nullable Overlay overlay)
    • stop

      public void stop()
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface MessageListener<Runnable>
    • render

      private void render​(boolean tick)
    • shouldMonitorTickDuration

      private boolean shouldMonitorTickDuration()
    • startMonitor

      private void startMonitor​(boolean active, @Nullable TickDurationMonitor monitor)
    • endMonitor

      private void endMonitor​(boolean active, @Nullable TickDurationMonitor monitor)
    • onResolutionChanged

      public void onResolutionChanged()
      Specified by:
      onResolutionChanged in interface WindowEventHandler
    • onCursorEnterChanged

      public void onCursorEnterChanged()
      Specified by:
      onCursorEnterChanged in interface WindowEventHandler
    • getFramerateLimit

      private int getFramerateLimit()
    • cleanUpAfterCrash

      public void cleanUpAfterCrash()
    • handleProfilerKeyPress

      void handleProfilerKeyPress​(int digit)
    • drawProfilerResults

      private void drawProfilerResults​(MatrixStack matrices, ProfileResult profileResult)
    • scheduleStop

      public void scheduleStop()
    • isRunning

      public boolean isRunning()
    • openPauseMenu

      public void openPauseMenu​(boolean pause)
    • handleBlockBreaking

      private void handleBlockBreaking​(boolean bool)
    • doAttack

      private void doAttack()
    • doItemUse

      private void doItemUse()
    • getMusicTracker

      public MusicTracker getMusicTracker()
    • tick

      public void tick()
    • method_31321

      private boolean method_31321()
    • handleInputEvents

      private void handleInputEvents()
    • method_29598

      public static DataPackSettings method_29598​(LevelStorage.Session session)
    • createSaveProperties

      public static SaveProperties createSaveProperties​(LevelStorage.Session session, DynamicRegistryManager.Impl registryTracker, ResourceManager resourceManager, DataPackSettings dataPackSettings)
    • startIntegratedServer

      public void startIntegratedServer​(String worldName)
    • createWorld

      public void createWorld​(String worldName, LevelInfo levelInfo, DynamicRegistryManager.Impl registryTracker, GeneratorOptions generatorOptions)
    • startIntegratedServer

      private void startIntegratedServer​(String worldName, DynamicRegistryManager.Impl registryTracker, Function<LevelStorage.Session,​DataPackSettings> dataPackSettingsGetter, com.mojang.datafixers.util.Function4<LevelStorage.Session,​DynamicRegistryManager.Impl,​ResourceManager,​DataPackSettings,​SaveProperties> savePropertiesGetter, boolean safeMode, MinecraftClient.WorldLoadAction worldLoadAction)
    • method_29601

      private void method_29601​(MinecraftClient.WorldLoadAction worldLoadAction, String string, boolean bool, Runnable runnable)
    • method_29604

    • joinWorld

      public void joinWorld​(ClientWorld world)
    • disconnect

      public void disconnect()
    • disconnect

      public void disconnect​(Screen screen)
    • reset

      private void reset​(Screen screen)
    • method_29970

      public void method_29970​(Screen screen)
    • setWorld

      private void setWorld​(@Nullable ClientWorld world)
    • isMultiplayerEnabled

      public boolean isMultiplayerEnabled()
    • shouldBlockMessages

      public boolean shouldBlockMessages​(UUID sender)
      Checks if the client should block messages from the sender.

      If true, messages will not be displayed in chat and narrator will not process them.

    • isOnlineChatEnabled

      public boolean isOnlineChatEnabled()
    • isDemo

      public final boolean isDemo()
    • getNetworkHandler

      @Nullable public ClientPlayNetworkHandler getNetworkHandler()
    • isHudEnabled

      public static boolean isHudEnabled()
    • isFancyGraphicsOrBetter

      public static boolean isFancyGraphicsOrBetter()
    • isFabulousGraphicsOrBetter

      public static boolean isFabulousGraphicsOrBetter()
    • isAmbientOcclusionEnabled

      public static boolean isAmbientOcclusionEnabled()
    • doItemPick

      private void doItemPick()
    • addBlockEntityNbt

      private ItemStack addBlockEntityNbt​(ItemStack stack, BlockEntity blockEntity)
    • addDetailsToCrashReport

      public CrashReport addDetailsToCrashReport​(CrashReport report)
    • addSystemDetailsToCrashReport

      public static void addSystemDetailsToCrashReport​(@Nullable LanguageManager languageManager, String version, @Nullable GameOptions options, CrashReport report)
    • getInstance

      public static MinecraftClient getInstance()
    • reloadResourcesConcurrently

      public CompletableFuture<Void> reloadResourcesConcurrently()
    • addSnooperInfo

      public void addSnooperInfo​(Snooper snooper)
      Specified by:
      addSnooperInfo in interface SnooperListener
    • getCurrentAction

      private String getCurrentAction()
    • setCurrentServerEntry

      public void setCurrentServerEntry​(@Nullable ServerInfo serverEntry)
    • getCurrentServerEntry

      @Nullable public ServerInfo getCurrentServerEntry()
    • isInSingleplayer

      public boolean isInSingleplayer()
    • isIntegratedServerRunning

      public boolean isIntegratedServerRunning()
    • getServer

      @Nullable public IntegratedServer getServer()
      Gets this client's own integrated server.

      The integrated server is only present when a local single player world is open.

    • getSnooper

      public Snooper getSnooper()
    • getSession

      public Session getSession()
    • getSessionProperties

      public com.mojang.authlib.properties.PropertyMap getSessionProperties()
    • getNetworkProxy

      public Proxy getNetworkProxy()
    • getTextureManager

      public TextureManager getTextureManager()
    • getResourceManager

      public ResourceManager getResourceManager()
    • getResourcePackManager

      public ResourcePackManager getResourcePackManager()
    • getResourcePackProvider

      public ClientBuiltinResourcePackProvider getResourcePackProvider()
    • getResourcePackDir

      public File getResourcePackDir()
    • getLanguageManager

      public LanguageManager getLanguageManager()
    • getSpriteAtlas

      public Function<Identifier,​Sprite> getSpriteAtlas​(Identifier id)
    • is64Bit

      public boolean is64Bit()
    • isPaused

      public boolean isPaused()
    • getVideoWarningManager

      public VideoWarningManager getVideoWarningManager()
    • getSoundManager

      public SoundManager getSoundManager()
    • getMusicType

      public MusicSound getMusicType()
    • getSessionService

      public com.mojang.authlib.minecraft.MinecraftSessionService getSessionService()
    • getSkinProvider

      public PlayerSkinProvider getSkinProvider()
    • getCameraEntity

      @Nullable public Entity getCameraEntity()
    • setCameraEntity

      public void setCameraEntity​(Entity entity)
    • hasOutline

      public boolean hasOutline​(Entity entity)
      Checks if the provided entity should display an outline around its model.
    • getThread

      protected Thread getThread()
      Specified by:
      getThread in class ThreadExecutor<Runnable>
    • createTask

      protected Runnable createTask​(Runnable runnable)
      Specified by:
      createTask in class ThreadExecutor<Runnable>
    • canExecute

      protected boolean canExecute​(Runnable task)
      Specified by:
      canExecute in class ThreadExecutor<Runnable>
    • getBlockRenderManager

      public BlockRenderManager getBlockRenderManager()
    • getEntityRenderDispatcher

      public EntityRenderDispatcher getEntityRenderDispatcher()
    • getItemRenderer

      public ItemRenderer getItemRenderer()
    • getHeldItemRenderer

      public HeldItemRenderer getHeldItemRenderer()
    • getSearchableContainer

      public <T> SearchableContainer<T> getSearchableContainer​(SearchManager.Key<T> key)
    • getMetricsData

      public MetricsData getMetricsData()
    • isConnectedToRealms

      public boolean isConnectedToRealms()
    • setConnectedToRealms

      public void setConnectedToRealms​(boolean connectedToRealms)
    • getDataFixer

      public com.mojang.datafixers.DataFixer getDataFixer()
    • getTickDelta

      public float getTickDelta()
    • getLastFrameDuration

      public float getLastFrameDuration()
    • getBlockColors

      public BlockColors getBlockColors()
    • hasReducedDebugInfo

      public boolean hasReducedDebugInfo()
    • getToastManager

      public ToastManager getToastManager()
    • getTutorialManager

      public TutorialManager getTutorialManager()
    • isWindowFocused

      public boolean isWindowFocused()
    • getCreativeHotbarStorage

      public HotbarStorage getCreativeHotbarStorage()
    • getBakedModelManager

      public BakedModelManager getBakedModelManager()
    • getPaintingManager

      public PaintingManager getPaintingManager()
    • getStatusEffectSpriteManager

      public StatusEffectSpriteManager getStatusEffectSpriteManager()
    • onWindowFocusChanged

      public void onWindowFocusChanged​(boolean focused)
      Specified by:
      onWindowFocusChanged in interface WindowEventHandler
    • getProfiler

      public Profiler getProfiler()
    • getGame

      public MinecraftClientGame getGame()
    • getSplashTextLoader

      public SplashTextResourceSupplier getSplashTextLoader()
    • getOverlay

      @Nullable public Overlay getOverlay()
    • getSocialInteractionsManager

      public SocialInteractionsManager getSocialInteractionsManager()
    • shouldRenderAsync

      public boolean shouldRenderAsync()
    • getWindow

      public Window getWindow()
    • getBufferBuilders

      public BufferBuilderStorage getBufferBuilders()
    • createResourcePackProfile

      private static ResourcePackProfile createResourcePackProfile​(String name, boolean alwaysEnabled, Supplier<ResourcePack> packFactory, ResourcePack pack, PackResourceMetadata metadata, ResourcePackProfile.InsertionPosition insertionPosition, ResourcePackSource source)
    • createV3ResourcePackFactory

      private static Supplier<ResourcePack> createV3ResourcePackFactory​(Supplier<ResourcePack> packFactory)
    • createV4ResourcePackFactory

      private static Supplier<ResourcePack> createV4ResourcePackFactory​(Supplier<ResourcePack> packFactory)
    • setMipmapLevels

      public void setMipmapLevels​(int mipmapLevels)