mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-02 13:07:06 +01:00
c97ce029e9
PaperMC believes that 1.16.2 is now ready for general release as we fixed the main issue plagueing the 1.16.x release, the MapLike data conversion issues. Until now, it was not safe for a server to convert a world to 1.16.2 without data conversion issues around villages and potentially other things. If you did, those MapLike errors meant something went wrong. This is now resolved. Big thanks to all those that helped, notably @BillyGalbreath and @Proximyst who did large parts of the update process with me. Please as always, backup your worlds and test before updating to 1.16.2! If you update to 1.16.2, there is no going back to an older build than this. --------------------------------- Co-authored-by: William Blake Galbreath <Blake.Galbreath@GMail.com> Co-authored-by: Mariell Hoversholm <proximyst@proximyst.com> Co-authored-by: krolik-exe <69214078+krolik-exe@users.noreply.github.com> Co-authored-by: BillyGalbreath <BillyGalbreath@users.noreply.github.com> Co-authored-by: stonar96 <minecraft.stonar96@gmail.com> Co-authored-by: Shane Freeder <theboyetronic@gmail.com> Co-authored-by: Jason <jasonpenilla2@me.com> Co-authored-by: kashike <kashike@vq.lc> Co-authored-by: Aurora <21148213+aurorasmiles@users.noreply.github.com> Co-authored-by: KennyTV <kennytv@t-online.de> Co-authored-by: commandblockguy <commandblockguy1@gmail.com> Co-authored-by: DigitalRegent <misterwener@gmail.com> Co-authored-by: ishland <ishlandmc@yeah.net>
102 lines
5.5 KiB
Diff
102 lines
5.5 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Mariell Hoversholm <proximyst@proximyst.com>
|
|
Date: Thu, 30 Apr 2020 16:56:54 +0200
|
|
Subject: [PATCH] Add Raw Byte ItemStack Serialization
|
|
|
|
Serializes using NBT which is safer for server data migrations than bukkits format.
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/DataConverterRegistry.java b/src/main/java/net/minecraft/server/DataConverterRegistry.java
|
|
index 08c11270c0409f3af9ba9b3a64488a2381b2a423..48e31e9142ffeb2725af6b1f483de67410e25694 100644
|
|
--- a/src/main/java/net/minecraft/server/DataConverterRegistry.java
|
|
+++ b/src/main/java/net/minecraft/server/DataConverterRegistry.java
|
|
@@ -24,6 +24,7 @@ public class DataConverterRegistry {
|
|
return datafixerbuilder.build(SystemUtils.e());
|
|
}
|
|
|
|
+ public static DataFixer getDataFixer() { return a(); } // Paper - OBFHELPER
|
|
public static DataFixer a() {
|
|
return DataConverterRegistry.c;
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/ItemStack.java b/src/main/java/net/minecraft/server/ItemStack.java
|
|
index b6703378e21a6cd7e140fd35756a20d47f49ed31..8c82f80bb21611b54a35e61c04f5ba3ee9efbd7d 100644
|
|
--- a/src/main/java/net/minecraft/server/ItemStack.java
|
|
+++ b/src/main/java/net/minecraft/server/ItemStack.java
|
|
@@ -144,6 +144,7 @@ public final class ItemStack {
|
|
this.checkEmpty();
|
|
}
|
|
|
|
+ public static ItemStack fromCompound(NBTTagCompound nbttagcompound) { return a(nbttagcompound); } // Paper - OBFHELPER
|
|
public static ItemStack a(NBTTagCompound nbttagcompound) {
|
|
try {
|
|
return new ItemStack(nbttagcompound);
|
|
diff --git a/src/main/java/net/minecraft/server/NBTCompressedStreamTools.java b/src/main/java/net/minecraft/server/NBTCompressedStreamTools.java
|
|
index 6e6cabc03bc3822ee973bdafef8f4adb61b6c263..0282dcb68fa185b342f59c5aaafe8f42c632cac3 100644
|
|
--- a/src/main/java/net/minecraft/server/NBTCompressedStreamTools.java
|
|
+++ b/src/main/java/net/minecraft/server/NBTCompressedStreamTools.java
|
|
@@ -47,6 +47,7 @@ public class NBTCompressedStreamTools {
|
|
return nbttagcompound;
|
|
}
|
|
|
|
+ public static NBTTagCompound readNBT(InputStream inputstream) throws IOException { return a(inputstream); } // Paper - OBFHELPER
|
|
public static NBTTagCompound a(InputStream inputstream) throws IOException {
|
|
DataInputStream datainputstream = new DataInputStream(new BufferedInputStream(new GZIPInputStream(inputstream)));
|
|
Throwable throwable = null;
|
|
@@ -102,6 +103,7 @@ public class NBTCompressedStreamTools {
|
|
|
|
}
|
|
|
|
+ public static void writeNBT(NBTTagCompound nbttagcompound, OutputStream outputstream) throws IOException { a(nbttagcompound, outputstream); } // Paper - OBFHELPER
|
|
public static void a(NBTTagCompound nbttagcompound, OutputStream outputstream) throws IOException {
|
|
DataOutputStream dataoutputstream = new DataOutputStream(new BufferedOutputStream(new GZIPOutputStream(outputstream)));
|
|
Throwable throwable = null;
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
index 1f1766f9396ad8c5be9725c2145e0ce29d110a55..c1efe830dd0807d5f7bda10cb582556af6d23383 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
@@ -333,6 +333,46 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|
public boolean isSupportedApiVersion(String apiVersion) {
|
|
return apiVersion != null && SUPPORTED_API.contains(apiVersion);
|
|
}
|
|
+
|
|
+ @Override
|
|
+ public byte[] serializeItem(ItemStack item) {
|
|
+ Preconditions.checkNotNull(item, "null cannot be serialized");
|
|
+ Preconditions.checkArgument(item.getType() != Material.AIR, "air cannot be serialized");
|
|
+
|
|
+ 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());
|
|
+ try {
|
|
+ net.minecraft.server.NBTCompressedStreamTools.writeNBT(
|
|
+ compound,
|
|
+ outputStream
|
|
+ );
|
|
+ } catch (IOException ex) {
|
|
+ throw new RuntimeException(ex);
|
|
+ }
|
|
+
|
|
+ return outputStream.toByteArray();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public ItemStack deserializeItem(byte[] data) {
|
|
+ Preconditions.checkNotNull(data, "null cannot be deserialized");
|
|
+ Preconditions.checkArgument(data.length > 0, "cannot deserialize nothing");
|
|
+
|
|
+ try {
|
|
+ NBTTagCompound compound = net.minecraft.server.NBTCompressedStreamTools.readNBT(
|
|
+ new java.io.ByteArrayInputStream(data)
|
|
+ );
|
|
+ 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.server.ItemStack.fromCompound((NBTTagCompound) converted.getValue()));
|
|
+ } catch (IOException ex) {
|
|
+ com.destroystokyo.paper.util.SneakyThrow.sneaky(ex);
|
|
+ throw new RuntimeException();
|
|
+ }
|
|
+ }
|
|
// Paper end
|
|
|
|
/**
|