https://github.com/defective4/jchatlib
A Minecraft NBT and text component parser library
https://github.com/defective4/jchatlib
Last synced: 4 months ago
JSON representation
A Minecraft NBT and text component parser library
- Host: GitHub
- URL: https://github.com/defective4/jchatlib
- Owner: Defective4
- License: mit
- Created: 2024-12-18T19:32:45.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-03-29T19:02:34.000Z (about 1 year ago)
- Last Synced: 2025-10-21T19:43:29.983Z (7 months ago)
- Language: Java
- Homepage:
- Size: 48.8 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jChatLib
jChatLib is a minimal Minecraft chat component **and** NBT parser library.
It allows you to parse and encode NBT with both named and unnamed root tags, used in Minecraft's files and sent over network.
It also lets you parse text components, both from JSON and NBT!
The library is still under development, new features and improvement, as well as proper documentation are planned.
## Features
- **Complete** - supports all standard NBT data types
- **Flexible** - Allows parsing text components both from JSON and NBT, making it compatible with **all** Minecraft versions!
- **Simple to use**
## Installation
Add
```xml
io.github.defective4.minecraft
jchatlib
1.1.1
```
to your `pom.xml`'s dependencies section
## Usage
Parsing chat components from JSON:
```java
String json = "{\"text\": \"Hello \", \"extra\": [\"World\", {\"text\": \"!\"}]}";
JsonElement parsed = JsonParser.parseString(json);
ChatComponent component = ChatComponent.fromJson(parsed);
System.out.println(component.toPlainString()); // Outputs "Hello World!"
```
Parsing NBT from file:
```java
Tag nbt;
try(InputStream is = new FileInputStream("Hello_world.nbt")) {
// v----- Read root tag name
nbt = NBT.parse(is, true, false);
// ^----- (don't) use GZIP compression
} catch(Exception e) {
e.printStackTrace();
return;
}
System.out.println(nbt);
```
Parsing text components from NBT:
```java
InputStream in = ...
Tag tag = NBT.parse(in, false, false);
ChatComponent component = ChatComponent.fromNBT(tag);
System.out.println(component.toPlainString());
```
Creating a NBT file:
```java
try (OutputStream os = new FileOutputStream("test.nbt") {
CompoundTag root = new CompoundTag("root");
// v----- Tag name
StringTag text = new StringTag("text", "Hello world!");
// ^----- Tag value
root.add(text); // v--------- (don't) use network format
byte[] data = NBT.encode(root, false);
os.write(data);
}