From 4eec8f628f22b0d74ab10ee4d33c3684e31b9ed5 Mon Sep 17 00:00:00 2001 From: maximumpower55 Date: Sun, 12 Jan 2025 15:45:47 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A6=80=20custom=20vec3=20stream=20codec?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../portalcubed/content/portal/PortalData.java | 3 +-- .../framework/util/PortalCubedStreamCodecs.java | 16 +--------------- .../serverbound/ClientTeleportedPacket.java | 3 +-- 3 files changed, 3 insertions(+), 19 deletions(-) diff --git a/src/main/java/io/github/fusionflux/portalcubed/content/portal/PortalData.java b/src/main/java/io/github/fusionflux/portalcubed/content/portal/PortalData.java index 63578076..7ce1e32a 100644 --- a/src/main/java/io/github/fusionflux/portalcubed/content/portal/PortalData.java +++ b/src/main/java/io/github/fusionflux/portalcubed/content/portal/PortalData.java @@ -5,7 +5,6 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; -import io.github.fusionflux.portalcubed.framework.util.PortalCubedStreamCodecs; import io.netty.buffer.ByteBuf; import net.minecraft.network.codec.ByteBufCodecs; import net.minecraft.network.codec.StreamCodec; @@ -23,7 +22,7 @@ public record PortalData(Vec3 origin, Quaternionf rotation, PortalSettings setti ).apply(instance, PortalData::new)); public static final StreamCodec STREAM_CODEC = StreamCodec.composite( - PortalCubedStreamCodecs.VEC3, PortalData::origin, + Vec3.STREAM_CODEC, PortalData::origin, ByteBufCodecs.QUATERNIONF, PortalData::rotation, PortalSettings.STREAM_CODEC, PortalData::settings, PortalData::new diff --git a/src/main/java/io/github/fusionflux/portalcubed/framework/util/PortalCubedStreamCodecs.java b/src/main/java/io/github/fusionflux/portalcubed/framework/util/PortalCubedStreamCodecs.java index 137f11b9..763e222d 100644 --- a/src/main/java/io/github/fusionflux/portalcubed/framework/util/PortalCubedStreamCodecs.java +++ b/src/main/java/io/github/fusionflux/portalcubed/framework/util/PortalCubedStreamCodecs.java @@ -23,20 +23,6 @@ public interface PortalCubedStreamCodecs { StreamCodec UNIT = StreamCodec.unit(Unit.INSTANCE); - StreamCodec VEC3 = new StreamCodec<>() { - @Override - public @NotNull Vec3 decode(ByteBuf buffer) { - return new Vec3(buffer.readDouble(), buffer.readDouble(), buffer.readDouble()); - } - - @Override - public void encode(ByteBuf buffer, Vec3 value) { - buffer.writeDouble(value.x); - buffer.writeDouble(value.y); - buffer.writeDouble(value.z); - } - }; - StreamCodec HAND = ByteBufCodecs.BOOL.map( value -> value ? InteractionHand.MAIN_HAND : InteractionHand.OFF_HAND, hand -> hand == InteractionHand.MAIN_HAND @@ -44,7 +30,7 @@ public void encode(ByteBuf buffer, Vec3 value) { StreamCodec BLOCK_HIT_RESULT = StreamCodec.composite( ByteBufCodecs.BOOL, i -> i.getType() == HitResult.Type.MISS, - VEC3, HitResult::getLocation, + Vec3.STREAM_CODEC, HitResult::getLocation, Direction.STREAM_CODEC, BlockHitResult::getDirection, BlockPos.STREAM_CODEC, BlockHitResult::getBlockPos, ByteBufCodecs.BOOL, BlockHitResult::isInside, diff --git a/src/main/java/io/github/fusionflux/portalcubed/packet/serverbound/ClientTeleportedPacket.java b/src/main/java/io/github/fusionflux/portalcubed/packet/serverbound/ClientTeleportedPacket.java index 57333ed7..6c99ba9a 100644 --- a/src/main/java/io/github/fusionflux/portalcubed/packet/serverbound/ClientTeleportedPacket.java +++ b/src/main/java/io/github/fusionflux/portalcubed/packet/serverbound/ClientTeleportedPacket.java @@ -8,7 +8,6 @@ import io.github.fusionflux.portalcubed.content.portal.PortalTeleportHandler; import io.github.fusionflux.portalcubed.content.portal.PortalTeleportInfo; import io.github.fusionflux.portalcubed.content.portal.manager.PortalManager; -import io.github.fusionflux.portalcubed.framework.util.PortalCubedStreamCodecs; import io.github.fusionflux.portalcubed.packet.PortalCubedPackets; import io.github.fusionflux.portalcubed.packet.ServerboundPacket; import io.netty.buffer.ByteBuf; @@ -22,7 +21,7 @@ public record ClientTeleportedPacket(PortalTeleportInfo info, Vec3 pos, float xRot, float yRot) implements ServerboundPacket { public static final StreamCodec CODEC = StreamCodec.composite( PortalTeleportInfo.STREAM_CODEC, ClientTeleportedPacket::info, - PortalCubedStreamCodecs.VEC3, ClientTeleportedPacket::pos, + Vec3.STREAM_CODEC, ClientTeleportedPacket::pos, ByteBufCodecs.FLOAT, ClientTeleportedPacket::xRot, ByteBufCodecs.FLOAT, ClientTeleportedPacket::yRot, ClientTeleportedPacket::new