4848import com .viaversion .viaversion .api .type .Types ;
4949import com .viaversion .viaversion .libs .gson .JsonElement ;
5050import com .viaversion .viaversion .libs .gson .JsonObject ;
51+ import com .viaversion .viaversion .libs .gson .JsonPrimitive ;
5152import com .viaversion .viaversion .protocols .v1_8to1_9 .packet .ClientboundPackets1_8 ;
5253import com .viaversion .viaversion .protocols .v1_8to1_9 .packet .ServerboundPackets1_8 ;
5354import com .viaversion .viaversion .util .ComponentUtil ;
@@ -788,6 +789,8 @@ public void register() {
788789 }
789790 });
790791
792+ // 1.7.10 custom payload constructor (String, ByteBuf) uses byteBuf.array(), so it sends the whole backing array capacity, not only the written bytes
793+ // After reading the proper packet data we discard the remaining bytes
791794 protocol .registerServerbound (ServerboundPackets1_7_2_5 .CUSTOM_PAYLOAD , new PacketHandlers () {
792795 @ Override
793796 public void register () {
@@ -798,7 +801,27 @@ public void register() {
798801 switch (channel ) {
799802 case "MC|TrSel" : {
800803 wrapper .passthrough (Types .INT );
801- wrapper .read (Types .REMAINING_BYTES ); // unused data ???
804+ wrapper .read (Types .REMAINING_BYTES ); // Discard remaining bytes
805+ break ;
806+ }
807+ case "MC|AdvCdm" : {
808+ final byte commandBlockType = wrapper .passthrough (Types .BYTE );
809+ if (commandBlockType == 0 ) { // Block
810+ wrapper .passthrough (Types .INT ); // X
811+ wrapper .passthrough (Types .INT ); // Y
812+ wrapper .passthrough (Types .INT ); // Z
813+ } else if (commandBlockType == 1 ) { // Minecart
814+ wrapper .passthrough (Types .INT ); // Entity id
815+ }
816+ wrapper .passthrough (Types .STRING ); // Command
817+ wrapper .write (Types .BOOLEAN , true ); // Track output, added in 1.8, default to true
818+ wrapper .read (Types .REMAINING_BYTES ); // Discard remaining bytes
819+ break ;
820+ }
821+ case "MC|Beacon" : {
822+ wrapper .passthrough (Types .INT ); // Primary effect
823+ wrapper .passthrough (Types .INT ); // Secondary effect
824+ wrapper .read (Types .REMAINING_BYTES ); // Discard remaining bytes
802825 break ;
803826 }
804827 case "MC|ItemName" : {
@@ -815,17 +838,28 @@ public void register() {
815838 }
816839 case "MC|BEdit" :
817840 case "MC|BSign" : {
841+ final boolean signBook = channel .equals ("MC|BSign" );
818842 final Item book = wrapper .read (RewindTypes .COMPRESSED_NBT_ITEM );
819- CompoundTag tag = book .tag ();
820- if (tag != null && tag .contains ("pages" )) {
821- ListTag <StringTag > pages = tag .getListTag ("pages" , StringTag .class );
822- for (int i = 0 ; i < pages .size (); i ++) {
823- StringTag page = pages .get (i );
824- String value = page .getValue ();
825- value = ComponentUtil .legacyToJsonString (value );
826- page .setValue (value );
843+ wrapper .read (Types .REMAINING_BYTES ); // Discard remaining bytes
844+
845+ if (book == null ) {
846+ wrapper .write (Types .ITEM1_8 , null );
847+ break ;
848+ }
849+
850+ final CompoundTag tag = book .tag ();
851+ if (signBook && tag != null && tag .contains ("pages" )) {
852+ final ListTag <StringTag > pages = tag .getListTag ("pages" , StringTag .class );
853+ if (pages != null ) {
854+ for (int i = 0 ; i < pages .size (); i ++) {
855+ final StringTag page = pages .get (i );
856+ String value = page .getValue ();
857+ value = new JsonPrimitive (value ).toString ();
858+ page .setValue (value );
859+ }
827860 }
828861 }
862+ protocol .getItemRewriter ().handleItemToServer (wrapper .user (), book );
829863 wrapper .write (Types .ITEM1_8 , book );
830864 break ;
831865 }
0 commit comments