Skip to content

Commit b7719f1

Browse files
committed
Expand README
1 parent fd28dab commit b7719f1

File tree

2 files changed

+80
-15
lines changed

2 files changed

+80
-15
lines changed

README.md

Lines changed: 79 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,102 @@
1+
# TOC
2+
* [About](#about)
3+
* [Utilities](#utilities)
4+
+ [Item NBT](#item-nbt)
5+
+ [Entity NBT](#entity-nbt)
6+
+ [Tile entity NBT](#tile-entity-nbt)
7+
+ [NBT parser](#nbt-parser)
8+
* [Usage](#usage)
9+
* [Examples](#examples)
10+
- [Mark an item](#mark-an-item)
11+
- [When pigs can fly](#when-pigs-can-fly)
12+
- [Locking chests](#locking-chests)
13+
- [Changelog](#changelog)
14+
* [Breaking changes in 1.0.2](#breaking-changes-in-102)
15+
+ [All utils](#all-utils)
16+
+ [ItemNBTUtil](#itemnbtutil)
17+
18+
119
# MiniNBT
2-
A small NBT library to allow the modification of NBT tags across different versions
20+
A small NBT library to allow the modification of NBT tags across different Minecraft versions.
21+
Currently supported are 1.8.8 up to 1.14.4, but very likely also future and *maybe* lower versions.
322

423
## About
5-
This is a small library, originally written for [PercieveCore](https://github.com/PerceiveDev/PerceiveCore) and adapted to be a standalone utility.
6-
It provides an easy way to interact with NBT (Notch's Binary Format), but only the interaction with item NBT is really tested ;)
24+
This is a small standalone library providing an easy way to interact with NBT (Notch's Binary Format).
25+
It is currently capable of reading and modifying `Item`, `Entity` and `TileEntity` NBT.
26+
27+
28+
## Utilities
729

830
### Item NBT
931
You can modify item NBT with the `ItemNBTUtil`.
1032
Supported are:
1133
- Setting a tag
1234
- Getting a tag
1335

14-
*The custom NBT on items is preserved.*
36+
*Custom NBT on items is preserved, so you can store whatever you want.*
1537

1638
### Entity NBT
17-
You can also modify entity NBT (`EntityNBTUtil`), but I think there are methods for that in Spigot now.
18-
19-
*Custom tags are never set and therefore impossible.*
39+
You can edit entity NBT (`NoGravity` and whatever other tag you like). Many of those settings are now exposed through Bukkit methods though.
40+
*Custom tags are never read by Minecraft and therefore impossible.*
2041

2142
### Tile entity NBT
22-
This allows you to modify the NBT of `TileEntities` (`TileEntityNBTUtil`), like a chest.
23-
It can be used to change the name of a furnace/chest or similiar after it was placed, or do some other trickery.
43+
`TileEntities` are blocks with some special data, like furnaces, chests, and so on.
44+
It can be used to change the name of a furnace/chest or similar after it was placed, or do some other trickery.
2445

25-
*Custom tags are never set and therefore impossible.*
46+
*Custom tags are never read by Minecraft and therefore impossible.*
2647

2748
### NBT parser
2849
This allows you to parse a String to a NBTTagCompound. It uses the `MojangsonParser` internally, but you will need to use the `NbtParser` class.
2950

3051
## Usage
31-
Quite easy. I have _nearly_ exactly recreated the original NBT classes, so you can use it in the same way you would use the original.
52+
This utility follows the exact same structure as the Minecraft tags do, so you can just change your imports and things might work. If not, it shouldn't be hard to figure out the small differences.
53+
The `NBTTagCompound` can serve as a good starting point.
54+
55+
## Examples
56+
#### Mark an item
57+
```java
58+
ItemStack item = player.getInventory().getItemInMainHand();
59+
60+
NBTTagCompound compound = ItemNBTUtil.getTag(item); // fetch the data
61+
String dataKey = "My custom data"; // the key to store it under
62+
if(compound.hasKey(dataKey)){
63+
player.sendMessage(ChatColor.GOLD + "Got: " + ChatColor.GREEN + compound.getString(dataKey));
64+
} else {
65+
compound.setString(dataKey, String.join(" ", args)); // set it to command arguments
66+
ItemNBTUtil.setNBTTag(compound, item);
67+
}
68+
```
69+
70+
#### When pigs can fly
71+
```java
72+
Entity pig = player.getNearbyEntities(5, 5, 5).stream()
73+
.filter(it -> it instanceof Pig)
74+
.findFirst().get();
75+
NBTTagCompound compound = EntityNBTUtil.getNbtTag(pig);
76+
System.out.println(compound); // prints all data
77+
compound.setBoolean("NoGravity", !compound.getBoolean("NoGravity"));
78+
EntityNBTUtil.setNbtTag(pig, compound); // overwrites the entity's data
79+
```
80+
81+
#### Locking chests
82+
```java
83+
Block block = player.getLocation().getBlock();
84+
if(block.getType() == Material.AIR){
85+
block = block.getRelative(BlockFace.DOWN);
86+
}
87+
NBTTagCompound compound = TileEntityNBTUtil.getNbtTag(block.getState());
88+
System.out.println(compound); // prints all data
89+
compound.setString("Lock", "Test"); // locks it to "Test"
90+
TileEntityNBTUtil.setNbtTag(block.getState(), compound); // applies the changes
91+
```
92+
93+
# Changelog
3294

33-
You can refer to the format on the MinecraftWiki pages and you will find any class you find there here too. With the same name.
95+
## Breaking changes in 1.0.2
96+
It should be ABI/API compatible except for the changes outlined below.
97+
### All utils
98+
* `ReflectionException` will now be thrown if initialization or any other operation fails.
3499

35-
## Breaking changes in 1.0.1
36100
### ItemNBTUtil
37-
* `getTag` now throws an exception if the tag was no compound or is unknown instead of returning an empty tag
101+
* `getTag` now throws an exception if the tag was no compound or is unknown instead of returning an empty tag.
102+
This will probably not impact you at all, but it still is a change in behaviour.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>me.ialistannen</groupId>
88
<artifactId>MiniNBT</artifactId>
9-
<version>1.0.1</version>
9+
<version>1.0.2</version>
1010
<packaging>jar</packaging>
1111

1212
<name>MiniNBT</name>

0 commit comments

Comments
 (0)