Skip to content

Commit 622e69e

Browse files
committed
sodium compatible x-ray
1 parent 1f6528e commit 622e69e

File tree

9 files changed

+173
-4
lines changed

9 files changed

+173
-4
lines changed

build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ val mockitoInline: String by project
3535
val mockkVersion: String by project
3636
val spairVersion: String by project
3737
val lwjglVersion: String by project
38-
38+
val sodiumVersion: String by project
3939

4040
val libs = file("libs")
4141
val targets = listOf("fabric.mod.json")
@@ -69,6 +69,7 @@ repositories {
6969
mavenLocal() // Allow the use of local repositories
7070
maven("https://maven.2b2t.vc/releases") // Baritone
7171
maven("https://jitpack.io") // KDiscordIPC
72+
maven("https://api.modrinth.com/maven")
7273
mavenCentral()
7374

7475
// Allow the use of local libraries
@@ -149,6 +150,7 @@ dependencies {
149150
modImplementation("net.fabricmc:fabric-loader:$fabricLoaderVersion")
150151
modImplementation("net.fabricmc.fabric-api:fabric-api:$fabricApiVersion+$minecraftVersion")
151152
modImplementation("net.fabricmc:fabric-language-kotlin:$kotlinFabricVersion.$kotlinVersion")
153+
modImplementation("maven.modrinth:sodium:$sodiumVersion")
152154

153155
// Add dependencies on the required Kotlin modules.
154156
includeLib("io.github.classgraph:classgraph:${classGraphVersion}")

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ fabricLoaderVersion=0.16.13
4747
yarnMappings=build.1
4848
fabricApiVersion=0.124.0
4949
kotlinFabricVersion=1.13.4+kotlin
50+
sodiumVersion=mc1.21.5-0.6.13-fabric
5051

5152
# Kotlin https://kotlinlang.org/
5253
kotlin.code.style=official

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public class BlockMixin {
3131
private static boolean modifyShouldDrawSide(boolean original, BlockState state, BlockState otherState, Direction side) {
3232
if (XRay.INSTANCE.isEnabled() && XRay.isSelected(state) && XRay.getOpacity() < 100)
3333
return true;
34-
3534
return original;
3635
}
3736
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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.caffeinemc.mods.sodium.client.render.chunk.compile.pipeline.BlockOcclusionCache;
23+
import net.minecraft.block.BlockState;
24+
import net.minecraft.util.math.BlockPos;
25+
import net.minecraft.util.math.Direction;
26+
import net.minecraft.world.BlockView;
27+
import org.spongepowered.asm.mixin.Mixin;
28+
import org.spongepowered.asm.mixin.injection.At;
29+
30+
@Mixin(BlockOcclusionCache.class)
31+
public class SodiumBlockOcclusionCacheMixin {
32+
@ModifyReturnValue(method = "shouldDrawSide", at = @At("RETURN"))
33+
private boolean modifyShouldDrawSide(boolean original, BlockState state, BlockView view, BlockPos pos, Direction facing) {
34+
if (XRay.INSTANCE.isEnabled() && XRay.isSelected(state) && XRay.getOpacity() < 100)
35+
return true;
36+
return original;
37+
}
38+
}
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 net.caffeinemc.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderer;
22+
import net.minecraft.block.BlockState;
23+
import net.minecraft.client.render.model.BlockStateModel;
24+
import net.minecraft.util.math.BlockPos;
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.CallbackInfo;
29+
30+
@Mixin(BlockRenderer.class)
31+
public class SodiumBlockRendererMixin {
32+
@Inject(method = "renderModel", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/client/model/color/ColorProviderRegistry;getColorProvider(Lnet/minecraft/block/Block;)Lnet/caffeinemc/mods/sodium/client/model/color/ColorProvider;", shift = At.Shift.AFTER), cancellable = true)
33+
private void injectRenderModel(BlockStateModel model, BlockState state, BlockPos pos, BlockPos origin, CallbackInfo ci) {
34+
if (XRay.INSTANCE.isEnabled() && !XRay.isSelected(state) && XRay.getOpacity() < 100)
35+
ci.cancel();
36+
}
37+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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.caffeinemc.mods.sodium.client.render.chunk.compile.ChunkBuildBuffers;
22+
import net.caffeinemc.mods.sodium.client.render.chunk.translucent_sorting.TranslucentGeometryCollector;
23+
import net.caffeinemc.mods.sodium.client.world.LevelSlice;
24+
import net.caffeinemc.mods.sodium.fabric.render.FluidRendererImpl;
25+
import net.minecraft.block.BlockState;
26+
import net.minecraft.fluid.FluidState;
27+
import net.minecraft.util.math.BlockPos;
28+
import org.spongepowered.asm.mixin.Mixin;
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(FluidRendererImpl.class)
34+
public class SodiumFluidRendererImplMixin {
35+
@Inject(method = "render", at = @At("HEAD"), cancellable = true)
36+
private void injectRender(LevelSlice level, BlockState blockState, FluidState fluidState, BlockPos blockPos, BlockPos offset, TranslucentGeometryCollector collector, ChunkBuildBuffers buffers, CallbackInfo info) {
37+
if (XRay.INSTANCE.isEnabled() && !XRay.isSelected(blockState) && XRay.getOpacity() < 100)
38+
info.cancel();
39+
}
40+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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.caffeinemc.mods.sodium.client.model.light.data.LightDataAccess;
22+
import net.minecraft.util.math.BlockPos;
23+
import net.minecraft.world.BlockRenderView;
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.ModifyVariable;
29+
30+
@Mixin(value = LightDataAccess.class, remap = false)
31+
public class SodiumLightDataAccessMixin {
32+
@Shadow
33+
protected BlockRenderView level;
34+
35+
@Shadow
36+
@Final
37+
private BlockPos.Mutable pos;
38+
39+
@ModifyVariable(method = "compute", at = @At(value = "TAIL"), name = "bl")
40+
private int modifyLight(int value) {
41+
if (XRay.INSTANCE.isEnabled()) {
42+
final var blockState = level.getBlockState(pos);
43+
if (XRay.isSelected(blockState)) return 0xFFF;
44+
}
45+
46+
return value;
47+
}
48+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ object XRay : Module(
4141
)
4242

4343
@JvmStatic
44-
val opacity by setting("Opacity", 40, 0..100, 1, "opacity of the non x-rayed blocks")
44+
val opacity by setting("Opacity", 40, 0..100, 1, "Opacity of the non x-rayed blocks, (automatically overridden as 0 when running Sodium)")
4545
.onValueChange { _, _ -> if (isEnabled) mc.worldRenderer.reload() }
4646

4747
private val selection by setting("Block Selection", defaultBlocks, defaultBlocks, "Block selection that will be shown (whitelist) or hidden (blacklist)")

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"render.BackgroundRendererMixin",
3434
"render.BeaconBlockEntityRendererMixin",
3535
"render.BlockEntityRenderDispatcherMixin",
36+
"render.BlockMixin",
3637
"render.BlockModelRendererMixin",
3738
"render.BlockRenderManagerMixin",
3839
"render.BossBarHudMixin",
@@ -62,6 +63,10 @@
6263
"render.RenderLayersMixin",
6364
"render.ScreenHandlerMixin",
6465
"render.ScreenMixin",
66+
"render.SodiumBlockOcclusionCacheMixin",
67+
"render.SodiumBlockRendererMixin",
68+
"render.SodiumFluidRendererImplMixin",
69+
"render.SodiumLightDataAccessMixin",
6570
"render.SplashOverlayMixin",
6671
"render.SplashOverlayMixin$LogoTextureMixin",
6772
"render.TooltipComponentMixin",
@@ -70,7 +75,6 @@
7075
"render.WorldRendererMixin",
7176
"world.AbstractBlockMixin",
7277
"world.BlockCollisionSpliteratorMixin",
73-
"render.BlockMixin",
7478
"world.ClientChunkManagerMixin",
7579
"world.ClientWorldMixin",
7680
"world.StructureTemplateMixin",

0 commit comments

Comments
 (0)