Skip to content

Commit

Permalink
Update wiki
Browse files Browse the repository at this point in the history
- Fix broken (block-)entities link in sidebar
- Change "(block)-entities" to "entities and block entities" in titles to better reflect title in links
- Move repository above artifact in Maven/Gradle usage
- Add info about preloadApi
- Add title for ItemMeta usage
- Small text changes
  • Loading branch information
SoSeDiK committed Jul 1, 2024
1 parent 5280ba8 commit 31b17fe
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 44 deletions.
3 changes: 3 additions & 0 deletions wiki/Example-Usages.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,8 @@ NBTFile playerNbtFile = new NBTFile(playerFile);
// Change player's health
float health = playerNbtFile.getFloat("Health");
playerNbtFile.setFloat("Health", health + 5);

// Once finished, save the file
playerNbtFile.save();
```

46 changes: 31 additions & 15 deletions wiki/Using-Gradle.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ To start using NB-API, you either need to depend on its plugin version, or shade

Add the following entries to your Gradle build at the correct locations:

```groovy
compileOnly("de.tr7zw:item-nbt-api-plugin:VERSION")
```

(Get the current ``VERSION`` from [here](https://modrinth.com/plugin/nbtapi/versions))

```groovy
repositories {
...
Expand All @@ -24,6 +18,12 @@ repositories {
}
```

```groovy
compileOnly("de.tr7zw:item-nbt-api-plugin:VERSION")
```

(Get the current ``VERSION`` from [here](https://modrinth.com/plugin/nbtapi/versions))

Add the API as dependency to your ``plugin.yml``:

```yml
Expand All @@ -46,15 +46,6 @@ The latest version of the shadow plugin can be found [here](https://github.com/j

Add NBT-API to your dependencies:

```groovy
implementation("de.tr7zw:item-nbt-api:VERSION")
```

(Get the current ``VERSION`` from [here](https://modrinth.com/plugin/nbtapi/versions))

> [!WARNING]
> Make sure you're using ``item-nbt-api`` as ``artifactId``, never shade the ``-plugin`` artifact!
```groovy
repositories {
...
Expand All @@ -66,6 +57,15 @@ repositories {
}
```

```groovy
implementation("de.tr7zw:item-nbt-api:VERSION")
```

(Get the current ``VERSION`` from [here](https://modrinth.com/plugin/nbtapi/versions))

> [!WARNING]
> Make sure you're using ``item-nbt-api`` as ``artifactId``, never shade the ``-plugin`` artifact!
After this you can add the shadowJar configuration to relocate the API package:

```groovy
Expand All @@ -82,3 +82,19 @@ build {
}
```

###### Initializing NBT-API early

If you are shading NBT-API, you may call ``NBT.preloadApi()`` during ``onEnable`` to initialize NBT-API early and check whether everything works. If you omit this step, NBT-API will be initialized on the first call to the API.

```java
@Override
public void onEnable() {
if (!NBT.preloadApi()) {
getLogger().warning("NBT-API wasn't initialized properly, disabling the plugin");
getPluginLoader().disablePlugin(this);
return;
}
// Load other things
}
```

64 changes: 40 additions & 24 deletions wiki/Using-Maven.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ To start using NB-API, you either need to depend on its plugin version, or shade

Add the following entries to your pom at the correct locations:

```xml
<repositories>
...
<!-- CodeMC -->
<repository>
<id>codemc-repo</id>
<url>https://repo.codemc.io/repository/maven-public/</url>
<layout>default</layout>
</repository>
...
</repositories>
```

```xml
<dependency>
<groupId>de.tr7zw</groupId>
Expand All @@ -18,19 +31,6 @@ Add the following entries to your pom at the correct locations:

(Get the current ``VERSION`` from [here](https://modrinth.com/plugin/nbtapi/versions))

```xml
<repositories>
...
<!-- CodeMC -->
<repository>
<id>codemc-repo</id>
<url>https://repo.codemc.io/repository/maven-public/</url>
<layout>default</layout>
</repository>
...
</repositories>
```

Add the API as dependency to your ``plugin.yml``:

```yaml
Expand Down Expand Up @@ -83,6 +83,19 @@ Replace ``YOUR PACKAGE WHERE THE API SHOULD END UP`` with your own unique packag

Then, add NBT-API to your dependencies by including the following entries to your pom at the correct locations:

```xml
<repositories>
...
<!-- CodeMC -->
<repository>
<id>codemc-repo</id>
<url>https://repo.codemc.io/repository/maven-public/</url>
<layout>default</layout>
</repository>
...
</repositories>
```

```xml
<dependency>
<groupId>de.tr7zw</groupId>
Expand All @@ -96,16 +109,19 @@ Then, add NBT-API to your dependencies by including the following entries to you
> [!WARNING]
> Make sure you're using ``item-nbt-api`` as ``artifactId``, never shade the ``-plugin`` artifact!
```xml
<repositories>
...
<!-- CodeMC -->
<repository>
<id>codemc-repo</id>
<url>https://repo.codemc.io/repository/maven-public/</url>
<layout>default</layout>
</repository>
...
</repositories>
###### Initializing NBT-API early

If you are shading NBT-API, you may call ``NBT.preloadApi()`` during ``onEnable`` to initialize NBT-API early and check whether everything works. If you omit this step, NBT-API will be initialized on the first call to the API.

```java
@Override
public void onEnable() {
if (!NBT.preloadApi()) {
getLogger().warning("NBT-API wasn't initialized properly, disabling the plugin");
getPluginLoader().disablePlugin(this);
return;
}
// Load other things
}
```

15 changes: 12 additions & 3 deletions wiki/Using-the-NBT-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ boolean bar = nbt.resolveOrDefault("foo.other_key[0].bar", false);

### Working with items

You can read/write nbt data on items using ``NBT.get``/``NBT.modify`` methods.

```java
// Setting data
NBT.modify(itemStack, nbt -> {
Expand All @@ -154,7 +156,14 @@ int someValue = NBT.modify(itemStack, nbt -> {
nbt.setInteger(i);
return i;
});
```

###### ItemMeta usage

> [!WARNING]
> Never mix the usage of ItemMeta and NBT.
```java
// Updating ItemMeta using NBT
NBT.modify(itemStack, nbt -> {
nbt.setInteger("kills", nbt.getOrDefault("kills", 0) + 1);
Expand All @@ -180,9 +189,9 @@ NBT.modifyComponents(item, nbt -> {
});
```

### Working with (block-)entities
### Working with entities and block entities

Working with entities and block entities is similar to working items.
Working with entities and block entities is similar to working with items.

#### Accessing vanilla nbt

Expand Down Expand Up @@ -313,7 +322,7 @@ String json = nbt.toString();
ReadWriteNBT nbt = NBT.parseNBT(json);
```

#### (Block-)Entities
#### Entities and block entities

```java
// Saving
Expand Down
4 changes: 2 additions & 2 deletions wiki/_Sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

### General

* [Basics](https://github.com/tr7zw/Item-NBT-API/wiki/Using-the-NBT-API#basics-overview)
* [Basics](https://github.com/tr7zw/Item-NBT-API/wiki/Using-the-NBT-API)
* [Items](https://github.com/tr7zw/Item-NBT-API/wiki/Using-the-NBT-API#working-with-items)
* [Block-Entities/Entities](https://github.com/tr7zw/Item-NBT-API/wiki/Using-the-NBT-API#working-with-(block-)entities)
* [Block-Entities/Entities](https://github.com/tr7zw/Item-NBT-API/wiki/Using-the-NBT-API#working-with-entities-and-block-entities)
* [Blocks](https://github.com/tr7zw/Item-NBT-API/wiki/Using-the-NBT-API#working-with-blocks)

### Extras
Expand Down

0 comments on commit 31b17fe

Please sign in to comment.