11package org .dave .compactmachines3 .network ;
22
33import io .netty .buffer .ByteBuf ;
4+ import io .netty .buffer .Unpooled ;
45import net .minecraft .nbt .NBTTagCompound ;
56import net .minecraft .util .math .BlockPos ;
67import net .minecraft .world .chunk .Chunk ;
1011import net .minecraftforge .fml .common .network .simpleimpl .MessageContext ;
1112import org .dave .compactmachines3 .CompactMachines3 ;
1213import org .dave .compactmachines3 .utility .ChunkUtils ;
14+ import org .dave .compactmachines3 .utility .Logz ;
1315import org .dave .compactmachines3 .world .tools .DimensionTools ;
1416
1517public class MessageMachineChunk implements IMessage , IMessageHandler <MessageMachineChunk , IMessage > {
@@ -34,7 +36,29 @@ public void fromBytes(ByteBuf buf) {
3436 @ Override
3537 public void toBytes (ByteBuf buf ) {
3638 buf .writeInt (coords );
37- ByteBufUtils .writeTag (buf , data );
39+
40+ ByteBuf tmpBuf = Unpooled .buffer ();
41+ ByteBufUtils .writeTag (tmpBuf , data );
42+
43+ if (tmpBuf .writerIndex () >= 2097152 - 8 ) {
44+ Logz .debug ("Chunk data to big to send. Stripping TileEntity nbt data!" );
45+ data .removeTag ("TileEntities" );
46+
47+ ByteBuf tmpBufNoTiles = Unpooled .buffer ();
48+ ByteBufUtils .writeTag (tmpBufNoTiles , data );
49+
50+ if (tmpBufNoTiles .writerIndex () >= 2097152 - 8 ) {
51+ Logz .warn ("Chunk data to big even without nbt data. Sending no chunk data!" );
52+ ByteBufUtils .writeTag (buf , new NBTTagCompound ());
53+ } else {
54+ buf .writeBytes (tmpBufNoTiles .readerIndex (0 ));
55+ }
56+ tmpBufNoTiles .release ();
57+ } else {
58+ buf .writeBytes (tmpBuf .readerIndex (0 ));
59+ }
60+
61+ tmpBuf .release ();
3862 }
3963
4064 @ Override
0 commit comments