2021-11-11 03:53:27 +01:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Mariell Hoversholm <proximyst@proximyst.com>
|
|
|
|
Date: Sun, 24 Oct 2021 16:20:31 -0400
|
|
|
|
Subject: [PATCH] Add Raw Byte Entity Serialization
|
|
|
|
|
2023-06-08 21:35:20 +02:00
|
|
|
== AT ==
|
|
|
|
public net.minecraft.world.entity.Entity setLevel(Lnet/minecraft/world/level/Level;)V
|
2021-11-11 03:53:27 +01:00
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
2024-03-23 20:27:30 +01:00
|
|
|
index 7dbbf0884b70acb37c3400364736fa8f6b68c964..5dce3d38ecd7b7639f02f3e1e92f3723f4a42c39 100644
|
2021-11-11 03:53:27 +01:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10277)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
9a80d38c SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-722: Add EntityRemoveEvent
258086d9 SPIGOT-7417, PR-967: Add Sign#getTargetSide and Sign#getAllowedEditor
ffaba051 SPIGOT-7584: Add missing Tag.ITEMS_NON_FLAMMABLE_WOOD
CraftBukkit Changes:
98b6c1ac7 SPIGOT-7589 Fix NullPointerException when bans expire
a2736ddb0 SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-1008: Add EntityRemoveEvent
5bf12cb89 SPIGOT-7565: Throw a more descriptive error message when a developer tries to spawn an entity from a CraftBukkit class
76d95fe7e SPIGOT-7417, PR-1343: Add Sign#getTargetSide and Sign#getAllowedEditor
Spigot Changes:
e9ec5485 Rebuild patches
f1b62e0c Rebuild patches
2024-02-23 14:37:33 +01:00
|
|
|
@@ -2078,6 +2078,15 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
|
2021-11-11 03:53:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start - Entity serialization api
|
|
|
|
+ public boolean serializeEntity(CompoundTag compound) {
|
|
|
|
+ List<Entity> pass = new java.util.ArrayList<>(this.getPassengers());
|
|
|
|
+ this.passengers = ImmutableList.of();
|
|
|
|
+ boolean result = save(compound);
|
|
|
|
+ this.passengers = ImmutableList.copyOf(pass);
|
|
|
|
+ return result;
|
|
|
|
+ }
|
2024-01-19 12:30:04 +01:00
|
|
|
+ // Paper end - Entity serialization api
|
2021-11-11 03:53:27 +01:00
|
|
|
public boolean save(CompoundTag nbt) {
|
|
|
|
return this.isPassenger() ? false : this.saveAsPassenger(nbt);
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
2024-04-06 22:38:37 +02:00
|
|
|
index 65ce8ab201e7e36f6d2637e906af325e11e425dd..c819fa8e5b69c23558a89b68f9a5a31e1b233ca3 100644
|
2021-11-11 03:53:27 +01:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
2024-04-06 22:38:37 +02:00
|
|
|
@@ -1058,6 +1058,18 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
2021-11-11 03:53:27 +01:00
|
|
|
}
|
2024-04-06 22:38:37 +02:00
|
|
|
// Paper end - tracked players API
|
|
|
|
|
|
|
|
+ // Paper start - raw entity serialization API
|
2021-11-11 03:53:27 +01:00
|
|
|
+ @Override
|
|
|
|
+ public boolean spawnAt(Location location, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason reason) {
|
|
|
|
+ Preconditions.checkNotNull(location, "location cannot be null");
|
|
|
|
+ Preconditions.checkNotNull(reason, "reason cannot be null");
|
2023-06-08 21:35:20 +02:00
|
|
|
+ this.entity.setLevel(((CraftWorld) location.getWorld()).getHandle());
|
|
|
|
+ this.entity.setPos(location.getX(), location.getY(), location.getZ());
|
|
|
|
+ this.entity.setRot(location.getYaw(), location.getPitch());
|
|
|
|
+ return !this.entity.valid && this.entity.level().addFreshEntity(this.entity, reason);
|
2021-11-11 03:53:27 +01:00
|
|
|
+ }
|
2024-04-06 22:38:37 +02:00
|
|
|
+ // Paper end - raw entity serialization API
|
|
|
|
+
|
2024-03-23 22:26:17 +01:00
|
|
|
// Paper start - missing entity api
|
2024-04-06 22:38:37 +02:00
|
|
|
@Override
|
|
|
|
public boolean isInvisible() { // Paper - moved up from LivingEntity
|
2021-11-11 03:53:27 +01:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
2024-04-06 21:53:39 +02:00
|
|
|
index 2734f4187a4b92ef461e1f2fdae9139c6f54d8fc..be82e1d52d7026facb20bf07f4b3a394e77ab708 100644
|
2021-11-11 03:53:27 +01:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
2024-04-06 21:53:39 +02:00
|
|
|
@@ -504,6 +504,32 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
2024-01-25 10:54:46 +01:00
|
|
|
return CraftItemStack.asCraftMirror(net.minecraft.world.item.ItemStack.of(compound));
|
2021-11-11 03:53:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public byte[] serializeEntity(org.bukkit.entity.Entity entity) {
|
|
|
|
+ Preconditions.checkNotNull(entity, "null cannot be serialized");
|
|
|
|
+ Preconditions.checkArgument(entity instanceof org.bukkit.craftbukkit.entity.CraftEntity, "only CraftEntities can be serialized");
|
|
|
|
+
|
|
|
|
+ CompoundTag compound = new CompoundTag();
|
|
|
|
+ ((org.bukkit.craftbukkit.entity.CraftEntity) entity).getHandle().serializeEntity(compound);
|
|
|
|
+ return serializeNbtToBytes(compound);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public org.bukkit.entity.Entity deserializeEntity(byte[] data, org.bukkit.World world, boolean preserveUUID) {
|
|
|
|
+ Preconditions.checkNotNull(data, "null cannot be deserialized");
|
|
|
|
+ Preconditions.checkArgument(data.length > 0, "cannot deserialize nothing");
|
|
|
|
+
|
|
|
|
+ CompoundTag compound = deserializeNbtFromBytes(data);
|
|
|
|
+ int dataVersion = compound.getInt("DataVersion");
|
2024-01-25 10:54:46 +01:00
|
|
|
+ compound = (CompoundTag) MinecraftServer.getServer().fixerUpper.update(References.ENTITY, new Dynamic<>(NbtOps.INSTANCE, compound), dataVersion, this.getDataVersion()).getValue();
|
|
|
|
+ if (!preserveUUID) {
|
|
|
|
+ // Generate a new UUID so we don't have to worry about deserializing the same entity twice
|
|
|
|
+ compound.remove("UUID");
|
|
|
|
+ }
|
2021-11-11 03:53:27 +01:00
|
|
|
+ return net.minecraft.world.entity.EntityType.create(compound, ((org.bukkit.craftbukkit.CraftWorld) world).getHandle())
|
|
|
|
+ .orElseThrow(() -> new IllegalArgumentException("An ID was not found for the data. Did you downgrade?")).getBukkitEntity();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
private byte[] serializeNbtToBytes(CompoundTag compound) {
|
|
|
|
compound.putInt("DataVersion", getDataVersion());
|
|
|
|
java.io.ByteArrayOutputStream outputStream = new java.io.ByteArrayOutputStream();
|