mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-09 04:09:54 +01:00
de04cbced5
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
83 lines
4.8 KiB
Diff
83 lines
4.8 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 6f023b22a1051baaa5310d8c5a1aa6d8b76d8992..65ab99c3f3f1478db6e14d713e82346d3ecc06a5 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -2157,6 +2157,15 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
|
|
}
|
|
}
|
|
|
|
+ // 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 f72c20c8b427c1dee1e58f03a02a6a59e28da0e7..5a498ccfa7832f0819ccf4c4c1d6ec5dbd4f48b3 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
@@ -1076,5 +1076,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");
|
|
+ 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
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
index 580b6c134743c35d9eb1d98a2d038d1c8f10054c..4a5af85ebb573950c0c65d3a5f25b586173d16dd 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
@@ -483,6 +483,29 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|
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())));
|
|
}
|
|
|
|
+ @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");
|
|
+ compound = ca.spottedleaf.dataconverter.minecraft.MCDataConverter.convertTag(ca.spottedleaf.dataconverter.minecraft.datatypes.MCTypeRegistry.ENTITY, compound, dataVersion, getDataVersion());
|
|
+ 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();
|