Skip to content

Commit

Permalink
fix: Fixed Fabric 1.21 support
Browse files Browse the repository at this point in the history
  • Loading branch information
4drian3d committed Aug 6, 2024
1 parent b4185b6 commit 4c6a187
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github._4drian3d.signedvelocity.fabric.model;

import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteStreams;
import io.github._4drian3d.signedvelocity.fabric.SignedVelocity;
import io.netty.buffer.ByteBuf;
import net.minecraft.network.FriendlyByteBuf;
Expand All @@ -20,12 +22,12 @@ public record QueuedDataPacket(
public static final StreamCodec<ByteBuf, QueuedDataPacket> PACKET_CODEC = CustomPacketPayload.codec(QueuedDataPacket::write, QueuedDataPacket::generate);

public static QueuedDataPacket generate(final ByteBuf buf) {
final FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(buf);
final UUID playerId = friendlyByteBuf.readUUID();
final String source = friendlyByteBuf.readUtf();
final String result = friendlyByteBuf.readUtf();
final ByteArrayDataInput input = ByteStreams.newDataInput(convertFromBuf(buf));
final UUID playerId = UUID.fromString(input.readUTF());
final String source = input.readUTF();
final String result = input.readUTF();
final String modifiedMessage = result.equals("MODIFY")
? friendlyByteBuf.readUtf()
? input.readUTF()
: null;
return new QueuedDataPacket(playerId, source, result, modifiedMessage);
}
Expand All @@ -43,4 +45,10 @@ public static void write(final QueuedDataPacket packet, final ByteBuf buf) {
public @NotNull Type<? extends CustomPacketPayload> type() {
return PACKET_ID;
}

private static byte[] convertFromBuf(final ByteBuf buf) {
final byte[] bytes = new byte[buf.readableBytes()];
buf.readBytes(bytes);
return bytes;
}
}

0 comments on commit 4c6a187

Please sign in to comment.