Skip to content

Commit

Permalink
avoid using CustomData#getUnsafe()
Browse files Browse the repository at this point in the history
  • Loading branch information
granny committed Apr 30, 2024
1 parent f2ab964 commit 2e2ceab
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions patches/server/0280-Stored-Bee-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,18 @@ index 1a2a05160ba51d9c75f1ae6ae61d944d81428722..3beb26ad2ef0fded49a8da8c5dec64f9
}
diff --git a/src/main/java/org/purpurmc/purpur/entity/PurpurStoredBee.java b/src/main/java/org/purpurmc/purpur/entity/PurpurStoredBee.java
new file mode 100644
index 0000000000000000000000000000000000000000..25d718489a1a589d9754b8a02340cec819eec6d8
index 0000000000000000000000000000000000000000..7608bf0981fa0d37031e51e57e4086cb5ec4c88b
--- /dev/null
+++ b/src/main/java/org/purpurmc/purpur/entity/PurpurStoredBee.java
@@ -0,0 +1,103 @@
@@ -0,0 +1,106 @@
+package org.purpurmc.purpur.entity;
+
+import io.papermc.paper.adventure.PaperAdventure;
+import net.kyori.adventure.text.Component;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.nbt.Tag;
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.world.item.component.CustomData;
+import net.minecraft.world.level.block.entity.BeehiveBlockEntity;
+import org.bukkit.block.EntityBlockStorage;
+import org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer;
Expand All @@ -176,12 +178,13 @@ index 0000000000000000000000000000000000000000..25d718489a1a589d9754b8a02340cec8
+ this.handle = data;
+ this.blockStorage = blockStorage;
+
+ this.customName = handle.occupant.entityData().contains("CustomName")
+ ? PaperAdventure.asAdventure(net.minecraft.network.chat.Component.Serializer.fromJson(handle.occupant.entityData().getUnsafe().getString("CustomName"), MinecraftServer.getDefaultRegistryAccess()))
+ CompoundTag customData = handle.occupant.entityData().copyTag();
+ this.customName = customData.contains("CustomName")
+ ? PaperAdventure.asAdventure(net.minecraft.network.chat.Component.Serializer.fromJson(customData.getString("CustomName"), MinecraftServer.getDefaultRegistryAccess()))
+ : null;
+
+ if(handle.occupant.entityData().getUnsafe().contains("BukkitValues", Tag.TAG_COMPOUND)) {
+ this.persistentDataContainer.putAll(handle.occupant.entityData().getUnsafe().getCompound("BukkitValues"));
+ if(customData.contains("BukkitValues", Tag.TAG_COMPOUND)) {
+ this.persistentDataContainer.putAll(customData.getCompound("BukkitValues"));
+ }
+ }
+
Expand Down

0 comments on commit 2e2ceab

Please sign in to comment.