Skip to content

Commit a839cb0

Browse files
authored
Handle text components in signs in 1.21.7→1.21.5 (#1173)
1 parent b243e5e commit a839cb0

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_6to1_21_5/rewriter/BlockItemPacketRewriter1_21_6.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.viaversion.viabackwards.api.rewriters.BackwardsStructuredItemRewriter;
2323
import com.viaversion.viabackwards.protocol.v1_21_6to1_21_5.Protocol1_21_6To1_21_5;
2424
import com.viaversion.viaversion.api.connection.UserConnection;
25+
import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity;
2526
import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
2627
import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
2728
import com.viaversion.viaversion.api.minecraft.item.Item;
@@ -40,6 +41,8 @@
4041
import static com.viaversion.viaversion.protocols.v1_21_5to1_21_6.rewriter.BlockItemPacketRewriter1_21_6.upgradeItemData;
4142

4243
public final class BlockItemPacketRewriter1_21_6 extends BackwardsStructuredItemRewriter<ClientboundPacket1_21_6, ServerboundPacket1_21_5, Protocol1_21_6To1_21_5> {
44+
private static final int SIGN_BOCK_ENTITY_ID = 7;
45+
private static final int HANGING_SIGN_BOCK_ENTITY_ID = 8;
4346

4447
public BlockItemPacketRewriter1_21_6(final Protocol1_21_6To1_21_5 protocol) {
4548
super(protocol);
@@ -52,8 +55,8 @@ public void registerPackets() {
5255
blockRewriter.registerBlockUpdate(ClientboundPackets1_21_6.BLOCK_UPDATE);
5356
blockRewriter.registerSectionBlocksUpdate1_20(ClientboundPackets1_21_6.SECTION_BLOCKS_UPDATE);
5457
blockRewriter.registerLevelEvent1_21(ClientboundPackets1_21_6.LEVEL_EVENT, 2001);
55-
blockRewriter.registerLevelChunk1_19(ClientboundPackets1_21_6.LEVEL_CHUNK_WITH_LIGHT, ChunkType1_21_5::new);
56-
blockRewriter.registerBlockEntityData(ClientboundPackets1_21_6.BLOCK_ENTITY_DATA);
58+
blockRewriter.registerLevelChunk1_19(ClientboundPackets1_21_6.LEVEL_CHUNK_WITH_LIGHT, ChunkType1_21_5::new, this::handleBlockEntity);
59+
blockRewriter.registerBlockEntityData(ClientboundPackets1_21_6.BLOCK_ENTITY_DATA, this::handleBlockEntity);
5760

5861
protocol.registerClientbound(ClientboundPackets1_21_6.SET_CURSOR_ITEM, this::passthroughClientboundItem);
5962
registerSetPlayerInventory(ClientboundPackets1_21_6.SET_PLAYER_INVENTORY);
@@ -149,4 +152,29 @@ protected void restoreBackupData(final Item item, final StructuredDataContainer
149152
));
150153
}
151154
}
155+
156+
private void handleBlockEntity(final UserConnection connection, final BlockEntity blockEntity) {
157+
final CompoundTag tag = blockEntity.tag();
158+
if (tag == null) {
159+
return;
160+
}
161+
162+
if (blockEntity.typeId() == SIGN_BOCK_ENTITY_ID || blockEntity.typeId() == HANGING_SIGN_BOCK_ENTITY_ID) {
163+
updateSignMessages(connection, tag.getCompoundTag("front_text"));
164+
updateSignMessages(connection, tag.getCompoundTag("back_text"));
165+
}
166+
}
167+
168+
private void updateSignMessages(final UserConnection connection, final CompoundTag tag) {
169+
if (tag == null) {
170+
return;
171+
}
172+
173+
final ListTag<?> messages = tag.getListTag("messages");
174+
protocol.getComponentRewriter().processTag(connection, messages);
175+
final ListTag<?> filteredMessages = tag.getListTag("filtered_messages");
176+
if (filteredMessages != null) {
177+
protocol.getComponentRewriter().processTag(connection, filteredMessages);
178+
}
179+
}
152180
}

0 commit comments

Comments
 (0)