Skip to content

Commit 1f6528e

Browse files
committed
working vanilla xray with opacity setting. Only works without sodium
1 parent 0dd3da0 commit 1f6528e

File tree

10 files changed

+300
-3
lines changed

10 files changed

+300
-3
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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.fabricmc.fabric.impl.client.indigo.renderer.mesh.MutableQuadViewImpl;
22+
import net.fabricmc.fabric.impl.client.indigo.renderer.render.AbstractTerrainRenderContext;
23+
import net.fabricmc.fabric.impl.client.indigo.renderer.render.BlockRenderInfo;
24+
import org.spongepowered.asm.mixin.Final;
25+
import org.spongepowered.asm.mixin.Mixin;
26+
import org.spongepowered.asm.mixin.Shadow;
27+
import org.spongepowered.asm.mixin.injection.At;
28+
import org.spongepowered.asm.mixin.injection.Inject;
29+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
30+
31+
@SuppressWarnings("UnstableApiUsage")
32+
@Mixin(AbstractTerrainRenderContext.class)
33+
public class AbstractTerrainRenderContextMixin {
34+
@Final
35+
@Shadow(remap = false)
36+
protected BlockRenderInfo blockInfo;
37+
38+
@Inject(method = "bufferQuad", at = @At(value = "INVOKE", target = "Lnet/fabricmc/fabric/impl/client/indigo/renderer/render/AbstractTerrainRenderContext;bufferQuad(Lnet/fabricmc/fabric/impl/client/indigo/renderer/mesh/MutableQuadViewImpl;Lnet/minecraft/client/render/VertexConsumer;)V"), cancellable = true)
39+
private void injectBufferQuad(MutableQuadViewImpl quad, CallbackInfo ci) {
40+
if (XRay.INSTANCE.isDisabled() || XRay.isSelected(blockInfo.blockState)) return;
41+
int opacity = XRay.getOpacity();
42+
43+
if (opacity == 0) ci.cancel();
44+
else if (opacity < 100) {
45+
int alpha = (int) (opacity * 2.55f);
46+
for (int i = 0; i < 4; i++) {
47+
quad.color(i, ((alpha & 0xFF) << 24) | (quad.color(i) & 0x00FFFFFF));
48+
}
49+
}
50+
}
51+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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 com.llamalad7.mixinextras.injector.ModifyReturnValue;
22+
import net.minecraft.block.Block;
23+
import net.minecraft.block.BlockState;
24+
import net.minecraft.util.math.Direction;
25+
import org.spongepowered.asm.mixin.Mixin;
26+
import org.spongepowered.asm.mixin.injection.At;
27+
28+
@Mixin(Block.class)
29+
public class BlockMixin {
30+
@ModifyReturnValue(method = "shouldDrawSide", at = @At("RETURN"))
31+
private static boolean modifyShouldDrawSide(boolean original, BlockState state, BlockState otherState, Direction side) {
32+
if (XRay.INSTANCE.isEnabled() && XRay.isSelected(state) && XRay.getOpacity() < 100)
33+
return true;
34+
35+
return original;
36+
}
37+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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.BlockModelRenderer;
24+
import net.minecraft.client.render.model.BlockModelPart;
25+
import net.minecraft.client.util.math.MatrixStack;
26+
import net.minecraft.util.math.BlockPos;
27+
import net.minecraft.world.BlockRenderView;
28+
import org.spongepowered.asm.mixin.Mixin;
29+
import org.spongepowered.asm.mixin.Unique;
30+
import org.spongepowered.asm.mixin.injection.At;
31+
import org.spongepowered.asm.mixin.injection.Constant;
32+
import org.spongepowered.asm.mixin.injection.Inject;
33+
import org.spongepowered.asm.mixin.injection.ModifyConstant;
34+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
35+
36+
import java.util.List;
37+
38+
@Mixin(BlockModelRenderer.class)
39+
public class BlockModelRendererMixin {
40+
@Unique private final ThreadLocal<Integer> opacity = new ThreadLocal<>();
41+
42+
@Inject(method = {"renderSmooth", "renderFlat"}, at = @At("HEAD"), cancellable = true)
43+
private void injectRenderSmoothFlat(BlockRenderView world, List<BlockModelPart> parts, BlockState state, BlockPos pos, MatrixStack matrices, VertexConsumer vertexConsumer, boolean cull, int overlay, CallbackInfo ci) {
44+
if (XRay.INSTANCE.isDisabled()) {
45+
this.opacity.set(-1);
46+
return;
47+
}
48+
int alpha = (int) (XRay.getOpacity() * 2.55);
49+
50+
if (alpha == 0) ci.cancel();
51+
else this.opacity.set(alpha);
52+
}
53+
54+
@ModifyConstant(method = "renderQuad", constant = @Constant(floatValue = 1, ordinal = 3))
55+
private float modifyAlpha(float original) {
56+
int alpha = this.opacity.get();
57+
return alpha == -1 ? original : alpha / 255f;
58+
}
59+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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.client.render.chunk.ChunkOcclusionDataBuilder;
22+
import net.minecraft.util.math.BlockPos;
23+
import org.spongepowered.asm.mixin.Mixin;
24+
import org.spongepowered.asm.mixin.injection.At;
25+
import org.spongepowered.asm.mixin.injection.Inject;
26+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
27+
28+
@Mixin(ChunkOcclusionDataBuilder.class)
29+
public class ChunkOcclusionDataBuilderMixin {
30+
@Inject(method = "markClosed", at = @At("HEAD"), cancellable = true)
31+
private void injectMarkClosed(BlockPos pos, CallbackInfo ci) {
32+
if (XRay.INSTANCE.isEnabled()) ci.cancel();
33+
}
34+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
}

src/main/java/com/lambda/mixin/render/LightmapTextureManagerMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class LightmapTextureManagerMixin {
4040
@Shadow @Final private GpuTexture glTexture;
4141

4242
@Inject(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/profiler/Profiler;pop()V", shift = At.Shift.BEFORE))
43-
private void updateModify(CallbackInfo ci) {
43+
private void injectUpdate(CallbackInfo ci) {
4444
if (Fullbright.INSTANCE.isEnabled() || XRay.INSTANCE.isEnabled()) {
4545
RenderSystem.getDevice().createCommandEncoder().createRenderPass(glTexture, OptionalInt.of(ColorHelper.getArgb(255, 255, 255, 255))).close();
4646
}

src/main/java/com/lambda/mixin/render/RenderLayersMixin.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import net.minecraft.block.BlockState;
2222
import net.minecraft.client.render.RenderLayer;
2323
import net.minecraft.client.render.RenderLayers;
24+
import net.minecraft.fluid.FluidState;
2425
import org.spongepowered.asm.mixin.Mixin;
2526
import org.spongepowered.asm.mixin.injection.At;
2627
import org.spongepowered.asm.mixin.injection.Inject;
@@ -29,8 +30,17 @@
2930
@Mixin(RenderLayers.class)
3031
public class RenderLayersMixin {
3132
@Inject(method = "getBlockLayer", at = @At("HEAD"), cancellable = true)
32-
private static void onGetBlockLayer(BlockState state, CallbackInfoReturnable<RenderLayer> cir) {
33+
private static void injectGetBlockLayer(BlockState state, CallbackInfoReturnable<RenderLayer> cir) {
3334
if (XRay.INSTANCE.isDisabled()) return;
35+
final var opacity = XRay.getOpacity();
36+
if (opacity <= 0 || opacity >= 100) return;
3437
if (!XRay.isSelected(state)) cir.setReturnValue(RenderLayer.getTranslucent());
3538
}
39+
40+
@Inject(method = "getFluidLayer", at = @At("HEAD"), cancellable = true)
41+
private static void injectGetFluidLayer(FluidState state, CallbackInfoReturnable<RenderLayer> cir) {
42+
if (XRay.INSTANCE.isDisabled()) return;
43+
final var opacity = XRay.getOpacity();
44+
if (opacity > 0 && opacity < 100) cir.setReturnValue(RenderLayer.getTranslucent());
45+
}
3646
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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.world;
19+
20+
import com.lambda.module.modules.render.XRay;
21+
import net.minecraft.block.AbstractBlock;
22+
import net.minecraft.block.BlockState;
23+
import net.minecraft.util.math.BlockPos;
24+
import net.minecraft.world.BlockView;
25+
import org.spongepowered.asm.mixin.Mixin;
26+
import org.spongepowered.asm.mixin.injection.At;
27+
import org.spongepowered.asm.mixin.injection.Inject;
28+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
29+
30+
@Mixin(AbstractBlock.class)
31+
public class AbstractBlockMixin {
32+
@Inject(method = "getAmbientOcclusionLightLevel", at = @At("HEAD"), cancellable = true)
33+
private void injectGetAmbientOcclusionLightLevel(BlockState state, BlockView world, BlockPos pos, CallbackInfoReturnable<Float> cir) {
34+
if (XRay.INSTANCE.isEnabled()) cir.setReturnValue(1f);
35+
}
36+
}

src/main/kotlin/com/lambda/module/modules/render/XRay.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ object XRay : Module(
2727
description = "Allows you to see ores through walls",
2828
tag = ModuleTag.RENDER,
2929
) {
30-
private val defaultBlocks = setOf(
30+
val defaultBlocks = setOf(
3131
Blocks.COAL_ORE, Blocks.DEEPSLATE_COAL_ORE,
3232
Blocks.IRON_ORE, Blocks.DEEPSLATE_IRON_ORE,
3333
Blocks.GOLD_ORE, Blocks.DEEPSLATE_GOLD_ORE,
@@ -40,7 +40,12 @@ object XRay : Module(
4040
Blocks.ANCIENT_DEBRIS
4141
)
4242

43+
@JvmStatic
44+
val opacity by setting("Opacity", 40, 0..100, 1, "opacity of the non x-rayed blocks")
45+
.onValueChange { _, _ -> if (isEnabled) mc.worldRenderer.reload() }
46+
4347
private val selection by setting("Block Selection", defaultBlocks, defaultBlocks, "Block selection that will be shown (whitelist) or hidden (blacklist)")
48+
.onValueChange { _, _ -> if (isEnabled) mc.worldRenderer.reload() }
4449
private val mode by setting("Selection Mode", Selection.Whitelist, "The mode of the block selection")
4550

4651
@JvmStatic

src/main/resources/lambda.mixins.common.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,26 @@
2828
"network.LoginHelloC2SPacketMixin",
2929
"network.LoginKeyC2SPacketMixin",
3030
"render.AbstractSignBlockEntityRendererMixin",
31+
"render.AbstractTerrainRenderContextMixin",
3132
"render.ArmorFeatureRendererMixin",
3233
"render.BackgroundRendererMixin",
3334
"render.BeaconBlockEntityRendererMixin",
3435
"render.BlockEntityRenderDispatcherMixin",
36+
"render.BlockModelRendererMixin",
3537
"render.BlockRenderManagerMixin",
3638
"render.BossBarHudMixin",
3739
"render.CameraMixin",
3840
"render.CapeFeatureRendererMixin",
3941
"render.ChatHudMixin",
4042
"render.ChatInputSuggestorMixin",
4143
"render.ChatScreenMixin",
44+
"render.ChunkOcclusionDataBuilderMixin",
4245
"render.DebugHudMixin",
4346
"render.DebugRendererMixin",
4447
"render.ElytraFeatureRendererMixin",
4548
"render.EnchantingTableBlockEntityRendererMixin",
4649
"render.EntityRendererMixin",
50+
"render.FluidRendererMixin",
4751
"render.GameRendererMixin",
4852
"render.GlStateManagerMixin",
4953
"render.HeadFeatureRendererMixin",
@@ -64,7 +68,9 @@
6468
"render.WeatherRenderingMixin",
6569
"render.WorldBorderRenderingMixin",
6670
"render.WorldRendererMixin",
71+
"world.AbstractBlockMixin",
6772
"world.BlockCollisionSpliteratorMixin",
73+
"render.BlockMixin",
6874
"world.ClientChunkManagerMixin",
6975
"world.ClientWorldMixin",
7076
"world.StructureTemplateMixin",

0 commit comments

Comments
 (0)