Fix item names and lore

This commit is contained in:
Draycia 2020-05-03 23:07:25 -07:00
parent 4ba85b4ff3
commit 6d45dc674d
2 changed files with 12 additions and 4 deletions

View File

@ -120,7 +120,11 @@ public class NbtReaderUtils {
String stringName = reader.readShortSizedString();
if (stringName.equals("Name")) {
item.setDisplayName(reader.readShortSizedString());
String jsonDisplayName = reader.readShortSizedString();
Component textObject = Chat.fromJsonString(jsonDisplayName);
String displayName = Chat.toLegacyText(textObject);
item.setDisplayName(displayName);
readItemStackDisplayNBT(reader, item);
}
break;
@ -134,7 +138,11 @@ public class NbtReaderUtils {
int size = reader.readInteger();
ArrayList<String> lore = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
lore.add(reader.readShortSizedString());
String string = reader.readShortSizedString();
Component textObject = Chat.fromJsonString(string);
String line = Chat.toLegacyText(textObject);
lore.add(line);
if (lore.size() == size) {
item.setLore(lore);
}

View File

@ -117,7 +117,7 @@ public class Utils {
if (hasDisplayName) {
packet.writeByte((byte) 0x08);
packet.writeShortSizedString("Name");
packet.writeShortSizedString(itemStack.getDisplayName());
packet.writeShortSizedString(Chat.toJsonString(Chat.fromLegacyText(itemStack.getDisplayName())));
}
if (hasLore) {
@ -128,7 +128,7 @@ public class Utils {
packet.writeByte((byte) 0x08);
packet.writeInt(lore.size());
for (String line : lore) {
packet.writeShortSizedString(line);
packet.writeShortSizedString(Chat.toJsonString(Chat.fromLegacyText(line)));
}
}