1818package com .viaversion .viabackwards .protocol .v1_20_5to1_20_3 .rewriter ;
1919
2020import com .viaversion .nbt .tag .CompoundTag ;
21- import com .viaversion .nbt .tag .IntArrayTag ;
2221import com .viaversion .nbt .tag .ListTag ;
23- import com .viaversion .nbt .tag .StringTag ;
2422import com .viaversion .nbt .tag .Tag ;
2523import com .viaversion .viabackwards .api .rewriters .BackwardsStructuredItemRewriter ;
2624import com .viaversion .viabackwards .api .rewriters .StructuredEnchantmentRewriter ;
4543import com .viaversion .viaversion .protocols .v1_20_2to1_20_3 .packet .ServerboundPackets1_20_3 ;
4644import com .viaversion .viaversion .protocols .v1_20_2to1_20_3 .rewriter .RecipeRewriter1_20_3 ;
4745import com .viaversion .viaversion .protocols .v1_20_3to1_20_5 .Protocol1_20_3To1_20_5 ;
48- import com .viaversion .viaversion .protocols .v1_20_3to1_20_5 .data .BannerPatterns1_20_5 ;
4946import com .viaversion .viaversion .protocols .v1_20_3to1_20_5 .packet .ClientboundPacket1_20_5 ;
5047import com .viaversion .viaversion .protocols .v1_20_3to1_20_5 .packet .ClientboundPackets1_20_5 ;
5148import com .viaversion .viaversion .protocols .v1_20_3to1_20_5 .rewriter .StructuredDataConverter ;
52- import com .viaversion .viaversion .rewriter .BlockRewriter ;
5349import com .viaversion .viaversion .util .Key ;
5450import org .checkerframework .checker .nullness .qual .Nullable ;
5551
@@ -66,17 +62,17 @@ public BlockItemPacketRewriter1_20_5(final Protocol1_20_5To1_20_3 protocol) {
6662
6763 @ Override
6864 public void registerPackets () {
69- final BlockRewriter < ClientboundPacket1_20_5 > blockRewriter = BlockRewriter . for1_20_2 (protocol );
65+ final BlockPacketRewriter1_20_5 blockRewriter = new BlockPacketRewriter1_20_5 (protocol );
7066 blockRewriter .registerBlockEvent (ClientboundPackets1_20_5 .BLOCK_EVENT );
7167 blockRewriter .registerBlockUpdate (ClientboundPackets1_20_5 .BLOCK_UPDATE );
7268 blockRewriter .registerSectionBlocksUpdate1_20 (ClientboundPackets1_20_5 .SECTION_BLOCKS_UPDATE );
7369 blockRewriter .registerLevelEvent (ClientboundPackets1_20_5 .LEVEL_EVENT , 1010 , 2001 );
74- blockRewriter .registerLevelChunk1_19 (ClientboundPackets1_20_5 .LEVEL_CHUNK_WITH_LIGHT , ChunkType1_20_2 ::new , ( user , blockEntity ) -> updateBlockEntityTag ( user , blockEntity . tag ()) );
70+ blockRewriter .registerLevelChunk1_19 (ClientboundPackets1_20_5 .LEVEL_CHUNK_WITH_LIGHT , ChunkType1_20_2 ::new );
7571 protocol .registerClientbound (ClientboundPackets1_20_5 .BLOCK_ENTITY_DATA , wrapper -> {
7672 wrapper .passthrough (Types .BLOCK_POSITION1_14 ); // Position
7773 wrapper .passthrough (Types .VAR_INT ); // Block entity type
7874 final CompoundTag tag = wrapper .passthrough (Types .COMPOUND_TAG );
79- updateBlockEntityTag (wrapper . user (), tag );
75+ blockRewriter . updateBlockEntityTag (tag );
8076 });
8177
8278 registerCooldown (ClientboundPackets1_20_5 .COOLDOWN );
@@ -220,76 +216,6 @@ public void registerPackets() {
220216 });
221217 }
222218
223- private void updateBlockEntityTag (final UserConnection connection , final CompoundTag tag ) {
224- if (tag == null ) {
225- return ;
226- }
227-
228- final Tag profileTag = tag .remove ("profile" );
229- if (profileTag instanceof StringTag ) {
230- tag .put ("SkullOwner" , profileTag );
231- } else if (profileTag instanceof CompoundTag ) {
232- updateProfileTag (tag , (CompoundTag ) profileTag );
233- }
234-
235- final ListTag <CompoundTag > patternsTag = tag .getListTag ("patterns" , CompoundTag .class );
236- if (patternsTag != null ) {
237- for (final CompoundTag patternTag : patternsTag ) {
238- final String pattern = patternTag .getString ("pattern" , "" );
239- final String color = patternTag .getString ("color" );
240- final String compactIdentifier = BannerPatterns1_20_5 .fullIdToCompact (Key .stripMinecraftNamespace (pattern ));
241- if (compactIdentifier == null || color == null ) {
242- continue ;
243- }
244-
245- patternTag .remove ("pattern" );
246- patternTag .remove ("color" );
247- patternTag .putString ("Pattern" , compactIdentifier );
248- patternTag .putInt ("Color" , colorId (color ));
249- }
250-
251- tag .remove ("patterns" );
252- tag .put ("Patterns" , patternsTag );
253- }
254- }
255-
256- private void updateProfileTag (final CompoundTag tag , final CompoundTag profileTag ) {
257- final CompoundTag skullOwnerTag = new CompoundTag ();
258- tag .put ("SkullOwner" , skullOwnerTag );
259-
260- final String name = profileTag .getString ("name" );
261- if (name != null ) {
262- skullOwnerTag .putString ("Name" , name );
263- }
264-
265- final IntArrayTag idTag = profileTag .getIntArrayTag ("id" );
266- if (idTag != null ) {
267- skullOwnerTag .put ("Id" , idTag );
268- }
269-
270- final ListTag <CompoundTag > propertiesListTag = profileTag .getListTag ("properties" , CompoundTag .class );
271- if (propertiesListTag == null ) {
272- return ;
273- }
274-
275- final CompoundTag propertiesTag = new CompoundTag ();
276- for (final CompoundTag propertyTag : propertiesListTag ) {
277- final String property = propertyTag .getString ("name" , "" );
278- final String value = propertyTag .getString ("value" , "" );
279- final String signature = propertyTag .getString ("signature" );
280-
281- final ListTag <CompoundTag > list = new ListTag <>(CompoundTag .class );
282- final CompoundTag updatedPropertyTag = new CompoundTag ();
283- updatedPropertyTag .putString ("Value" , value );
284- if (signature != null ) {
285- updatedPropertyTag .putString ("Signature" , signature );
286- }
287- list .add (updatedPropertyTag );
288- propertiesTag .put (property , list );
289- }
290- skullOwnerTag .put ("Properties" , propertiesTag );
291- }
292-
293219 private void cleanInput (@ Nullable final Item item ) {
294220 // Try to maybe hopefully get the tag matching to what the client will try to input by removing default data
295221 if (item == null || item .tag () == null ) {
@@ -326,27 +252,6 @@ private void removeEmptyList(final CompoundTag tag, final String key) {
326252 }
327253 }
328254
329- private static int colorId (final String color ) {
330- return switch (color ) {
331- case "orange" -> 1 ;
332- case "magenta" -> 2 ;
333- case "light_blue" -> 3 ;
334- case "yellow" -> 4 ;
335- case "lime" -> 5 ;
336- case "pink" -> 6 ;
337- case "gray" -> 7 ;
338- case "light_gray" -> 8 ;
339- case "cyan" -> 9 ;
340- case "purple" -> 10 ;
341- case "blue" -> 11 ;
342- case "brown" -> 12 ;
343- case "green" -> 13 ;
344- case "red" -> 14 ;
345- case "black" -> 15 ;
346- default -> 0 ;
347- };
348- }
349-
350255 @ Override
351256 public @ Nullable Item handleItemToClient (final UserConnection connection , Item item ) {
352257 if (item .isEmpty ()) {
0 commit comments