Download the PHP package cartograph/minecraft-text without Composer

On this page you can find all versions of the php package cartograph/minecraft-text. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package minecraft-text

Minecraft Text

A pure-PHP library for parsing and rendering Minecraft chat text in every format the live ecosystem uses: JSON text components, SNBT text components, legacy §/&-coded strings, MiniMessage, and HTML.

Packagist Version Total Downloads PHP Version

Features

Requirements

No PHP extensions are required.

Installation

Install via Composer:

Quick start

Parse a legacy MOTD and render it as themed HTML:

That's a complete, runnable example. The bundled reference stylesheet (Html::referenceStylesheet()) defines the default mc-color-* and mc-bold rules so the output drops straight into any page.

Build a tree programmatically and serialise it as JSON for Minecraft:

Concepts

Minecraft chat text is a tree of typed components. Each component carries some content (literal text, a translation key, a keybind, a score reference, a selector, or an NBT path) plus an optional style (colour, decorations, font, shadow colour, click/hover events, insertion text) and an "extra" list of child components that inherit the parent's effective style.

Vanilla Minecraft serialises this tree in three main ways:

The community uses two more:

This library reads, writes, and converts between all five. A shared, immutable Component AST sits between the readers and the renderers, so any input format can be re-rendered to any output format.

Output that targets Minecraft's JSON/SNBT wire format is dialect- driven: a Profile for the target Minecraft generation decides which fields are valid, which click/hover actions are allowed, what casing event keys use (clickEvent vs click_event), and whether shadow_color and the legacy NBT-string show_item payload are supported. Fields the dialect cannot represent record a Diagnostic and drop, or throw ProfileMismatchException under strict mode.

Lossy conversions (rendering a KeybindComponent to legacy, an unresolved TranslateComponent to HTML, an unknown <wibble> tag in MiniMessage) record dotted diagnostics on the result rather than silently failing.

Usage

Parse JSON, SNBT, legacy, or MiniMessage

Every reader has two facade entry points: a one-shot version returning just the parsed Component, and a *Result version returning a ParseResult bundling the component with any diagnostics raised.

Parsers are permissive by default — bare strings, list-as-component, both clickEvent and click_event casings, both legacy and modern show_item payloads, and unknown click actions all parse without throwing. Pass new JsonOptions(strict: true) (or the per-format equivalent) to reject non-canonical shapes.

Render to JSON, SNBT, legacy, MiniMessage, or HTML

The JSON and SNBT renderers take a JsonOptions / SnbtOptions with a dialect field — pick the Minecraft schema generation you're targeting:

Build trees programmatically

Two equivalent APIs:

The Text facade has a static factory for every component type:

TextBuilder is a fluent, immutable helper for chained construction:

Resolve translations

TranslationResolver walks a tree replacing every TranslateComponent with its resolved text. The package ships no locale data — implement the Translator interface against your own locale source:

The HtmlRenderer accepts an optional Translator via HtmlOptions and runs the resolution pass automatically before walking the tree.

Interpret legacy codes inside text fields

JSON, SNBT, and MiniMessage parsers leave §/& codes inside a text field as raw characters — that matches vanilla Minecraft's own behaviour but doesn't help with the very common ecosystem case of a JSON MOTD or SNBT block carrying legacy-coded text:

Text::interpretLegacyInText() walks a tree and expands every legacy-coded TextComponent in place via LegacyReader. The wrapping node's own style and trailing children are preserved; the legacy-parsed styled runs are spliced in as the first children of a rewrapped TextComponent carrying the original style:

The transform is opt-in (the parsers themselves never run it automatically) and lossy in one direction: once codes have been expanded into styled runs, the original raw text is gone, so a tree transformed this way will no longer re-serialise byte-identically back to its source wire format. Pass a LegacyOptions to enable & interpretation, Essentials &#RRGGBB hex, or BungeeCord §x§R§R§G§G§B§B hex (the last is on by default):

Customise HTML rendering

By default, any component that would render as a <span> carrying no class, inline style, click/hover data, insertion, or obfuscation payload is emitted as bare body text — so plain text renders as hi, not <span>hi</span>, and the empty-text root container that comes out of LegacyReader and LegacyInterpreter no longer prepends a stray <span></span>. An <a href> envelope from an OpenUrl click is kept and wraps the body directly. Pass omitUnstyledSpans: false if your consumer needs a stable one-span-per-leaf DOM for CSS hooks or position-indexed JS.

The bundled reference stylesheet (Html::referenceStylesheet()) defines the default mc-color-*, mc-bold, mc-italic, etc. classes plus a CSS-only animation for mc-obfuscated.

Class overview

The public surface splits into the AST (Component namespace), the five readers, the five renderers, the dialect/profile system, and a small set of supporting types.

Entry point

Class Method group Returns
Text parseJson/parseSnbt/parseLegacy/parseMiniMessage (+*Result) Component (or ParseResult)
Text renderJson/renderSnbt/renderLegacy/renderMiniMessage/renderHtml (+*Result) string (or RenderResult)
Text interpretLegacyInText Component (legacy codes in text fields expanded into styled runs)
Text text/translate/keybind/score/selector/nbt/gradient/rainbow/transition the matching *Component
Text color(string\|int\|NamedColor) Color
Text build() TextBuilder seeded with empty text

Component AST (Cartograph\Text\Component)

Class Role
Component sealed interface implemented by every node
TextComponent literal text (JSON {"text": "..."})
TranslateComponent locale key + with arguments (JSON {"translate": ...})
KeybindComponent keybind reference, e.g. key.jump
ScoreComponent scoreboard score reference
SelectorComponent target selector, e.g. @p, with optional separator
NbtComponent NBT path read from a block/entity/storage
GradientComponent MiniMessage-native colour gradient
RainbowComponent MiniMessage-native HSL hue cycle
TransitionComponent MiniMessage-native single sampled colour
Style immutable container for colour, decorations, font, events, etc.
Decorations tri-state record of bold/italic/underlined/strikethrough/obfuscated
Color / NamedColor / HexColor colour interface and its two implementations
NbtSource enum: Block, Entity, Storage
Events\ClickEvent sealed: OpenUrl, RunCommand, SuggestCommand, CopyToClipboard, ChangePage, CustomClickEvent
Events\HoverEvent sealed: ShowText, ShowItem, ShowEntity

Readers and renderers

Format Reader Renderer Options class
JSON JsonReader JsonRenderer JsonOptions
SNBT SnbtReader SnbtRenderer SnbtOptions
Legacy LegacyReader LegacyRenderer LegacyOptions
MiniMessage MiniMessageReader MiniMessageRenderer MiniMessageOptions
HTML HtmlRenderer HtmlOptions

Profiles and diagnostics

Class Role
Profile\JsonDialect enum: Mc1_20, Mc1_20_5, Mc1_21_4, Mc1_21_5, Mc26_1
Profile\Profile per-dialect field naming and action allowlists
Render\Diagnostic severity + dotted code + message + optional path/offset
Render\Severity enum: Info, Warning, Error
Read\ParseResult parsed component + diagnostics
Render\RenderResult rendered text + diagnostics

Extension points

Class / interface Purpose
MiniMessage\TagHandler Register custom MiniMessage tags via TagRegistry::register
Html\Palette / Html\StaticPalette Map NamedColor to RGB; ship chat() and sign() palettes
Translation\Translator Caller-supplied locale lookup

Compatibility

Bedrock Edition's text format variants are not supported.

Contributing

Bug reports, feature requests, and pull requests are welcome at github.com/cartographgg/minecraft-text. See CONTRIBUTING.md for development setup and the required checks (tests, static analysis, code style, and mutation testing). Each check has a Composer script: composer test, composer static, composer style, and composer mutation.

License

Released under the MIT License. © Cartograph contributors.


Maintained as part of Cartograph, a Minecraft server directory and monitoring platform. The library is self-contained and has no Cartograph-specific behaviour; use it anywhere you need to work with Minecraft chat text in PHP.


All versions of minecraft-text with dependencies

PHP Build Version
Package Version
Requires php Version ^8.5
cartograph/minecraft-nbt Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package cartograph/minecraft-text contains the following files

Loading the files please wait ...