3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 08:30:09 +01:00

Merge pull request #752 from mmxw11/master

Format the book data correctly, fixes #737 + spaces
Dieser Commit ist enthalten in:
Myles 2017-09-24 17:19:01 +01:00 committet von GitHub
Commit 358267d6e3
2 geänderte Dateien mit 36 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -187,6 +187,41 @@ public class ItemRewriter {
} }
} }
public static void rewriteBookToServer(Item item) {
short id = item.getId();
if (id != 387) {
return;
}
CompoundTag tag = item.getTag();
ListTag pages = tag.get("pages");
if (pages == null) { // is this even possible?
return;
}
for (int i = 0; i < pages.size(); i++) {
Tag pageTag = pages.get(i);
if (!(pageTag instanceof StringTag)) {
continue;
}
StringTag stag = (StringTag) pageTag;
String value = stag.getValue();
if (value.replaceAll(" ", "").isEmpty()) {
value = "\"" + fixBookSpaceChars(value) + "\"";
} else {
value = fixBookSpaceChars(value);
}
stag.setValue(value);
}
}
private static String fixBookSpaceChars(String str) {
if (!str.startsWith(" ")) {
return str;
}
// hacky but it works :)
str = "\u00A7r" + str;
return str;
}
public static void toClient(Item item) { public static void toClient(Item item) {
if (item != null) { if (item != null) {
if (item.getId() == 383 && item.getData() != 0) { // Monster Egg if (item.getId() == 383 && item.getData() != 0) { // Monster Egg

Datei anzeigen

@ -502,6 +502,7 @@ public class PlayerPackets {
Item item = wrapper.passthrough(Type.ITEM); Item item = wrapper.passthrough(Type.ITEM);
if (item != null) { if (item != null) {
item.setId((short) 387); // Written Book item.setId((short) 387); // Written Book
ItemRewriter.rewriteBookToServer(item);
} }
} }
if (name.equalsIgnoreCase("MC|AutoCmd")) { if (name.equalsIgnoreCase("MC|AutoCmd")) {