Skip to content

Commit 999ec52

Browse files
committed
Yee haw
1 parent 39faeae commit 999ec52

File tree

133 files changed

+2197
-387
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+2197
-387
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ neoForge {
5757
}
5858

5959
mods {
60-
kmath {
60+
klib {
6161
sourceSet sourceSets.main
6262
}
6363
}

interfaces.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
{
22
"net/minecraft/util/RandomSource": [
3-
"dev/latvian/mods/kmath/core/KMathRandomSource"
3+
"dev/latvian/mods/klib/core/KLibRandomSource"
44
],
55
"com/mojang/blaze3d/vertex/VertexConsumer": [
6-
"dev/latvian/mods/kmath/core/KMathVertexConsumer"
6+
"dev/latvian/mods/klib/core/KLibVertexConsumer"
77
],
88
"com/mojang/blaze3d/vertex/PoseStack$Pose": [
9-
"dev/latvian/mods/kmath/core/KMathPoseStackPose"
9+
"dev/latvian/mods/klib/core/KLibPoseStackPose"
10+
],
11+
"net/minecraft/network/codec/StreamCodec": [
12+
"dev/latvian/mods/klib/core/KLibStreamCodec<B, V>"
1013
]
1114
}

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ plugins {
1212
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0'
1313
}
1414

15-
rootProject.name = 'kmath'
15+
rootProject.name = 'klib'

src/main/java/dev/latvian/mods/kmath/KMathMod.java renamed to src/main/java/dev/latvian/mods/klib/KLibMod.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package dev.latvian.mods.kmath;
1+
package dev.latvian.mods.klib;
22

33
import net.minecraft.resources.ResourceLocation;
44
import net.neoforged.api.distmarker.Dist;
@@ -7,19 +7,19 @@
77
import net.neoforged.fml.common.Mod;
88
import net.neoforged.fml.event.lifecycle.FMLLoadCompleteEvent;
99

10-
@Mod(KMathMod.ID)
11-
@EventBusSubscriber(modid = KMathMod.ID, value = Dist.CLIENT, bus = EventBusSubscriber.Bus.MOD)
12-
public class KMathMod {
13-
public static final String ID = "kmath";
14-
public static final String NAME = "KMath";
10+
@Mod(KLibMod.ID)
11+
@EventBusSubscriber(modid = KLibMod.ID, value = Dist.CLIENT, bus = EventBusSubscriber.Bus.MOD)
12+
public class KLibMod {
13+
public static final String ID = "klib";
14+
public static final String NAME = "KLib";
1515

1616
public static ResourceLocation id(String path) {
1717
return ResourceLocation.fromNamespaceAndPath(ID, path);
1818
}
1919

2020
@SubscribeEvent
2121
public static void setup(FMLLoadCompleteEvent event) {
22-
event.enqueueWork(KMathMod::test);
22+
event.enqueueWork(KLibMod::test);
2323
}
2424

2525
private static void test() {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package dev.latvian.mods.klib.codec;
2+
3+
import com.mojang.datafixers.util.Either;
4+
import com.mojang.serialization.Codec;
5+
import it.unimi.dsi.fastutil.ints.IntArrayList;
6+
import it.unimi.dsi.fastutil.ints.IntList;
7+
import it.unimi.dsi.fastutil.longs.LongCollection;
8+
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
9+
import it.unimi.dsi.fastutil.longs.LongSet;
10+
import it.unimi.dsi.fastutil.shorts.ShortArrayList;
11+
import it.unimi.dsi.fastutil.shorts.ShortList;
12+
13+
import java.util.function.Function;
14+
15+
public interface CollectionCodecs {
16+
Codec<IntList> INT_LIST = Codec.INT.listOf().xmap(IntArrayList::new, Function.identity());
17+
Codec<IntList> INT_LIST_OR_SELF = Codec.either(Codec.INT, INT_LIST).xmap(either -> either.map(IntArrayList::of, Function.identity()), list -> list.size() == 1 ? Either.left(list.getFirst()) : Either.right(list));
18+
Codec<ShortList> SHORT_LIST = Codec.SHORT.listOf().xmap(ShortArrayList::new, Function.identity());
19+
Codec<LongSet> LONG_SET = Codec.LONG_STREAM.xmap(LongOpenHashSet::toSet, LongCollection::longStream);
20+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package dev.latvian.mods.klib.codec;
2+
3+
import io.netty.buffer.ByteBuf;
4+
import it.unimi.dsi.fastutil.ints.IntArrayList;
5+
import it.unimi.dsi.fastutil.ints.IntList;
6+
import it.unimi.dsi.fastutil.ints.IntLists;
7+
import it.unimi.dsi.fastutil.longs.LongArrayList;
8+
import it.unimi.dsi.fastutil.longs.LongList;
9+
import it.unimi.dsi.fastutil.longs.LongLists;
10+
import it.unimi.dsi.fastutil.shorts.ShortArrayList;
11+
import it.unimi.dsi.fastutil.shorts.ShortList;
12+
import it.unimi.dsi.fastutil.shorts.ShortLists;
13+
import net.minecraft.network.VarInt;
14+
import net.minecraft.network.codec.StreamCodec;
15+
16+
public interface CollectionStreamCodecs {
17+
StreamCodec<ByteBuf, IntList> VAR_INT_LIST = new StreamCodec<>() {
18+
@Override
19+
public IntList decode(ByteBuf buf) {
20+
int size = VarInt.read(buf);
21+
22+
if (size == 0) {
23+
return IntLists.emptyList();
24+
} else if (size == 1) {
25+
return IntLists.singleton(VarInt.read(buf));
26+
} else {
27+
var list = new IntArrayList(size);
28+
29+
for (int i = 0; i < size; i++) {
30+
list.add(VarInt.read(buf));
31+
}
32+
33+
return list;
34+
}
35+
}
36+
37+
@Override
38+
public void encode(ByteBuf buf, IntList value) {
39+
VarInt.write(buf, value.size());
40+
41+
for (int i = 0; i < value.size(); i++) {
42+
VarInt.write(buf, value.getInt(i));
43+
}
44+
}
45+
};
46+
47+
StreamCodec<ByteBuf, LongList> LONG_LIST = new StreamCodec<>() {
48+
@Override
49+
public LongList decode(ByteBuf buf) {
50+
int size = VarInt.read(buf);
51+
52+
if (size == 0) {
53+
return LongLists.emptyList();
54+
} else if (size == 1) {
55+
return LongLists.singleton(buf.readLong());
56+
} else {
57+
var list = new LongArrayList(size);
58+
59+
for (int i = 0; i < size; i++) {
60+
list.add(buf.readLong());
61+
}
62+
63+
return list;
64+
}
65+
}
66+
67+
@Override
68+
public void encode(ByteBuf buf, LongList value) {
69+
VarInt.write(buf, value.size());
70+
71+
for (int i = 0; i < value.size(); i++) {
72+
buf.writeLong(value.getLong(i));
73+
}
74+
}
75+
};
76+
77+
StreamCodec<ByteBuf, ShortList> SHORT_LIST = new StreamCodec<>() {
78+
@Override
79+
public ShortList decode(ByteBuf buf) {
80+
int size = VarInt.read(buf);
81+
82+
if (size == 0) {
83+
return ShortLists.emptyList();
84+
} else if (size == 1) {
85+
return ShortLists.singleton((short) VarInt.read(buf));
86+
} else {
87+
var list = new ShortArrayList(size);
88+
89+
for (int i = 0; i < size; i++) {
90+
list.add((short) VarInt.read(buf));
91+
}
92+
93+
return list;
94+
}
95+
}
96+
97+
@Override
98+
public void encode(ByteBuf buf, ShortList value) {
99+
VarInt.write(buf, value.size());
100+
101+
for (int i = 0; i < value.size(); i++) {
102+
VarInt.write(buf, value.getShort(i));
103+
}
104+
}
105+
};
106+
}

src/main/java/dev/latvian/mods/kmath/codec/JOMLCodecs.java renamed to src/main/java/dev/latvian/mods/klib/codec/JOMLCodecs.java

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,41 @@
1-
package dev.latvian.mods.kmath.codec;
1+
package dev.latvian.mods.klib.codec;
22

33
import com.mojang.datafixers.util.Either;
44
import com.mojang.serialization.Codec;
55
import org.joml.Matrix2d;
6+
import org.joml.Matrix2dc;
67
import org.joml.Matrix2f;
8+
import org.joml.Matrix2fc;
79
import org.joml.Matrix3d;
10+
import org.joml.Matrix3dc;
811
import org.joml.Matrix3f;
12+
import org.joml.Matrix3fc;
913
import org.joml.Matrix4d;
14+
import org.joml.Matrix4dc;
1015
import org.joml.Matrix4f;
16+
import org.joml.Matrix4fc;
1117
import org.joml.Quaterniond;
18+
import org.joml.Quaterniondc;
1219
import org.joml.Quaternionf;
20+
import org.joml.Quaternionfc;
1321
import org.joml.Vector2d;
22+
import org.joml.Vector2dc;
1423
import org.joml.Vector2f;
24+
import org.joml.Vector2fc;
1525
import org.joml.Vector2i;
26+
import org.joml.Vector2ic;
1627
import org.joml.Vector3d;
28+
import org.joml.Vector3dc;
1729
import org.joml.Vector3f;
30+
import org.joml.Vector3fc;
1831
import org.joml.Vector3i;
32+
import org.joml.Vector3ic;
1933
import org.joml.Vector4d;
34+
import org.joml.Vector4dc;
2035
import org.joml.Vector4f;
36+
import org.joml.Vector4fc;
2137
import org.joml.Vector4i;
38+
import org.joml.Vector4ic;
2239

2340
import java.util.List;
2441
import java.util.function.Function;
@@ -112,4 +129,31 @@ public interface JOMLCodecs {
112129
Codec<Vector2i> IVEC_2S = Codec.either(Codec.INT, IVEC_2).xmap(e -> e.map(v -> new Vector2i(v, v), Function.identity()), v -> v.x == v.y ? Either.left(v.x) : Either.right(v));
113130
Codec<Vector3i> IVEC_3S = Codec.either(Codec.INT, IVEC_3).xmap(e -> e.map(v -> new Vector3i(v, v, v), Function.identity()), v -> v.x == v.y && v.x == v.z ? Either.left(v.x) : Either.right(v));
114131
Codec<Vector4i> IVEC_4S = Codec.either(Codec.INT, IVEC_4).xmap(e -> e.map(v -> new Vector4i(v, v, v, 1), Function.identity()), v -> v.x == v.y && v.x == v.z && v.w == 1 ? Either.left(v.x) : Either.right(v));
132+
133+
Codec<Vector2fc> VEC_2C = VEC_2.xmap(Function.identity(), v -> v instanceof Vector2f c ? c : new Vector2f(v));
134+
Codec<Vector3fc> VEC_3C = VEC_3.xmap(Function.identity(), v -> v instanceof Vector3f c ? c : new Vector3f(v));
135+
Codec<Vector4fc> VEC_4C = VEC_4.xmap(Function.identity(), v -> v instanceof Vector4f c ? c : new Vector4f(v));
136+
Codec<Vector2fc> VEC_2SC = VEC_2S.xmap(Function.identity(), v -> v instanceof Vector2f c ? c : new Vector2f(v));
137+
Codec<Vector3fc> VEC_3SC = VEC_3S.xmap(Function.identity(), v -> v instanceof Vector3f c ? c : new Vector3f(v));
138+
Codec<Vector4fc> VEC_4SC = VEC_4S.xmap(Function.identity(), v -> v instanceof Vector4f c ? c : new Vector4f(v));
139+
Codec<Quaternionfc> QUATERNIONC = QUATERNION.xmap(Function.identity(), v -> v instanceof Quaternionf c ? c : new Quaternionf(v));
140+
Codec<Matrix2fc> MAT_2C = MAT_2.xmap(Function.identity(), v -> v instanceof Matrix2f c ? c : new Matrix2f(v));
141+
Codec<Matrix3fc> MAT_3C = MAT_3.xmap(Function.identity(), v -> v instanceof Matrix3f c ? c : new Matrix3f(v));
142+
Codec<Matrix4fc> MAT_4C = MAT_4.xmap(Function.identity(), v -> v instanceof Matrix4f c ? c : new Matrix4f(v));
143+
Codec<Vector2dc> DVEC_2C = DVEC_2.xmap(Function.identity(), v -> v instanceof Vector2d c ? c : new Vector2d(v));
144+
Codec<Vector3dc> DVEC_3C = DVEC_3.xmap(Function.identity(), v -> v instanceof Vector3d c ? c : new Vector3d(v));
145+
Codec<Vector4dc> DVEC_4C = DVEC_4.xmap(Function.identity(), v -> v instanceof Vector4d c ? c : new Vector4d(v));
146+
Codec<Vector2dc> DVEC_2SC = DVEC_2S.xmap(Function.identity(), v -> v instanceof Vector2d c ? c : new Vector2d(v));
147+
Codec<Vector3dc> DVEC_3SC = DVEC_3S.xmap(Function.identity(), v -> v instanceof Vector3d c ? c : new Vector3d(v));
148+
Codec<Vector4dc> DVEC_4SC = DVEC_4S.xmap(Function.identity(), v -> v instanceof Vector4d c ? c : new Vector4d(v));
149+
Codec<Quaterniondc> DQUATERNIONC = DQUATERNION.xmap(Function.identity(), v -> v instanceof Quaterniond c ? c : new Quaterniond(v));
150+
Codec<Matrix2dc> DMAT_2C = DMAT_2.xmap(Function.identity(), v -> v instanceof Matrix2d c ? c : new Matrix2d(v));
151+
Codec<Matrix3dc> DMAT_3C = DMAT_3.xmap(Function.identity(), v -> v instanceof Matrix3d c ? c : new Matrix3d(v));
152+
Codec<Matrix4dc> DMAT_4C = DMAT_4.xmap(Function.identity(), v -> v instanceof Matrix4d c ? c : new Matrix4d(v));
153+
Codec<Vector2ic> IVEC_2C = IVEC_2.xmap(Function.identity(), v -> v instanceof Vector2i c ? c : new Vector2i(v));
154+
Codec<Vector3ic> IVEC_3C = IVEC_3.xmap(Function.identity(), v -> v instanceof Vector3i c ? c : new Vector3i(v));
155+
Codec<Vector4ic> IVEC_4C = IVEC_4.xmap(Function.identity(), v -> v instanceof Vector4i c ? c : new Vector4i(v));
156+
Codec<Vector2ic> IVEC_2SC = IVEC_2S.xmap(Function.identity(), v -> v instanceof Vector2i c ? c : new Vector2i(v));
157+
Codec<Vector3ic> IVEC_3SC = IVEC_3S.xmap(Function.identity(), v -> v instanceof Vector3i c ? c : new Vector3i(v));
158+
Codec<Vector4ic> IVEC_4SC = IVEC_4S.xmap(Function.identity(), v -> v instanceof Vector4i c ? c : new Vector4i(v));
115159
}

src/main/java/dev/latvian/mods/kmath/codec/JOMLStreamCodecs.java renamed to src/main/java/dev/latvian/mods/klib/codec/JOMLStreamCodecs.java

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
package dev.latvian.mods.kmath.codec;
1+
package dev.latvian.mods.klib.codec;
22

33
import io.netty.buffer.ByteBuf;
4+
import net.minecraft.network.VarInt;
45
import net.minecraft.network.codec.StreamCodec;
56
import org.joml.Matrix2d;
67
import org.joml.Matrix2dc;
@@ -22,14 +23,20 @@
2223
import org.joml.Vector2dc;
2324
import org.joml.Vector2f;
2425
import org.joml.Vector2fc;
26+
import org.joml.Vector2i;
27+
import org.joml.Vector2ic;
2528
import org.joml.Vector3d;
2629
import org.joml.Vector3dc;
2730
import org.joml.Vector3f;
2831
import org.joml.Vector3fc;
32+
import org.joml.Vector3i;
33+
import org.joml.Vector3ic;
2934
import org.joml.Vector4d;
3035
import org.joml.Vector4dc;
3136
import org.joml.Vector4f;
3237
import org.joml.Vector4fc;
38+
import org.joml.Vector4i;
39+
import org.joml.Vector4ic;
3340

3441
import java.util.function.Function;
3542

@@ -460,6 +467,89 @@ public void encode(ByteBuf buf, Matrix4d v) {
460467
(float) m.m30(), (float) m.m31(), (float) m.m32(), (float) m.m33()
461468
));
462469

470+
StreamCodec<ByteBuf, Vector2i> IVEC_2 = new StreamCodec<>() {
471+
@Override
472+
public Vector2i decode(ByteBuf buf) {
473+
return new Vector2i(buf.readInt(), buf.readInt());
474+
}
475+
476+
@Override
477+
public void encode(ByteBuf buf, Vector2i v) {
478+
buf.writeInt(v.x());
479+
buf.writeInt(v.y());
480+
}
481+
};
482+
483+
StreamCodec<ByteBuf, Vector3i> IVEC_3 = new StreamCodec<>() {
484+
@Override
485+
public Vector3i decode(ByteBuf buf) {
486+
return new Vector3i(buf.readInt(), buf.readInt(), buf.readInt());
487+
}
488+
489+
@Override
490+
public void encode(ByteBuf buf, Vector3i v) {
491+
buf.writeInt(v.x());
492+
buf.writeInt(v.y());
493+
buf.writeInt(v.z());
494+
}
495+
};
496+
497+
StreamCodec<ByteBuf, Vector4i> IVEC_4 = new StreamCodec<>() {
498+
@Override
499+
public Vector4i decode(ByteBuf buf) {
500+
return new Vector4i(buf.readInt(), buf.readInt(), buf.readInt(), buf.readInt());
501+
}
502+
503+
@Override
504+
public void encode(ByteBuf buf, Vector4i v) {
505+
buf.writeInt(v.x());
506+
buf.writeInt(v.y());
507+
buf.writeInt(v.z());
508+
}
509+
};
510+
511+
StreamCodec<ByteBuf, Vector2i> VIVEC_2 = new StreamCodec<>() {
512+
@Override
513+
public Vector2i decode(ByteBuf buf) {
514+
return new Vector2i(VarInt.read(buf), VarInt.read(buf));
515+
}
516+
517+
@Override
518+
public void encode(ByteBuf buf, Vector2i v) {
519+
VarInt.write(buf, v.x());
520+
VarInt.write(buf, v.y());
521+
}
522+
};
523+
524+
StreamCodec<ByteBuf, Vector3i> VIVEC_3 = new StreamCodec<>() {
525+
@Override
526+
public Vector3i decode(ByteBuf buf) {
527+
return new Vector3i(VarInt.read(buf), VarInt.read(buf), VarInt.read(buf));
528+
}
529+
530+
@Override
531+
public void encode(ByteBuf buf, Vector3i v) {
532+
VarInt.write(buf, v.x());
533+
VarInt.write(buf, v.y());
534+
VarInt.write(buf, v.z());
535+
}
536+
};
537+
538+
StreamCodec<ByteBuf, Vector4i> VIVEC_4 = new StreamCodec<>() {
539+
@Override
540+
public Vector4i decode(ByteBuf buf) {
541+
return new Vector4i(VarInt.read(buf), VarInt.read(buf), VarInt.read(buf), VarInt.read(buf));
542+
}
543+
544+
@Override
545+
public void encode(ByteBuf buf, Vector4i v) {
546+
VarInt.write(buf, v.x());
547+
VarInt.write(buf, v.y());
548+
VarInt.write(buf, v.z());
549+
VarInt.write(buf, v.w());
550+
}
551+
};
552+
463553
StreamCodec<ByteBuf, Vector2fc> VEC_2C = VEC_2.map(Function.identity(), v -> v instanceof Vector2f c ? c : new Vector2f(v));
464554
StreamCodec<ByteBuf, Vector3fc> VEC_3C = VEC_3.map(Function.identity(), v -> v instanceof Vector3f c ? c : new Vector3f(v));
465555
StreamCodec<ByteBuf, Vector4fc> VEC_4C = VEC_4.map(Function.identity(), v -> v instanceof Vector4f c ? c : new Vector4f(v));
@@ -477,4 +567,10 @@ public void encode(ByteBuf buf, Matrix4d v) {
477567
StreamCodec<ByteBuf, Matrix2dc> FDMAT_2C = FDMAT_2.map(Function.identity(), v -> v instanceof Matrix2d c ? c : new Matrix2d(v));
478568
StreamCodec<ByteBuf, Matrix3dc> FDMAT_3C = FDMAT_3.map(Function.identity(), v -> v instanceof Matrix3d c ? c : new Matrix3d(v));
479569
StreamCodec<ByteBuf, Matrix4dc> FDMAT_4C = FDMAT_4.map(Function.identity(), v -> v instanceof Matrix4d c ? c : new Matrix4d(v));
570+
StreamCodec<ByteBuf, Vector2ic> IVEC_2C = IVEC_2.map(Function.identity(), v -> v instanceof Vector2i c ? c : new Vector2i(v));
571+
StreamCodec<ByteBuf, Vector3ic> IVEC_3C = IVEC_3.map(Function.identity(), v -> v instanceof Vector3i c ? c : new Vector3i(v));
572+
StreamCodec<ByteBuf, Vector4ic> IVEC_4C = IVEC_4.map(Function.identity(), v -> v instanceof Vector4i c ? c : new Vector4i(v));
573+
StreamCodec<ByteBuf, Vector2ic> VIVEC_2C = VIVEC_2.map(Function.identity(), v -> v instanceof Vector2i c ? c : new Vector2i(v));
574+
StreamCodec<ByteBuf, Vector3ic> VIVEC_3C = VIVEC_3.map(Function.identity(), v -> v instanceof Vector3i c ? c : new Vector3i(v));
575+
StreamCodec<ByteBuf, Vector4ic> VIVEC_4C = VIVEC_4.map(Function.identity(), v -> v instanceof Vector4i c ? c : new Vector4i(v));
480576
}

0 commit comments

Comments
 (0)