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/ActionFormData.md.

Class: ActionFormData

Beta

构建一个带有按钮的简单玩家表单,让玩家可以执行操作。

Builds a simple player form with buttons that let the player take action.

Examples

showActionForm.ts
showFavoriteMonth.ts
import { world, DimensionLocation } from '@minecraft/server';
import { ActionFormData, ActionFormResponse } from '@minecraft/server-ui';

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

  if (playerList.length >= 1) {
    const form = new ActionFormData()
      .title('Test Title')
      .body('Body text here!')
      .button('btn 1')
      .button('btn 2')
      .button('btn 3')
      .button('btn 4')
      .button('btn 5');

    form.show(playerList[0]).then((result: ActionFormResponse) => {
      if (result.canceled) {
        log('Player exited out of the dialog. Note that if the chat window is up, dialogs are automatically canceled.');
        return -1;
      } else {
        log('Your result was: ' + result.selection);
      }
    });
  }
}

Constructors

Constructor

new ActionFormData(): ActionFormData

Beta

Returns

ActionFormData

Methods

body()

body(bodyText): ActionFormData

Beta

Parameters

bodyText

any

Returns

ActionFormData

Remarks

设置模态表单主体文本的方法。

Method that sets the body text for the modal form.


button()

button(text, iconPath?): ActionFormData

Beta

Parameters

text

any

iconPath?

string

Returns

ActionFormData

Remarks

向此表单添加一个带有资源包图标的按钮。

Adds a button to this form with an icon from a resource pack.


divider()

divider(): ActionFormData

Beta

Returns

ActionFormData

Remarks

向表单添加一个区域分隔线。

Adds a section divider to the form.


header(text): ActionFormData

Beta

Parameters

text

any

要显示的文本。

Text to display.

Returns

ActionFormData

Remarks

向表单添加一个标题。

Adds a header to the form.


label()

label(text): ActionFormData

Beta

Parameters

text

any

要显示的文本。

Text to display.

Returns

ActionFormData

Remarks

向表单添加一个标签。

Adds a label to the form.


show()

show(player): Promise<ActionFormResponse>

World Mutation Beta

Parameters

player

Player

要向其显示此对话框的玩家。

Player to show this dialog to.

Returns

Promise<ActionFormResponse>

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): ActionFormData

Beta

Parameters

titleText

any

Returns

ActionFormData

Remarks

此构建器方法设置模态对话框的标题。

This builder method sets the title for the modal dialog.