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
2024-01-22 19:01:10 +01:00
Subject: [PATCH] ensureServerConversions API
2021-06-11 14:02:28 +02:00
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
2024-01-14 10:46:04 +01:00
index b0ea04fc0bac640f7076100e44c16c03b86b2a0e..7f85121b6830ebf480c5ca7b42d3c835911de836 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
2024-01-14 10:46:04 +01:00
index 0875dfe89644f5f54d004488ed980092b31c6416..89bc6cb62123bc17d579b578c4d1d2e5f8c40837 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
2024-01-14 10:46:04 +01:00
@@ -505,4 +505,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
}