Skip to content

Commit

Permalink
Merge pull request #313 from SoSeDiK/wiki
Browse files Browse the repository at this point in the history
Update wiki
  • Loading branch information
tr7zw authored Dec 28, 2024
2 parents f3af749 + d9a93e9 commit da6be72
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
4 changes: 1 addition & 3 deletions wiki/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,4 @@ The experimental NBTInjector became unsupported since Minecraft 1.14 and was rem

NBTInjector is incompatible with reloads and may break things, and thus is not recommended.

If you're using Minecraft 1.14+, you should switch to the persistent storage API instead.

In versions prior to 1.14, you may use a workaround like storing data inside an item's nbt that the entity is wearing (e.g. having a button in mob's helmet, and storing data on that button).
See [this wiki section](https://github.com/tr7zw/Item-NBT-API/wiki/Using-the-NBT-API#accessing-custom-data) on how to handle custom entity nbt data without NBTInjector.
17 changes: 14 additions & 3 deletions wiki/Using-Gradle.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,30 @@ Add the API as dependency to your ``plugin.yml``:
depend: [NBTAPI]
```
Or, if you are using ``paper-plugin.yml``:
```yml
dependencies:
server:
NBTAPI:
load: BEFORE
required: true
join-classpath: true
```
# Option 2) Shading the NBT-API into your plugin
To include NBT-API directly in your plugin, you can use the gradle shadow plugin.
To include NBT-API directly in your plugin, you can use the [Gradle Shadow Plugin](https://gradleup.com/shadow/).
Add the plugin to the build configuration, as shown here:
```groovy
plugins {
id("com.github.johnrengelman.shadow") version "VERSION"
id("com.gradleup.shadow") version "VERSION"
}
```

The latest version of the shadow plugin can be found [here](https://github.com/johnrengelman/shadow/releases).
The latest version of the shadow plugin can be found [here](https://plugins.gradle.org/plugin/com.gradleup.shadow).

Add NBT-API to your dependencies:

Expand Down
11 changes: 11 additions & 0 deletions wiki/Using-Maven.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ Add the API as dependency to your ``plugin.yml``:
depend: [NBTAPI]
```
Or, if you are using ``paper-plugin.yml``:
```yml
dependencies:
server:
NBTAPI:
load: BEFORE
required: true
join-classpath: true
```
# Option 2) Shading the NBT-API into your plugin
To include NBT-API directly in your plugin, you can use the maven shade plugin.
Expand Down
9 changes: 7 additions & 2 deletions wiki/Using-the-NBT-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ Alternatively, you may safely modify ItemMeta inside the NBT scope:
// Updating ItemMeta using NBT
NBT.modify(itemStack, nbt -> {
nbt.setInteger("kills", nbt.getOrDefault("kills", 0) + 1);
nbt.modifyMeta((meta, readOnlyNbt) -> { // Do not modify the nbt while modifying the meta!
nbt.modifyMeta((readOnlyNbt, meta) -> { // Do not modify the nbt while modifying the meta!
meta.setDisplayName("Kills: " + readOnlyNbt.getOrDefault("kills", 0));
});
// Do more stuff
Expand Down Expand Up @@ -243,7 +243,12 @@ NBT.modify(entity, nbt -> {

#### Accessing custom data

For reading/storing custom data on (block-)entities, you should use methods that end with PersistentData.
> [!WARNING]
> Persistent data storage for custom (block-)entity nbt is only available in 1.14+.
>
> If you need to support versions below that, for entities you may use a workaround like storing data inside an item's nbt that the entity is wearing (e.g. having a button in mob's helmet, and storing data on that button).
For reading/storing custom data on (block-)entities, you should use methods that end with ``PersistentData``.

> [!IMPORTANT]
> When working with block entities, make sure that the block entity exists in the world.
Expand Down

0 comments on commit da6be72

Please sign in to comment.