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

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

Dieser Commit ist enthalten in:
EnZaXD 2024-06-21 14:38:00 +02:00 committet von GitHub
Ursprung 64497b305a
Commit d03207289e
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194
2 geänderte Dateien mit 31 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -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));
} }

Datei anzeigen

@ -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;