Skip to content

@minecraft/server-ui


@minecraft/server-ui / ActionFormData

Class: ActionFormData

Defined in: @minecraft/server-ui/index.d.ts:222

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

Examples

showActionForm.ts

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

showFavoriteMonth.ts

typescript
import { world, DimensionLocation } from '@minecraft/server';
import { ActionFormData, ActionFormResponse } from '@minecraft/server-ui';

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

  if (players.length >= 1) {
    const form = new ActionFormData()
      .title('Months')
      .body('Choose your favorite month!')
      .button('January')
      .button('February')
      .button('March')
      .button('April')
      .button('May');

    form.show(players[0]).then((response: ActionFormResponse) => {
      if (response.selection === 3) {
        log('I like April too!');
        return -1;
      }
    });
  }
}

Constructors

Constructor

new ActionFormData(): ActionFormData

Returns

ActionFormData

Methods

body()

body(bodyText): ActionFormData

Defined in: @minecraft/server-ui/index.d.ts:228

Parameters

bodyText

string | RawMessage

Returns

ActionFormData

Remarks

Method that sets the body text for the modal form.


button()

button(text, iconPath?): ActionFormData

Defined in: @minecraft/server-ui/index.d.ts:235

Parameters

text

string | RawMessage

iconPath?

string

Returns

ActionFormData

Remarks

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


divider()

divider(): ActionFormData

Defined in: @minecraft/server-ui/index.d.ts:241

Returns

ActionFormData

Remarks

Adds a section divider to the form.


header(text): ActionFormData

Defined in: @minecraft/server-ui/index.d.ts:249

Parameters

text

string | RawMessage

Text to display.

Returns

ActionFormData

Remarks

Adds a header to the form.


label()

label(text): ActionFormData

Defined in: @minecraft/server-ui/index.d.ts:257

Parameters

text

string | RawMessage

Text to display.

Returns

ActionFormData

Remarks

Adds a label to the form.


show()

show(player): Promise<ActionFormResponse>

Defined in: @minecraft/server-ui/index.d.ts:276

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.

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

Throws

This function can throw errors.

minecraftcommon.EngineError

minecraftserver.InvalidEntityError

minecraftserver.RawMessageError


title()

title(titleText): ActionFormData

Defined in: @minecraft/server-ui/index.d.ts:282

Parameters

titleText

string | RawMessage

Returns

ActionFormData

Remarks

This builder method sets the title for the modal dialog.