Skip to content

Commit e722dc2

Browse files
committed
Add natural textures capabilities to crossed squares rendering
1 parent 0e135de commit e722dc2

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import com.llamalad7.mixinextras.expression.Definition;
2929
import com.llamalad7.mixinextras.expression.Expression;
3030
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
31+
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
32+
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
3133
import com.llamalad7.mixinextras.sugar.Local;
3234
import org.jetbrains.annotations.Nullable;
3335
import org.spongepowered.asm.lib.Opcodes;
@@ -52,6 +54,9 @@ public abstract class RenderBlocksMixin {
5254
@Unique
5355
private final double[] mcp$vertexVs = new double[4];
5456

57+
@Unique
58+
private int mcp$vertexCounter = 0;
59+
5560
@Unique
5661
private void mcp$captureVertexes(int x, int y, int z, Side side, @Nullable IIcon texture,
5762
double uA, double vA, double uB, double vB,
@@ -73,6 +78,11 @@ public abstract class RenderBlocksMixin {
7378
NaturalTexturesEngine.applyNaturalTexture(x, y, z, side, texture, mcp$vertexUs, mcp$vertexVs);
7479
}
7580

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) {
83+
mcp$vertexCounter = 0;
84+
}
85+
7686
/** Standard block render: UV Capturing Mixins */
7787

7888
// Down
@@ -419,4 +429,40 @@ private boolean swizzleVerticesVineYNeg(boolean original, Block block, int x, in
419429

420430
return false;
421431
}
432+
433+
/** Crossed Squares */
434+
@WrapOperation(
435+
method = "drawCrossedSquares",
436+
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/Tessellator;addVertexWithUV(DDDDD)V"))
437+
private void swizzleCrossedSquareVertexUV(Tessellator instance, double x, double y, double z, double u, double v,
438+
Operation<Void> original, @Local(argsOnly = true) IIcon texture,
439+
@Local(ordinal = 3) double minU, @Local(ordinal = 4) double minV,
440+
@Local(ordinal = 5) double maxU, @Local(ordinal = 6) double maxV) {
441+
if (!ModuleConfig.naturalTextures) {
442+
original.call(instance, x, y, z, u, v);
443+
return;
444+
}
445+
446+
int vertIndex = mcp$vertexCounter % 4;
447+
if (vertIndex == 0) { // First vertex, rotate UVs for the next 4 calls
448+
449+
// Since the quads are diagonal, the choice of side is arbitrary
450+
mcp$captureVertexes((int) x, (int) y, (int) z, Side.YPos, texture, minU, maxV, maxU, maxV, maxU, minV, minU, minV);
451+
452+
double swap = mcp$vertexUs[0];
453+
mcp$vertexUs[0] = mcp$vertexUs[3];
454+
mcp$vertexUs[3] = mcp$vertexUs[2];
455+
mcp$vertexUs[2] = mcp$vertexUs[1];
456+
mcp$vertexUs[1] = swap;
457+
458+
swap = mcp$vertexVs[0];
459+
mcp$vertexVs[0] = mcp$vertexVs[3];
460+
mcp$vertexVs[3] = mcp$vertexVs[2];
461+
mcp$vertexVs[2] = mcp$vertexVs[1];
462+
mcp$vertexVs[1] = swap;
463+
}
464+
465+
original.call(instance, x, y, z, mcp$vertexUs[vertIndex], mcp$vertexVs[vertIndex]);
466+
mcp$vertexCounter++;
467+
}
422468
}

0 commit comments

Comments
 (0)