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: .
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: .
You have several ways to do this.
Visual Studio
To install MineJason in Visual Studio, follow these steps:
- Right click your project (or use the Project menu bar), and click
Manage NuGet packages
. - In the
NuGet Package Manager
page, selectBrowse
. - Check the
Include prerelease
option. - Enter
MineJason
in the search box, and select theMineJason
package. - Click
Install
. - 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"}