|
| 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 | +} |
0 commit comments