Fix compatibility when joml.fastmath is enabled, fixes physics mod causing everything to detonate

Version bump
This commit is contained in:
mcrcortex
2025-07-07 22:20:46 +10:00
parent 7551ca3484
commit 492e2a707a
2 changed files with 17 additions and 4 deletions

View File

@@ -14,6 +14,6 @@ loader_version=0.16.14
fabric_version=0.128.1+1.21.7 fabric_version=0.128.1+1.21.7
# Mod Properties # Mod Properties
mod_version = 0.2.2-alpha mod_version = 0.2.3-alpha
maven_group = me.cortex maven_group = me.cortex
archives_base_name = voxy archives_base_name = voxy

View File

@@ -18,6 +18,8 @@ import net.minecraft.world.biome.ColorResolver;
import net.minecraft.world.chunk.light.LightingProvider; import net.minecraft.world.chunk.light.LightingProvider;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.joml.Matrix4f; import org.joml.Matrix4f;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import org.lwjgl.opengl.GL14; import org.lwjgl.opengl.GL14;
import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.opengl.GL11.*;
@@ -335,11 +337,22 @@ public class ModelTextureBakery {
private static void addView(int i, float pitch, float yaw, float rotation, int flip) { private static void addView(int i, float pitch, float yaw, float rotation, int flip) {
var stack = new MatrixStack(); var stack = new MatrixStack();
stack.translate(0.5f,0.5f,0.5f); stack.translate(0.5f,0.5f,0.5f);
stack.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(rotation)); stack.multiply(makeQuatFromAxisExact(new Vector3f(0,0,1), rotation));
stack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(pitch)); stack.multiply(makeQuatFromAxisExact(new Vector3f(1,0,0), pitch));
stack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(yaw)); stack.multiply(makeQuatFromAxisExact(new Vector3f(0,1,0), yaw));
stack.multiplyPositionMatrix(new Matrix4f().scale(1-2*(flip&1), 1-(flip&2), 1-((flip>>1)&2))); stack.multiplyPositionMatrix(new Matrix4f().scale(1-2*(flip&1), 1-(flip&2), 1-((flip>>1)&2)));
stack.translate(-0.5f,-0.5f,-0.5f); stack.translate(-0.5f,-0.5f,-0.5f);
VIEWS[i] = new Matrix4f(stack.peek().getPositionMatrix()); VIEWS[i] = new Matrix4f(stack.peek().getPositionMatrix());
} }
private static Quaternionf makeQuatFromAxisExact(Vector3f vec, float angle) {
angle = (float) Math.toRadians(angle);
float hangle = angle / 2.0f;
float sinAngle = (float) Math.sin(hangle);
float invVLength = (float) (1/Math.sqrt(vec.lengthSquared()));
return new Quaternionf(vec.x * invVLength * sinAngle,
vec.y * invVLength * sinAngle,
vec.z * invVLength * sinAngle,
Math.cos(hangle));
}
} }