Paper/patches/server/0434-Update-itemstack-legacy-name-and-lore.patch

64 lines
3.2 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <Blake.Galbreath@GMail.com>
Date: Wed, 1 Jul 2020 11:57:40 -0500
Subject: [PATCH] Update itemstack legacy name and lore
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#9440) 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: 01aa02eb PR-858: Add LivingEntity#playHurtAnimation() 9421320f PR-884: Refinements to new ban API for improved compatibility and correctness 37a60b45 SPIGOT-6455, SPIGOT-7030, PR-750: Improve ban API 4eeb174b All smithing inventories are now the new smithing inventory f2bb168e PR-880: Add methods to get/set FallingBlock CancelDrop e7a807fa PR-879: Add Player#sendHealthUpdate() 692b8e96 SPIGOT-7370: Remove float value conversion in plugin.yml 2d033390 SPIGOT-7403: Add direct API for waxed signs 16a08373 PR-876: Add missing Raider API and 'no action ticks' CraftBukkit Changes: b60a95c8c PR-1189: Add LivingEntity#playHurtAnimation() 95c335c63 PR-1226: Fix VehicleEnterEvent not being called for certain entities 0a0fc3bee PR-1227: Refinements to new ban API for improved compatibility and correctness 0d0b1e5dc Revert bad change to PathfinderGoalSit causing all cats to sit 648196070 SPIGOT-6455, SPIGOT-7030, PR-1054: Improve ban API 31fe848d6 All smithing inventories are now the new smithing inventory 9a919a143 SPIGOT-7416: SmithItemEvent not firing in Smithing Table 9f64f0d22 PR-1221: Add methods to get/set FallingBlock CancelDrop 3be9ac171 PR-1220: Add Player#sendHealthUpdate() c1279f775 PR-1209: Clean up various patches c432e4397 Fix Raider#setCelebrating() implementation 504d96665 SPIGOT-7403: Add direct API for waxed signs c68c1f1b3 PR-1216: Add missing Raider API and 'no action ticks' 85b89c3dd Increase outdated build delay Spigot Changes: 9ebce8af Rebuild patches 64b565e6 Rebuild patches
2023-07-04 10:22:56 +02:00
index 7d80eded30109982fd3a1b815ba5dff4b699689a..dcb01c399d2b30d907bfc51584215d9300b6d23e 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
2023-06-08 01:20:26 +02:00
@@ -171,6 +171,44 @@ public final class ItemStack {
2022-06-08 15:38:56 +02:00
list.sort((java.util.Comparator<? super net.minecraft.nbt.Tag>) enchantSorter); // Paper
2021-06-11 14:02:28 +02:00
} catch (Exception ignored) {}
}
+
+ private void processText() {
2021-06-17 22:20:03 +02:00
+ CompoundTag display = getTagElement("display");
2021-06-11 14:02:28 +02:00
+ if (display != null) {
+ if (display.contains("Name", 8)) {
+ String json = display.getString("Name");
+ if (json != null && json.contains("\u00A7")) {
+ try {
+ display.put("Name", convert(json));
2021-12-10 15:24:07 +01:00
+ } catch (com.google.gson.JsonParseException jsonparseexception) {
2021-06-11 14:02:28 +02:00
+ display.remove("Name");
+ }
+ }
+ }
+ if (display.contains("Lore", 9)) {
+ ListTag list = display.getList("Lore", 8);
+ for (int index = 0; index < list.size(); index++) {
+ String json = list.getString(index);
+ if (json != null && json.contains("\u00A7")) { // Only try if it has legacy in the unparsed json
+ try {
+ list.set(index, convert(json));
2021-12-10 15:24:07 +01:00
+ } catch (com.google.gson.JsonParseException e) {
2022-06-08 10:45:59 +02:00
+ list.set(index, net.minecraft.nbt.StringTag.valueOf(org.bukkit.craftbukkit.util.CraftChatMessage.toJSON(net.minecraft.network.chat.Component.literal(""))));
2021-06-11 14:02:28 +02:00
+ }
+ }
+ }
+ }
+ }
+ }
+
2021-06-14 11:46:59 +02:00
+ private net.minecraft.nbt.StringTag convert(String json) {
2021-06-16 19:48:25 +02:00
+ Component component = Component.Serializer.fromJson(json);
2022-06-08 15:03:33 +02:00
+ if (component.getContents() instanceof net.minecraft.network.chat.contents.LiteralContents literalContents && literalContents.text().contains("\u00A7") && component.getSiblings().isEmpty()) {
2021-06-11 14:02:28 +02:00
+ // Only convert if the root component is a single comp with legacy in it, don't convert already normal components
2022-06-08 15:03:33 +02:00
+ component = org.bukkit.craftbukkit.util.CraftChatMessage.fromString(literalContents.text())[0];
2021-06-11 14:02:28 +02:00
+ }
2021-06-16 19:48:25 +02:00
+ return net.minecraft.nbt.StringTag.valueOf(org.bukkit.craftbukkit.util.CraftChatMessage.toJSON(component));
2021-06-11 14:02:28 +02:00
+ }
// Paper end
public ItemStack(ItemLike item) {
2023-06-08 01:20:26 +02:00
@@ -222,6 +260,7 @@ public final class ItemStack {
this.tag = nbttagcompound.getCompound("tag").copy();
2021-06-11 14:02:28 +02:00
// CraftBukkit end
2021-06-14 11:46:59 +02:00
this.processEnchantOrder(this.tag); // Paper
+ this.processText(); // Paper
this.getItem().verifyTagAfterLoad(this.tag);
2021-06-11 14:02:28 +02:00
}
2021-06-14 11:46:59 +02:00