Skip to content

Commit 72297f0

Browse files
committed
Add natural textures capabilities to crop blocks
1 parent e722dc2 commit 72297f0

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

src/main/java/com/falsepattern/mcpatcher/internal/mixin/mixins/client/natural/RenderBlocksMixin.java

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,11 @@ public abstract class RenderBlocksMixin {
7878
NaturalTexturesEngine.applyNaturalTexture(x, y, z, side, texture, mcp$vertexUs, mcp$vertexVs);
7979
}
8080

81-
@Inject(method = { "drawCrossedSquares" }, at = @At(value = "HEAD"))
82-
private void mcp$resetVertexCounter(IIcon texture, double x, double y, double z, float height, CallbackInfo ci) {
81+
@Inject(method = {
82+
"drawCrossedSquares",
83+
"renderBlockCropsImpl",
84+
}, at = @At(value = "HEAD"))
85+
private void mcp$resetVertexCounter(CallbackInfo ci) {
8386
mcp$vertexCounter = 0;
8487
}
8588

@@ -465,4 +468,41 @@ private void swizzleCrossedSquareVertexUV(Tessellator instance, double x, double
465468
original.call(instance, x, y, z, mcp$vertexUs[vertIndex], mcp$vertexVs[vertIndex]);
466469
mcp$vertexCounter++;
467470
}
471+
472+
/** Crops */
473+
@WrapOperation(
474+
method = "renderBlockCropsImpl",
475+
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/Tessellator;addVertexWithUV(DDDDD)V"))
476+
private void swizzleCropVertexUV(Tessellator instance, double x, double y, double z, double u, double v,
477+
Operation<Void> original, @Local IIcon texture,
478+
@Local(ordinal = 3) double minU, @Local(ordinal = 4) double minV,
479+
@Local(ordinal = 5) double maxU, @Local(ordinal = 6) double maxV) {
480+
if (!ModuleConfig.naturalTextures) {
481+
original.call(instance, x, y, z, u, v);
482+
return;
483+
}
484+
485+
if (mcp$vertexCounter % 8 == 0) { // First vertex, rotate UVs for the next 8 calls (front and back quads for each side)
486+
487+
Side side = Side.values()[((mcp$vertexCounter / 8 + 2) % 4) + 2];
488+
489+
mcp$captureVertexes((int) x, (int) y, (int) z, side, texture, minU, maxV, maxU, maxV, maxU, minV, minU, minV);
490+
491+
double swap = mcp$vertexUs[0];
492+
mcp$vertexUs[0] = mcp$vertexUs[3];
493+
mcp$vertexUs[3] = mcp$vertexUs[2];
494+
mcp$vertexUs[2] = mcp$vertexUs[1];
495+
mcp$vertexUs[1] = swap;
496+
497+
swap = mcp$vertexVs[0];
498+
mcp$vertexVs[0] = mcp$vertexVs[3];
499+
mcp$vertexVs[3] = mcp$vertexVs[2];
500+
mcp$vertexVs[2] = mcp$vertexVs[1];
501+
mcp$vertexVs[1] = swap;
502+
}
503+
504+
int vertIndex = mcp$vertexCounter % 4;
505+
original.call(instance, x, y, z, mcp$vertexUs[vertIndex], mcp$vertexVs[vertIndex]);
506+
mcp$vertexCounter++;
507+
}
468508
}

0 commit comments

Comments
 (0)