Skip to content

Commit

Permalink
Release version
Browse files Browse the repository at this point in the history
  • Loading branch information
falkreon committed Jun 18, 2023
1 parent ca2f00f commit b80dcd9
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 151 deletions.
18 changes: 3 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ plugins {
id "org.quiltmc.loom" version "1.+"
}


base.archivesName = project.archives_base_name
version = "${project.version}+${project.minecraft}"
group = project.maven_group
Expand All @@ -20,6 +19,7 @@ dependencies {
mappings "org.quiltmc:quilt-mappings:${project.minecraft}+build.${project.mappings}:intermediary-v2"

modImplementation "org.quiltmc:quilt-loader:${project.loader}"
modImplementation "org.quiltmc:qsl:${project.qsl}+${project.minecraft}"
modImplementation "org.quiltmc.quilted-fabric-api:quilted-fabric-api:${project.qfapi}"
}

Expand All @@ -33,25 +33,17 @@ processResources {

tasks.withType(JavaCompile).configureEach {
it.options.encoding = 'UTF-8'
// Minecraft 1.18 (1.18-pre2) upwards uses Java 17.
it.options.release = 17
}

java {
// Still required by IDEs such as Eclipse and Visual Studio Code
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()

// If this mod is going to be a library, then it should also generate Javadocs in order to aid with development.
// Uncomment this line to generate them.
// withJavadocJar()
//withJavadocJar()
}

// If you plan to use a different file for the license, don't forget to change the file name here!
jar {
from('LICENSE') {
rename { "${it}_${archivesBaseName}" }
Expand All @@ -65,11 +57,7 @@ publishing {
}
}

// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
// Notice: This block does NOT have the same function as the block in the top level.
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.

}
}
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ archives_base_name = SuspiciousShapes
# Dependencies
minecraft = 1.20.1
mappings = 1
loader = 0.19.0-beta.18
qfapi = 7.0.2+0.83.0-1.20.1
loader = 0.19.0
qsl = 6.0.3
qfapi = 7.0.3+0.83.1-1.20.1
1 change: 1 addition & 0 deletions src/main/java/blue/endless/glow/model/ShaderAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ public String getName() {

//Additional minecraft attributes
public static final ShaderAttribute<Integer> COLOR_INDEX = new ShaderAttribute<>("color_index");
public static final ShaderAttribute<Integer> DIFFUSE_COLOR = new ShaderAttribute<>("diffuse_color");
}
26 changes: 18 additions & 8 deletions src/main/java/blue/endless/glow/model/gltf/GLTFLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,39 @@ public static Model loadString(String json) throws IOException {

Model result = new Model();

Vector3d globalTranslate = new Vector3d(0, 0, 0);
if (gltfData.asset.generator != null && gltfData.asset.generator.startsWith("Blockbench")) {
globalTranslate = new Vector3d(0, -0.5, 0);
}

for(GLTFData.GLTFMesh mesh : gltfData.meshes) {
for (GLTFData.GLTFPrimitive primitive : mesh.primitives) {
int[] indexBuffer = gltfData.getScalarAccess(primitive.indices);
Vector3d[] positionBuffer = gltfData.getVec3Access(primitive.attributes.POSITION);
Vector2d[] uvBuffer = gltfData.getVec2Access(primitive.attributes.TEXCOORD_0);
Vector3d[] normalBuffer = gltfData.getVec3Access(primitive.attributes.NORMAL);
//TODO: look for ColorAccess

GLTFData.GLTFMaterial gl_material = gltfData.materials[primitive.material];
Material material = new Material();
material.put(ShaderAttribute.METALNESS, (double) gl_material.pbrMetallicRoughness.metallicFactor);
material.put(ShaderAttribute.ROUGHNESS, (double) gl_material.pbrMetallicRoughness.roughnessFactor);

int texIndex = gl_material.pbrMetallicRoughness.baseColorTexture.index;
GLTFData.GLTFTexture tex = gltfData.textures[texIndex];
//if (tex.name!=null) {
// material.put(ShaderAttribute.DIFFUSE_TEXTURE, tex.name);
//} else {
GLTFData.GLTFImage imageSource = gltfData.images[tex.source];
material.put(ShaderAttribute.DIFFUSE_TEXTURE, imageSource.uri);
//}
GLTFData.GLTFTexture tex = (texIndex < gltfData.textures.length) ?
gltfData.textures[texIndex] :
new GLTFData.GLTFTexture();

GLTFData.GLTFImage imageSource = (tex.source < gltfData.images.length) ?
gltfData.images[tex.source] :
new GLTFData.GLTFImage();

material.put(ShaderAttribute.DIFFUSE_TEXTURE, imageSource.uri);


for(int i=0; i<positionBuffer.length; i++) {
Vector3d pos = positionBuffer[i];
positionBuffer[i] = new Vector3d(pos.x()+0.5, pos.y(), pos.z()+0.5);
positionBuffer[i] = new Vector3d(pos.x() + globalTranslate.x(), pos.y() + globalTranslate.y(), pos.z() + globalTranslate.z());
}

result.getMeshes().add(new Mesh(material, positionBuffer, uvBuffer, normalBuffer, indexBuffer));
Expand Down
50 changes: 0 additions & 50 deletions src/main/java/gay/debuggy/shapes/TestBlock.java

This file was deleted.

134 changes: 70 additions & 64 deletions src/main/java/gay/debuggy/shapes/client/GLTFModelProvider.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package gay.debuggy.shapes.client;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
Expand All @@ -19,6 +18,7 @@
import net.fabricmc.fabric.api.client.model.ModelProviderContext;
import net.fabricmc.fabric.api.client.model.ModelProviderException;
import net.fabricmc.fabric.api.client.model.ModelResourceProvider;
import net.minecraft.client.render.model.ModelLoader;
import net.minecraft.client.render.model.UnbakedModel;
import net.minecraft.client.render.model.json.Transformation;
import net.minecraft.client.render.model.json.ModelTransformation;
Expand All @@ -35,6 +35,10 @@ public class GLTFModelProvider implements ModelResourceProvider {
"item/generated",
"builtin/generated"
);

private static final Identifier GLTF_LOADER_KEY = new Identifier(SuspiciousShapesClient.MODID, "gltf");
private static final Identifier OBJ_LOADER_KEY = new Identifier(SuspiciousShapesClient.MODID, "obj");

private final ResourceManager resourceManager;

public GLTFModelProvider(ResourceManager rm) {
Expand All @@ -45,77 +49,79 @@ public GLTFModelProvider(ResourceManager rm) {
public @Nullable UnbakedModel loadModelResource(Identifier resourceId, ModelProviderContext context) throws ModelProviderException {
return loadModelResource(resourceId, context, new HashSet<>());
}

public @Nullable UnbakedModel loadGltfResourceDirectly(Identifier resourceId, ModelProviderContext context, Set<String> alreadyTraversed) throws ModelProviderException {
Optional<Resource> maybeResource = resourceManager.getResource(new Identifier(resourceId.getNamespace(), "models/"+resourceId.getPath()));
if (maybeResource.isEmpty()) {
return context.loadModel(ModelLoader.MISSING_ID);
}

public @Nullable UnbakedModel loadModelResource(Identifier resourceId, ModelProviderContext context, Set<String> alreadyTraversed) throws ModelProviderException {
if (resourceId.getPath().endsWith(".gltf")) {
// Simple glTF model load
try (InputStream in = maybeResource.get().open()) {

Optional<Resource> maybeResource = resourceManager.getResource(new Identifier(resourceId.getNamespace(), "models/"+resourceId.getPath()));
if (maybeResource.isEmpty()) {
return null;
}
String resData = new String(in.readAllBytes(), StandardCharsets.UTF_8);
return new GlowUnbakedModel(GLTFLoader.loadString(resData), resourceId);

try (InputStream in = maybeResource.get().open()) {

String resData = new String(in.readAllBytes(), StandardCharsets.UTF_8);
return new GlowUnbakedModel(GLTFLoader.loadString(resData), resourceId);

} catch (IOException e) {
e.printStackTrace();
return null;
}
} catch (Exception e) {
e.printStackTrace();
return context.loadModel(ModelLoader.MISSING_ID);
}
}

public @Nullable UnbakedModel loadModelResource(Identifier resourceId, ModelProviderContext context, Set<String> alreadyTraversed) throws ModelProviderException {
if (resourceId.toString().endsWith(".gltf")) return null; //STOP DOING THIS, VANILLA

} else if (resourceId.getPath().endsWith(".obj")) {
// obj model - no .mtl will be loaded!

@SuppressWarnings("unused")
Optional<Resource> maybeResource = resourceManager.getResource(new Identifier(resourceId.getNamespace(), "models/"+resourceId.getPath()));

// TODO: Obj loader

return null;

Optional<String> maybeChild = Resources.loadString(resourceManager, new Identifier(resourceId.getNamespace(), "models/"+resourceId.getPath()+".json"));
if (maybeChild.isEmpty()) {
return null; //Let vanilla handle it, and then throw an error
}

BlockModelPlus modelChild = new GsonBuilder()
//These type adapters are cleaned-up copies of Mojang code since it's private
.registerTypeAdapter(Transformation.class, new TransformationDeserializer())
.registerTypeAdapter(ModelTransformation.class, new ModelTransformationDeserializer())
.create().fromJson(maybeChild.get(), BlockModelPlus.class);
if (modelChild.parent == null || FORBIDDEN_PARENTS.contains(modelChild.parent)) {
return null; //Let vanilla handle it
}

//if (modelChild.loader == null || !VALID_LOADER_KEYS.contains(modelChild.loader)) return null; // Require a valid "loader" key to prevent other mods from exploding

Identifier parentId = new Identifier(modelChild.parent);
if (alreadyTraversed.contains(parentId.toString())) {
throw new ModelProviderException("Encountered a circular reference while resolving model '"+resourceId+"' - resources loaded: "+alreadyTraversed);
}

alreadyTraversed.add(parentId.toString());

UnbakedModel parentModel = null;

if (modelChild.loader!=null && modelChild.loader.equals(GLTF_LOADER_KEY.toString())) {
parentModel = loadGltfResourceDirectly(parentId, context, alreadyTraversed);
} else if (modelChild.loader!=null && modelChild.loader.equals(OBJ_LOADER_KEY.toString())) {
parentModel = null; //TODO: Load Obj
} else {

Optional<String> maybeChild = Resources.loadString(resourceManager, new Identifier(resourceId.getNamespace(), "models/"+resourceId.getPath()+".json"));
if (maybeChild.isEmpty()) {
return null; //Let vanilla handle it, and then throw an error
}

BlockModelPlus modelChild = new GsonBuilder()
//These type adapters are cleaned-up copies of Mojang code since it's private
.registerTypeAdapter(Transformation.class, new TransformationDeserializer())
.registerTypeAdapter(ModelTransformation.class, new ModelTransformationDeserializer())
.create().fromJson(maybeChild.get(), BlockModelPlus.class);
if (modelChild.parent == null || FORBIDDEN_PARENTS.contains(modelChild.parent)) {
return null; //Let vanilla handle it
}

Identifier parentId = new Identifier(modelChild.parent);
if (alreadyTraversed.contains(parentId.toString())) {
throw new ModelProviderException("Encountered a circular reference while resolving model '"+resourceId+"' - resources loaded: "+alreadyTraversed);
}
alreadyTraversed.add(parentId.toString());

UnbakedModel parentModel = loadModelResource(parentId, context, alreadyTraversed);
//UnbakedModel parentModel = context.loadModel(new Identifier(modelChild.parent));
if (parentModel instanceof GlowUnbakedModel glowParent) {
// Operating in blockmodel-plus mode since an ancestor was ours
glowParent.provideTextures(modelChild.textures);
if (modelChild.display != null) glowParent.setModelTransformation(modelChild.display);
if (modelChild.colorIndexes != null) {
for(int i=0; i<modelChild.colorIndexes.length; i++) {
int colorIndex = modelChild.colorIndexes[i];
if (i >= glowParent.model.getMeshes().size()) break;
glowParent.model.getMeshes().get(i).getMaterial().put(ShaderAttribute.COLOR_INDEX, colorIndex);
}
parentModel = loadModelResource(parentId, context, alreadyTraversed);
}

if (parentModel == null) return null;

//UnbakedModel parentModel = context.loadModel(new Identifier(modelChild.parent));
if (parentModel instanceof GlowUnbakedModel glowParent) {
// Operating in blockmodel-plus mode since an ancestor was ours
glowParent.provideTextures(modelChild.textures);
if (modelChild.display != null) glowParent.setModelTransformation(modelChild.display);
if (modelChild.colorIndexes != null) {
for(int i=0; i<modelChild.colorIndexes.length; i++) {
int colorIndex = modelChild.colorIndexes[i];
if (i >= glowParent.model.getMeshes().size()) break;
glowParent.model.getMeshes().get(i).getMaterial().put(ShaderAttribute.COLOR_INDEX, colorIndex);
}

return glowParent;
} else {
return null;
}

return glowParent;
} else {
return null;
}

}
}
Loading

0 comments on commit b80dcd9

Please sign in to comment.