mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2025-01-10 14:26:10 +01:00
f14aca4517
- Fix matrix mixins being applied on dedicated server - Expand PartialModel functionality: add location getter and model setter - Remove Loader.getResourceType since selective reloading is deprecated - Organize imports and mixin order - Other formatting - Update Gradle and Forge
61 lines
1.5 KiB
Java
61 lines
1.5 KiB
Java
package com.jozufozu.flywheel.util;
|
|
|
|
import java.util.function.Supplier;
|
|
|
|
import com.mojang.blaze3d.vertex.PoseStack;
|
|
import com.mojang.math.Matrix4f;
|
|
import com.mojang.math.Vector3f;
|
|
|
|
import net.minecraft.core.Direction;
|
|
|
|
public class RenderUtil {
|
|
|
|
private static final Matrix4f IDENTITY = new Matrix4f();
|
|
static {
|
|
IDENTITY.setIdentity();
|
|
}
|
|
|
|
public static Matrix4f getIdentity() {
|
|
return IDENTITY;
|
|
}
|
|
|
|
public static Matrix4f copyIdentity() {
|
|
return IDENTITY.copy();
|
|
}
|
|
|
|
public static int nextPowerOf2(int a) {
|
|
int h = Integer.highestOneBit(a);
|
|
return (h == a) ? h : (h << 1);
|
|
}
|
|
|
|
public static boolean isPowerOf2(int n) {
|
|
int b = n & (n - 1);
|
|
return b == 0 && n != 0;
|
|
}
|
|
|
|
public static double lengthSqr(double x, double y, double z) {
|
|
return x * x + y * y + z * z;
|
|
}
|
|
|
|
public static double length(double x, double y, double z) {
|
|
return Math.sqrt(lengthSqr(x, y, z));
|
|
}
|
|
|
|
public static Supplier<PoseStack> rotateToFace(Direction facing) {
|
|
return () -> {
|
|
PoseStack stack = new PoseStack();
|
|
// MatrixStacker.of(stack)
|
|
// .centre()
|
|
// .rotateY(AngleHelper.horizontalAngle(facing))
|
|
// .rotateX(AngleHelper.verticalAngle(facing))
|
|
// .unCentre();
|
|
stack.last()
|
|
.pose()
|
|
.setTranslation(0.5f, 0.5f, 0.5f);
|
|
stack.mulPose(Vector3f.YP.rotationDegrees(AngleHelper.horizontalAngle(facing)));
|
|
stack.mulPose(Vector3f.XP.rotationDegrees(AngleHelper.verticalAngle(facing)));
|
|
stack.translate(-0.5f, -0.5f, -0.5f);
|
|
return stack;
|
|
};
|
|
}
|
|
}
|