Skip to content

Commit

Permalink
Try fix readerIndex > writerIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
zbx1425 committed Aug 11, 2024
1 parent 6c098d3 commit 9259fa8
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Type<? extends CustomPacketPayload> type() {
public final StreamCodec<ByteBuf, Payload> STREAM_CODEC = new StreamCodec<>() {
@Override
public void encode(ByteBuf dest, Payload src) {
src.buffer.resetReaderIndex();
src.buffer.readerIndex(0);
dest.writeInt(src.buffer.readableBytes());
dest.writeBytes(src.buffer);
}
Expand All @@ -44,7 +44,7 @@ public void encode(ByteBuf dest, Payload src) {
public Payload decode(ByteBuf src) {
final int length = src.readInt();
FriendlyByteBuf result = new FriendlyByteBuf(src.readBytes(length));
result.resetReaderIndex();
result.readerIndex(0);
return new Payload(result);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static void registerTickEvent(Consumer<MinecraftServer> consumer) {
}

public static void sendPacketToPlayer(ServerPlayer player, ResourceLocation id, FriendlyByteBuf packet) {
packet.resetReaderIndex();
packet.readerIndex(0);
NetworkManager.sendToPlayer(player, id, packet);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static void registerTickEvent(Consumer<Minecraft> consumer) {
}

public static void sendPacketToServer(ResourceLocation id, FriendlyByteBuf packet) {
packet.resetReaderIndex();
packet.readerIndex(0);
#if MC_VERSION >= "12100"
MainForge.PACKET_REGISTRY.sendC2S(id, packet);
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Type<? extends CustomPacketPayload> type() {
public final StreamCodec<ByteBuf, Payload> STREAM_CODEC = new StreamCodec<>() {
@Override
public void encode(ByteBuf dest, Payload src) {
src.buffer.resetReaderIndex();
src.buffer.readerIndex(0);
dest.writeInt(src.buffer.readableBytes());
dest.writeBytes(src.buffer);
}
Expand All @@ -44,7 +44,7 @@ public void encode(ByteBuf dest, Payload src) {
public Payload decode(ByteBuf src) {
final int length = src.readInt();
FriendlyByteBuf result = new FriendlyByteBuf(src.readBytes(length));
result.resetReaderIndex();
result.readerIndex(0);
return new Payload(result);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static void registerTickEvent(Consumer<MinecraftServer> consumer) {
}

public static void sendPacketToPlayer(ServerPlayer player, ResourceLocation id, FriendlyByteBuf packet) {
packet.resetReaderIndex();
packet.readerIndex(0);
#if MC_VERSION >= "12100"
MainForge.PACKET_REGISTRY.sendS2C(player, id, packet);
#else
Expand Down

0 comments on commit 9259fa8

Please sign in to comment.