2021-06-11 12:02:28 +00: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
|
2021-06-18 05:51:04 +00:00
|
|
|
index 1496035b925b47c45fa3a9d4f68060d2e0408a9c..41de19cc0cf5d4a2e5963a4226d08585d396fe42 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
|
2021-06-14 09:46:59 +00:00
|
|
|
@@ -170,6 +170,44 @@ public final class ItemStack {
|
|
|
|
list.sort((Comparator<? super net.minecraft.nbt.Tag>) enchantSorter); // Paper
|
2021-06-11 12:02:28 +00:00
|
|
|
} catch (Exception ignored) {}
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ private void processText() {
|
2021-06-17 20:20:03 +00:00
|
|
|
+ CompoundTag display = getTagElement("display");
|
2021-06-11 12:02:28 +00: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));
|
|
|
|
+ } catch (JsonParseException jsonparseexception) {
|
|
|
|
+ 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));
|
|
|
|
+ } catch (JsonParseException e) {
|
2021-06-16 17:48:25 +00:00
|
|
|
+ list.set(index, net.minecraft.nbt.StringTag.valueOf(org.bukkit.craftbukkit.util.CraftChatMessage.toJSON(new TextComponent(""))));
|
2021-06-11 12:02:28 +00:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
2021-06-14 09:46:59 +00:00
|
|
|
+ private net.minecraft.nbt.StringTag convert(String json) {
|
2021-06-16 17:48:25 +00:00
|
|
|
+ Component component = Component.Serializer.fromJson(json);
|
2021-06-11 12:02:28 +00:00
|
|
|
+ if (component instanceof TextComponent && component.getContents().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
|
|
|
|
+ component = org.bukkit.craftbukkit.util.CraftChatMessage.fromString(component.getContents())[0];
|
|
|
|
+ }
|
2021-06-16 17:48:25 +00:00
|
|
|
+ return net.minecraft.nbt.StringTag.valueOf(org.bukkit.craftbukkit.util.CraftChatMessage.toJSON(component));
|
2021-06-11 12:02:28 +00:00
|
|
|
+ }
|
|
|
|
// Paper end
|
|
|
|
|
|
|
|
public ItemStack(ItemLike item) {
|
2021-06-14 09:46:59 +00:00
|
|
|
@@ -216,6 +254,7 @@ public final class ItemStack {
|
2021-06-11 12:02:28 +00:00
|
|
|
this.tag = (CompoundTag) nbttagcompound.getCompound("tag").copy();
|
|
|
|
// CraftBukkit end
|
2021-06-14 09:46:59 +00:00
|
|
|
this.processEnchantOrder(this.tag); // Paper
|
|
|
|
+ this.processText(); // Paper
|
|
|
|
this.getItem().verifyTagAfterLoad(this.tag);
|
2021-06-11 12:02:28 +00:00
|
|
|
}
|
2021-06-14 09:46:59 +00:00
|
|
|
|