Backup original book pages for creative mode clients in 1.8->1.9 (#3952)

This commit is contained in:
EnZaXD 2024-06-21 14:38:00 +02:00 committed by GitHub
parent 64497b305a
commit d03207289e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 3 deletions

View File

@ -1089,13 +1089,13 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
data.set(StructuredDataKey.SUSPICIOUS_STEW_EFFECTS, suspiciousStewEffects); data.set(StructuredDataKey.SUSPICIOUS_STEW_EFFECTS, suspiciousStewEffects);
} }
private void updateLodestoneTracker(final boolean tracked, final CompoundTag lodestonePosTag, final String lodestoneDimensionTag, final StructuredDataContainer data) { private void updateLodestoneTracker(final boolean tracked, final CompoundTag lodestonePosTag, final String lodestoneDimension, final StructuredDataContainer data) {
GlobalBlockPosition position = null; GlobalBlockPosition position = null;
if (lodestonePosTag != null && lodestoneDimensionTag != null) { if (lodestonePosTag != null && lodestoneDimension != null) {
final int x = lodestonePosTag.getInt("X"); final int x = lodestonePosTag.getInt("X");
final int y = lodestonePosTag.getInt("Y"); final int y = lodestonePosTag.getInt("Y");
final int z = lodestonePosTag.getInt("Z"); final int z = lodestonePosTag.getInt("Z");
position = new GlobalBlockPosition(lodestoneDimensionTag, x, y, z); position = new GlobalBlockPosition(lodestoneDimension, x, y, z);
} }
data.set(StructuredDataKey.LODESTONE_TRACKER, new LodestoneTracker(position, tracked)); data.set(StructuredDataKey.LODESTONE_TRACKER, new LodestoneTracker(position, tracked));
} }

View File

@ -418,6 +418,8 @@ public class ItemPacketRewriter1_9 extends ItemRewriter<ClientboundPackets1_8, S
} }
ListTag<StringTag> pages = tag.getListTag("pages", StringTag.class); ListTag<StringTag> pages = tag.getListTag("pages", StringTag.class);
tag.put(nbtTagName("pages"), pages == null ? new ListTag<>(StringTag.class) : pages.copy());
if (pages == null) { if (pages == null) {
pages = new ListTag<>(Collections.singletonList(new StringTag(ComponentUtil.emptyJsonComponent().toString()))); pages = new ListTag<>(Collections.singletonList(new StringTag(ComponentUtil.emptyJsonComponent().toString())));
tag.put("pages", pages); tag.put("pages", pages);
@ -481,6 +483,32 @@ public class ItemPacketRewriter1_9 extends ItemRewriter<ClientboundPackets1_8, S
item.setTag(tag); item.setTag(tag);
item.setData((short) data); item.setData((short) data);
} }
if (item.identifier() == 387) { // WRITTEN_BOOK
CompoundTag tag = item.tag();
if (tag != null) {
// Prefer saved pages since they are more likely to be accurate
ListTag<StringTag> backup = tag.removeUnchecked(nbtTagName("pages"));
if (backup != null) {
if (!backup.isEmpty()) {
tag.put("pages", backup);
} else {
tag.remove("pages");
if (tag.isEmpty()) {
item.setTag(null);
}
}
} else {
// Fallback to normal pages tag
ListTag<StringTag> pages = tag.getListTag("pages", StringTag.class);
if (pages != null) {
for (int i = 0; i < pages.size(); i++) {
final StringTag page = pages.get(i);
page.setValue(ComponentUtil.convertJsonOrEmpty(page.getValue(), SerializerVersion.V1_9, SerializerVersion.V1_8).toString());
}
}
}
}
}
boolean newItem = item.identifier() >= 198 && item.identifier() <= 212; boolean newItem = item.identifier() >= 198 && item.identifier() <= 212;
newItem |= item.identifier() == 397 && item.data() == 5; newItem |= item.identifier() == 397 && item.data() == 5;