mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-22 01:55:47 +01:00
Backup original book pages for creative mode clients in 1.8->1.9 (#3952)
This commit is contained in:
parent
64497b305a
commit
d03207289e
@ -1089,13 +1089,13 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
||||
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;
|
||||
if (lodestonePosTag != null && lodestoneDimensionTag != null) {
|
||||
if (lodestonePosTag != null && lodestoneDimension != null) {
|
||||
final int x = lodestonePosTag.getInt("X");
|
||||
final int y = lodestonePosTag.getInt("Y");
|
||||
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));
|
||||
}
|
||||
|
@ -418,6 +418,8 @@ public class ItemPacketRewriter1_9 extends ItemRewriter<ClientboundPackets1_8, S
|
||||
}
|
||||
|
||||
ListTag<StringTag> pages = tag.getListTag("pages", StringTag.class);
|
||||
tag.put(nbtTagName("pages"), pages == null ? new ListTag<>(StringTag.class) : pages.copy());
|
||||
|
||||
if (pages == null) {
|
||||
pages = new ListTag<>(Collections.singletonList(new StringTag(ComponentUtil.emptyJsonComponent().toString())));
|
||||
tag.put("pages", pages);
|
||||
@ -481,6 +483,32 @@ public class ItemPacketRewriter1_9 extends ItemRewriter<ClientboundPackets1_8, S
|
||||
item.setTag(tag);
|
||||
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;
|
||||
newItem |= item.identifier() == 397 && item.data() == 5;
|
||||
|
Loading…
Reference in New Issue
Block a user