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
|
2023-03-14 20:54:57 +01:00
|
|
|
index fa83827a80335ac1075f28c9acdfe7ca2ada8790..e4e2d3676c354218e1d334a89a082c5f57a09673 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-03-14 20:54:57 +01: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-03-14 20:54:57 +01:00
|
|
|
@@ -225,6 +263,7 @@ public final class ItemStack {
|
2021-11-24 16:07:19 +01:00
|
|
|
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
|
|
|
|