Skip to content

Commit d032072

Browse files
Backup original book pages for creative mode clients in 1.8->1.9 (ViaVersion#3952)
1 parent 64497b3 commit d032072

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,13 +1089,13 @@ private void updateEffects(final ListTag<CompoundTag> effects, final StructuredD
10891089
data.set(StructuredDataKey.SUSPICIOUS_STEW_EFFECTS, suspiciousStewEffects);
10901090
}
10911091

1092-
private void updateLodestoneTracker(final boolean tracked, final CompoundTag lodestonePosTag, final String lodestoneDimensionTag, final StructuredDataContainer data) {
1092+
private void updateLodestoneTracker(final boolean tracked, final CompoundTag lodestonePosTag, final String lodestoneDimension, final StructuredDataContainer data) {
10931093
GlobalBlockPosition position = null;
1094-
if (lodestonePosTag != null && lodestoneDimensionTag != null) {
1094+
if (lodestonePosTag != null && lodestoneDimension != null) {
10951095
final int x = lodestonePosTag.getInt("X");
10961096
final int y = lodestonePosTag.getInt("Y");
10971097
final int z = lodestonePosTag.getInt("Z");
1098-
position = new GlobalBlockPosition(lodestoneDimensionTag, x, y, z);
1098+
position = new GlobalBlockPosition(lodestoneDimension, x, y, z);
10991099
}
11001100
data.set(StructuredDataKey.LODESTONE_TRACKER, new LodestoneTracker(position, tracked));
11011101
}

common/src/main/java/com/viaversion/viaversion/protocols/v1_8to1_9/rewriter/ItemPacketRewriter1_9.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,8 @@ public void register() {
418418
}
419419

420420
ListTag<StringTag> pages = tag.getListTag("pages", StringTag.class);
421+
tag.put(nbtTagName("pages"), pages == null ? new ListTag<>(StringTag.class) : pages.copy());
422+
421423
if (pages == null) {
422424
pages = new ListTag<>(Collections.singletonList(new StringTag(ComponentUtil.emptyJsonComponent().toString())));
423425
tag.put("pages", pages);
@@ -481,6 +483,32 @@ public void register() {
481483
item.setTag(tag);
482484
item.setData((short) data);
483485
}
486+
if (item.identifier() == 387) { // WRITTEN_BOOK
487+
CompoundTag tag = item.tag();
488+
if (tag != null) {
489+
// Prefer saved pages since they are more likely to be accurate
490+
ListTag<StringTag> backup = tag.removeUnchecked(nbtTagName("pages"));
491+
if (backup != null) {
492+
if (!backup.isEmpty()) {
493+
tag.put("pages", backup);
494+
} else {
495+
tag.remove("pages");
496+
if (tag.isEmpty()) {
497+
item.setTag(null);
498+
}
499+
}
500+
} else {
501+
// Fallback to normal pages tag
502+
ListTag<StringTag> pages = tag.getListTag("pages", StringTag.class);
503+
if (pages != null) {
504+
for (int i = 0; i < pages.size(); i++) {
505+
final StringTag page = pages.get(i);
506+
page.setValue(ComponentUtil.convertJsonOrEmpty(page.getValue(), SerializerVersion.V1_9, SerializerVersion.V1_8).toString());
507+
}
508+
}
509+
}
510+
}
511+
}
484512

485513
boolean newItem = item.identifier() >= 198 && item.identifier() <= 212;
486514
newItem |= item.identifier() == 397 && item.data() == 5;

0 commit comments

Comments
 (0)