Skip to content

@minecraft/server


@minecraft/server / ScreenDisplay

Class: ScreenDisplay ​

Defined in: @minecraft/server/index.d.ts:19327

Contains information about user interface elements that are showing up on the screen.

Examples ​

setTitle.ts

typescript
import { world, DimensionLocation } from '@minecraft/server';

function setTitle(targetLocation: DimensionLocation) {
  const players = world.getPlayers();

  if (players.length > 0) {
    players[0].onScreenDisplay.setTitle('§o§6Fancy Title§r');
  }
}

setTitleAndSubtitle.ts

typescript
import { world, DimensionLocation } from '@minecraft/server';

function setTitleAndSubtitle(targetLocation: DimensionLocation) {
  const players = world.getPlayers();

  players[0].onScreenDisplay.setTitle('Chapter 1', {
    stayDuration: 100,
    fadeInDuration: 2,
    fadeOutDuration: 4,
    subtitle: 'Trouble in Block Town',
  });
}

countdown.ts

typescript
import { world, system, DimensionLocation } from '@minecraft/server';

function countdown(targetLocation: DimensionLocation) {
  const players = world.getPlayers();

  players[0].onScreenDisplay.setTitle('Get ready!', {
    stayDuration: 220,
    fadeInDuration: 2,
    fadeOutDuration: 4,
    subtitle: '10',
  });

  let countdown = 10;

  const intervalId = system.runInterval(() => {
    countdown--;
    players[0].onScreenDisplay.updateSubtitle(countdown.toString());

    if (countdown == 0) {
      system.clearRun(intervalId);
    }
  }, 20);
}

Properties ​

isValid ​

readonly isValid: boolean

Defined in: @minecraft/server/index.d.ts:19335

Remarks ​

Returns true if the current reference to this screen display manager object is valid and functional.

Methods ​

getHiddenHudElements() ​

getHiddenHudElements(): HudElement[]

Defined in: @minecraft/server/index.d.ts:19344

Returns ​

HudElement[]

Remarks ​

This function can't be called in restricted-execution mode.

Throws ​

This function can throw errors.

InvalidEntityError


hideAllExcept() ​

hideAllExcept(hudElements?): void

Defined in: @minecraft/server/index.d.ts:19353

Parameters ​

hudElements? ​

HudElement[]

Returns ​

void

Remarks ​

This function can't be called in restricted-execution mode.

Throws ​

This function can throw errors.

InvalidEntityError


isForcedHidden() ​

isForcedHidden(hudElement): boolean

Defined in: @minecraft/server/index.d.ts:19362

Parameters ​

hudElement ​

HudElement

Returns ​

boolean

Remarks ​

This function can't be called in restricted-execution mode.

Throws ​

This function can throw errors.

InvalidEntityError


resetHudElementsVisibility() ​

resetHudElementsVisibility(): void

Defined in: @minecraft/server/index.d.ts:19371

Returns ​

void

Remarks ​

This function can't be called in restricted-execution mode.

Throws ​

This function can throw errors.

InvalidEntityError


setActionBar() ​

setActionBar(text): void

Defined in: @minecraft/server/index.d.ts:19387

Parameters ​

text ​

string | RawMessage | (string | RawMessage)[]

New value for the action bar text.

Returns ​

void

Remarks ​

Set the action bar text - a piece of text that displays beneath the title and above the hot-bar.

This function can't be called in restricted-execution mode.

Throws ​

This function can throw errors.

InvalidEntityError

RawMessageError


setHudVisibility() ​

setHudVisibility(visible, hudElements?): void

Defined in: @minecraft/server/index.d.ts:19404

Parameters ​

visible ​

HudVisibility

Whether to set the HUD element to invisible, or to reset it back to its default.

hudElements? ​

HudElement[]

Optional list of HUD elements to configure visibility for.

Returns ​

void

Remarks ​

Sets visibility of a particular element of the heads up display (HUD).

This function can't be called in restricted-execution mode.

Throws ​

This function can throw errors.

InvalidEntityError


setTitle() ​

setTitle(title, options?): void

Defined in: @minecraft/server/index.d.ts:19475

Parameters ​

title ​

string | RawMessage | (string | RawMessage)[]

options? ​

TitleDisplayOptions

Returns ​

void

Remarks ​

Will cause a title to show up on the player's on screen display. Will clear the title if set to empty string. You can optionally specify an additional subtitle as well as fade in, stay and fade out times.

This function can't be called in restricted-execution mode.

Throws ​

This function can throw errors.

minecraftcommon.ArgumentOutOfBoundsError

InvalidEntityError

RawMessageError

Examples ​

setTitle.ts

typescript
import { world, DimensionLocation } from '@minecraft/server';

function setTitle(targetLocation: DimensionLocation) {
  const players = world.getPlayers();

  if (players.length > 0) {
    players[0].onScreenDisplay.setTitle('§o§6Fancy Title§r');
  }
}

setTitleAndSubtitle.ts

typescript
import { world, DimensionLocation } from '@minecraft/server';

function setTitleAndSubtitle(targetLocation: DimensionLocation) {
  const players = world.getPlayers();

  players[0].onScreenDisplay.setTitle('Chapter 1', {
    stayDuration: 100,
    fadeInDuration: 2,
    fadeOutDuration: 4,
    subtitle: 'Trouble in Block Town',
  });
}

countdown.ts

typescript
import { world, system, DimensionLocation } from '@minecraft/server';

function countdown(targetLocation: DimensionLocation) {
  const players = world.getPlayers();

  players[0].onScreenDisplay.setTitle('Get ready!', {
    stayDuration: 220,
    fadeInDuration: 2,
    fadeOutDuration: 4,
    subtitle: '10',
  });

  let countdown = 10;

  const intervalId = system.runInterval(() => {
    countdown--;
    players[0].onScreenDisplay.updateSubtitle(countdown.toString());

    if (countdown == 0) {
      system.clearRun(intervalId);
    }
  }, 20);
}

updateSubtitle() ​

updateSubtitle(subtitle): void

Defined in: @minecraft/server/index.d.ts:19515

Parameters ​

subtitle ​

string | RawMessage | (string | RawMessage)[]

Returns ​

void

Remarks ​

Updates the subtitle if the subtitle was previously displayed via the setTitle method.

This function can't be called in restricted-execution mode.

Throws ​

This function can throw errors.

InvalidEntityError

RawMessageError

Example ​

countdown.ts

typescript
import { world, system, DimensionLocation } from '@minecraft/server';

function countdown(targetLocation: DimensionLocation) {
  const players = world.getPlayers();

  players[0].onScreenDisplay.setTitle('Get ready!', {
    stayDuration: 220,
    fadeInDuration: 2,
    fadeOutDuration: 4,
    subtitle: '10',
  });

  let countdown = 10;

  const intervalId = system.runInterval(() => {
    countdown--;
    players[0].onScreenDisplay.updateSubtitle(countdown.toString());

    if (countdown == 0) {
      system.clearRun(intervalId);
    }
  }, 20);
}