Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/java/detrav/net/DetravNetwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ protected void encode(ChannelHandlerContext ctx, DetravPacket msg, List<Object>
ByteBuf buf = Unpooled.buffer();
buf.writeByte(msg.getPacketID());
msg.encode(new ByteBufOutputStream(buf));
// FMLProxyPacket sends the whole backing array of its buffer, so give it one holding only the written bytes
out.add(
new FMLProxyPacket(
buf,
buf.copy(),
ctx.channel()
.attr(NetworkRegistry.FML_CHANNEL)
.get()));
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/gregtech/api/net/GTPacketLMACraftingFX.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public void encode(ByteBuf buffer) {
try {
ByteBuf stackBuffer = Unpooled.buffer();
itemStack.writeToPacket(stackBuffer);
byte[] data = stackBuffer.array();
// only the written bytes: the backing array also holds the buffer's unused capacity
byte[] data = new byte[stackBuffer.readableBytes()];
stackBuffer.readBytes(data);
buffer.writeInt(data.length);
buffer.writeBytes(data);
} catch (IOException e) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/gregtech/common/GTNetwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ protected void encode(ChannelHandlerContext aContext, GTPacket aPacket, List<Obj
final ByteBuf tBuf = Unpooled.buffer()
.writeByte(aPacket.getPacketID());
aPacket.encode(tBuf);
// FMLProxyPacket sends the whole backing array of its buffer, so give it one holding only the written bytes
aOutput.add(
new FMLProxyPacket(
tBuf,
tBuf.copy(),
aContext.channel()
.attr(NetworkRegistry.FML_CHANNEL)
.get()));
Expand Down
Loading