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-ui/classes/MessageFormData.md.

Class: MessageFormData

Beta

Builds a simple two-button modal dialog. 构建一个简单的双按钮模态对话框。

Examples

showBasicMessageForm.ts
showTranslatedMessageForm.ts
import { world, DimensionLocation } from '@minecraft/server';
import { MessageFormResponse, MessageFormData } from '@minecraft/server-ui';

function showBasicMessageForm(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) {
  const players = world.getPlayers();

  const messageForm = new MessageFormData()
    .title('Message Form Example')
    .body('This shows a simple example using §o§7MessageFormData§r.')
    .button1('Button 1')
    .button2('Button 2');

  messageForm
    .show(players[0])
    .then((formData: MessageFormResponse) => {
      // player canceled the form, or another dialog was up and open.
      if (formData.canceled || formData.selection === undefined) {
        return;
      }

      log(`You selected ${formData.selection === 0 ? 'Button 1' : 'Button 2'}`);
    })
    .catch((error: Error) => {
      log('Failed to show form: ' + error);
      return -1;
    });
}

Constructors

Constructor

new MessageFormData(): MessageFormData

Beta

Returns

MessageFormData

Methods

body()

body(bodyText): MessageFormData

Beta

Parameters

bodyText

any

Returns

MessageFormData

Remarks

Method that sets the body text for the modal form. 设置模态表单正文文本的方法。


button1()

button1(text): MessageFormData

Beta

Parameters

text

any

Returns

MessageFormData

Remarks

Method that sets the text for the first button of the dialog. 设置对话框第一个按钮文本的方法。


button2()

button2(text): MessageFormData

Beta

Parameters

text

any

Returns

MessageFormData

Remarks

This method sets the text for the second button on the dialog. 此方法设置对话框上第二个按钮的文本。


show()

show(player): Promise<MessageFormResponse>

World Mutation Beta

Parameters

player

Player

Player to show this dialog to. 要向其展示此对话框的玩家。

Returns

Promise<MessageFormResponse>

Remarks

Creates and shows this modal popup form. Returns asynchronously when the player confirms or cancels the dialog. 创建并显示此模态弹出表单。当玩家确认或取消对话框时异步返回。

Throws

This function can throw errors.

EngineError

InvalidEntityError

RawMessageError


title()

title(titleText): MessageFormData

Beta

Parameters

titleText

any

Returns

MessageFormData

Remarks

This builder method sets the title for the modal dialog. 此构建器方法设置模态对话框的标题。