RawMessage Interface

Defines a JSON structure that is used for more flexible.

Properties

rawtext

rawtext?: RawMessage[];

Provides a raw-text equivalent of the current message.

Type: RawMessage[]

score

score?: RawMessageScore;

Provides a token that will get replaced with the value of a score.

Type: RawMessageScore

text

text?: string;

Provides a string literal value to use.

Type: string

translate

translate?: string;

Provides a translation token where, if the client has an available resource in the players' language which matches the token, will get translated on the client.

Type: string

with

with?: string[] | RawMessage;

Arguments for the translation token. Can be either an array of strings or RawMessage containing an array of raw text objects.

Type: string[] | RawMessage

Examples

addTranslatedSign.ts
  const players = mc.world.getPlayers();

  const dim = players[0].dimension;

  const signBlock = dim.getBlock(targetLocation);

  if (!signBlock) {
    log("Could not find a block at specified location.");
    return -1;
  }
  let signPerm = mc.BlockPermutation.resolve("minecraft:standing_sign", { ground_sign_direction: 8 });

  signBlock.setPermutation(signPerm);

  const signComponent = signBlock.getComponent("minecraft:sign") as mc.BlockSignComponent;

  signComponent.setText({ translate: "item.skull.player.name", with: [players[0].name] });
showTranslatedMessageForm.ts
  const players = mc.world.getPlayers();

  const messageForm = new mcui.MessageFormData()
    .title({ translate: "permissions.removeplayer" })
    .body({ translate: "accessibility.list.or.two", with: ["Player 1", "Player 2"] })
    .button1("Player 1")
    .button2("Player 2");

  messageForm
    .show(players[0])
    .then((formData: mcui.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 ? "Player 1" : "Player 2"}`);
    })
    .catch((error: Error) => {
      log("Failed to show form: " + error);
      return -1;
    });