mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-23 11:06:29 +01:00
385f313a8b
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: d41796de SPIGOT-7071: Add Player#stopSound(SoundCategory category) 61dae5b2 SPIGOT-7011, SPIGOT-7065: Overhaul of structures CraftBukkit Changes: 991aeda12 SPIGOT-1729, SPIGOT-7090: Keep precision in teleportation between worlds 5c9a5f628 SPIGOT-7071: Add Player#stopSound(SoundCategory category) 68f888ded SPIGOT-7011, SPIGOT-7065: Overhaul of structures 0231a3746 Remove outdated build delay. Spigot Changes: 475f6008 Rebuild patches 8ce1761f Rebuild patches
82 lines
4.5 KiB
Diff
82 lines
4.5 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
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
index 4473937b65fbdde5a77b508213935488e4f97888..37e67c8543410f754c5e75e375575564621296cf 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -1926,6 +1926,15 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
|
}
|
|
}
|
|
|
|
+ // 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
|
|
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 b8e5205c165bcba5b8383334f3d0d1daf9d0a8cd..ff8562821ebb363c755e9d316679226d9febe54f 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
@@ -1295,5 +1295,15 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
|
}
|
|
return set;
|
|
}
|
|
+
|
|
+ @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");
|
|
+ entity.level = ((CraftWorld) location.getWorld()).getHandle();
|
|
+ entity.setPos(location.getX(), location.getY(), location.getZ());
|
|
+ entity.setRot(location.getYaw(), location.getPitch());
|
|
+ return !entity.valid && entity.level.addFreshEntity(entity, reason);
|
|
+ }
|
|
// Paper end
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
index 142451a2aa0ba9e9eae6e62294e2cbdfd5361ca2..e8787c6d674178be3beadf3391e77948d9460b0c 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
@@ -457,6 +457,30 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|
return CraftItemStack.asCraftMirror(net.minecraft.world.item.ItemStack.of((CompoundTag) converted.getValue()));
|
|
}
|
|
|
|
+ @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");
|
|
+ Dynamic<Tag> converted = DataFixers.getDataFixer().update(References.ENTITY_TREE, new Dynamic<>(NbtOps.INSTANCE, compound), dataVersion, getDataVersion());
|
|
+ compound = (CompoundTag) converted.getValue();
|
|
+ if (!preserveUUID) compound.remove("UUID"); // Generate a new UUID so we don't have to worry about deserializing the same entity twice
|
|
+ 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();
|