Script API - v26.70.26
    Preparing search index...

    A customizable data driven (DDUI) form that lets you add buttons, labels, toggles, dropdowns, sliders, text fields, and more. The form layout is built by calling methods to add components before calling show(). Any Observable values bound to form components will automatically update the UI when their values change.

    import { Player, system } from "@minecraft/server";
    import { CustomForm, ObservableBoolean, ObservableNumber, ObservableString } from "@minecraft/server-ui";

    // Run `/scriptevent example:demo` in chat to open the form.
    system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
    if (id !== "example:demo" || !(sourceEntity instanceof Player)) return;

    const playerName = new ObservableString(sourceEntity.name, { clientWritable: true });
    const difficulty = new ObservableNumber(1, { clientWritable: true });
    const musicEnabled = new ObservableBoolean(true, { clientWritable: true });
    const volumeLevel = new ObservableNumber(75, { clientWritable: true });

    new CustomForm(sourceEntity, "Game Settings")
    .closeButton()
    .spacer()
    .label("General Settings")
    .divider()
    .textField("Player Name", playerName, { description: "Your display name in-game" })
    .dropdown("Difficulty", difficulty, [
    { label: "Peaceful", value: 0 },
    { label: "Easy", value: 1 },
    { label: "Normal", value: 2 },
    { label: "Hard", value: 3 },
    ])
    .spacer()
    .divider()
    .label("Audio Settings")
    .toggle("Music Enabled", musicEnabled)
    .slider("Volume", volumeLevel, 0, 100, { description: "Master volume level", step: 5 })
    .show()
    .then(() => {
    sourceEntity.sendMessage(
    `Saved: name=${playerName.getData()}, difficulty=${difficulty.getData()}, music=${musicEnabled.getData()}, volume=${volumeLevel.getData()}`,
    );
    });
    });
    import { Player, system } from "@minecraft/server";
    import { CustomForm } from "@minecraft/server-ui";

    // Run `/scriptevent example:localizedtext` in chat to open the form.
    // This example expects translation keys to exist in your resource pack language files.
    system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
    if (id !== "example:localizedtext" || !(sourceEntity instanceof Player)) return;

    new CustomForm(sourceEntity, { translate: "ui.settings.title" })
    .label({ translate: "ui.settings.description", with: ["value1", "value2"] })
    .button({ translate: "ui.button.save" }, () => {
    sourceEntity.sendMessage("Localized save button clicked.");
    })
    .closeButton()
    .show();
    });
    import { Player, TicksPerSecond, system } from "@minecraft/server";
    import { CustomForm, ObservableBoolean, ObservableString } from "@minecraft/server-ui";

    // Run `/scriptevent example:realtimeentitymonitor` in chat to open the form.
    system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
    if (id !== "example:realtimeentitymonitor" || !(sourceEntity instanceof Player)) return;

    const entityStatus = new ObservableString("Scanning...");
    const clearButtonDisabled = new ObservableBoolean(true);
    const statusMessage = new ObservableString("No action yet.");

    // Update the entity count every 4 seconds while the form stays open.
    const intervalId = system.runInterval(() => {
    const location = sourceEntity.location;
    const nearbyEntities = sourceEntity.dimension.getEntities({
    location,
    maxDistance: 20,
    excludeTypes: ["minecraft:player"],
    });

    entityStatus.setData(`Found ${nearbyEntities.length} entities within 20 blocks.`);
    clearButtonDisabled.setData(nearbyEntities.length === 0);
    }, TicksPerSecond * 4);

    new CustomForm(sourceEntity, "Entity Monitor")
    .label(entityStatus)
    .button(
    "Remove Nearby Entities",
    () => {
    const location = sourceEntity.location;
    const entities = sourceEntity.dimension.getEntities({
    location,
    maxDistance: 20,
    excludeTypes: ["minecraft:player"],
    });

    for (const entity of entities) {
    entity.kill();
    }
    statusMessage.setData(`Removed ${entities.length} entities.`);
    },
    { tooltip: "Removes non-player entities in range", disabled: clearButtonDisabled },
    )
    .divider()
    .label(statusMessage)
    .closeButton()
    .show()
    .then(() => system.clearRun(intervalId));
    });
    import { Player, system } from "@minecraft/server";
    import { CustomForm, ObservableBoolean, ObservableNumber, ObservableString } from "@minecraft/server-ui";

    // Run `/scriptevent example:settingswithvalidation` in chat to open the form.
    system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
    if (id !== "example:settingswithvalidation" || !(sourceEntity instanceof Player)) return;

    const username = new ObservableString("", { clientWritable: true });
    const renderDistance = new ObservableNumber(12, { clientWritable: true });
    const showParticles = new ObservableBoolean(true, { clientWritable: true });
    const language = new ObservableNumber(0, { clientWritable: true });
    const languages = ["English", "Spanish", "French"];

    new CustomForm(sourceEntity, "Settings")
    .textField("Username", username, { description: "Your display name" })
    .slider("Render Distance", renderDistance, 2, 32, {
    step: 1,
    description: "Higher values may affect performance",
    })
    .toggle("Show Particles", showParticles, { description: "Display particle effects" })
    .dropdown("Language", language, [
    { label: "English", value: 0 },
    { label: "Spanish", value: 1 },
    { label: "French", value: 2 },
    ])
    .closeButton()
    .show()
    .then(() => {
    const finalUsername = username.getData().trim();
    if (!finalUsername) {
    sourceEntity.sendMessage("Username is required. Open the form again to set one.");
    return;
    }

    const selectedLanguage = languages[language.getData()] ?? "Unknown";
    sourceEntity.sendMessage(
    `Saved settings: username=${finalUsername}, renderDistance=${renderDistance.getData()}, particles=${showParticles.getData()}, language=${selectedLanguage}`,
    );
    });
    });
    import { Player, system } from "@minecraft/server";
    import { CustomForm } from "@minecraft/server-ui";

    function runMenuAction(player: Player, action: "play" | "settings" | "exit") {
    switch (action) {
    case "play":
    player.sendMessage("Selected: Play Game.");
    break;
    case "settings":
    player.sendMessage("Selected: Settings.");
    break;
    case "exit":
    player.sendMessage("Selected: Exit.");
    break;
    }
    }

    // Run `/scriptevent example:simpleactionmenu` in chat to open the form.
    system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
    if (id !== "example:simpleactionmenu" || !(sourceEntity instanceof Player)) return;

    new CustomForm(sourceEntity, "Main Menu")
    .label("What would you like to do?")
    .spacer()
    .button("Play Game", () => runMenuAction(sourceEntity, "play"))
    .button("Settings", () => runMenuAction(sourceEntity, "settings"))
    .button("Exit", () => runMenuAction(sourceEntity, "exit"))
    .show();
    });
    Important

    • Colour codes are only supported by the non-blurry Ore UI text (form title, header and label)
    • Glyphs are not supported by Ore UI at all
    • As of April 2026, Mojang is planning to support screens with rich layouts by defining a layout file.
    export class CustomForm {
    constructor(
    player: minecraftserver.Player,
    title: ObservableString | ObservableUIRawMessage | string | UIRawMessage,
    );
    button(
    label: ObservableString | ObservableUIRawMessage | string | UIRawMessage,
    onClick: () => void,
    options?: ButtonOptions,
    ): CustomForm;
    close(): void;
    closeButton(): CustomForm;
    divider(options?: DividerOptions): CustomForm;
    dropdown(
    label: ObservableString | ObservableUIRawMessage | string | UIRawMessage,
    value: ObservableNumber,
    items: DropdownItemData[],
    options?: DropdownOptions,
    ): CustomForm;
    header(text: ObservableString | ObservableUIRawMessage | string | UIRawMessage, options?: TextOptions): CustomForm;
    image(src: ObservableString | string, pack: ObservableString | string, options?: ImageOptions): CustomForm;
    isShowing(): boolean;
    label(text: ObservableString | ObservableUIRawMessage | string | UIRawMessage, options?: TextOptions): CustomForm;
    multiButtonRow(buttons: ButtonData[], options?: MultiButtonRowOptions): CustomForm;
    show(): Promise<DataDrivenScreenClosedReason>;
    slider(
    label: ObservableString | ObservableUIRawMessage | string | UIRawMessage,
    value: ObservableNumber,
    min: number | ObservableNumber,
    max: number | ObservableNumber,
    options?: SliderOptions,
    ): CustomForm;
    spacer(options?: SpacingOptions): CustomForm;
    textField(
    label: ObservableString | ObservableUIRawMessage | string | UIRawMessage,
    text: ObservableString,
    options?: TextFieldOptions,
    ): CustomForm;
    toggle(
    label: ObservableString | ObservableUIRawMessage | string | UIRawMessage,
    toggled: ObservableBoolean,
    options?: ToggleOptions,
    ): CustomForm;
    }
    Index
    • Parameters

      • label: string | ObservableString | ObservableUIRawMessage | UIRawMessage

        The text label to display on the button.

      • onClick: () => void

        A callback function that is invoked when the player clicks the button.

      • Optionaloptions: ButtonOptions

        Optional configuration for the button, such as a tooltip, disabled state, or visibility.

      Returns CustomForm

      Adds a clickable button to the form layout. Returns the form instance to allow method chaining.

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

      This function can throw errors.

      InvalidFormModificationError

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

      import { Player, system } from "@minecraft/server";
      import { CustomForm, DataDrivenScreenClosedReason } from "@minecraft/server-ui";

      // Run `/scriptevent example:teleporthub` in chat to open the form.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:teleporthub" || !(sourceEntity instanceof Player)) return;

      const form = new CustomForm(sourceEntity, "Teleport Hub");
      form.button("Teleport to Spawn", () => {
      sourceEntity.sendMessage("Teleported to spawn.");
      });

      form.show().then((reason) => {
      if (reason === DataDrivenScreenClosedReason.ServerClosed) {
      sourceEntity.sendMessage("The server closed the teleport hub.");
      } else {
      sourceEntity.sendMessage("You closed the teleport hub.");
      }
      });
      });
    • Returns void

      Closes the form if it is currently being shown to the player. Throws a FormVisibilityError if the form is not currently open.

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

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

      import { Player, system } from "@minecraft/server";
      import { CustomForm, DataDrivenScreenClosedReason } from "@minecraft/server-ui";

      // Run `/scriptevent example:timedoffer` in chat to open the form.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:timedoffer" || !(sourceEntity instanceof Player)) return;

      const form = new CustomForm(sourceEntity, "Timed Offer");
      form.label("This offer will close in 3 seconds.");
      form.show().then((reason) => {
      if (reason === DataDrivenScreenClosedReason.ServerClosed) {
      sourceEntity.sendMessage("The server closed the timed offer.");
      } else {
      sourceEntity.sendMessage("You closed the timed offer.");
      }
      });

      // Close the open form after 3 seconds (60 ticks).
      system.runTimeout(() => {
      if (form.isShowing()) {
      form.close();
      }
      }, 60);
      });
    • Returns CustomForm

      Adds a close button to the form at the bottom and as an 'X' in the corner. Returns the form instance to allow method chaining.

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

      This function can throw errors.

      InvalidFormModificationError

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

      import { Player, system } from "@minecraft/server";
      import { CustomForm, DataDrivenScreenClosedReason } from "@minecraft/server-ui";

      // Run `/scriptevent example:serverinfo` in chat to open the form.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:serverinfo" || !(sourceEntity instanceof Player)) return;

      const form = new CustomForm(sourceEntity, "Server Info");
      form.label("Welcome to the server! Explore custom biomes and quests.");
      form.closeButton();

      form.show().then((reason) => {
      if (reason === DataDrivenScreenClosedReason.ServerClosed) {
      sourceEntity.sendMessage("The server closed the server info.");
      } else {
      sourceEntity.sendMessage("You closed the server info.");
      }
      });
      });
    • Parameters

      • Optionaloptions: DividerOptions

        Optional configuration for the divider, such as visibility.

      Returns CustomForm

      Adds a horizontal divider line to the form layout. Useful for visually separating sections of the form. Returns the form instance to allow method chaining.

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

      This function can throw errors.

      InvalidFormModificationError

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

      import { Player, system } from "@minecraft/server";
      import { CustomForm, DataDrivenScreenClosedReason } from "@minecraft/server-ui";

      // Run `/scriptevent example:accountoverview` in chat to open the form.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:accountoverview" || !(sourceEntity instanceof Player)) return;

      const form = new CustomForm(sourceEntity, "Account Overview");
      form.label("Manage account settings.");
      form.divider();
      form.button("Log Out", () => {
      sourceEntity.sendMessage("Logged out.");
      });

      form.show().then((reason) => {
      if (reason === DataDrivenScreenClosedReason.ServerClosed) {
      sourceEntity.sendMessage("The server closed the account overview.");
      } else {
      sourceEntity.sendMessage("You closed the account overview.");
      }
      });
      });
    • Parameters

      Returns CustomForm

      Adds a dropdown selection control to the form layout. The current selection is tracked via an ObservableNumber and will update when the player changes the selection. Returns the form instance to allow method chaining.

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

      This function can throw errors.

      InvalidFormModificationError

      InvalidObservableError

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

      import { Player, system } from "@minecraft/server";
      import { CustomForm, DataDrivenScreenClosedReason, ObservableNumber } from "@minecraft/server-ui";

      // Run `/scriptevent example:chooseheroclass` in chat to open the form.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:chooseheroclass" || !(sourceEntity instanceof Player)) return;

      const classNames = ["Warrior", "Mage", "Rogue"];
      const selectedClass = new ObservableNumber(0, { clientWritable: true });
      selectedClass.subscribe((value) => {
      const heroClass = classNames[value] ?? "Unknown";
      sourceEntity.sendMessage(`Selected class: ${heroClass}.`);
      });

      const form = new CustomForm(sourceEntity, "Hero Class");
      form.dropdown("Choose Class", selectedClass, [
      { label: "Warrior", value: 0 },
      { label: "Mage", value: 1 },
      { label: "Rogue", value: 2 },
      ]);

      form.show().then((reason) => {
      if (reason === DataDrivenScreenClosedReason.ServerClosed) {
      sourceEntity.sendMessage("The server closed the hero class form.");
      } else {
      sourceEntity.sendMessage("You closed the hero class form.");
      }
      });
      });
    • Parameters

      Returns CustomForm

      Adds a header text component to the form layout. Headers are displayed in a larger or bolder style than regular labels, and are suitable for section titles. Returns the form instance to allow method chaining.

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

      This function can throw errors.

      InvalidFormModificationError

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

      import { Player, system } from "@minecraft/server";
      import { CustomForm, DataDrivenScreenClosedReason } from "@minecraft/server-ui";

      // Run `/scriptevent example:servercontrols` in chat to open the form.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:servercontrols" || !(sourceEntity instanceof Player)) return;

      const form = new CustomForm(sourceEntity, "Server Controls");
      form.header("Gameplay Rules");
      form.button("Toggle Fall Damage", () => {
      sourceEntity.sendMessage("Updated fall damage setting.");
      });

      form.show().then((reason) => {
      if (reason === DataDrivenScreenClosedReason.ServerClosed) {
      sourceEntity.sendMessage("The server closed the controls form.");
      } else {
      sourceEntity.sendMessage("You closed the controls form.");
      }
      });
      });
    • Parameters

      • src: string | ObservableString

        The image source path to display. Must be a relative path to an image file within the provided pack.

      • pack: string | ObservableString

        The resource pack identifier that contains the provided image source.

      • Optionaloptions: ImageOptions

        Optional configuration for the image, such as visibility or width.

      Returns CustomForm

      The form instance to allow method chaining.

      Adds an image component to the form layout. Gifs are supported but are extremely slow to load - always try to have the gif as small as possible.

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

      This function can throw errors.

      InvalidFormModificationError

      InvalidObservableError

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

      import { Player, system } from "@minecraft/server";
      import { CustomForm, DataDrivenScreenClosedReason } from "@minecraft/server-ui";

      // Run `/scriptevent example:welcomebadge` in chat to open the form.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:welcomebadge" || !(sourceEntity instanceof Player)) return;

      const form = new CustomForm(sourceEntity, "Welcome Badge");
      form.image("textures/ui/World", "core", { width: 0.5 });
      form.label("Welcome to the realm.");

      form.show().then((reason) => {
      if (reason === DataDrivenScreenClosedReason.ServerClosed) {
      sourceEntity.sendMessage("The server closed the welcome badge.");
      } else {
      sourceEntity.sendMessage("You closed the welcome badge.");
      }
      });
      });
    • Returns boolean

      Returns true if the form is currently being shown to the player, false otherwise.

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

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

      import { Player, system } from "@minecraft/server";
      import { CustomForm, DataDrivenScreenClosedReason } from "@minecraft/server-ui";

      // Run `/scriptevent example:closeafterthreeseconds` in chat to open the form.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:closeafterthreeseconds" || !(sourceEntity instanceof Player)) return;

      const form = new CustomForm(sourceEntity, "Visibility Panel");
      form.label("Monitoring form visibility state.");
      form.show().then((reason) => {
      if (reason === DataDrivenScreenClosedReason.ServerClosed) {
      sourceEntity.sendMessage("The server closed the visibility panel.");
      } else {
      sourceEntity.sendMessage("You closed the visibility panel.");
      }
      });

      // Check whether the form is still open before closing it.
      system.runTimeout(() => {
      if (form.isShowing()) {
      sourceEntity.sendMessage("Form is open. Closing now.");
      form.close();
      }
      }, 60);
      });
    • Parameters

      Returns CustomForm

      Adds a read-only text label to the form layout. Returns the form instance to allow method chaining.

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

      This function can throw errors.

      InvalidFormModificationError

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

      import { Player, system } from "@minecraft/server";
      import { CustomForm, DataDrivenScreenClosedReason } from "@minecraft/server-ui";

      // Run `/scriptevent example:questguide` in chat to open the form.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:questguide" || !(sourceEntity instanceof Player)) return;

      const form = new CustomForm(sourceEntity, "Quest Guidance");
      form.label("Defeat 10 zombies in the mines to complete this bounty.");

      form.show().then((reason) => {
      if (reason === DataDrivenScreenClosedReason.ServerClosed) {
      sourceEntity.sendMessage("The server closed the quest guide.");
      } else {
      sourceEntity.sendMessage("You closed the quest guide.");
      }
      });
      });
    • Rc

      Parameters

      • buttons: ButtonData[]

        The buttons to display in the row. Maximum Length: 3

      • Optionaloptions: MultiButtonRowOptions

        Optional configuration for the row, such as visibility.

      Returns CustomForm

      Adds a horizontal row of up to three clickable buttons to the form layout. Returns the form instance to allow method chaining.

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

      This function can throw errors.

      InvalidFormModificationError

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

      import { Player, system } from "@minecraft/server";
      import { CustomForm, DataDrivenScreenClosedReason } from "@minecraft/server-ui";

      // Run `/scriptevent example:acceptordecline` in chat to open the form.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:acceptordecline" || !(sourceEntity instanceof Player)) return;

      const form = new CustomForm(sourceEntity, "Confirm Action");
      form.label("Do you want to proceed with this purchase?");
      form.multiButtonRow([
      { label: "Accept", onClick: () => sourceEntity.sendMessage("Accepted.") },
      { label: "Decline", onClick: () => sourceEntity.sendMessage("Declined.") },
      ]);

      form.show().then((reason) => {
      if (reason === DataDrivenScreenClosedReason.ServerClosed) {
      sourceEntity.sendMessage("The server closed the confirmation form.");
      } else {
      sourceEntity.sendMessage("You closed the confirmation form.");
      }
      });
      });
    • Returns Promise<DataDrivenScreenClosedReason>

      Shows the form to the player. Returns a promise that resolves with a DataDrivenScreenClosedReason indicating how the form was closed.

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

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

      import { Player, system } from "@minecraft/server";
      import { CustomForm, DataDrivenScreenClosedReason } from "@minecraft/server-ui";

      // Run `/scriptevent example:dailycheckin` in chat to open the form.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:dailycheckin" || !(sourceEntity instanceof Player)) return;

      const form = new CustomForm(sourceEntity, "Daily Check-in");
      form.label("Welcome back to another adventure day.");

      form.show().then((closeReason) => {
      if (closeReason === DataDrivenScreenClosedReason.ServerClosed) {
      sourceEntity.sendMessage("The server closed the daily check-in.");
      } else {
      sourceEntity.sendMessage("You closed the daily check-in.");
      }
      });
      });
    • Parameters

      Returns CustomForm

      Adds a numeric slider control to the form layout. The current value is tracked via an ObservableNumber and will update as the player moves the slider. Returns the form instance to allow method chaining.

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

      This function can throw errors.

      InvalidFormModificationError

      InvalidObservableError

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

      import { Player, system } from "@minecraft/server";
      import { CustomForm, DataDrivenScreenClosedReason, ObservableNumber } from "@minecraft/server-ui";

      // Run `/scriptevent example:renderdistance` in chat to open the form.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:renderdistance" || !(sourceEntity instanceof Player)) return;

      const renderDistance = new ObservableNumber(8, { clientWritable: true });
      renderDistance.subscribe((newDistance) => {
      sourceEntity.sendMessage(`Render distance set to ${newDistance} chunks.`);
      });

      const form = new CustomForm(sourceEntity, "Video Settings");
      form.slider("Render Distance (Chunks)", renderDistance, 4, 16, { step: 2 });

      form.show().then((reason) => {
      if (reason === DataDrivenScreenClosedReason.ServerClosed) {
      sourceEntity.sendMessage("The server closed the settings form.");
      } else {
      sourceEntity.sendMessage("You closed the settings form.");
      }
      });
      });
    • Parameters

      • Optionaloptions: SpacingOptions

        Optional configuration for the spacer, such as visibility.

      Returns CustomForm

      Adds a vertical spacer component to the form layout. Useful for adding empty space between form components. Returns the form instance to allow method chaining.

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

      This function can throw errors.

      InvalidFormModificationError

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

      import { Player, system } from "@minecraft/server";
      import { CustomForm, DataDrivenScreenClosedReason } from "@minecraft/server-ui";

      // Run `/scriptevent example:spacebeforebutton` in chat to open the form.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:spacebeforebutton" || !(sourceEntity instanceof Player)) return;

      const form = new CustomForm(sourceEntity, "Layout Spacing");
      form.header("Top Section");
      form.spacer();
      form.button("Continue", () => {
      sourceEntity.sendMessage("Proceeding.");
      });

      form.show().then((reason) => {
      if (reason === DataDrivenScreenClosedReason.ServerClosed) {
      sourceEntity.sendMessage("The server closed the form.");
      } else {
      sourceEntity.sendMessage("You closed the form.");
      }
      });
      });
    • Parameters

      Returns CustomForm

      Adds a text input field to the form layout. The current text value is tracked via an ObservableString and will update as the player types. Returns the form instance to allow method chaining.

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

      This function can throw errors.

      InvalidFormModificationError

      InvalidObservableError

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

      import { Player, system } from "@minecraft/server";
      import { CustomForm, DataDrivenScreenClosedReason, ObservableString } from "@minecraft/server-ui";

      // Run `/scriptevent example:nameyourcharacter` in chat to open the form.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:nameyourcharacter" || !(sourceEntity instanceof Player)) return;

      const playerNameInput = new ObservableString("", { clientWritable: true });
      playerNameInput.subscribe((text) => {
      sourceEntity.sendMessage(`Name updated to: ${text}`);
      });

      const form = new CustomForm(sourceEntity, "Character Setup");
      form.textField("Character Name", playerNameInput);

      form.show().then((reason) => {
      if (reason === DataDrivenScreenClosedReason.ServerClosed) {
      sourceEntity.sendMessage("The server closed character setup.");
      } else {
      sourceEntity.sendMessage("You closed character setup.");
      }
      });
      });
    • Parameters

      Returns CustomForm

      Adds a toggle (on/off switch) control to the form layout. The current state is tracked via an ObservableBoolean and will update when the player toggles it. Returns the form instance to allow method chaining.

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

      This function can throw errors.

      InvalidFormModificationError

      InvalidObservableError

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

      import { Player, system } from "@minecraft/server";
      import { CustomForm, DataDrivenScreenClosedReason, ObservableBoolean } from "@minecraft/server-ui";

      // Run `/scriptevent example:soundtoggle` in chat to open the form.
      system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
      if (id !== "example:soundtoggle" || !(sourceEntity instanceof Player)) return;

      const soundEnabled = new ObservableBoolean(true, { clientWritable: true });
      soundEnabled.subscribe((enabled) => {
      sourceEntity.sendMessage(`Background music ${enabled ? "enabled" : "disabled"}.`);
      });

      const form = new CustomForm(sourceEntity, "Preferences");
      form.toggle("Play Background Music", soundEnabled);

      form.show().then((reason) => {
      if (reason === DataDrivenScreenClosedReason.ServerClosed) {
      sourceEntity.sendMessage("The server closed preferences.");
      } else {
      sourceEntity.sendMessage("You closed preferences.");
      }
      });
      });