2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Wed, 4 May 2016 22:43:12 -0400
Subject: [PATCH] Implement ensureServerConversions API
This will take a Bukkit ItemStack and run it through any conversions a server process would perform on it,
to ensure it meets latest minecraft expectations.
2023-09-25 01:05:05 +02:00
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
2023-12-05 23:12:48 +01:00
index e6a47317eb24fc65ed02a4d4f9c4b19b5abc920d..8e8bcf829818fbbaedb13d9eddca096d457c511a 100644
2023-09-25 01:05:05 +02:00
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
2023-12-05 23:12:48 +01:00
@@ -229,7 +229,7 @@ public final class ItemStack {
2023-09-25 01:05:05 +02:00
// Called to run this stack through the data converter to handle older storage methods and serialized items
public void convertStack(int version) {
- if (0 < version && version < CraftMagicNumbers.INSTANCE.getDataVersion()) {
+ if (0 < version && version < CraftMagicNumbers.INSTANCE.getDataVersion() && MinecraftServer.getServer() != null) { // Paper - skip conversion if the server doesn't exist (for tests)
CompoundTag savedStack = new CompoundTag();
this.save(savedStack);
savedStack = (CompoundTag) MinecraftServer.getServer().fixerUpper.update(References.ITEM_STACK, new Dynamic(NbtOps.INSTANCE, savedStack), version, CraftMagicNumbers.INSTANCE.getDataVersion()).getValue();
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
2023-12-05 23:12:48 +01:00
index 4c5ef6472947baf2ca3cc294eed77ceebd6cd5af..edb3b4efb38a644e312bf4dde4c756bec21192f7 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
2023-12-05 23:12:48 +01:00
@@ -511,4 +511,11 @@ public final class CraftItemFactory implements ItemFactory {
2021-06-16 19:48:25 +02:00
return io.papermc.paper.adventure.PaperAdventure.asAdventure(CraftItemStack.asNMSCopy(itemStack).getDisplayName());
2021-06-11 14:02:28 +02:00
}
2023-08-06 02:21:59 +02:00
// Paper end - Adventure
2021-06-11 14:02:28 +02:00
+
2023-08-06 02:21:59 +02:00
+ // Paper start - ensure server conversions API
2021-06-11 14:02:28 +02:00
+ @Override
+ public ItemStack ensureServerConversions(ItemStack item) {
+ return CraftItemStack.asCraftMirror(CraftItemStack.asNMSCopy(item));
+ }
2023-08-06 02:21:59 +02:00
+ // Paper end - ensure server conversions API
2021-06-11 14:02:28 +02:00
}