Skip to content

Commit bd4d1fc

Browse files
committed
fix: Triangulator broken without BSP sorting enabled
1 parent a000cfc commit bd4d1fc

4 files changed

Lines changed: 154 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Swansong
3+
*
4+
* Copyright 2025 Ven, FalsePattern
5+
*
6+
* This software is licensed under the Open Software License version
7+
* 3.0. The full text of this license can be found in https://opensource.org/licenses/OSL-3.0
8+
* or in the LICENSES directory which is distributed along with the software.
9+
*/
10+
11+
package com.falsepattern.falsetweaks.mixin.mixins.client.triangulator;
12+
13+
import com.falsepattern.falsetweaks.modules.triangulator.TriComparator;
14+
import com.falsepattern.falsetweaks.modules.triangulator.interfaces.ITriangulatorTessellator;
15+
import com.falsepattern.falsetweaks.modules.vertexapi.VertexInfo;
16+
import org.spongepowered.asm.mixin.Mixin;
17+
import org.spongepowered.asm.mixin.injection.At;
18+
import org.spongepowered.asm.mixin.injection.Constant;
19+
import org.spongepowered.asm.mixin.injection.ModifyConstant;
20+
import org.spongepowered.asm.mixin.injection.Redirect;
21+
22+
import net.minecraft.client.renderer.Tessellator;
23+
import net.minecraft.client.util.QuadComparator;
24+
25+
@Mixin(value = Tessellator.class,
26+
//Hodgepodge compat
27+
priority = 900)
28+
public abstract class TessellatorMixin_AvoidFoamFix implements ITriangulatorTessellator {
29+
@Redirect(method = "getVertexState",
30+
at = @At(value = "NEW",
31+
target = "([IFFF)Lnet/minecraft/client/util/QuadComparator;"),
32+
require = 1)
33+
private QuadComparator hackQuadComparator(int[] vertexData, float x, float y, float z) {
34+
if (this.drawingTris()) {
35+
return new TriComparator(vertexData, x, y, z);
36+
} else {
37+
return new QuadComparator(vertexData, x, y, z);
38+
}
39+
}
40+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Swansong
3+
*
4+
* Copyright 2025 Ven, FalsePattern
5+
*
6+
* This software is licensed under the Open Software License version
7+
* 3.0. The full text of this license can be found in https://opensource.org/licenses/OSL-3.0
8+
* or in the LICENSES directory which is distributed along with the software.
9+
*/
10+
11+
package com.falsepattern.falsetweaks.mixin.mixins.client.triangulator;
12+
13+
import com.falsepattern.falsetweaks.modules.triangulator.TriComparator;
14+
import com.falsepattern.falsetweaks.modules.triangulator.interfaces.ITriangulatorTessellator;
15+
import com.falsepattern.falsetweaks.modules.vertexapi.VertexInfo;
16+
import org.spongepowered.asm.mixin.Dynamic;
17+
import org.spongepowered.asm.mixin.Mixin;
18+
import org.spongepowered.asm.mixin.injection.At;
19+
import org.spongepowered.asm.mixin.injection.Constant;
20+
import org.spongepowered.asm.mixin.injection.ModifyConstant;
21+
import org.spongepowered.asm.mixin.injection.Redirect;
22+
23+
import net.minecraft.client.renderer.Tessellator;
24+
import net.minecraft.client.util.QuadComparator;
25+
26+
@Mixin(value = Tessellator.class,
27+
//Hodgepodge compat
28+
priority = 900)
29+
public abstract class TessellatorMixin_RequireFoamFix implements ITriangulatorTessellator {
30+
@Dynamic
31+
@Redirect(method = "getVertexState_foamfix_old",
32+
at = @At(value = "NEW",
33+
target = "([IFFF)Lnet/minecraft/client/util/QuadComparator;"),
34+
require = 1)
35+
private QuadComparator hackQuadComparator(int[] vertexData, float x, float y, float z) {
36+
if (this.drawingTris()) {
37+
return new TriComparator(vertexData, x, y, z);
38+
} else {
39+
return new QuadComparator(vertexData, x, y, z);
40+
}
41+
}
42+
}

src/main/java/com/falsepattern/falsetweaks/mixin/plugin/standard/Mixin.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ public enum Mixin implements IMixins {
9797
"triangulator.RenderingRegistryMixin",
9898
"triangulator.TessellatorMixin",
9999
"triangulator.WorldRendererMixin")),
100+
Triangulator_NoFoamFix(Phase.EARLY,
101+
() -> ModuleConfig.TRIANGULATOR && !ModuleConfig.BSP_SORTING,
102+
mods(avoid(FoamFix)),
103+
client("triangulator.TessellatorMixin_AvoidFoamFix")),
104+
Triangulator_FoamFix(Phase.EARLY,
105+
() -> ModuleConfig.TRIANGULATOR && !ModuleConfig.BSP_SORTING,
106+
mods(require(FoamFix)),
107+
client("triangulator.TessellatorMixin_RequireFoamFix")),
100108
Triangulator_NoOptiFine(Phase.EARLY,
101109
() -> ModuleConfig.TRIANGULATOR,
102110
mods(avoid(OptiFine), avoid(SwanSong)),
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* This file is part of FalseTweaks.
3+
*
4+
* Copyright (C) 2022-2025 FalsePattern
5+
* All Rights Reserved
6+
*
7+
* The above copyright notice and this permission notice shall be included
8+
* in all copies or substantial portions of the Software.
9+
*
10+
* FalseTweaks is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU Lesser General Public License as published by
12+
* the Free Software Foundation, only version 3 of the License.
13+
*
14+
* FalseTweaks is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with FalseTweaks. If not, see <https://www.gnu.org/licenses/>.
21+
*/
22+
23+
package com.falsepattern.falsetweaks.modules.triangulator;
24+
25+
import com.falsepattern.falsetweaks.Compat;
26+
import com.falsepattern.falsetweaks.modules.vertexapi.VertexInfo;
27+
import lombok.val;
28+
29+
import net.minecraft.client.util.QuadComparator;
30+
31+
public class TriComparator extends QuadComparator {
32+
public TriComparator(int[] vertexData, float x, float y, float z) {
33+
super(vertexData, x, y, z);
34+
}
35+
36+
@Override
37+
public int compare(Integer o1, Integer o2) {
38+
val vertexData = this.field_147627_d;
39+
val stride = VertexInfo.getVertexInfo(Compat.shaderType(), 1);
40+
val stride2 = stride * 2;
41+
val refX = field_147630_a;
42+
val refY = field_147628_b;
43+
val refZ = field_147629_c;
44+
val aSQ = ft$getDistSQ(vertexData, o1, stride, stride2, refX, refY, refZ);
45+
val bSQ = ft$getDistSQ(vertexData, o2, stride, stride2, refX, refY, refZ);
46+
return Float.compare(bSQ, aSQ);
47+
}
48+
private static float ft$getDistSQ(int[] vertexData, int primitive, int stride, int stride2, float refX, float refY, float refZ) {
49+
val x1 = Float.intBitsToFloat(vertexData[primitive]) - refX;
50+
val y1 = Float.intBitsToFloat(vertexData[primitive + 1]) - refY;
51+
val z1 = Float.intBitsToFloat(vertexData[primitive + 2]) - refZ;
52+
val x2 = Float.intBitsToFloat(vertexData[primitive + stride]) - refX;
53+
val y2 = Float.intBitsToFloat(vertexData[primitive + stride + 1]) - refY;
54+
val z2 = Float.intBitsToFloat(vertexData[primitive + stride + 2]) - refZ;
55+
val x3 = Float.intBitsToFloat(vertexData[primitive + stride2]) - refX;
56+
val y3 = Float.intBitsToFloat(vertexData[primitive + stride2 + 1]) - refY;
57+
val z3 = Float.intBitsToFloat(vertexData[primitive + stride2 + 2]) - refZ;
58+
59+
val x = (x1 + x2 + x3) * 0.25F;
60+
val y = (y1 + y2 + y3) * 0.25F;
61+
val z = (z1 + z2 + z3) * 0.25F;
62+
return x * x + y * y + z * z;
63+
}
64+
}

0 commit comments

Comments
 (0)