diff --git a/src/main/java/xiamomc/morph/client/entities/MorphLocalPlayer.java b/src/main/java/xiamomc/morph/client/entities/MorphLocalPlayer.java index baf5a11..d0477ed 100644 --- a/src/main/java/xiamomc/morph/client/entities/MorphLocalPlayer.java +++ b/src/main/java/xiamomc/morph/client/entities/MorphLocalPlayer.java @@ -315,7 +315,7 @@ protected void initDataTracker(DataTracker.Builder builder) { super.initDataTracker(builder); - builder.add(PLAYER_MODEL_PARTS, (byte)127); + //builder.add(PLAYER_MODEL_PARTS, (byte)127); this.dataTracker.set(PLAYER_MODEL_PARTS, (byte)127); } diff --git a/src/main/java/xiamomc/morph/client/mixin/CodecDispatcherMixin.java b/src/main/java/xiamomc/morph/client/mixin/CodecDispatcherMixin.java index 36c757e..1256db2 100644 --- a/src/main/java/xiamomc/morph/client/mixin/CodecDispatcherMixin.java +++ b/src/main/java/xiamomc/morph/client/mixin/CodecDispatcherMixin.java @@ -36,12 +36,6 @@ public class CodecDispatcherMixin exception.printStackTrace(); System.err.println("- x - x - x - x - x - x - x - x - x - x - x -"); - System.err.println("All available types at this moment:"); - - for (PacketCodecDispatcher.PacketType type : packetTypes) - System.err.println(" - " + type.id()); - - System.err.println("- x - x - x - x - x - x - x - x - x - x - x -"); System.err.println(); } } diff --git a/src/main/java/xiamomc/morph/client/network/payload/MorphCommandPayload.java b/src/main/java/xiamomc/morph/client/network/payload/MorphCommandPayload.java index e985e6a..9f2d1ee 100644 --- a/src/main/java/xiamomc/morph/client/network/payload/MorphCommandPayload.java +++ b/src/main/java/xiamomc/morph/client/network/payload/MorphCommandPayload.java @@ -8,9 +8,10 @@ public record MorphCommandPayload(String content) implements CustomPayload { - public static final PacketCodec CODEC = PacketCodecs.STRING - .xmap(MorphCommandPayload::new, MorphCommandPayload::content) - .cast(); + public static final PacketCodec CODEC = PacketCodec.of( + (value, buf) -> buf.writeBytes(MorphInitChannelPayload.writeString(value.content())), + buf -> new MorphCommandPayload(MorphInitChannelPayload.readString(buf)) + ); public static final CustomPayload.Id id = new Id<>(ServerHandler.commandChannelIdentifier); diff --git a/src/main/java/xiamomc/morph/client/network/payload/MorphInitChannelPayload.java b/src/main/java/xiamomc/morph/client/network/payload/MorphInitChannelPayload.java index d056fe9..18d9d27 100644 --- a/src/main/java/xiamomc/morph/client/network/payload/MorphInitChannelPayload.java +++ b/src/main/java/xiamomc/morph/client/network/payload/MorphInitChannelPayload.java @@ -1,16 +1,45 @@ package xiamomc.morph.client.network.payload; -import net.minecraft.network.RegistryByteBuf; +import com.google.common.io.ByteStreams; +import net.minecraft.network.PacketByteBuf; import net.minecraft.network.codec.PacketCodec; -import net.minecraft.network.codec.PacketCodecs; import net.minecraft.network.packet.CustomPayload; import xiamomc.morph.client.ServerHandler; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; + public record MorphInitChannelPayload(String message) implements CustomPayload { - public static final PacketCodec CODEC = PacketCodecs.string(32768) - .xmap(MorphInitChannelPayload::new, MorphInitChannelPayload::message) - .cast(); + public static final PacketCodec CODEC = PacketCodec.of( + (value, buf) -> buf.writeString(value.message()), + buf -> new MorphInitChannelPayload(readString(buf)) + ); + + public static byte[] writeString(String string) + { + var out = ByteStreams.newDataOutput(); + out.writeUTF(string); + + return out.toByteArray(); + } + + public static String readString(PacketByteBuf buf) + { + //System.out.println("Buf is '" + buf.toString(StandardCharsets.UTF_8) + "' :: with hashCode" + buf.hashCode()); + + var directBuffer = buf.readBytes(buf.readableBytes()); + var dst = new byte[directBuffer.capacity()]; + directBuffer.getBytes(0, dst); + + //System.out.printf("DST is '%s'%n", Arrays.toString(dst)); + + var input = ByteStreams.newDataInput(dst); + var asByteBuf = input.readUTF(); + + buf.clear(); + return asByteBuf; + } public static final CustomPayload.Id id = new Id<>(ServerHandler.initializeChannelIdentifier); diff --git a/src/main/java/xiamomc/morph/client/network/payload/MorphVersionChannelPayload.java b/src/main/java/xiamomc/morph/client/network/payload/MorphVersionChannelPayload.java index 321b7c8..140ea7e 100644 --- a/src/main/java/xiamomc/morph/client/network/payload/MorphVersionChannelPayload.java +++ b/src/main/java/xiamomc/morph/client/network/payload/MorphVersionChannelPayload.java @@ -6,11 +6,32 @@ import net.minecraft.network.packet.CustomPayload; import xiamomc.morph.client.ServerHandler; +import java.nio.charset.StandardCharsets; + public record MorphVersionChannelPayload(int protocolVersion) implements CustomPayload { - public static final PacketCodec CODEC = PacketCodecs.INTEGER - .xmap(MorphVersionChannelPayload::new, MorphVersionChannelPayload::protocolVersion) - .cast(); + public static final PacketCodec CODEC = PacketCodec.of( + (value, buf) -> buf.writeInt(value.protocolVersion()), + buf -> new MorphVersionChannelPayload(parseInt(buf)) + ); + + public static int parseInt(PacketByteBuf buf) + { + //System.out.println("Buf is '" + buf.toString(StandardCharsets.UTF_8) + "' :: with hashCode" + buf.hashCode()); + int read = -1; + try + { + read = buf.readInt(); + } + catch (Throwable t) + { + System.err.println("[FeatherMorph] Error parsing protocol version from server: " + t.getMessage()); + t.printStackTrace(); + } + + buf.clear(); + return read; + } public static final Id id = new Id<>(ServerHandler.versionChannelIdentifier);