3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-12-27 00:22:53 +01:00

Put books through component conversion in 1.20.3->1.20.2

Dieser Commit ist enthalten in:
Nassim Jahnke 2024-01-27 21:04:32 +01:00
Ursprung b40f77fed3
Commit 1f3555df4a
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F

Datei anzeigen

@ -21,15 +21,23 @@ import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viabackwards.api.rewriters.ItemRewriter;
import com.viaversion.viabackwards.protocol.protocol1_20_2to1_20_3.Protocol1_20_2To1_20_3;
import com.viaversion.viaversion.api.data.ParticleMappings;
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;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2;
import com.viaversion.viaversion.api.type.types.version.Types1_20_3;
import com.viaversion.viaversion.libs.gson.JsonElement;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ServerboundPackets1_20_2;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPackets1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.rewriter.RecipeRewriter1_20_3;
import com.viaversion.viaversion.rewriter.BlockRewriter;
import com.viaversion.viaversion.util.ComponentUtil;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class BlockItemPacketRewriter1_20_3 extends ItemRewriter<ClientboundPackets1_20_3, ServerboundPackets1_20_2, Protocol1_20_2To1_20_3> {
@ -155,4 +163,33 @@ public final class BlockItemPacketRewriter1_20_3 extends ItemRewriter<Clientboun
wrapper.read(Type.OPTIONAL_FLOAT); // 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_20_3, ComponentUtil.SerializerVersion.V1_19_4);
stringTag.setValue(updatedComponent.toString());
}
}
}