|
| 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.vertexapi; |
| 24 | + |
| 25 | +import com.falsepattern.falsetweaks.Compat; |
| 26 | +import com.falsepattern.falsetweaks.modules.vertexapi.VertexInfo; |
| 27 | +import lombok.val; |
| 28 | +import org.joml.Math; |
| 29 | +import org.spongepowered.asm.mixin.Mixin; |
| 30 | +import org.spongepowered.asm.mixin.Overwrite; |
| 31 | +import org.spongepowered.asm.mixin.Shadow; |
| 32 | +import org.spongepowered.asm.mixin.Unique; |
| 33 | + |
| 34 | +import net.minecraft.client.util.QuadComparator; |
| 35 | + |
| 36 | +import java.util.Comparator; |
| 37 | + |
| 38 | +@Mixin(value = QuadComparator.class, |
| 39 | + //Swansong is 900 |
| 40 | + //Overwritten by other stuff at level 1000 |
| 41 | + priority = 950) |
| 42 | +public abstract class QuadComparatorMixin implements Comparator<Integer> { |
| 43 | + @Shadow public int[] field_147627_d; |
| 44 | + |
| 45 | + @Shadow public float field_147630_a; |
| 46 | + |
| 47 | + @Shadow public float field_147628_b; |
| 48 | + |
| 49 | + @Shadow public float field_147629_c; |
| 50 | + |
| 51 | + /** |
| 52 | + * @author FalsePattern |
| 53 | + * @reason VertexAPI compat |
| 54 | + */ |
| 55 | + @Overwrite |
| 56 | + public int compare(Integer o1, Integer o2) { |
| 57 | + val vertexData = this.field_147627_d; |
| 58 | + val stride = VertexInfo.getVertexInfo(Compat.shaderType(), 1); |
| 59 | + val stride2 = stride * 2; |
| 60 | + val stride3 = stride * 3; |
| 61 | + val refX = field_147630_a; |
| 62 | + val refY = field_147628_b; |
| 63 | + val refZ = field_147629_c; |
| 64 | + val aSQ = ft$getDistSQ(vertexData, o1, stride, stride2, stride3, refX, refY, refZ); |
| 65 | + val bSQ = ft$getDistSQ(vertexData, o2, stride, stride2, stride3, refX, refY, refZ); |
| 66 | + return Float.compare(bSQ, aSQ); |
| 67 | + } |
| 68 | + |
| 69 | + @Unique |
| 70 | + private static float ft$getDistSQ(int[] vertexData, int primitive, int stride, int stride2, int stride3, float refX, float refY, float refZ) { |
| 71 | + val x1 = Float.intBitsToFloat(vertexData[primitive]) - refX; |
| 72 | + val y1 = Float.intBitsToFloat(vertexData[primitive + 1]) - refY; |
| 73 | + val z1 = Float.intBitsToFloat(vertexData[primitive + 2]) - refZ; |
| 74 | + val x2 = Float.intBitsToFloat(vertexData[primitive + stride]) - refX; |
| 75 | + val y2 = Float.intBitsToFloat(vertexData[primitive + stride + 1]) - refY; |
| 76 | + val z2 = Float.intBitsToFloat(vertexData[primitive + stride + 2]) - refZ; |
| 77 | + val x3 = Float.intBitsToFloat(vertexData[primitive + stride2]) - refX; |
| 78 | + val y3 = Float.intBitsToFloat(vertexData[primitive + stride2 + 1]) - refY; |
| 79 | + val z3 = Float.intBitsToFloat(vertexData[primitive + stride2 + 2]) - refZ; |
| 80 | + val x4 = Float.intBitsToFloat(vertexData[primitive + stride3]) - refX; |
| 81 | + val y4 = Float.intBitsToFloat(vertexData[primitive + stride3 + 1]) - refY; |
| 82 | + val z4 = Float.intBitsToFloat(vertexData[primitive + stride3 + 2]) - refZ; |
| 83 | + |
| 84 | + val x = (x1 + x2 + x3 + x4) * 0.25F; |
| 85 | + val y = (y1 + y2 + y3 + y4) * 0.25F; |
| 86 | + val z = (z1 + z2 + z3 + z4) * 0.25F; |
| 87 | + return x * x + y * y + z * z; |
| 88 | + } |
| 89 | +} |
0 commit comments