aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/api/0317-Add-Raw-Byte-Entity-Serialization.patch
blob: b90e495870f350f3cea32eaf8e150347d7df1eac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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 cbc63144e5eb35799548209f8fbee70d0c20a53d..240ac3f658ed24d3980707e146e6dfee6c9b31a0 100644
--- a/src/main/java/org/bukkit/UnsafeValues.java
+++ b/src/main/java/org/bukkit/UnsafeValues.java
@@ -167,6 +167,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 827574b3eff9b912500b092ca081e7163677695e..18fa592f9159a5377eeac8325c0b8e16f74be7b8 100644
--- a/src/main/java/org/bukkit/entity/Entity.java
+++ b/src/main/java/org/bukkit/entity/Entity.java
@@ -946,5 +946,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
 }