mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-25 03:25:11 +01:00
Handle WRITTEN_BOOK_CONTENT component in rewriters as well (#4175)
Closes https://github.com/ViaVersion/ViaVersion/issues/4144
This commit is contained in:
parent
6ad9a71907
commit
1a9cda0579
@ -39,8 +39,8 @@ import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
|
||||
import com.viaversion.viaversion.util.ComponentUtil;
|
||||
import com.viaversion.viaversion.util.SerializerVersion;
|
||||
import com.viaversion.viaversion.util.TagUtil;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import java.util.BitSet;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
* Handles json and tag components, containing methods to override certain parts of the handling.
|
||||
@ -360,6 +360,8 @@ public class ComponentRewriter<C extends ClientboundPacketType> implements com.v
|
||||
handleShowItem(connection, contentsTag, componentsTag);
|
||||
if (componentsTag != null) {
|
||||
handleContainerContents(connection, componentsTag);
|
||||
handleWrittenBookContents(connection, componentsTag);
|
||||
|
||||
handleItemArrayContents(connection, componentsTag, "bundle_contents");
|
||||
handleItemArrayContents(connection, componentsTag, "charged_projectiles");
|
||||
}
|
||||
@ -386,6 +388,40 @@ public class ComponentRewriter<C extends ClientboundPacketType> implements com.v
|
||||
}
|
||||
}
|
||||
|
||||
protected void handleWrittenBookContents(final UserConnection connection, final CompoundTag tag) {
|
||||
final CompoundTag book = TagUtil.getNamespacedCompoundTag(tag, "minecraft:written_book_content");
|
||||
if (book == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final ListTag<CompoundTag> pagesTag = book.getListTag("pages", CompoundTag.class);
|
||||
if (pagesTag == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (final CompoundTag compoundTag : pagesTag) {
|
||||
final StringTag raw = compoundTag.getStringTag("raw");
|
||||
processJsonString(connection, raw);
|
||||
|
||||
final StringTag filtered = compoundTag.getStringTag("filtered");
|
||||
processJsonString(connection, filtered);
|
||||
}
|
||||
}
|
||||
|
||||
private void processJsonString(final UserConnection connection, final StringTag tag) {
|
||||
if (tag == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final var input = inputSerializerVersion();
|
||||
final var output = outputSerializerVersion();
|
||||
|
||||
final Tag asTag = input.toTag(input.toComponent(tag.getValue()));
|
||||
processTag(connection, asTag);
|
||||
|
||||
tag.setValue(output.toString(output.toComponent(asTag)));
|
||||
}
|
||||
|
||||
protected void handleItemArrayContents(final UserConnection connection, final CompoundTag tag, final String key) {
|
||||
final ListTag<CompoundTag> container = TagUtil.getNamespacedCompoundTagList(tag, key);
|
||||
if (container == null) {
|
||||
|
@ -28,6 +28,8 @@ import com.viaversion.viaversion.api.minecraft.data.StructuredData;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.FilterableComponent;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.WrittenBook;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
|
||||
@ -138,6 +140,16 @@ public class StructuredItemRewriter<C extends ClientboundPacketType, S extends S
|
||||
protocol.getComponentRewriter().processTag(connection, tag);
|
||||
}
|
||||
}
|
||||
|
||||
final WrittenBook book = container.get(StructuredDataKey.WRITTEN_BOOK_CONTENT);
|
||||
if (book != null) {
|
||||
for (final FilterableComponent page : book.pages()) {
|
||||
protocol.getComponentRewriter().processTag(connection, page.raw());
|
||||
if (page.isFiltered()) {
|
||||
protocol.getComponentRewriter().processTag(connection, page.filtered());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Look for item types
|
||||
|
Loading…
Reference in New Issue
Block a user