Testing for curved cloak
This commit is contained in:
@@ -23,9 +23,11 @@ import net.minecraft.item.equipment.EquipmentAsset;
|
|||||||
import net.minecraft.registry.RegistryKey;
|
import net.minecraft.registry.RegistryKey;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.math.RotationAxis;
|
import net.minecraft.util.math.RotationAxis;
|
||||||
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
|
||||||
public class CloakFeatureRenderer extends FeatureRenderer<PlayerEntityRenderState, PlayerEntityModel> {
|
public class CloakFeatureRenderer extends FeatureRenderer<PlayerEntityRenderState, PlayerEntityModel> {
|
||||||
private final EquipmentModelLoader equipmentModelLoader;
|
private final EquipmentModelLoader equipmentModelLoader;
|
||||||
|
private static final int PARTS = 16;
|
||||||
|
|
||||||
public CloakFeatureRenderer(FeatureRendererContext<PlayerEntityRenderState, PlayerEntityModel> context,
|
public CloakFeatureRenderer(FeatureRendererContext<PlayerEntityRenderState, PlayerEntityModel> context,
|
||||||
EquipmentModelLoader equipmentModelLoader) {
|
EquipmentModelLoader equipmentModelLoader) {
|
||||||
@@ -44,17 +46,34 @@ public class CloakFeatureRenderer extends FeatureRenderer<PlayerEntityRenderStat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render quad with correct winding order (counter-clockwise for front face)
|
|
||||||
private void renderCapeQuad(VertexConsumer vertexConsumer, MatrixStack matrixStack,
|
private void renderCapeQuad(VertexConsumer vertexConsumer, MatrixStack matrixStack,
|
||||||
float x1, float y1, float z1, float x2, float y2, float z2,
|
float x1, float y1, float z1, float x2, float y2, float z2,
|
||||||
float u1, float v1, float u2, float v2, int light, int overlay,
|
float u1, float v1, float u2, float v2, int light, int overlay,
|
||||||
float normalX, float normalY, float normalZ, boolean flipWinding) {
|
float normalX, float normalY, float normalZ, boolean flipWinding) {
|
||||||
|
// Create the four corner vectors from the provided x, y, z coordinates
|
||||||
|
Vec3d bottomLeft = new Vec3d(x1, y2, z1);
|
||||||
|
Vec3d bottomRight = new Vec3d(x2, y2, z2);
|
||||||
|
Vec3d topRight = new Vec3d(x2, y1, z2);
|
||||||
|
Vec3d topLeft = new Vec3d(x1, y1, z1);
|
||||||
|
|
||||||
|
// Call the more detailed render method with the newly created vectors
|
||||||
|
renderCapeQuad(vertexConsumer, matrixStack,
|
||||||
|
bottomLeft, bottomRight, topRight, topLeft,
|
||||||
|
u1, v1, u2, v2, light, overlay,
|
||||||
|
normalX, normalY, normalZ, flipWinding);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderCapeQuad(VertexConsumer vertexConsumer, MatrixStack matrixStack,
|
||||||
|
Vec3d bottomLeft, Vec3d bottomRight, Vec3d topRight, Vec3d topLeft,
|
||||||
|
float u1, float v1, float u2, float v2, int light, int overlay,
|
||||||
|
float normalX, float normalY, float normalZ, boolean flipWinding) {
|
||||||
MatrixStack.Entry entry = matrixStack.peek();
|
MatrixStack.Entry entry = matrixStack.peek();
|
||||||
|
|
||||||
if (!flipWinding) {
|
if (!flipWinding) {
|
||||||
// Counter-clockwise winding (front face)
|
// Counter-clockwise winding (front face)
|
||||||
// Vertex 1 (bottom-left)
|
// Vertex 1 (bottom-left)
|
||||||
vertexConsumer.vertex(entry.getPositionMatrix(), x1, y2, z1)
|
vertexConsumer
|
||||||
|
.vertex(entry.getPositionMatrix(), (float) bottomLeft.x, (float) bottomLeft.y, (float) bottomLeft.z)
|
||||||
.color(255, 255, 255, 255)
|
.color(255, 255, 255, 255)
|
||||||
.texture(u1, v2)
|
.texture(u1, v2)
|
||||||
.overlay(overlay)
|
.overlay(overlay)
|
||||||
@@ -62,7 +81,9 @@ public class CloakFeatureRenderer extends FeatureRenderer<PlayerEntityRenderStat
|
|||||||
.normal(normalX, normalY, normalZ);
|
.normal(normalX, normalY, normalZ);
|
||||||
|
|
||||||
// Vertex 2 (bottom-right)
|
// Vertex 2 (bottom-right)
|
||||||
vertexConsumer.vertex(entry.getPositionMatrix(), x2, y2, z2)
|
vertexConsumer
|
||||||
|
.vertex(entry.getPositionMatrix(), (float) bottomRight.x, (float) bottomRight.y,
|
||||||
|
(float) bottomRight.z)
|
||||||
.color(255, 255, 255, 255)
|
.color(255, 255, 255, 255)
|
||||||
.texture(u2, v2)
|
.texture(u2, v2)
|
||||||
.overlay(overlay)
|
.overlay(overlay)
|
||||||
@@ -70,7 +91,7 @@ public class CloakFeatureRenderer extends FeatureRenderer<PlayerEntityRenderStat
|
|||||||
.normal(normalX, normalY, normalZ);
|
.normal(normalX, normalY, normalZ);
|
||||||
|
|
||||||
// Vertex 3 (top-right)
|
// Vertex 3 (top-right)
|
||||||
vertexConsumer.vertex(entry.getPositionMatrix(), x2, y1, z2)
|
vertexConsumer.vertex(entry.getPositionMatrix(), (float) topRight.x, (float) topRight.y, (float) topRight.z)
|
||||||
.color(255, 255, 255, 255)
|
.color(255, 255, 255, 255)
|
||||||
.texture(u2, v1)
|
.texture(u2, v1)
|
||||||
.overlay(overlay)
|
.overlay(overlay)
|
||||||
@@ -78,7 +99,7 @@ public class CloakFeatureRenderer extends FeatureRenderer<PlayerEntityRenderStat
|
|||||||
.normal(normalX, normalY, normalZ);
|
.normal(normalX, normalY, normalZ);
|
||||||
|
|
||||||
// Vertex 4 (top-left)
|
// Vertex 4 (top-left)
|
||||||
vertexConsumer.vertex(entry.getPositionMatrix(), x1, y1, z1)
|
vertexConsumer.vertex(entry.getPositionMatrix(), (float) topLeft.x, (float) topLeft.y, (float) topLeft.z)
|
||||||
.color(255, 255, 255, 255)
|
.color(255, 255, 255, 255)
|
||||||
.texture(u1, v1)
|
.texture(u1, v1)
|
||||||
.overlay(overlay)
|
.overlay(overlay)
|
||||||
@@ -87,7 +108,7 @@ public class CloakFeatureRenderer extends FeatureRenderer<PlayerEntityRenderStat
|
|||||||
} else {
|
} else {
|
||||||
// Clockwise winding (back face) - reverse vertex order
|
// Clockwise winding (back face) - reverse vertex order
|
||||||
// Vertex 4 (top-left)
|
// Vertex 4 (top-left)
|
||||||
vertexConsumer.vertex(entry.getPositionMatrix(), x1, y1, z1)
|
vertexConsumer.vertex(entry.getPositionMatrix(), (float) topLeft.x, (float) topLeft.y, (float) topLeft.z)
|
||||||
.color(255, 255, 255, 255)
|
.color(255, 255, 255, 255)
|
||||||
.texture(u1, v1)
|
.texture(u1, v1)
|
||||||
.overlay(overlay)
|
.overlay(overlay)
|
||||||
@@ -95,7 +116,7 @@ public class CloakFeatureRenderer extends FeatureRenderer<PlayerEntityRenderStat
|
|||||||
.normal(normalX, normalY, normalZ);
|
.normal(normalX, normalY, normalZ);
|
||||||
|
|
||||||
// Vertex 3 (top-right)
|
// Vertex 3 (top-right)
|
||||||
vertexConsumer.vertex(entry.getPositionMatrix(), x2, y1, z2)
|
vertexConsumer.vertex(entry.getPositionMatrix(), (float) topRight.x, (float) topRight.y, (float) topRight.z)
|
||||||
.color(255, 255, 255, 255)
|
.color(255, 255, 255, 255)
|
||||||
.texture(u2, v1)
|
.texture(u2, v1)
|
||||||
.overlay(overlay)
|
.overlay(overlay)
|
||||||
@@ -103,7 +124,9 @@ public class CloakFeatureRenderer extends FeatureRenderer<PlayerEntityRenderStat
|
|||||||
.normal(normalX, normalY, normalZ);
|
.normal(normalX, normalY, normalZ);
|
||||||
|
|
||||||
// Vertex 2 (bottom-right)
|
// Vertex 2 (bottom-right)
|
||||||
vertexConsumer.vertex(entry.getPositionMatrix(), x2, y2, z2)
|
vertexConsumer
|
||||||
|
.vertex(entry.getPositionMatrix(), (float) bottomRight.x, (float) bottomRight.y,
|
||||||
|
(float) bottomRight.z)
|
||||||
.color(255, 255, 255, 255)
|
.color(255, 255, 255, 255)
|
||||||
.texture(u2, v2)
|
.texture(u2, v2)
|
||||||
.overlay(overlay)
|
.overlay(overlay)
|
||||||
@@ -111,7 +134,8 @@ public class CloakFeatureRenderer extends FeatureRenderer<PlayerEntityRenderStat
|
|||||||
.normal(normalX, normalY, normalZ);
|
.normal(normalX, normalY, normalZ);
|
||||||
|
|
||||||
// Vertex 1 (bottom-left)
|
// Vertex 1 (bottom-left)
|
||||||
vertexConsumer.vertex(entry.getPositionMatrix(), x1, y2, z1)
|
vertexConsumer
|
||||||
|
.vertex(entry.getPositionMatrix(), (float) bottomLeft.x, (float) bottomLeft.y, (float) bottomLeft.z)
|
||||||
.color(255, 255, 255, 255)
|
.color(255, 255, 255, 255)
|
||||||
.texture(u1, v2)
|
.texture(u1, v2)
|
||||||
.overlay(overlay)
|
.overlay(overlay)
|
||||||
@@ -125,6 +149,7 @@ public class CloakFeatureRenderer extends FeatureRenderer<PlayerEntityRenderStat
|
|||||||
float capeWidth = 10.0f / 16.0f; // 10 pixels wide
|
float capeWidth = 10.0f / 16.0f; // 10 pixels wide
|
||||||
float capeHeight = 16.0f / 16.0f; // 16 pixels tall
|
float capeHeight = 16.0f / 16.0f; // 16 pixels tall
|
||||||
float capeDepth = 1.0f / 16.0f; // 1 pixel deep
|
float capeDepth = 1.0f / 16.0f; // 1 pixel deep
|
||||||
|
float capePartHeight = capeHeight / PARTS;
|
||||||
|
|
||||||
matrixStack.push();
|
matrixStack.push();
|
||||||
matrixStack.translate(0.0f, 1.25, 0.125f);
|
matrixStack.translate(0.0f, 1.25, 0.125f);
|
||||||
@@ -163,56 +188,87 @@ public class CloakFeatureRenderer extends FeatureRenderer<PlayerEntityRenderStat
|
|||||||
float bottomV1 = 17.0f / 32.0f; // Start at pixel 17
|
float bottomV1 = 17.0f / 32.0f; // Start at pixel 17
|
||||||
float bottomV2 = 18.0f / 32.0f; // End at pixel 18
|
float bottomV2 = 18.0f / 32.0f; // End at pixel 18
|
||||||
|
|
||||||
// FRONT FACE
|
float curveMagnitude = 0.5f;
|
||||||
renderCapeQuad(vertexConsumer, matrixStack,
|
|
||||||
x2, y2, z2, x1, y1, z2,
|
for (int i = 0; i < PARTS; i++) {
|
||||||
frontU1, frontV1, frontU2, frontV2,
|
float y3 = -(capePartHeight * i);
|
||||||
|
float y4 = -(capePartHeight * (i + 1));
|
||||||
|
float totalVHeight = frontV2 - frontV1;
|
||||||
|
float partVHeight = totalVHeight / PARTS;
|
||||||
|
|
||||||
|
float v1 = frontV2 - (partVHeight * i);
|
||||||
|
float v2 = frontV2 - (partVHeight * (i + 1));
|
||||||
|
|
||||||
|
float u1 = frontU1;
|
||||||
|
float u2 = frontU2;
|
||||||
|
|
||||||
|
// Calculate the curve offset
|
||||||
|
float curveOffsetTop = (float) Math.sin((double) i / PARTS * Math.PI) * curveMagnitude;
|
||||||
|
float curveOffsetBottom = (float) Math.sin((double) (i + 1) / PARTS * Math.PI) * curveMagnitude;
|
||||||
|
|
||||||
|
// Adjust the x and z coordinates
|
||||||
|
Vec3d topLeft = new Vec3d(x1, y3, z1 + curveOffsetTop);
|
||||||
|
Vec3d topRight = new Vec3d(x2, y3, z2 + curveOffsetTop);
|
||||||
|
Vec3d bottomLeft = new Vec3d(x1, y4, z1 + curveOffsetBottom);
|
||||||
|
Vec3d bottomRight = new Vec3d(x2, y4, z2 + curveOffsetBottom);
|
||||||
|
|
||||||
|
this.renderCapeQuad(vertexConsumer, matrixStack,
|
||||||
|
bottomLeft, bottomRight, topRight, topLeft,
|
||||||
|
u1, v1, u2, v2,
|
||||||
light, overlay,
|
light, overlay,
|
||||||
0.0f, 0.0f, 1.0f, false);
|
0.0f, 0.0f, 1.0f, false);
|
||||||
|
}
|
||||||
|
|
||||||
// BACK FACE
|
// // BACK FACE
|
||||||
renderCapeQuad(vertexConsumer, matrixStack,
|
// this.renderCapeQuad(vertexConsumer, matrixStack,
|
||||||
x1, y2, z1, x2, y1, z1,
|
// new Vec3d(x1, y1, z1), new Vec3d(x2, y1, z1), new Vec3d(x2, y2, z1), new
|
||||||
backU1, backV1, backU2, backV2,
|
// Vec3d(x1, y2, z1),
|
||||||
light, overlay,
|
// backU1, backV1, backU2, backV2,
|
||||||
0.0f, 0.0f, 1.0f, false);
|
// light, overlay,
|
||||||
|
// 0.0f, 0.0f, 1.0f, false);
|
||||||
|
|
||||||
// LEFT SIDE
|
// // LEFT SIDE
|
||||||
renderCapeQuad(vertexConsumer, matrixStack,
|
// this.renderCapeQuad(vertexConsumer, matrixStack,
|
||||||
x2, y2, z1, x2, y1, z2,
|
// new Vec3d(x2, y1, z1), new Vec3d(x2, y1, z2), new Vec3d(x2, y2, z2), new
|
||||||
0.0f, frontV1, 1.0f / 64.0f, frontV2,
|
// Vec3d(x2, y2, z1),
|
||||||
light, overlay,
|
// 0.0f, frontV1, 1.0f / 64.0f, frontV2,
|
||||||
1.0f, 0.0f, 0.0f, false);
|
// light, overlay,
|
||||||
|
// 1.0f, 0.0f, 0.0f, false);
|
||||||
|
|
||||||
// RIGHT SIDE
|
// // RIGHT SIDE
|
||||||
renderCapeQuad(vertexConsumer, matrixStack,
|
// this.renderCapeQuad(vertexConsumer, matrixStack,
|
||||||
x1, y2, z2, x1, y1, z1,
|
// new Vec3d(x1, y1, z2), new Vec3d(x1, y1, z1), new Vec3d(x1, y2, z1), new
|
||||||
frontU2, frontV1, frontU2 + 1.0f / 64.0f, frontV2,
|
// Vec3d(x1, y2, z2),
|
||||||
light, overlay,
|
// frontU2, frontV1, frontU2 + 1.0f / 64.0f, frontV2,
|
||||||
-1.0f, 0.0f, 0.0f, false);
|
// light, overlay,
|
||||||
|
// -1.0f, 0.0f, 0.0f, false);
|
||||||
|
|
||||||
// TOP FACE
|
// // TOP FACE
|
||||||
matrixStack.push();
|
// matrixStack.push();
|
||||||
matrixStack.translate(0.0f, y2 + capeDepth, 0.0f);
|
// matrixStack.translate(0.0f, y2 + capeDepth, 0.0f);
|
||||||
matrixStack.multiply(net.minecraft.util.math.RotationAxis.POSITIVE_X.rotationDegrees(90.0f));
|
// matrixStack.multiply(net.minecraft.util.math.RotationAxis.POSITIVE_X.rotationDegrees(90.0f));
|
||||||
matrixStack.translate(0.0f, -y2, 0.0f);
|
// matrixStack.translate(0.0f, -y2, 0.0f);
|
||||||
renderCapeQuad(vertexConsumer, matrixStack,
|
// this.renderCapeQuad(vertexConsumer, matrixStack,
|
||||||
x2, y2, z2, x1, y2 + capeDepth, z2,
|
// new Vec3d(x2, y2 + capeDepth, z2), new Vec3d(x1, y2 + capeDepth, z2), new
|
||||||
topU1, topV1, topU2, topV2,
|
// Vec3d(x1, y2, z2),
|
||||||
light, overlay,
|
// new Vec3d(x2, y2, z2),
|
||||||
0.0f, 1.0f, 0.0f, true);
|
// topU1, topV1, topU2, topV2,
|
||||||
matrixStack.pop();
|
// light, overlay,
|
||||||
|
// 0.0f, 1.0f, 0.0f, true);
|
||||||
|
// matrixStack.pop();
|
||||||
|
|
||||||
// BOTTOM FACE
|
// // BOTTOM FACE
|
||||||
matrixStack.push();
|
// matrixStack.push();
|
||||||
matrixStack.multiply(net.minecraft.util.math.RotationAxis.POSITIVE_X.rotationDegrees(-90.0f));
|
// matrixStack.multiply(net.minecraft.util.math.RotationAxis.POSITIVE_X.rotationDegrees(-90.0f));
|
||||||
matrixStack.translate(0.0f, -z2, -z2);
|
// matrixStack.translate(0.0f, -z2, -z2);
|
||||||
renderCapeQuad(vertexConsumer, matrixStack,
|
// this.renderCapeQuad(vertexConsumer, matrixStack,
|
||||||
x2, y1, z2, x1, y1 + capeDepth, z2,
|
// new Vec3d(x2, y1 + capeDepth, z2), new Vec3d(x1, y1 + capeDepth, z2), new
|
||||||
bottomU1, bottomV1, bottomU2, bottomV2,
|
// Vec3d(x1, y1, z2),
|
||||||
light, overlay,
|
// new Vec3d(x2, y1, z2),
|
||||||
0.0f, -1.0f, 0.0f, false);
|
// bottomU1, bottomV1, bottomU2, bottomV2,
|
||||||
matrixStack.pop();
|
// light, overlay,
|
||||||
|
// 0.0f, -1.0f, 0.0f, false);
|
||||||
|
// matrixStack.pop();
|
||||||
|
|
||||||
matrixStack.pop();
|
matrixStack.pop();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user