Yatopia/patches/api/0005-Add-NBT-API-as-a-first-class-lib.patch
Simon Gardling 22be9f2d6f
Upstream (#502)
* Updated Upstream and Sidestream(s) (Paper/Purpur/Origami)

Upstream/An Sidestream has released updates that appears to apply and compile correctly
This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing.

Paper Changes:
2299159bb Add option to fix items merging through blocks (#5334)
d8c20ddc7 Fix PlayerBucketEmptyEvent result itemstack (#5698)
ceb3762fb Add PufferFishStateChangeEvent (#5606)
cd4defec0 [CI-SKIP] Update version checker to use V2 downloads API (#5728)
b9f2a673d Limit item frame cursors on maps (#5730)
81a537c1f Add PlayerKickEvent causes (#5648)
b7976b956 Add More Lidded Block API (#5707)

Purpur Changes:
b88aef3a Fix Paper#4748 - Shulkerbox allow oversized stacks
9fec1bae Updated Upstream (Paper)
2aacc766 Update Toothpick to 1.1.0-SNAPSHOT
a08d7470 Configurable anvil cumulative cost (#352)

Origami Changes:
3b8adab Fix importing of classes not working if their directory doesn't exist

* Updated Upstream and Sidestream(s) (Paper/Tuinity/Purpur/Empirecraft/Origami)

Upstream/An Sidestream has released updates that appears to apply and compile correctly
This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing.

Paper Changes:
525d0e3d3 fix beacon activate/deactivate events (#5646)
e403d6aaf [Auto] Updated Upstream (CraftBukkit)
6bcd8b57c Updated Upstream (CraftBukkit) (#5742)
501cc9448 Reset villager inventory on cancelled pickup event (#5738)
3f72a549b Exit with non-zero exit code when killed by watchdog (#5732)
a8d7ad099 Updated Upstream (Bukkit/CraftBukkit) (#5735)

Tuinity Changes:
e9c8348 Revert entity ticking chunk map for tracker

Purpur Changes:
687936be Updated Upstream (Paper)
4c2d7e56 Fix advancement triggers on entity death
49a0fb90 Fix oversized shulker box dupe
e92d259e Fix raid captains not giving voluntary exile advancement
a97fdc48 Config to broadcast the death message to the affected player (#363)
9bf8e165 Add burn in daylight API for LivingEntity (#331)
96460068 Fix dupe bug caused by SPIGOT-6452
2618c24f Revert "allow disabling offline mode message on an ONLINE MODE proxy"
aa79fa5c allow disabling offline mode message on an ONLINE MODE proxy
830141ca Bee can work when raining or at night (#365)
ae6ca468 Updated Upstream (Paper)
d99cc6e8 [ci-skip] Add better issue templates (#360)

Empirecraft Changes:
12009c31 Updated Paper
5305540d Updated Paper
1043bd94 Revert "Call EntityPickupItemEvent for villagers" CB commit
820b9bdf Updated Paper

Origami Changes:
64fba4f Fix importing of classes not working if their directory doesn't exist
3b8adab Fix importing of classes not working if their directory doesn't exist

* rebuild Patches
2021-05-29 19:17:00 -04:00

178 lines
6.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: tr7zw <tr7zw@live.de>
Date: Sat, 1 Aug 2020 15:55:15 -0500
Subject: [PATCH] Add NBT API as a first-class lib
diff --git a/pom.xml b/pom.xml
index f0ef93cb0c1d369265b2a6fc56c80f79d61d4ebc..a6a2fd50e685f64afecac5da6aaaad6227a3731e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -47,6 +47,11 @@
<id>mojang</id>
<url>https://libraries.minecraft.net/</url>
</repository>
+ <!-- CodeMC -->
+ <repository>
+ <id>codemc-repo</id>
+ <url>https://repo.codemc.io/repository/maven-public/</url>
+ </repository>
</repositories>
<!-- Paper start -->
@@ -205,6 +210,11 @@
<artifactId>asm-commons</artifactId>
<version>9.1</version>
</dependency>
+ <dependency>
+ <groupId>de.tr7zw</groupId>
+ <artifactId>item-nbt-api</artifactId>
+ <version>2.7.1</version>
+ </dependency>
</dependencies>
<build>
@@ -279,6 +289,12 @@
<dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml</dependencyReducedPomLocation>
<!-- when downloading via Maven we can pull depends individually -->
<shadedArtifactAttached>true</shadedArtifactAttached>
+ <relocations>
+ <relocation>
+ <pattern>de.tr7zw.changeme.nbtapi</pattern>
+ <shadedPattern>de.tr7zw.nbtapi</shadedPattern>
+ </relocation>
+ </relocations>
</configuration>
</plugin>
<plugin>
diff --git a/src/main/java/org/bukkit/Chunk.java b/src/main/java/org/bukkit/Chunk.java
index 98263d896f316983609432c45b85401a2692432d..afaa459d2c351f99b598ec9054a6838ffb0098e8 100644
--- a/src/main/java/org/bukkit/Chunk.java
+++ b/src/main/java/org/bukkit/Chunk.java
@@ -275,4 +275,16 @@ public interface Chunk extends PersistentDataHolder {
* @return if the block is contained within
*/
boolean contains(@NotNull BlockData block);
+
+ // Yatopia start
+ /**
+ * Returns a custom tag container of this chunk.
+ *
+ * @return custom NBT tags container
+ */
+ @NotNull
+ default de.tr7zw.changeme.nbtapi.NBTCompound getNBTC() {
+ return new de.tr7zw.changeme.nbtapi.NBTChunk(this).getPersistentDataContainer();
+ }
+ // Yatopia end
}
diff --git a/src/main/java/org/bukkit/block/TileState.java b/src/main/java/org/bukkit/block/TileState.java
index 3b10fcc13893403b29f0260b8605144679e89b82..1e9a96d8b08cc396acf73dc42083009354e89d8a 100644
--- a/src/main/java/org/bukkit/block/TileState.java
+++ b/src/main/java/org/bukkit/block/TileState.java
@@ -36,4 +36,26 @@ public interface TileState extends BlockState, PersistentDataHolder {
@NotNull
@Override
PersistentDataContainer getPersistentDataContainer();
+
+ // Yatopia start
+ /**
+ * Returns NBT representation of this tile entity.
+ *
+ * @return vanilla NBT tags container
+ */
+ @NotNull
+ default de.tr7zw.changeme.nbtapi.NBTTileEntity getNBT() {
+ return new de.tr7zw.changeme.nbtapi.NBTTileEntity(this);
+ }
+
+ /**
+ * Returns a custom tag container of this tile entity.
+ *
+ * @return custom NBT tags container
+ */
+ @NotNull
+ default de.tr7zw.changeme.nbtapi.NBTCompound getNBTC() {
+ return getNBT().getPersistentDataContainer();
+ }
+ // Yatopia end
}
diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java
index 62d8d7dbd4d602ca8cb00ff0cf1331583b398323..7cb395466babc84dd4ce1c91cbab7d130a5437b3 100644
--- a/src/main/java/org/bukkit/entity/Entity.java
+++ b/src/main/java/org/bukkit/entity/Entity.java
@@ -778,4 +778,26 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
*/
boolean isInDaylight();
// Purpur end
+
+ // Yatopia start
+ /**
+ * Returns NBT representation of this entity.
+ *
+ * @return vanilla NBT tags container
+ */
+ @NotNull
+ default de.tr7zw.changeme.nbtapi.NBTEntity getNBT() {
+ return new de.tr7zw.changeme.nbtapi.NBTEntity(this);
+ }
+
+ /**
+ * Returns a custom tag container of this entity.
+ *
+ * @return custom NBT tags container
+ */
+ @NotNull
+ default de.tr7zw.changeme.nbtapi.NBTCompound getNBTC() {
+ return getNBT().getPersistentDataContainer();
+ }
+ // Yatopia end
}
diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java
index fceba6780a15c274c4689eccbeb6dfb2eee25ed9..1ba63c21245c4d4b9326b89ac83add9481fec243 100644
--- a/src/main/java/org/bukkit/inventory/ItemStack.java
+++ b/src/main/java/org/bukkit/inventory/ItemStack.java
@@ -1548,4 +1548,42 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, net.kyor
return random.nextInt(unbreaking + 1) > 0;
}
// Purpur end
+
+ // Yatopia start
+ /**
+ * Returns NBT representation of this item. The ItemStack will be cloned!
+ *
+ * @return item's NBT tags container
+ */
+ @NotNull
+ public de.tr7zw.changeme.nbtapi.NBTItem getNBT() {
+ return getNBT(false);
+ }
+
+ /**
+ * Returns NBT representation of this item. If directApply is true,
+ * all changes will be mapped to the original item. Changes to the NBTItem will
+ * overwrite changes done to the original item in that case.
+ *
+ * @param directApply if true, changes to NBTItem will affect this ItemStack
+ * @return item's NBT tags container
+ */
+ @NotNull
+ public de.tr7zw.changeme.nbtapi.NBTItem getNBT(boolean directApply) {
+ return new de.tr7zw.changeme.nbtapi.NBTItem(this, directApply);
+ }
+
+ /**
+ * Applies NBT data from the provided NBT item.
+ *
+ * @param nbt ItemStack's NBT container
+ */
+ public void setNBT(@NotNull de.tr7zw.changeme.nbtapi.NBTItem nbt) {
+ ItemStack nbtItem = nbt.getItem();
+ setType(nbtItem.getType());
+ setAmount(nbtItem.getAmount());
+ setData(nbtItem.getData());
+ setItemMeta(nbtItem.getItemMeta());
+ }
+ // Yatopia end
}