Skip to content

Getting Started

MineJason is a .NET library providing support for creating, serializing and deserializing Minecraft: Java Edition text components and related types, such as target selectors and "Resource Location" (namespaced identifiers).

Warning

MineJason is in alpha development stage, and breaking changes may happen at any time at this stage with or without prior notice.

Installation

To install MineJason, simply use the MineJason NuGet package: Nuget.

In some cases you may want to use the SharpNbt to support certain fields (especially, in target selector nbt arguments) that requires an NBT component. If this is the case, then use the SharpNbt extension library: Nuget.

You have several ways to do this.

Visual Studio

To install MineJason in Visual Studio, follow these steps:

  1. Right click your project (or use the Project menu bar), and click Manage NuGet packages.
  2. In the NuGet Package Manager page, select Browse.
  3. Check the Include prerelease option.
  4. Enter MineJason in the search box, and select the MineJason package.
  5. Click Install.
  6. When prompted to accept license, review the license and click Accept.

.NET CLI

Open your favourite shell, navigate to the directory of the project, and run:

dotnet add package MineJason --prerelease

Usage

Chat components are at the core of MineJason. It provides support for serializing almost (if not all of) any chat components into the instance representations provided by it. By default, serializing MineJason components requires no serializer configuration!

Just serialize and deserialize the components with regular serialization methods in System.Text.Json, and you are ready to go.

var component = ChatComponent.CreateText("Hello World!");

Console.WriteLine(JsonSerializer.Serialize(component));

// Output: {"text":"Hello World!"}

There are more complex types of chat components; see Components. The ChatComponent type provides Create-methods to help you easily creating most types of components, from creating directly to using builders.

var component = ChatComponent.CreateText()
    .Text("Hello World!")
    .Color(KnownColor.Red)
    .Build();

Console.WriteLine(JsonSerializer.Serialize(component));

// Output: {"text":"Hello World!","color":"red"}