Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-27 16:40:10 +01:00
Push books through component conversion in 1.20.2->1.20.3
Fixes #3579
Dieser Commit ist enthalten in:
Ursprung
f3d95b1e5e
Commit
cfc9011cee
@ -17,8 +17,14 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.rewriter;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.viaversion.viaversion.api.data.ParticleMappings;
|
||||
import com.viaversion.viaversion.api.minecraft.Particle;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
@ -30,7 +36,9 @@ import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.Protocol1_20_3
|
||||
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ServerboundPackets1_20_3;
|
||||
import com.viaversion.viaversion.rewriter.BlockRewriter;
|
||||
import com.viaversion.viaversion.rewriter.ItemRewriter;
|
||||
import com.viaversion.viaversion.util.ComponentUtil;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class BlockItemPacketRewriter1_20_3 extends ItemRewriter<ClientboundPackets1_20_2, ServerboundPackets1_20_3, Protocol1_20_3To1_20_2> {
|
||||
|
||||
@ -125,4 +133,35 @@ public final class BlockItemPacketRewriter1_20_3 extends ItemRewriter<Clientboun
|
||||
wrapper.write(Type.OPTIONAL_FLOAT, null); // Sound range
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Item handleItemToClient(@Nullable final Item item) {
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final CompoundTag tag = item.tag();
|
||||
if (tag != null) {
|
||||
updatePages(tag, "pages");
|
||||
updatePages(tag, "filtered_pages");
|
||||
}
|
||||
return super.handleItemToClient(item);
|
||||
}
|
||||
|
||||
private void updatePages(final CompoundTag tag, final String key) {
|
||||
if (!(tag.get(key) instanceof ListTag)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final ListTag pages = tag.get(key);
|
||||
for (final Tag pageTag : pages) {
|
||||
if (!(pageTag instanceof StringTag)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final StringTag stringTag = (StringTag) pageTag;
|
||||
final JsonElement updatedComponent = ComponentUtil.convertJson(stringTag.getValue(), ComponentUtil.SerializerVersion.V1_19_4, ComponentUtil.SerializerVersion.V1_20_3);
|
||||
stringTag.setValue(updatedComponent.toString());
|
||||
}
|
||||
}
|
||||
}
|
@ -77,11 +77,14 @@ public final class ComponentUtil {
|
||||
}
|
||||
|
||||
public static @Nullable JsonElement convertJson(@Nullable final JsonElement element, final SerializerVersion from, final SerializerVersion to) {
|
||||
final ATextComponent component = from.jsonSerializer.deserialize(element);
|
||||
if (element == null) {
|
||||
return null;
|
||||
return element != null ? convert(from, to, from.jsonSerializer.deserialize(element)) : null;
|
||||
}
|
||||
|
||||
public static @Nullable JsonElement convertJson(@Nullable final String json, final SerializerVersion from, final SerializerVersion to) {
|
||||
return json != null ? convert(from, to, from.jsonSerializer.deserialize(json)) : null;
|
||||
}
|
||||
|
||||
private static JsonElement convert(final SerializerVersion from, final SerializerVersion to, final ATextComponent component) {
|
||||
if (from.ordinal() >= SerializerVersion.V1_16.ordinal() && to.ordinal() < SerializerVersion.V1_16.ordinal()) {
|
||||
// Convert hover event to legacy format
|
||||
final Style style = component.getStyle();
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren