mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 08:27:43 +01:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: 809466f2e Fix anchor respawn acting as a bed respawn when using the end portal (#5540) d219fd642 [Auto] Updated Upstream (Bukkit/CraftBukkit) db464b099 Implement methods to convert between Component and Brigadier's Message (#5542) 4047cffca Add PlayerBedFailEnterEvent (#4935) 70d697e6e Update Paperpclip 5ed771591 [CI-SKIP] Remove bad null annotation (#5538) 454a4c78e More World API (#3850) 869e02304 Add PlayerDeepSleepEvent (#5525) fb56fc35e fix non-dummy objectives not updating dc859a61f [CI-SKIP] [Auto] Rebuild Patches 7d1689f1a Add missing checkReachable check for shulker boxes (#5453) ba8eb3d4b Add missing Javadoc for COLORABLE MaterialTag (#5376) db801cbf3 Fix PlayerItemHeldEvent firing twice (#5534) 14de2b795 fix PigZombieAngerEvent cancellation (fixes #5319) (v2) (#5329) 86d684ad1 Add get-set drop chance to EntityEquipment (#5528) 33fb8cf63 Add consumeFuel to FurnaceBurnEvent (#5532) 9957f4630 Fix duplicating /give items on item drop cancel (#5536) d94882043 Fix legacyComposer not using AsyncChatEvent messages (#5509) 053bd82cc Don't print spawn load time when not loading spawn (#5467) a6d78caae Add isDeeplySleeping to HumanEntity (#5470) 711b7a80b Expose more Adventure serializers through PaperComponents (#5443) 3f63bde0c Set Area Effect Cloud Rotation (#5462) 3523f0fda Remove useless check on player interact cancellation (#5448) 6574d1aa8 fix #5526 - use correct type when sending message to clients dbfa833ec don't throw when loading TE with invalid keys a9525a6f7 Do not schedule poi task for each block write on chunk gen 39bf5b525 Update teams known as code owners fbae9dbe0 [Auto] Updated Upstream (Bukkit/CraftBukkit) ac4a33aab [Auto] Updated Upstream (Bukkit) c1e07158b [Auto] Updated Upstream (Bukkit/CraftBukkit) 5e4b88e95 Fix dangling sout 23afda179 basic hostname validation 0fb8bdf0e Updated Upstream (Bukkit/CraftBukkit) (#5508) 88ab784da [Auto] Updated Upstream (CraftBukkit) ca7111d5f Fix PlayerItemConsumeEvent cancelling (fixes #4682) (#5383) 06fb560dc Add support for tab completing and highlighting console input from the Brigadier command tree (#5437) 0a9b89c7a Fix occasional light gen issues for neighbor blocks (#5500) Tuinity Changes: b12d0cce3 Replace ticket level propagator 42df8e1e0 Correctly handle recursion for chunkholder updates 73eb2a856 Do not copy visible chunks 8a4f3be69 Do not schedule poi task for each block write on chunk gen 7d36676fc Fix light source locking f1ec0c20d Add concurrency check to ProtoChunk light sources 159d1468f Improvements to chunk loader system 32b4d526b Updated Upstream (Paper) ac5adca33 Make sure lit is set for pre 1.14 chunks Airplane Changes: d8bdbc508 Reduce allocations for fire spreading 41051fd56 Redo reduction of entity chunk ticking check patch 31272d80f Flare Update 8f3271328 Remove criterion patch 0fed2df62 Various patches that need to be reorganized later f78856bde Updated Upstream (Tuinity) f7d6382ad Flare Update 71d079991 Update gradle configuration 0f7977428 Updated Upstream (Tuinity) 3b3cde7b0 Correctly use DEAR values, fix config reloading dd6091981 Updated Upstream (Tuinity) 07897895b Updated Upstream (Tuinity) c1e4d7143 Fluid cache patch
130 lines
7.6 KiB
Diff
130 lines
7.6 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Mariell Hoversholm <proximyst@proximyst.com>
|
|
Date: Sat, 9 Jan 2021 21:22:58 +0100
|
|
Subject: [PATCH] Add unsafe Entity serialization API
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/EntityTypes.java b/src/main/java/net/minecraft/world/entity/EntityTypes.java
|
|
index e1ef642f06078202fb782ac16b268e6429c5e202..778c981d4458957533fc3ac44095051b279c74e3 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/EntityTypes.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/EntityTypes.java
|
|
@@ -534,6 +534,7 @@ public class EntityTypes<T extends Entity> {
|
|
return this.bf.create(this, world);
|
|
}
|
|
|
|
+ public static Optional<Entity> loadEntityFixedData(NBTTagCompound nbtTagCompound, World world) { return a(nbtTagCompound, world); } // Purpur - OBFHELPER
|
|
public static Optional<Entity> a(NBTTagCompound nbttagcompound, World world) {
|
|
return SystemUtils.a(a(nbttagcompound).map((entitytypes) -> {
|
|
return entitytypes.a(world);
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
index a80f664d2cf713fd751421be3735e2f4779f0056..6c37bf58bd269c2d7e1c84e5791e8245e4c75aea 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
@@ -1200,5 +1200,12 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
|
public boolean isRidableInWater() {
|
|
return getHandle().isRidableInWater();
|
|
}
|
|
+
|
|
+ @Override
|
|
+ public boolean spawnAt(Location location, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) {
|
|
+ entity.world = ((CraftWorld) location.getWorld()).getHandle();
|
|
+ entity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
|
|
+ return !entity.valid && entity.world.addEntity(entity, spawnReason);
|
|
+ }
|
|
// Purpur end
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
index 67f93f252a26f8b598a4b48c63c321728b246cae..b05b6e911026b8b8ad2e12b7a6705364ec90769d 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
@@ -410,9 +410,14 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|
Preconditions.checkNotNull(item, "null cannot be serialized");
|
|
Preconditions.checkArgument(item.getType() != Material.AIR, "air cannot be serialized");
|
|
|
|
+ // Purpur start - rework NBT <-> bytes
|
|
+ return serializeNbtToBytes(CraftItemStack.asNMSCopy(item).save(new NBTTagCompound()), true);
|
|
+ }
|
|
+
|
|
+ public byte[] serializeNbtToBytes(NBTTagCompound compound, boolean addDataVersion) {
|
|
+ if (addDataVersion) compound.setInt("DataVersion", getDataVersion());
|
|
java.io.ByteArrayOutputStream outputStream = new java.io.ByteArrayOutputStream();
|
|
- NBTTagCompound compound = (item instanceof CraftItemStack ? ((CraftItemStack) item).getHandle() : CraftItemStack.asNMSCopy(item)).save(new NBTTagCompound());
|
|
- compound.setInt("DataVersion", getDataVersion());
|
|
+ // Purpur end
|
|
try {
|
|
net.minecraft.nbt.NBTCompressedStreamTools.writeNBT(
|
|
compound,
|
|
@@ -425,26 +430,58 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|
return outputStream.toByteArray();
|
|
}
|
|
|
|
+ public static DynamicOpsNBT getDynamicOpsNbtInstance() { return DynamicOpsNBT.a; } // Purpur - OBFHELPER - keeping out of the class because it's FULL of decompile errors
|
|
@Override
|
|
public ItemStack deserializeItem(byte[] data) {
|
|
Preconditions.checkNotNull(data, "null cannot be deserialized");
|
|
Preconditions.checkArgument(data.length > 0, "cannot deserialize nothing");
|
|
|
|
+ // Purpur start - rework NBT <-> bytes
|
|
+ NBTTagCompound compound = deserializeNbtFromBytes(data, true);
|
|
+ Dynamic<NBTBase> converted = DataConverterRegistry.getDataFixer().update(DataConverterTypes.ITEM_STACK, new Dynamic<>(getDynamicOpsNbtInstance(), compound), compound.getInt("DataVersion"), getDataVersion()); // TODO: obfhelper
|
|
+ return net.minecraft.world.item.ItemStack.fromCompound((NBTTagCompound) converted.getValue()).asBukkitMirror();
|
|
+ }
|
|
+
|
|
+ public NBTTagCompound deserializeNbtFromBytes(byte[] data, boolean verifyDataVersion) {
|
|
+ // Purpur end
|
|
try {
|
|
NBTTagCompound compound = net.minecraft.nbt.NBTCompressedStreamTools.readNBT(
|
|
new java.io.ByteArrayInputStream(data)
|
|
);
|
|
+ if (verifyDataVersion) { // Purpur
|
|
int dataVersion = compound.getInt("DataVersion");
|
|
|
|
Preconditions.checkArgument(dataVersion <= getDataVersion(), "Newer version! Server downgrades are not supported!");
|
|
- Dynamic<NBTBase> converted = DataConverterRegistry.getDataFixer().update(DataConverterTypes.ITEM_STACK, new Dynamic<NBTBase>(DynamicOpsNBT.a, compound), dataVersion, getDataVersion());
|
|
- return CraftItemStack.asCraftMirror(net.minecraft.world.item.ItemStack.fromCompound((NBTTagCompound) converted.getValue()));
|
|
+ } // Purpur
|
|
+ return compound; // Purpur
|
|
} catch (IOException ex) {
|
|
com.destroystokyo.paper.util.SneakyThrow.sneaky(ex);
|
|
throw new RuntimeException();
|
|
}
|
|
}
|
|
|
|
+ // Purpur start
|
|
+ @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, "non-CraftEntity cannot be serialized");
|
|
+ NBTTagCompound compound = new NBTTagCompound();
|
|
+ compound.setString("id", ((org.bukkit.craftbukkit.entity.CraftEntity) entity).getHandle().getMinecraftKeyString());
|
|
+ return serializeNbtToBytes(((org.bukkit.craftbukkit.entity.CraftEntity) entity).getHandle().save(compound), true);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public org.bukkit.entity.Entity deserializeEntity(byte[] data, org.bukkit.World world) {
|
|
+ NBTTagCompound compound = deserializeNbtFromBytes(data, true);
|
|
+ Dynamic<NBTBase> converted = DataConverterRegistry.getDataFixer().update(DataConverterTypes.ENTITY, new Dynamic<>(getDynamicOpsNbtInstance(), compound), compound.getInt("DataVersion"), getDataVersion());
|
|
+ compound = (NBTTagCompound) converted.getValue();
|
|
+ compound.remove("UUID"); // Make the server make a new UUID for this entity; makes entities always spawnable.
|
|
+ return net.minecraft.world.entity.EntityTypes.loadEntityFixedData(compound, ((org.bukkit.craftbukkit.CraftWorld) world).getHandle())
|
|
+ .orElseThrow(() -> new IllegalArgumentException("unknown ID was found for the data; did you downgrade?"))
|
|
+ .getBukkitEntity();
|
|
+ }
|
|
+ // Pupur end
|
|
+
|
|
@Override
|
|
public String getTranslationKey(Material mat) {
|
|
if (mat.isBlock()) {
|