Skip to content

Commit e56264e

Browse files
committed
Rebuild loader flow almost entirely to deal with model-loader v1
1 parent 506a980 commit e56264e

File tree

10 files changed

+432
-167
lines changed

10 files changed

+432
-167
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ dependencies {
1919
mappings "org.quiltmc:quilt-mappings:${project.minecraft}+build.${project.mappings}:intermediary-v2"
2020

2121
modImplementation "org.quiltmc:quilt-loader:${project.loader}"
22-
modImplementation "org.quiltmc:qsl:${project.qsl}+${project.minecraft}"
22+
//modImplementation "org.quiltmc:qsl:${project.qsl}+${project.minecraft}"
2323
modImplementation "org.quiltmc.quilted-fabric-api:quilted-fabric-api:${project.qfapi}"
2424
}
2525

gradle.properties

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@ org.gradle.jvmargs = -Xmx1G
33
org.gradle.parallel = true
44

55
# Mod Properties
6-
version = 1.0.2
6+
version = 1.0.3
77
maven_group = gay.debuggy
88
archives_base_name = SuspiciousShapes
99

1010
# Dependencies
11+
#minecraft = 1.20.1
12+
#mappings = 1
13+
#loader = 0.19.0
14+
#qsl = 6.0.3
15+
#qfapi = 7.0.3+0.83.1-1.20.1
16+
1117
minecraft = 1.20.1
12-
mappings = 1
13-
loader = 0.19.0
14-
qsl = 6.0.3
15-
qfapi = 7.0.3+0.83.1-1.20.1
18+
mappings = 23
19+
loader = 0.20.0-beta.11
20+
qsl = 6.1.1
21+
qfapi = 7.1.0+0.86.1-1.20.1

src/main/java/blue/endless/glow/model/Mesh.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,20 @@ public Stream<Vertex> stream() {
182182

183183
public static class Vertex extends AbstractShaderAttributeHolder {
184184
}
185+
186+
public Mesh copy() {
187+
Material resultMaterial = new Material();
188+
resultMaterial.putAll(material);
189+
Mesh result = new Mesh(resultMaterial, vertexBuffer.clone(), uvBuffer.clone(), normalBuffer.clone(), indices.clone());
190+
for(int i=0; i<result.vertexData.length; i++) {
191+
Vertex v = vertexData[i];
192+
if (v != null) {
193+
Vertex w = new Vertex();
194+
w.putAll(v);
195+
result.vertexData[i] = w;
196+
}
197+
}
198+
199+
return result;
200+
}
185201
}

src/main/java/blue/endless/glow/model/Model.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import java.util.List;
1212

1313
public class Model implements Iterable<Mesh> {
14-
protected ShaderAttributeHolder environment = new Material();
14+
protected Material environment = new Material();
1515
protected List<Mesh> meshes = new ArrayList<>();
1616

1717
public ShaderAttributeHolder getEnvironment() {
@@ -34,4 +34,14 @@ public List<Mesh> getMeshes() {
3434
public Iterator<Mesh> iterator() {
3535
return meshes.iterator();
3636
}
37+
38+
public Model copy() {
39+
Model result = new Model();
40+
result.environment.putAll(environment);
41+
for(Mesh m : meshes) {
42+
result.meshes.add(m.copy());
43+
}
44+
45+
return result;
46+
}
3747
}

src/main/java/gay/debuggy/shapes/client/GLTFModelProvider.java

Lines changed: 0 additions & 136 deletions
This file was deleted.
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package gay.debuggy.shapes.client;
2+
3+
import java.util.List;
4+
import java.util.ArrayList;
5+
import java.util.Map;
6+
7+
import com.google.common.collect.Lists;
8+
9+
import java.util.HashMap;
10+
import java.util.HashSet;
11+
12+
import blue.endless.glow.model.Model;
13+
import gay.debuggy.shapes.client.schema.BlockModelPlus;
14+
15+
import net.minecraft.util.Identifier;
16+
17+
public class ProcessedModelData {
18+
public List<ErrorNode> errors = new ArrayList<>();
19+
public List<Node> detached = new ArrayList<>();
20+
public List<Node> roots = new ArrayList<>();
21+
22+
public Map<Identifier, Node> byId = new HashMap<>();
23+
24+
public static class Node {
25+
Identifier location;
26+
Identifier id;
27+
GlowUnbakedModel model;
28+
String error = null;
29+
Node parent;
30+
List<Node> children = new ArrayList<>();
31+
32+
public Node(Identifier location) {
33+
this.location = location;
34+
String namespace = location.getNamespace();
35+
String path = location.getPath();
36+
if (path.startsWith("models/")) path = path.substring("models/".length());
37+
if (path.endsWith(".json")) {
38+
path = path.substring(0, path.length() - ".json".length());
39+
}// else if (path.endsWith(".gltf")) {
40+
// path = path.substring(0, path.length() - ".gltf".length());
41+
//}
42+
this.id = new Identifier(namespace, path);
43+
}
44+
45+
public int treeSize() {
46+
return 1 + children.stream().mapToInt(Node::treeSize).sum();
47+
}
48+
49+
public boolean hasPathToRoot(List<Node> roots) {
50+
HashSet<Identifier> traversed = new HashSet<>();
51+
Node cur = this;
52+
while(cur.parent != null) {
53+
cur = cur.parent;
54+
if (traversed.contains(cur.location)) throw new IllegalStateException("Circular reference detected.");
55+
traversed.add(cur.location);
56+
}
57+
return roots.contains(cur);
58+
}
59+
60+
public Node getRoot() {
61+
HashSet<Identifier> traversed = new HashSet<>();
62+
Node cur = this;
63+
while(cur.parent != null) {
64+
cur = cur.parent;
65+
if (traversed.contains(cur.location)) throw new IllegalStateException("Circular reference detected.");
66+
traversed.add(cur.location);
67+
}
68+
return cur;
69+
}
70+
71+
public List<Node> getPathFromRoot() {
72+
ArrayList<Node> traversed = new ArrayList<>();
73+
Node cur = this;
74+
traversed.add(cur);
75+
while (cur.parent != null) {
76+
cur = cur.parent;
77+
if (traversed.contains(cur)) throw new IllegalStateException("Circular reference detected.");
78+
traversed.add(cur);
79+
}
80+
81+
return Lists.reverse(traversed);
82+
}
83+
}
84+
85+
public static class JsonNode extends Node {
86+
BlockModelPlus blockModelPlus;
87+
88+
public JsonNode(Identifier location, BlockModelPlus model) {
89+
super(location);
90+
this.blockModelPlus = model;
91+
}
92+
}
93+
94+
public static class GltfNode extends Node {
95+
Model model;
96+
97+
public GltfNode(Identifier location, Model model) {
98+
super(location);
99+
this.model = model;
100+
}
101+
}
102+
103+
public static record ErrorNode(Identifier id, String message, Throwable t) {}
104+
}

src/main/java/gay/debuggy/shapes/client/Resources.java

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/main/java/gay/debuggy/shapes/client/SuspiciousShapesClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
import org.slf4j.Logger;
66
import org.slf4j.LoggerFactory;
77

8-
import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry;
8+
import net.fabricmc.fabric.api.client.model.loading.v1.PreparableModelLoadingPlugin;
99

1010
public class SuspiciousShapesClient implements ClientModInitializer {
1111
public static final String MODID = "suspicious_shapes";
1212
public static final Logger LOGGER = LoggerFactory.getLogger("Suspicious Shapes");
1313

1414
@Override
1515
public void onInitializeClient(ModContainer mod) {
16-
ModelLoadingRegistry.INSTANCE.registerResourceProvider(rm->new GLTFModelProvider(rm));
16+
PreparableModelLoadingPlugin.register(SuspiciousShapesModelLoadingPlugin::loadData, new SuspiciousShapesModelLoadingPlugin());
1717
}
1818

1919
}

0 commit comments

Comments
 (0)