Paper/patches/api/0325-Add-Raw-Byte-Entity-Serialization.patch
Nassim Jahnke 8e8d6aeeb0 Finish API
2023-12-05 18:33:18 +01:00

63 lines
2.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Mariell Hoversholm <proximyst@proximyst.com>
Date: Sun, 24 Oct 2021 16:19:26 -0400
Subject: [PATCH] Add Raw Byte Entity Serialization
diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java
index 7dc808f94c42e821fa125073b1a9b853e16d5b41..fc0356b0600946af0a46312cee16b080a7769ae2 100644
--- a/src/main/java/org/bukkit/UnsafeValues.java
+++ b/src/main/java/org/bukkit/UnsafeValues.java
@@ -139,6 +139,14 @@ public interface UnsafeValues {
ItemStack deserializeItem(byte[] data);
+ byte[] serializeEntity(org.bukkit.entity.Entity entity);
+
+ default org.bukkit.entity.Entity deserializeEntity(byte[] data, World world) {
+ return deserializeEntity(data, world, false);
+ }
+
+ org.bukkit.entity.Entity deserializeEntity(byte[] data, World world, boolean preserveUUID);
+
/**
* Creates and returns the next EntityId available.
* <p>
diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java
index d98fe98f703ff478ea4427783fd68debe9a6f267..6356370eed537cec782f036dc73fe5bfbe4c1fb7 100644
--- a/src/main/java/org/bukkit/entity/Entity.java
+++ b/src/main/java/org/bukkit/entity/Entity.java
@@ -894,5 +894,32 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
*/
@Deprecated
@NotNull Set<Player> getTrackedPlayers();
+
+ /**
+ * Spawns the entity in the world at the given {@link Location} with the default spawn reason.
+ * <p>
+ * This will not spawn the entity if the entity is already spawned or has previously been despawned.
+ * <p>
+ * Also, this method will fire the same events as a normal entity spawn.
+ *
+ * @param location The location to spawn the entity at.
+ * @return Whether the entity was successfully spawned.
+ */
+ public default boolean spawnAt(@NotNull Location location) {
+ return spawnAt(location, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT);
+ }
+
+ /**
+ * Spawns the entity in the world at the given {@link Location} with the reason given.
+ * <p>
+ * This will not spawn the entity if the entity is already spawned or has previously been despawned.
+ * <p>
+ * Also, this method will fire the same events as a normal entity spawn.
+ *
+ * @param location The location to spawn the entity at.
+ * @param reason The reason for the entity being spawned.
+ * @return Whether the entity was successfully spawned.
+ */
+ public boolean spawnAt(@NotNull Location location, @NotNull org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason reason);
// Paper end
}