22
33import codechicken .lib .math .MathHelper ;
44import codechicken .lib .util .Copyable ;
5+ import com .mojang .serialization .Codec ;
6+ import com .mojang .serialization .codecs .PrimitiveCodec ;
7+ import com .mojang .serialization .codecs .RecordCodecBuilder ;
8+ import io .netty .buffer .ByteBuf ;
59import net .minecraft .core .BlockPos ;
610import net .minecraft .core .Vec3i ;
711import net .minecraft .nbt .CompoundTag ;
12+ import net .minecraft .network .codec .ByteBufCodecs ;
13+ import net .minecraft .network .codec .StreamCodec ;
814import net .minecraft .world .entity .Entity ;
915import net .minecraft .world .level .block .entity .BlockEntity ;
1016import net .minecraft .world .phys .Vec3 ;
@@ -30,6 +36,20 @@ public class Vector3 implements Copyable<Vector3> {
3036 public static final Vector3 Z_NEG = new Vector3 ( 0 , 0 ,-1 );
3137 //@formatter:on
3238
39+ public static final Codec <Vector3 > CODEC = RecordCodecBuilder .create (b -> b .group (
40+ PrimitiveCodec .DOUBLE .fieldOf ("x" ).forGetter (e -> e .x ),
41+ PrimitiveCodec .DOUBLE .fieldOf ("y" ).forGetter (e -> e .y ),
42+ PrimitiveCodec .DOUBLE .fieldOf ("z" ).forGetter (e -> e .z )
43+ ).apply (b , Vector3 ::new )
44+ );
45+
46+ public static final StreamCodec <ByteBuf , Vector3 > STREAM_CODEC = StreamCodec .composite (
47+ ByteBufCodecs .DOUBLE , e -> e .x ,
48+ ByteBufCodecs .DOUBLE , e -> e .y ,
49+ ByteBufCodecs .DOUBLE , e -> e .z ,
50+ Vector3 ::new
51+ );
52+
3353 public double x ;
3454 public double y ;
3555 public double z ;
0 commit comments