mirror of
https://github.com/tr7zw/Item-NBT-API.git
synced 2026-11-13 12:31:58 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0f926998f6 | ||
|
|
3a44a5e989 | ||
|
|
30b931945c | ||
|
|
88d8629541 | ||
|
|
00ae0448f4 | ||
|
|
ce26e180e6 | ||
|
|
c939105e45 | ||
|
|
2079123a42 | ||
|
|
31b17fe9c9 | ||
|
|
b565902006 |
No files matched your search
@@ -8,7 +8,7 @@ updates:
|
||||
ignore:
|
||||
- dependency-name: com.github.ekryd.sortpom:sortpom-maven-plugin
|
||||
versions:
|
||||
- 2.13.1
|
||||
- 2.13.2
|
||||
- 2.14.0
|
||||
- 2.14.1
|
||||
- 2.15.0
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-parent</artifactId>
|
||||
<version>2.13.1</version>
|
||||
<version>2.13.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>item-nbt-api</artifactId>
|
||||
|
||||
@@ -39,7 +39,7 @@ public enum MinecraftVersion {
|
||||
private static Logger logger = Logger.getLogger("NBTAPI");
|
||||
|
||||
// NBT-API Version
|
||||
protected static final String VERSION = "2.13.1";
|
||||
protected static final String VERSION = "2.13.2";
|
||||
|
||||
private final int versionId;
|
||||
private final boolean mojangMapping;
|
||||
@@ -56,6 +56,7 @@ public enum MinecraftVersion {
|
||||
this.put("1.20.5", MC1_20_R4);
|
||||
this.put("1.20.6", MC1_20_R4);
|
||||
this.put("1.21", MC1_21_R1);
|
||||
this.put("1.21.1", MC1_21_R1);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-parent</artifactId>
|
||||
<version>2.13.1</version>
|
||||
<version>2.13.2</version>
|
||||
</parent>
|
||||
<artifactId>item-nbt-api-plugin</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
@@ -12,7 +12,7 @@
|
||||
<dependency>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-api</artifactId>
|
||||
<version>2.13.1</version>
|
||||
<version>2.13.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -22,7 +22,7 @@ public class TileTest implements Test {
|
||||
try {
|
||||
Block block = world.getBlockAt(world.getSpawnLocation().getBlockX(), 254,
|
||||
world.getSpawnLocation().getBlockZ());
|
||||
if (block.getChunk().isLoaded() && block.getType() == Material.AIR) {
|
||||
if (world.isChunkLoaded(block.getX() >> 4, block.getZ() >> 4) && block.getType() == Material.AIR) {
|
||||
block.setType(Material.CHEST);
|
||||
NBTTileEntity tile = new NBTTileEntity(block.getState());
|
||||
if (!MinecraftVersion.isNewerThan(MinecraftVersion.MC1_17_R1)) {
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ public class TilesCustomNBTPersistentTest implements Test {
|
||||
try {
|
||||
Block block = world.getBlockAt(world.getSpawnLocation().getBlockX(), 250,
|
||||
world.getSpawnLocation().getBlockZ());
|
||||
if (block.getType() == Material.AIR) {
|
||||
if (world.isChunkLoaded(block.getX() >> 4, block.getZ() >> 4) && block.getType() == Material.AIR) {
|
||||
block.setType(Material.CHEST);
|
||||
NBTTileEntity comp = new NBTTileEntity(block.getState());
|
||||
NBTCompound persistentData = comp.getPersistentDataContainer();
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-parent</artifactId>
|
||||
<version>2.13.1</version>
|
||||
<version>2.13.2</version>
|
||||
</parent>
|
||||
<artifactId>mappings-parser</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
@@ -12,7 +12,7 @@
|
||||
<dependency>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-api</artifactId>
|
||||
<version>2.13.1</version>
|
||||
<version>2.13.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-parent</artifactId>
|
||||
<version>2.13.1</version>
|
||||
<version>2.13.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>nbt-data-api</artifactId>
|
||||
@@ -14,7 +14,7 @@
|
||||
<dependency>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-api</artifactId>
|
||||
<version>2.13.1</version>
|
||||
<version>2.13.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-parent</artifactId>
|
||||
<version>2.13.1</version>
|
||||
<version>2.13.2</version>
|
||||
</parent>
|
||||
<artifactId>nbt-injector</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
@@ -12,7 +12,7 @@
|
||||
<dependency>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-api</artifactId>
|
||||
<version>2.13.1</version>
|
||||
<version>2.13.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-parent</artifactId>
|
||||
<version>2.13.1</version>
|
||||
<version>2.13.2</version>
|
||||
<packaging>pom</packaging>
|
||||
<inceptionYear>2015</inceptionYear>
|
||||
<organization>
|
||||
@@ -110,7 +110,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.7.0</version>
|
||||
<version>3.8.0</version>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
</configuration>
|
||||
|
||||
@@ -112,7 +112,7 @@ Just use the Plugin as Maven dependency and remember to add "NBTAPI" as dependen
|
||||
<dependency>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-api-plugin</artifactId>
|
||||
<version>2.13.1</version>
|
||||
<version>2.13.2</version>
|
||||
</dependency>
|
||||
[/CODE]
|
||||
[/SPOILER]
|
||||
@@ -122,7 +122,7 @@ Using this method the API gets copied into your plugin. Server owners don't have
|
||||
<dependency>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-api</artifactId>
|
||||
<version>2.13.1</version>
|
||||
<version>2.13.2</version>
|
||||
</dependency>
|
||||
...
|
||||
<plugins>
|
||||
|
||||
@@ -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();
|
||||
```
|
||||
|
||||
+31
-15
@@ -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 {
|
||||
...
|
||||
@@ -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
|
||||
@@ -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 {
|
||||
...
|
||||
@@ -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
|
||||
@@ -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
|
||||
}
|
||||
```
|
||||
|
||||
+40
-24
@@ -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>
|
||||
@@ -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
|
||||
@@ -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>
|
||||
@@ -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
|
||||
}
|
||||
```
|
||||
|
||||
@@ -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 -> {
|
||||
@@ -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);
|
||||
@@ -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
|
||||
|
||||
@@ -313,7 +322,7 @@ String json = nbt.toString();
|
||||
ReadWriteNBT nbt = NBT.parseNBT(json);
|
||||
```
|
||||
|
||||
#### (Block-)Entities
|
||||
#### Entities and block entities
|
||||
|
||||
```java
|
||||
// Saving
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
Reference in new issue
Block a user