|
| 1 | +/* |
| 2 | + * Copyright 2025 Lambda |
| 3 | + * |
| 4 | + * This program is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | + |
| 18 | +package com.lambda.mixin.render; |
| 19 | + |
| 20 | +import com.lambda.module.modules.render.XRay; |
| 21 | +import net.minecraft.block.BlockState; |
| 22 | +import net.minecraft.client.render.VertexConsumer; |
| 23 | +import net.minecraft.client.render.block.FluidRenderer; |
| 24 | +import net.minecraft.fluid.FluidState; |
| 25 | +import net.minecraft.util.math.BlockPos; |
| 26 | +import net.minecraft.world.BlockRenderView; |
| 27 | +import org.spongepowered.asm.mixin.Mixin; |
| 28 | +import org.spongepowered.asm.mixin.Unique; |
| 29 | +import org.spongepowered.asm.mixin.injection.At; |
| 30 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 31 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 32 | + |
| 33 | +@Mixin(FluidRenderer.class) |
| 34 | +public class FluidRendererMixin { |
| 35 | + @Unique |
| 36 | + private final ThreadLocal<Integer> opacity = new ThreadLocal<>(); |
| 37 | + |
| 38 | + @Inject(method = "render", at = @At("HEAD"), cancellable = true) |
| 39 | + private void injectRender(BlockRenderView world, BlockPos pos, VertexConsumer vertexConsumer, BlockState blockState, FluidState fluidState, CallbackInfo info) { |
| 40 | + if (XRay.INSTANCE.isDisabled()) { |
| 41 | + opacity.set(255); |
| 42 | + return; |
| 43 | + } |
| 44 | + int alpha = (int) (XRay.getOpacity() * 2.55); |
| 45 | + |
| 46 | + if (alpha == 0) info.cancel(); |
| 47 | + else this.opacity.set(alpha); |
| 48 | + } |
| 49 | + |
| 50 | + @Inject(method = "vertex", at = @At("HEAD"), cancellable = true) |
| 51 | + private void injectVertex(VertexConsumer vertexConsumer, float x, float y, float z, float red, float green, float blue, float u, float v, int light, CallbackInfo info) { |
| 52 | + int alpha = this.opacity.get(); |
| 53 | + |
| 54 | + if (alpha != 255) { |
| 55 | + vertexConsumer.vertex(x, y, z).color((int) (red * 255), (int) (green * 255), (int) (blue * 255), alpha).texture(u, v).light(light).normal(0.0f, 1.0f, 0.0f); |
| 56 | + info.cancel(); |
| 57 | + } |
| 58 | + } |
| 59 | +} |
0 commit comments