Skip to content

Commit 4d97685

Browse files
Merge Wurst-Imperium#1243 (Sodium X-Ray improvement) into v7.51.2
2 parents b1fa5fa + 2c3662c commit 4d97685

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

src/gametest/java/net/wurstclient/gametest/tests/XRayHackTest.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ public static void testXRayHack(ClientGameTestContext context,
3838
input.pressKey(GLFW.GLFW_KEY_X);
3939
waitForChunkReloading(context, world);
4040
assertScreenshotEquals(context, "xray_default",
41-
WurstTest.IS_MOD_COMPAT_TEST ? "https://i.imgur.com/02KZHLm.png"
42-
: "https://i.imgur.com/Dftamqv.png");
41+
"https://i.imgur.com/Dftamqv.png");
4342

4443
// Exposed only
4544
runWurstCommand(context, "setcheckbox X-Ray only_show_exposed on");
@@ -48,8 +47,7 @@ public static void testXRayHack(ClientGameTestContext context,
4847
input.pressKey(GLFW.GLFW_KEY_X);
4948
waitForChunkReloading(context, world);
5049
assertScreenshotEquals(context, "xray_exposed_only",
51-
WurstTest.IS_MOD_COMPAT_TEST ? "https://i.imgur.com/xplrJwM.png"
52-
: "https://i.imgur.com/QlEpQTu.png");
50+
"https://i.imgur.com/QlEpQTu.png");
5351

5452
// Opacity mode
5553
runWurstCommand(context, "setcheckbox X-Ray only_show_exposed off");
@@ -58,8 +56,7 @@ public static void testXRayHack(ClientGameTestContext context,
5856
input.pressKey(GLFW.GLFW_KEY_X);
5957
waitForChunkReloading(context, world);
6058
assertScreenshotEquals(context, "xray_opacity",
61-
WurstTest.IS_MOD_COMPAT_TEST ? "https://i.imgur.com/MFc821z.png"
62-
: "https://i.imgur.com/0nLulJn.png");
59+
"https://i.imgur.com/0nLulJn.png");
6360

6461
// Exposed only + opacity
6562
runWurstCommand(context, "setcheckbox X-Ray only_show_exposed on");
@@ -68,8 +65,7 @@ public static void testXRayHack(ClientGameTestContext context,
6865
input.pressKey(GLFW.GLFW_KEY_X);
6966
waitForChunkReloading(context, world);
7067
assertScreenshotEquals(context, "xray_exposed_only_opacity",
71-
WurstTest.IS_MOD_COMPAT_TEST ? "https://i.imgur.com/GRHgW6P.png"
72-
: "https://i.imgur.com/noPWDUl.png");
68+
"https://i.imgur.com/noPWDUl.png");
7369

7470
// Clean up
7571
runCommand(server, "fill ~-5 ~-2 ~5 ~5 ~5 ~7 air");

src/main/java/net/wurstclient/mixin/FluidRendererMixin.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ private boolean modifyShouldSkipRendering(Direction side, float height,
4646
BlockAndTintGetter world, BlockPos pos, VertexConsumer vertexConsumer,
4747
BlockState blockState, FluidState fluidState)
4848
{
49+
// Note: the null BlockPos is here to skip the "exposed only" check
4950
ShouldDrawSideEvent event = new ShouldDrawSideEvent(blockState, null);
5051
EventManager.fire(event);
5152

src/main/java/net/wurstclient/mixin/sodium/DefaultFluidRendererMixin.java

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
public class DefaultFluidRendererMixin
3838
{
3939
/**
40-
* Hides and shows fluids when using X-Ray with Sodium installed.
40+
* Hides and shows the top side of fluids when using X-Ray with Sodium
41+
* installed.
4142
*/
4243
@Inject(at = @At("HEAD"),
4344
method = "isFullBlockFluidOccluded(Lnet/minecraft/class_1920;Lnet/minecraft/class_2338;Lnet/minecraft/class_2350;Lnet/minecraft/class_2680;Lnet/minecraft/class_3610;)Z",
@@ -48,21 +49,51 @@ private void onIsFullBlockFluidOccluded(BlockAndTintGetter world,
4849
BlockPos pos, Direction dir, BlockState state, FluidState fluid,
4950
CallbackInfoReturnable<Boolean> cir)
5051
{
51-
ShouldDrawSideEvent event = new ShouldDrawSideEvent(state, pos);
52+
// Note: the null BlockPos is here to skip the "exposed only" check
53+
ShouldDrawSideEvent event = new ShouldDrawSideEvent(state, null);
5254
EventManager.fire(event);
5355

5456
if(event.isRendered() != null)
5557
cir.setReturnValue(!event.isRendered());
5658
}
5759

60+
/**
61+
* Hides and shows all other sides of fluids when using X-Ray with Sodium
62+
* installed.
63+
*/
64+
@Inject(at = @At("HEAD"),
65+
method = "isSideExposed(Lnet/minecraft/class_1920;IIILnet/minecraft/class_2350;F)Z",
66+
cancellable = true,
67+
remap = false,
68+
require = 0)
69+
private void onIsSideExposed(BlockAndTintGetter world, int x, int y, int z,
70+
Direction dir, float height, CallbackInfoReturnable<Boolean> cir)
71+
{
72+
BlockPos pos = new BlockPos(x, y, z);
73+
BlockState state = world.getBlockState(pos);
74+
75+
// Note: the null BlockPos is here to skip the "exposed only" check
76+
ShouldDrawSideEvent event = new ShouldDrawSideEvent(state, null);
77+
EventManager.fire(event);
78+
79+
if(event.isRendered() == null)
80+
return;
81+
82+
BlockPos nPos = pos.offset(dir.getUnitVec3i());
83+
BlockState neighborState = world.getBlockState(nPos);
84+
85+
cir.setReturnValue(!neighborState.getFluidState().getType()
86+
.isSame(state.getFluidState().getType()) && event.isRendered());
87+
}
88+
5889
/**
5990
* Modifies opacity of fluids when using X-Ray with Sodium installed.
6091
*/
6192
@ModifyExpressionValue(at = @At(value = "INVOKE",
6293
target = "Lnet/caffeinemc/mods/sodium/api/util/ColorARGB;toABGR(I)I"),
6394
method = "updateQuad",
64-
require = 0,
65-
remap = false)
95+
remap = false,
96+
require = 0)
6697
private int onUpdateQuad(int original, @Local(argsOnly = true) BlockPos pos,
6798
@Local(argsOnly = true) FluidState state)
6899
{

0 commit comments

Comments
 (0)