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-01-14 10:46:04 +01:00
|
|
|
index 8db434d01f2771a94cd4c4a662ea0482b2a02307..58aa16888666f81ba688037bff61d149a03767af 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
|
2024-01-14 10:46:04 +01:00
|
|
|
@@ -2159,6 +2159,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;
|
|
|
|
+ }
|
|
|
|
+ // 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
|
2023-12-25 23:51:56 +01:00
|
|
|
index a6492b6a9f66d8bcda8928fadf0a5920ff7f0dab..71845027ba1b755ead76cf75d011547d9910597a 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
|
Updated Upstream (Bukkit/CraftBukkit) (#10034)
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:
f29cb801 Separate checkstyle-suppressions file is not required
86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API
d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor
b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack
9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode()
994a6163 Attempt upgrade of resolver libraries
CraftBukkit Changes:
b3b43a6ad Add Checkstyle check for unused imports
13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names
3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API
2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor
1dbdbbed4 PR-1238: Remove unnecessary sign ticking
659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper
e37e29ce0 Increase outdated build delay
c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack
492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode()
e11fbb9d7 Upgrade MySQL driver
9f3a0bd2a Attempt upgrade of resolver libraries
60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion
Spigot Changes:
06d602e7 Rebuild patches
2023-12-17 03:09:28 +01:00
|
|
|
@@ -1076,5 +1076,15 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
2021-11-11 03:53:27 +01:00
|
|
|
}
|
|
|
|
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");
|
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
|
|
|
+ }
|
|
|
|
// Paper end
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
2023-12-06 20:40:37 +01:00
|
|
|
index 580b6c134743c35d9eb1d98a2d038d1c8f10054c..4a5af85ebb573950c0c65d3a5f25b586173d16dd 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
|
2023-12-06 05:49:31 +01:00
|
|
|
@@ -483,6 +483,29 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
2023-01-24 15:30:51 +01:00
|
|
|
return CraftItemStack.asCraftMirror(net.minecraft.world.item.ItemStack.of(ca.spottedleaf.dataconverter.minecraft.MCDataConverter.convertTag(ca.spottedleaf.dataconverter.minecraft.datatypes.MCTypeRegistry.ITEM_STACK, compound, dataVersion, getDataVersion())));
|
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");
|
2023-01-24 15:30:51 +01:00
|
|
|
+ compound = ca.spottedleaf.dataconverter.minecraft.MCDataConverter.convertTag(ca.spottedleaf.dataconverter.minecraft.datatypes.MCTypeRegistry.ENTITY, compound, dataVersion, getDataVersion());
|
2021-11-11 03:53:27 +01:00
|
|
|
+ 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();
|