Skip to content

Commit 0133642

Browse files
committed
fix: Crash with swansong when Triangulator module is disabled
1 parent 7891c91 commit 0133642

File tree

3 files changed

+102
-65
lines changed

3 files changed

+102
-65
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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.mixin.mixins.client.triangulator.swansong;
24+
25+
import com.falsepattern.falsetweaks.Compat;
26+
import com.falsepattern.falsetweaks.modules.triangulator.interfaces.ITriangulatorTessellator;
27+
import com.ventooth.swansong.tessellator.ShaderTess;
28+
import lombok.val;
29+
import org.lwjgl.opengl.GL11;
30+
import org.spongepowered.asm.mixin.Final;
31+
import org.spongepowered.asm.mixin.Mixin;
32+
import org.spongepowered.asm.mixin.Shadow;
33+
import org.spongepowered.asm.mixin.Unique;
34+
import org.spongepowered.asm.mixin.injection.At;
35+
import org.spongepowered.asm.mixin.injection.Inject;
36+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
37+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
38+
39+
import net.minecraft.client.renderer.Tessellator;
40+
41+
@Mixin(value = ShaderTess.class,
42+
remap = false)
43+
public abstract class ShaderTessMixin {
44+
@Shadow
45+
@Final
46+
protected Tessellator tess;
47+
@Unique
48+
private boolean ft$trollSwansongAddVertex;
49+
50+
@Inject(method = "addVertex(DDD)V",
51+
at = @At(value = "HEAD"),
52+
require = 1)
53+
private void clearShaderCheck(CallbackInfo ci) {
54+
val triTess = (ITriangulatorTessellator) tess;
55+
triTess.shaderOn(Compat.ShaderType.Swansong);
56+
if (triTess.hackedQuadRendering()) {
57+
ft$trollSwansongAddVertex = true;
58+
if (triTess.quadTriangulationActive()) {
59+
tess.drawMode = GL11.GL_QUADS;
60+
}
61+
}
62+
}
63+
64+
@Inject(method = "addVertex(DDD)V",
65+
at = @At(value = "RETURN"),
66+
require = 1)
67+
private void hackVertex(CallbackInfo ci) {
68+
val triTess = (ITriangulatorTessellator) tess;
69+
if (ft$trollSwansongAddVertex) {
70+
tess.drawMode = GL11.GL_TRIANGLES;
71+
ft$trollSwansongAddVertex = false;
72+
}
73+
triTess.triangulate();
74+
triTess.shaderOn(Compat.ShaderType.None);
75+
}
76+
77+
@Inject(method = "draw",
78+
at = @At(value = "HEAD"),
79+
require = 1)
80+
private void stateSwitchingForDrawCallStart(CallbackInfoReturnable<Integer> cir) {
81+
val triTess = (ITriangulatorTessellator) tess;
82+
if (triTess.hackedQuadRendering() && ft$trollSwansongAddVertex) {
83+
tess.drawMode = GL11.GL_TRIANGLES;
84+
}
85+
}
86+
87+
@Inject(method = "draw",
88+
at = @At(value = "RETURN"),
89+
require = 1)
90+
private void stateSwitchingForDrawCallEnd(CallbackInfoReturnable<Integer> cir) {
91+
val triTess = (ITriangulatorTessellator) tess;
92+
if (triTess.hackedQuadRendering() && ft$trollSwansongAddVertex) {
93+
if (triTess.quadTriangulationActive()) {
94+
tess.drawMode = GL11.GL_QUADS;
95+
}
96+
}
97+
}
98+
}

src/main/java/com/falsepattern/falsetweaks/mixin/mixins/client/vertexapi/swansong/ShaderTessMixin.java

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -22,85 +22,20 @@
2222

2323
package com.falsepattern.falsetweaks.mixin.mixins.client.vertexapi.swansong;
2424

25-
import com.falsepattern.falsetweaks.Compat;
2625
import com.falsepattern.falsetweaks.api.triangulator.VertexAPI;
27-
import com.falsepattern.falsetweaks.modules.triangulator.interfaces.ITriangulatorTessellator;
2826
import com.ventooth.swansong.tessellator.ShaderTess;
29-
import lombok.val;
30-
import org.lwjgl.opengl.GL11;
31-
import org.spongepowered.asm.mixin.Final;
3227
import org.spongepowered.asm.mixin.Mixin;
33-
import org.spongepowered.asm.mixin.Shadow;
34-
import org.spongepowered.asm.mixin.injection.At;
3528
import org.spongepowered.asm.mixin.injection.Constant;
36-
import org.spongepowered.asm.mixin.injection.Inject;
3729
import org.spongepowered.asm.mixin.injection.ModifyConstant;
38-
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
39-
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
40-
41-
import net.minecraft.client.renderer.Tessellator;
4230

4331
@Mixin(value = ShaderTess.class,
4432
remap = false)
4533
public abstract class ShaderTessMixin {
46-
@Shadow
47-
@Final
48-
protected Tessellator tess;
49-
private boolean trollSwansongAddVertex;
5034

5135
@ModifyConstant(method = "vertexStrideInt",
5236
constant = @Constant(),
5337
require = 1)
5438
private static int recompute(int constant) {
5539
return VertexAPI.recomputeVertexInfo(constant, 1);
5640
}
57-
58-
@Inject(method = "addVertex(DDD)V",
59-
at = @At(value = "HEAD"),
60-
require = 1)
61-
private void clearShaderCheck(CallbackInfo ci) {
62-
val triTess = (ITriangulatorTessellator) tess;
63-
triTess.shaderOn(Compat.ShaderType.Swansong);
64-
if (triTess.hackedQuadRendering()) {
65-
trollSwansongAddVertex = true;
66-
if (triTess.quadTriangulationActive()) {
67-
tess.drawMode = GL11.GL_QUADS;
68-
}
69-
}
70-
}
71-
72-
@Inject(method = "addVertex(DDD)V",
73-
at = @At(value = "RETURN"),
74-
require = 1)
75-
private void hackVertex(CallbackInfo ci) {
76-
val triTess = (ITriangulatorTessellator) tess;
77-
if (trollSwansongAddVertex) {
78-
tess.drawMode = GL11.GL_TRIANGLES;
79-
trollSwansongAddVertex = false;
80-
}
81-
triTess.triangulate();
82-
triTess.shaderOn(Compat.ShaderType.None);
83-
}
84-
85-
@Inject(method = "draw",
86-
at = @At(value = "HEAD"),
87-
require = 1)
88-
private void stateSwitchingForDrawCallStart(CallbackInfoReturnable<Integer> cir) {
89-
val triTess = (ITriangulatorTessellator) tess;
90-
if (triTess.hackedQuadRendering() && trollSwansongAddVertex) {
91-
tess.drawMode = GL11.GL_TRIANGLES;
92-
}
93-
}
94-
95-
@Inject(method = "draw",
96-
at = @At(value = "RETURN"),
97-
require = 1)
98-
private void stateSwitchingForDrawCallEnd(CallbackInfoReturnable<Integer> cir) {
99-
val triTess = (ITriangulatorTessellator) tess;
100-
if (triTess.hackedQuadRendering() && trollSwansongAddVertex) {
101-
if (triTess.quadTriangulationActive()) {
102-
tess.drawMode = GL11.GL_QUADS;
103-
}
104-
}
105-
}
10641
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ public enum Mixin implements IMixins {
130130
() -> ModuleConfig.TRIANGULATOR,
131131
require(RedstonePaste),
132132
client("triangulator.redstonepaste.RedstonePasteHighlighterMixin")),
133+
Triangulator_SwanSong(Phase.EARLY,
134+
() -> ModuleConfig.TRIANGULATOR,
135+
require(SwanSong),
136+
client("triangulator.swansong.ShaderTessMixin")),
133137

134138
CrackFix(Phase.EARLY,
135139
() -> ModuleConfig.blockCrackFix,

0 commit comments

Comments
 (0)