Skip to content

Commit 8e4a97b

Browse files
committed
Commit
1 parent 8835742 commit 8e4a97b

File tree

4 files changed

+133
-0
lines changed

4 files changed

+133
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package gg.generations.rarecandy.pokeutils.codec;
2+
3+
import com.mojang.datafixers.DSL;
4+
import com.mojang.datafixers.types.templates.TypeTemplate;
5+
6+
public class ModelCOnfigTypes {
7+
public static final DSL.TypeReference MODEL_CONFIG = () -> "model_config";
8+
public static final DSL.TypeReference OBJECT_VALUE = () -> "object_value";
9+
public static final DSL.TypeReference MATERIAL_REFERENCE = () -> "material_reference";
10+
11+
public static final DSL.TypeReference COLOR = () -> "vector3f";
12+
13+
public static final DSL.TypeReference NEW_VECTOR3F = () -> "new_vector3f";
14+
15+
public static class TypeTemplates {
16+
public static TypeTemplate VECTOR3F_OBJECT = DSL.fields(
17+
"x", DSL.constType(DSL.floatType()),
18+
"y", DSL.constType(DSL.floatType()),
19+
"z", DSL.constType(DSL.floatType())
20+
);
21+
}
22+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package gg.generations.rarecandy.pokeutils.codec;
2+
3+
import com.mojang.datafixers.*;
4+
import com.mojang.datafixers.schemas.Schema;
5+
import com.mojang.datafixers.types.Type;
6+
7+
import java.util.Optional;
8+
9+
public class ModelConfigDataFixer {
10+
11+
12+
public static void register() {
13+
var builder = new DataFixerBuilder(2);
14+
builder.addFixer(new DataFix() {
15+
@Override
16+
protected TypeRewriteRule makeRule() {
17+
return new TypeRewriteRule() {
18+
@Override
19+
public <A> Optional<RewriteResult<A, ?>> rewrite(Type<A> type) {
20+
return Optional.empty();
21+
}
22+
};
23+
}
24+
});
25+
builder.addSchema(new Schema());
26+
27+
builder.addFixer(new DataFix() {
28+
@Override
29+
protected TypeRewriteRule makeRule() {
30+
return null;
31+
}
32+
});
33+
}
34+
35+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package gg.generations.rarecandy.pokeutils.codec.schema;
2+
3+
import com.mojang.datafixers.DSL;
4+
import com.mojang.datafixers.schemas.Schema;
5+
import com.mojang.datafixers.types.Type;
6+
import com.mojang.datafixers.types.templates.TypeTemplate;
7+
import gg.generations.rarecandy.pokeutils.codec.ModelCOnfigTypes;
8+
9+
import java.util.Map;
10+
import java.util.function.BinaryOperator;
11+
import java.util.function.Supplier;
12+
import java.util.stream.Stream;
13+
14+
public class V1 extends Schema {
15+
16+
public V1(int versionKey, Schema parent) {
17+
super(versionKey, parent);
18+
19+
registerType(false, ModelCOnfigTypes.OBJECT_VALUE, () -> or(
20+
DSL.constType(DSL.floatType()),
21+
DSL.constType(DSL.bool()),
22+
ModelCOnfigTypes.COLOR.in(this),
23+
DSL.taggedChoice("type", DSL.string(), Map.of(
24+
"boolean", DSL.constType(DSL.bool()),
25+
"float", DSL.constType(DSL.floatType()),
26+
"color", ModelCOnfigTypes.COLOR.in(this))
27+
))
28+
);
29+
30+
registerType(false, ModelCOnfigTypes.COLOR, () -> or(
31+
DSL.list(DSL.constType(DSL.floatType())),
32+
DSL.constType(DSL.string()),
33+
DSL.fields(
34+
"x", DSL.constType(DSL.floatType()),
35+
"y", DSL.constType(DSL.floatType()),
36+
"z", DSL.constType(DSL.floatType())
37+
)
38+
));
39+
40+
registerType(false, ModelCOnfigTypes.MATERIAL_REFERENCE, () -> DSL.allWithRemainder(
41+
DSL.or(
42+
DSL.field("parent", nullable("parent", DSL.string())),
43+
DSL.field("inherits", nullable("inherits", DSL.string()))
44+
),
45+
DSL.field("shader", nullable("shader", DSL.string())),
46+
DSL.field("effect", nullable("effect", DSL.string())),
47+
DSL.field("effect", nullable("effect", DSL.string())),
48+
DSL.field("effect", nullable("effect", DSL.string())),
49+
DSL.field("images", nullable("images", DSL.compoundList(
50+
DSL.constType(DSL.string()),
51+
DSL.constType(DSL.string())
52+
))),
53+
DSL.field("values", nullable("values", DSL.compoundList(
54+
DSL.constType(DSL.string()),
55+
ModelCOnfigTypes.OBJECT_VALUE.in(this))
56+
))));
57+
}
58+
59+
private TypeTemplate or(TypeTemplate... templates) {
60+
return Stream.of(templates).reduce(DSL::or).orElse(DSL.emptyPart());
61+
}
62+
63+
64+
public static TypeTemplate nullable(String name, TypeTemplate template) {
65+
return DSL.optionalFields(name, template);
66+
}
67+
68+
public static TypeTemplate nullable(String name, Type<?> type) {
69+
return nullable(name, DSL.constType(type));
70+
}
71+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package gg.generations.rarecandy.pokeutils.material;
2+
3+
import gg.generations.rarecandy.pokeutils.ModelConfig;
4+
import gg.generations.rarecandy.pokeutils.codec.JsonIo;
5+

0 commit comments

Comments
 (0)