1. Go to this page and download the library: Download cartograph/minecraft-text library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Cartograph\Text\Json\JsonOptions;
use Cartograph\Text\Profile\JsonDialect;
use Cartograph\Text\Text;
echo Text::renderJson($c, new JsonOptions(JsonDialect::Mc1_20));
// Pre-1.21.5 wire shape: clickEvent (camelCase), legacy show_item, no shadow_color
echo Text::renderJson($c, new JsonOptions(JsonDialect::Mc26_1));
// Latest wire shape: click_event (snake_case), components-form show_item, shadow_color
use Cartograph\Text\Component\NamedColor;
use Cartograph\Text\Component\Style;
use Cartograph\Text\Component\Decorations;
use Cartograph\Text\Text;
$c = Text::text(
'Hello',
style: new Style(color: NamedColor::Gold, decorations: new Decorations(bold: true)),
);
use Cartograph\Text\Build\TextBuilder;
use Cartograph\Text\Component\NamedColor;
use Cartograph\Text\Component\Events\OpenUrl;
use Cartograph\Text\Text;
$c = Text::build()
->append(TextBuilder::text('Click here')
->color(NamedColor::Aqua)
->underlined()
->onClick(new OpenUrl('https://example.com')))
->append(TextBuilder::text(' to continue.'))
->build();
use Cartograph\Text\Translation\TranslationResolver;
use Cartograph\Text\Translation\Translator;
$translator = new class implements Translator {
public function translate(string $key, ?string $locale = null): ?string
{
return match ($key) {
'chat.type.text' => '<%s> %s',
default => null,
};
}
};
$resolved = new TranslationResolver($translator)->resolve($component);
use Cartograph\Text\Text;
$tree = Text::interpretLegacyInText(Text::parseJson($motd));
$html = Text::renderHtml($tree);
use Cartograph\Text\Legacy\LegacyOptions;
use Cartograph\Text\Legacy\Marker;
use Cartograph\Text\Text;
$tree = Text::interpretLegacyInText(
Text::parseJson($motd),
new LegacyOptions(parseMarkers: Marker::SECTION | Marker::AMPERSAND),
);
use Cartograph\Text\Html\EventStrategy;
use Cartograph\Text\Html\HtmlOptions;
use Cartograph\Text\Html\StaticPalette;
use Cartograph\Text\Html\StylingMode;
use Cartograph\Text\Text;
$opts = new HtmlOptions(
stylingMode: StylingMode::Inline, // Inline / Classes / Hybrid (default)
classPrefix: 'mc-',
events: EventStrategy::AnchorPlusData,
palette: StaticPalette::sign(), // chat (default) or sign
allowedUrlSchemes: ['https'], // default ['http','https','mailto']
omitUnstyledSpans: true, // default true; set false for an always-emit-span DOM
);
echo Text::renderHtml($component, $opts);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.