mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-24 19:46:21 +01:00
52a05907c7
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: 97c59261 PR-1073: Make Biome an interface a38581aa Fix further javadoc errors 8271c490 Fix javadoc error 8a9ecf29 PR-1072: Fix bad naming for Vault State methods 6dd58108 PR-1071: Make Fluid an interface and add missing entry ed2cdfc3 PR-1070: Make Attribute an interface and align names with the new minecraft ones 63472efb PR-1069: Add missing winter drop experimental annotation to pale boats CraftBukkit Changes: 7235ad7b0 PR-1501: Make Biome an interface 602904003 PR-1500: Rename implementation for Vault State methods 75f26f79f PR-1499: Make Fluid an interface and add missing entry 4cfd87adc PR-1498: Make Attribute an interface and align names with the new minecraft ones 6bb0db5cb SPIGOT-7928: ExactChoice acts as MaterialChoice 3eaf3a13c SPIGOT-7929: Error when setting EquippableComponent abbf57bac SPIGOT-7930: Fix spawning entities with SummonEntityEffect 92d6ab6cf PR-1497: Move boat field rename entries to below key renaming, so that keys are also renamed abfe292aa PR-1496: Use correct Fluid class on Tags type check c7aab7fa7 SPIGOT-7923: Fix Dispenser logic to avoid firing empty projectiles
91 lines
5.2 KiB
Diff
91 lines
5.2 KiB
Diff
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
|
|
|
|
== AT ==
|
|
public net.minecraft.world.entity.Entity setLevel(Lnet/minecraft/world/level/Level;)V
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
index 88d3b1997bba632c5746d295bb39095f5d328369..900765b0129e8bf485aca93af6f523c9948e288b 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -2260,6 +2260,15 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
}
|
|
}
|
|
|
|
+ // 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;
|
|
+ }
|
|
+ // Paper end - Entity serialization api
|
|
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
|
|
index 0c1c9033646dedcf1d11dee74d6965683adadf0a..1ed01978611cddb2558e441863dadc468bc07c3d 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
@@ -1088,6 +1088,18 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
|
}
|
|
// Paper end - tracked players API
|
|
|
|
+ // Paper start - raw entity serialization API
|
|
+ @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");
|
|
+ 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);
|
|
+ }
|
|
+ // Paper end - raw entity serialization API
|
|
+
|
|
// Paper start - missing entity api
|
|
@Override
|
|
public boolean isInvisible() { // Paper - moved up from LivingEntity
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
index 1dd9a5cc45d5073adb150abdcbe2025e6ed2c315..2a3dc48aa50b41ede0e1a0e280314624961967f2 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
@@ -510,7 +510,33 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|
return CraftItemStack.asCraftMirror(net.minecraft.world.item.ItemStack.parse(MinecraftServer.getServer().registryAccess(), compound).orElseThrow());
|
|
}
|
|
|
|
- private byte[] serializeNbtToBytes(CompoundTag compound) {
|
|
+ @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");
|
|
+
|
|
+ net.minecraft.nbt.CompoundTag compound = new net.minecraft.nbt.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");
|
|
+
|
|
+ net.minecraft.nbt.CompoundTag compound = deserializeNbtFromBytes(data);
|
|
+ int dataVersion = compound.getInt("DataVersion");
|
|
+ compound = (net.minecraft.nbt.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");
|
|
+ }
|
|
+ return net.minecraft.world.entity.EntityType.create(compound, ((org.bukkit.craftbukkit.CraftWorld) world).getHandle(), net.minecraft.world.entity.EntitySpawnReason.LOAD)
|
|
+ .orElseThrow(() -> new IllegalArgumentException("An ID was not found for the data. Did you downgrade?")).getBukkitEntity();
|
|
+ }
|
|
+
|
|
+ private byte[] serializeNbtToBytes(net.minecraft.nbt.CompoundTag compound) {
|
|
compound.putInt("DataVersion", getDataVersion());
|
|
java.io.ByteArrayOutputStream outputStream = new java.io.ByteArrayOutputStream();
|
|
try {
|