2020-07-05 02:47:24 +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
|
|
|
|
|
|
|
|
|
2021-03-16 08:19:45 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
|
|
|
|
index 3d5a4d662ae4880fa27bd681127ddf7d1f70b51c..8b5aaa18d278f20e32e25edddc2a10069c2ba5e6 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
|
|
|
|
@@ -137,6 +137,44 @@ public final class ItemStack {
|
2020-07-05 02:47:24 +02:00
|
|
|
list.sort((Comparator<? super NBTBase>) enchantSorter); // Paper
|
|
|
|
} catch (Exception ignored) {}
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ private void processText() {
|
|
|
|
+ NBTTagCompound display = getSubTag("display");
|
|
|
|
+ if (display != null) {
|
|
|
|
+ if (display.hasKeyOfType("Name", 8)) {
|
|
|
|
+ String json = display.getString("Name");
|
|
|
|
+ if (json != null && json.contains("\u00A7")) {
|
|
|
|
+ try {
|
|
|
|
+ display.set("Name", convert(json));
|
|
|
|
+ } catch (JsonParseException jsonparseexception) {
|
|
|
|
+ display.remove("Name");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (display.hasKeyOfType("Lore", 9)) {
|
|
|
|
+ NBTTagList list = display.getList("Lore", 8);
|
|
|
|
+ for (int index = 0; index < list.size(); index++) {
|
|
|
|
+ String json = list.getString(index);
|
2020-07-10 02:31:04 +02:00
|
|
|
+ if (json != null && json.contains("\u00A7")) { // Only try if it has legacy in the unparsed json
|
2020-07-05 02:47:24 +02:00
|
|
|
+ try {
|
2020-07-10 02:31:04 +02:00
|
|
|
+ list.set(index, convert(json));
|
|
|
|
+ } catch (JsonParseException e) {
|
|
|
|
+ list.set(index, NBTTagString.create(org.bukkit.craftbukkit.util.CraftChatMessage.toJSON(new ChatComponentText(""))));
|
2020-07-05 02:47:24 +02:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private NBTTagString convert(String json) {
|
|
|
|
+ IChatBaseComponent component = IChatBaseComponent.ChatSerializer.jsonToComponent(json);
|
2020-07-10 02:31:04 +02:00
|
|
|
+ if (component instanceof ChatComponentText && component.getText().contains("\u00A7") && component.getSiblings().isEmpty()) {
|
|
|
|
+ // Only convert if the root component is a single comp with legacy in it, don't convert already normal components
|
2020-07-05 02:47:24 +02:00
|
|
|
+ component = org.bukkit.craftbukkit.util.CraftChatMessage.fromString(component.getText())[0];
|
|
|
|
+ }
|
|
|
|
+ return NBTTagString.create(org.bukkit.craftbukkit.util.CraftChatMessage.toJSON(component));
|
|
|
|
+ }
|
|
|
|
// Paper end
|
|
|
|
|
|
|
|
public ItemStack(IMaterial imaterial) {
|
2021-03-16 08:19:45 +01:00
|
|
|
@@ -182,6 +220,7 @@ public final class ItemStack {
|
2020-07-05 02:47:24 +02:00
|
|
|
// CraftBukkit start - make defensive copy as this data may be coming from the save thread
|
|
|
|
this.tag = (NBTTagCompound) nbttagcompound.getCompound("tag").clone();
|
|
|
|
processEnchantOrder(this.tag); // Paper
|
|
|
|
+ processText(); // Paper
|
|
|
|
this.getItem().b(this.tag);
|
|
|
|
// CraftBukkit end
|
|
|
|
}
|
2021-03-16 08:19:45 +01:00
|
|
|
@@ -665,6 +704,7 @@ public final class ItemStack {
|
2020-07-05 02:47:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ @Nullable public NBTTagCompound getSubTag(String s) { return b(s); } // Paper - OBFHELPER
|
|
|
|
@Nullable
|
|
|
|
public NBTTagCompound b(String s) {
|
|
|
|
return this.tag != null && this.tag.hasKeyOfType(s, 10) ? this.tag.getCompound(s) : null;
|