Play Strawberry Docs
Scripts

Text and translations

Build structured messages and load translations under your own namespace.

Text components

text::TextComponent::text(plain) makes plain text. The component also has translate, translate_cross, colors, styles, click and hover actions and JSON parsing; from_json returns a Result, so handle bad input. Messages are sent with functions such as player.send_system_message(text, overlay), player.show_actionbar(text) and sender.send_message(text).

Gradient and rainbow effects refuse texts longer than 32,767 characters.

JSON components take shadow_color in both of vanilla's forms: one ARGB integer (0 turns the shadow off, -16777216 is opaque black) or a list of four numbers (red, green, blue, alpha, each 0 to 1). A component turned into JSON has the integer form.

Translations

i18n::load_translations(namespace, json, locale) loads a JSON map of keys to strings for one locale. i18n::translate(key, locale) returns the string for a locale.

  • Only your script's own namespace is accepted: its name in lowercase, the same as content::namespace() (a script named "Shop" loads under shop). minecraft, the platform's namespaces and another script's namespace load nothing.
  • A script can load up to 16,384 keys per language and 8 MiB of texts in all. A call that would pass a limit loads nothing, and neither does a JSON that is not one object of texts. The console names each refusal.
  • Your texts are freed when your script unloads.

Translations that the game client shows from the server's resource pack (item names, subtitles) are added with content::add_translations, under your own keys; see Custom items.

A bare vanilla key such as commands.save.success (the same as minecraft:commands.save.success) gives the wording a Java client shows, such as "Saved the game". The texts the server sends to Bedrock players keep Bedrock's wording.

Java and Bedrock

Bedrock players' chat works exactly like Java players' chat. A script that formats, decorates, filters or cancels chat applies to Bedrock senders too, and a formatted line reaches Bedrock players as your script made it, colours included. Colour codes typed by Bedrock players are removed, and their chat lines have the same length limit as Java's.

TextComponent::translate_cross(java_key, bedrock_key, with) uses a different key on each edition. Test the result on both clients: a locale or a key does not prove that a client has an asset or a glyph.

Untrusted text

Treat player-supplied JSON, URLs, commands and hover text as input. Bound their size, allow only the actions your feature needs, and never turn player text into a click action that runs a command with more rights.

Books

A book a script edits is kept within the game's own limits: pages beyond the 100th are dropped, a page of a book and quill is cut to 1,024 characters, and a signed book's title over 32 characters is not taken (the title the player typed stays). A saved book that is over these limits is not loaded.

When a script cancels a book edit, the player gets the book in their hand again, exactly as the server holds it.

PlayerEditBookEvent::slot(data.slot) gives the hotbar slot (0 to 8) of the edited book, or -1 when it is in the off hand.

On this page