fix(render): anchor video to clicked block's bottom-left, EAST/WEST flush
Some checks failed
build / build (push) Has been cancelled
Some checks failed
build / build (push) Has been cancelled
Three fixes for v0.4.1:
1. Video stick item rendered as missing-texture because 26.1.2 requires the
new client_item descriptor at assets/<mod>/items/<name>.json. Add it; the
existing models/item/video_stick.json is kept as the underlying model.
2. Quad placement now anchors the local (0,0) corner at the bottom-left of
the wall face the player clicked, so the clicked block is the BL and the
video grows up & right. Previously it was centered on the anchor.
3. EAST/WEST face rotations were swapped, which placed the quad on the far
side of the air block (~1 block away from the wall) instead of flush.
Derived the correct rotations from first principles:
EAST = Axis.YP +90° (local +Z → world +X, +X → -Z = north)
WEST = Axis.YP -90° (local +Z → world -X, +X → +Z = south)
NORTH/SOUTH/UP/DOWN math re-verified — those were already correct.
This commit is contained in:
@@ -5,7 +5,7 @@ org.gradle.configuration-cache=false
|
||||
|
||||
# Mod
|
||||
mod_id=video_player
|
||||
mod_version=0.4.0
|
||||
mod_version=0.4.1
|
||||
maven_group=com.ejclaw.videoplayer
|
||||
archives_base_name=video_player
|
||||
|
||||
|
||||
@@ -67,9 +67,11 @@ public class VideoAnchorRenderer implements BlockEntityRenderer<VideoAnchorBlock
|
||||
pose.translate(0.5F, 0.5F, 0.5F);
|
||||
// 2) Rotate local +Z to align with the wall's outward normal.
|
||||
applyFaceRotation(pose, f);
|
||||
// 3) Center the quad on origin (local XY) and push it back 0.5 - ε so it lands on the
|
||||
// wall surface (the boundary face between the anchor's air block and the wall block).
|
||||
pose.translate(-w / 2.0F, -h / 2.0F, -0.5F + SURFACE_EPSILON);
|
||||
// 3) Place the quad's local origin (0,0) at the bottom-left corner of the anchor block's
|
||||
// wall face, so the clicked block becomes the lower-left and the video grows up & right.
|
||||
// Push it onto the wall surface (-0.5 along local +Z, the outward normal) plus a tiny
|
||||
// epsilon outward so the quad doesn't z-fight with the wall.
|
||||
pose.translate(-0.5F, -0.5F, -0.5F + SURFACE_EPSILON);
|
||||
|
||||
final Matrix4f mat = new Matrix4f(pose.last().pose());
|
||||
RenderType rt = RenderTypes.entityCutout(tex);
|
||||
@@ -89,15 +91,21 @@ public class VideoAnchorRenderer implements BlockEntityRenderer<VideoAnchorBlock
|
||||
pose.popPose();
|
||||
}
|
||||
|
||||
/** Rotate so local +Z (the quad's outward normal in its base orientation) becomes world {@code f}. */
|
||||
/**
|
||||
* Rotate so local +Z (the quad's outward normal in its base orientation) becomes world {@code f},
|
||||
* with local +X mapped to the natural "right" direction the player sees when looking at the face.
|
||||
* Derivation: for each face {@code f}, pick the rotation that maps local +Z → f, +Y → world up
|
||||
* (or a sensible substitute for top/bottom), so the quad lies flush against the wall, oriented
|
||||
* the way the player intuits.
|
||||
*/
|
||||
private static void applyFaceRotation(PoseStack pose, Direction f) {
|
||||
switch (f) {
|
||||
case SOUTH -> { /* identity: local +Z already faces world +Z (south) */ }
|
||||
case NORTH -> pose.mulPose(Axis.YP.rotationDegrees(180F));
|
||||
case EAST -> pose.mulPose(Axis.YP.rotationDegrees(-90F));
|
||||
case WEST -> pose.mulPose(Axis.YP.rotationDegrees(90F));
|
||||
case UP -> pose.mulPose(Axis.XP.rotationDegrees(-90F));
|
||||
case DOWN -> pose.mulPose(Axis.XP.rotationDegrees(90F));
|
||||
case SOUTH -> { /* identity: local +Z = world +Z (south). +X = east, +Y = up. */ }
|
||||
case NORTH -> pose.mulPose(Axis.YP.rotationDegrees(180F)); // +Z → -Z, +X → -X (west)
|
||||
case EAST -> pose.mulPose(Axis.YP.rotationDegrees(90F)); // +Z → +X, +X → -Z (north)
|
||||
case WEST -> pose.mulPose(Axis.YP.rotationDegrees(-90F)); // +Z → -X, +X → +Z (south)
|
||||
case UP -> pose.mulPose(Axis.XP.rotationDegrees(-90F)); // +Z → +Y, +Y → -Z (north)
|
||||
case DOWN -> pose.mulPose(Axis.XP.rotationDegrees(90F)); // +Z → -Y, +Y → +Z (south)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "video_player:item/video_stick"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user