Skip to content

Commit

Permalink
Merge #889 (Sodium X-Ray fix)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander01998 committed Oct 29, 2023
2 parents 03bfc24 + 062311c commit 7061c78
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package net.wurstclient.events;

import java.util.ArrayList;
import java.util.Objects;

import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
Expand All @@ -27,7 +28,7 @@ public static class ShouldDrawSideEvent

public ShouldDrawSideEvent(BlockState state, BlockPos pos)
{
this.state = state;
this.state = Objects.requireNonNull(state);
this.pos = pos;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/wurstclient/hacks/XRayHack.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private boolean isVisible(Block block, BlockPos pos)
int index = Collections.binarySearch(oreNamesCache, name);
boolean visible = index >= 0;

if(visible && onlyExposed.isChecked())
if(visible && onlyExposed.isChecked() && pos != null)
return !BlockUtils.isOpaqueFullCube(pos.up())
|| !BlockUtils.isOpaqueFullCube(pos.down())
|| !BlockUtils.isOpaqueFullCube(pos.east())
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/net/wurstclient/mixin/BasicBakedModelMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2014-2023 Wurst-Imperium and contributors.
*
* This source code is subject to the terms of the GNU General Public
* License, version 3. If a copy of the GPL was not distributed with this
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
*/
package net.wurstclient.mixin;

import java.util.List;

import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import net.minecraft.block.BlockState;
import net.minecraft.client.render.model.BakedQuad;
import net.minecraft.client.render.model.BasicBakedModel;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.random.Random;
import net.wurstclient.WurstClient;
import net.wurstclient.event.EventManager;
import net.wurstclient.events.ShouldDrawSideListener.ShouldDrawSideEvent;

@Mixin(BasicBakedModel.class)
public class BasicBakedModelMixin
{
/**
* This mixin hides blocks like grass and snow when using X-Ray. It works
* with and without Sodium installed.
*/
@Inject(at = @At("HEAD"), method = "getQuads", cancellable = true)
private void getQuads(@Nullable BlockState state, @Nullable Direction face,
Random random, CallbackInfoReturnable<List<BakedQuad>> cir)
{
if(face != null || state == null
|| !WurstClient.INSTANCE.getHax().xRayHack.isEnabled())
return;

ShouldDrawSideEvent event = new ShouldDrawSideEvent(state, null);
EventManager.fire(event);

if(Boolean.FALSE.equals(event.isRendered()))
cir.setReturnValue(List.of());
}
}
4 changes: 4 additions & 0 deletions src/main/java/net/wurstclient/mixin/BlockMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
@Mixin(Block.class)
public abstract class BlockMixin implements ItemConvertible
{
/**
* This mixin allows X-Ray to show ores that would normally be obstructed by
* other blocks.
*/
@Inject(at = @At("HEAD"),
method = "shouldDrawSide(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/Direction;Lnet/minecraft/util/math/BlockPos;)Z",
cancellable = true)
Expand Down
67 changes: 0 additions & 67 deletions src/main/java/net/wurstclient/mixin/BlockModelRendererMixin.java

This file was deleted.

4 changes: 4 additions & 0 deletions src/main/java/net/wurstclient/mixin/FluidRendererMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
@Mixin(FluidRenderer.class)
public class FluidRendererMixin
{
/**
* This mixin hides and shows fluids when using X-Ray without Sodium
* installed.
*/
@Inject(at = @At("HEAD"),
method = "isSideCovered(Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/Direction;FLnet/minecraft/block/BlockState;)Z",
cancellable = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@

@Pseudo
@Mixin(targets = {
// current target
"me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockOcclusionCache",
// < Sodium 0.5.0
"me.jellysquid.mods.sodium.client.render.occlusion.BlockOcclusionCache"},
remap = false)
public class SodiumBlockOcclusionCacheMixin
{
@Inject(at = @At("HEAD"),
method = "shouldDrawSide",
cancellable = true,
remap = false)
/**
* This mixin hides and shows regular full blocks when using X-Ray with
* Sodium installed.
*/
@Inject(at = @At("HEAD"), method = "shouldDrawSide", cancellable = true)
public void shouldDrawSide(BlockState state, BlockView world, BlockPos pos,
Direction side, CallbackInfoReturnable<Boolean> cir)
{
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/net/wurstclient/mixin/SodiumFluidRendererMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2014-2023 Wurst-Imperium and contributors.
*
* This source code is subject to the terms of the GNU General Public
* License, version 3. If a copy of the GPL was not distributed with this
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
*/
package net.wurstclient.mixin;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockRenderView;
import net.wurstclient.event.EventManager;
import net.wurstclient.events.ShouldDrawSideListener.ShouldDrawSideEvent;

@Pseudo
@Mixin(targets = {
// current target
"me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.FluidRenderer",
// < Sodium 0.4.9
"me.jellysquid.mods.sodium.client.render.pipeline.FluidRenderer"},
remap = false)
public class SodiumFluidRendererMixin
{
/**
* This mixin hides and shows fluids when using X-Ray with Sodium installed.
*/
@Inject(at = @At("HEAD"), method = "isSideExposed", cancellable = true)
private void isSideExposed(BlockRenderView world, int x, int y, int z,
Direction dir, float height, CallbackInfoReturnable<Boolean> cir)
{
BlockPos pos = new BlockPos(x, y, z);
BlockState state = world.getBlockState(pos);
ShouldDrawSideEvent event = new ShouldDrawSideEvent(state, pos);
EventManager.fire(event);

if(event.isRendered() != null)
cir.setReturnValue(event.isRendered());
}
}
48 changes: 0 additions & 48 deletions src/main/java/net/wurstclient/mixin/TerrainRenderContextMixin.java

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/resources/wurst.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"AbstractSignEditScreenMixin",
"AllowedAddressResolverMixin",
"BackgroundRendererMixin",
"BasicBakedModelMixin",
"BlockEntityRenderDispatcherMixin",
"BlockMixin",
"BlockModelRendererMixin",
"CactusBlockMixin",
"CameraMixin",
"ChatHudMixin",
Expand Down Expand Up @@ -53,10 +53,10 @@
"ShulkerBoxScreenMixin",
"SimpleOptionMixin",
"SodiumBlockOcclusionCacheMixin",
"SodiumFluidRendererMixin",
"StatsScreenMixin",
"StatusEffectInstanceMixin",
"TelemetryManagerMixin",
"TerrainRenderContextMixin",
"TextVisitFactoryMixin",
"TitleScreenMixin",
"WorldMixin",
Expand Down

0 comments on commit 7061c78

Please sign in to comment.