For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /server/classes/ScreenDisplay.md.

Class: ScreenDisplay

Beta

包含关于显示在屏幕上的用户界面元素的信息。

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

Examples

setTitle.ts
setTitleAndSubtitle.ts
countdown.ts
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');
  }
}

Properties

isValid

readonly isValid: boolean

Beta

Remarks

返回当前对此屏幕显示管理器对象的引用是否有效且可用。

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

Methods

getHiddenHudElements()

getHiddenHudElements(): HudElement[]

World Mutation Beta

Returns

HudElement[]

Remarks

Throws

This function can throw errors.

InvalidEntityError


hideAllExcept()

hideAllExcept(hudElements?): void

World Mutation Beta

Parameters

hudElements?

HudElement[]

Returns

void

Remarks

Throws

This function can throw errors.

InvalidEntityError


isForcedHidden()

isForcedHidden(hudElement): boolean

World Mutation Beta

Parameters

hudElement

HudElement

Returns

boolean

Remarks

Throws

This function can throw errors.

InvalidEntityError


resetHudElementsVisibility()

resetHudElementsVisibility(): void

World Mutation Beta

Returns

void

Remarks

Throws

This function can throw errors.

InvalidEntityError


setActionBar()

setActionBar(text): void

World Mutation Beta

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.

Throws

This function can throw errors.

InvalidEntityError

RawMessageError


setHudVisibility()

setHudVisibility(visible, hudElements?): void

World Mutation Beta

Parameters

visible

HudVisibility

是否将 HUD 元素设置为不可见,或恢复为默认状态。

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

hudElements?

HudElement[]

可选的 HUD 元素列表,用于配置可见性。

Optional list of HUD elements to configure visibility for.

Returns

void

Remarks

设置平视显示器(HUD)特定元素的可见性。

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

Throws

This function can throw errors.

InvalidEntityError


setTitle()

setTitle(title, options?): void

World Mutation Beta

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.

Throws

This function can throw errors.

ArgumentOutOfBoundsError

InvalidEntityError

RawMessageError

Examples

setTitle.ts

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

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

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

World Mutation Beta

Parameters

subtitle

string | RawMessage | (string | RawMessage)[]

Returns

void

Remarks

如果副标题先前已通过 setTitle 方法显示,则更新副标题。

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

Throws

This function can throw errors.

InvalidEntityError

RawMessageError

Example

countdown.ts

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);
}