Skip to content

Commit 70da35b

Browse files
committed
Just catch the error if the nbt data is to big
Guessing the nbt size from the bytebuffer size was not feasible. Fixes #359
1 parent 591549d commit 70da35b

File tree

1 file changed

+7
-25
lines changed

1 file changed

+7
-25
lines changed

src/main/java/org/dave/compactmachines3/network/MessageMachineChunk.java

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,36 +30,18 @@ public MessageMachineChunk(int coords) {
3030
@Override
3131
public void fromBytes(ByteBuf buf) {
3232
coords = buf.readInt();
33-
data = ByteBufUtils.readTag(buf);
33+
try {
34+
data = ByteBufUtils.readTag(buf);
35+
} catch (Exception e) {
36+
Logz.debug("Unable to read nbt data from buffer: %s", e.getMessage());
37+
data = new NBTTagCompound();
38+
}
3439
}
3540

3641
@Override
3742
public void toBytes(ByteBuf buf) {
3843
buf.writeInt(coords);
39-
40-
ByteBuf tmpBuf = Unpooled.buffer();
41-
ByteBufUtils.writeTag(tmpBuf, data);
42-
43-
if(tmpBuf.writerIndex() >= 1900000 - 8) {
44-
Logz.debug("Chunk data to big to send. Stripping TileEntity nbt data!");
45-
46-
data.removeTag("TileEntities");
47-
48-
ByteBuf tmpBufNoTiles = Unpooled.buffer();
49-
ByteBufUtils.writeTag(tmpBufNoTiles, data);
50-
51-
if(tmpBufNoTiles.writerIndex() >= 1900000 - 8) {
52-
Logz.warn("Chunk data to big even without nbt data. Sending no chunk data!");
53-
ByteBufUtils.writeTag(buf, new NBTTagCompound());
54-
} else {
55-
buf.writeBytes(tmpBufNoTiles.readerIndex(0));
56-
}
57-
tmpBufNoTiles.release();
58-
} else {
59-
buf.writeBytes(tmpBuf.readerIndex(0));
60-
}
61-
62-
tmpBuf.release();
44+
ByteBufUtils.writeTag(buf, data);
6345
}
6446

6547
@Override

0 commit comments

Comments
 (0)