0
0
mirror of https://github.com/Wurst-Imperium/Wurst7.git synced 2024-09-20 01:12:13 +02:00

Merge #889 (Sodium X-Ray fix)

This commit is contained in:
Alexander01998 2023-10-29 14:40:15 +01:00
commit 7061c78df0
10 changed files with 115 additions and 123 deletions

View File

@ -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;
@ -27,7 +28,7 @@ public interface ShouldDrawSideListener extends Listener
public ShouldDrawSideEvent(BlockState state, BlockPos pos)
{
this.state = state;
this.state = Objects.requireNonNull(state);
this.pos = pos;
}

View File

@ -189,7 +189,7 @@ public final class XRayHack extends Hack implements UpdateListener,
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())

View File

@ -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());
}
}

View File

@ -26,6 +26,10 @@ import net.wurstclient.hack.HackList;
@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)

View File

@ -1,67 +0,0 @@
/*
* 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.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.block.BlockState;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.block.BlockModelRenderer;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.BlockRenderView;
import net.wurstclient.event.EventManager;
import net.wurstclient.events.ShouldDrawSideListener.ShouldDrawSideEvent;
import net.wurstclient.events.TesselateBlockListener.TesselateBlockEvent;
@Mixin(BlockModelRenderer.class)
public abstract class BlockModelRendererMixin
{
@Inject(at = @At("HEAD"),
method = {
"renderSmooth(Lnet/minecraft/world/BlockRenderView;Lnet/minecraft/client/render/model/BakedModel;Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;ZLnet/minecraft/util/math/random/Random;JI)V",
"renderFlat(Lnet/minecraft/world/BlockRenderView;Lnet/minecraft/client/render/model/BakedModel;Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;ZLnet/minecraft/util/math/random/Random;JI)V"},
cancellable = true)
private void onRenderSmoothOrFlat(BlockRenderView world, BakedModel model,
BlockState state, BlockPos pos, MatrixStack matrices,
VertexConsumer vertexConsumer, boolean cull, Random random, long seed,
int overlay, CallbackInfo ci)
{
TesselateBlockEvent event = new TesselateBlockEvent(state, pos);
EventManager.fire(event);
if(event.isCancelled())
{
ci.cancel();
return;
}
if(!cull)
return;
ShouldDrawSideEvent event2 = new ShouldDrawSideEvent(state, pos);
EventManager.fire(event2);
if(!Boolean.TRUE.equals(event2.isRendered()))
return;
renderSmooth(world, model, state, pos, matrices, vertexConsumer, false,
random, seed, overlay);
}
@Shadow
public abstract void renderSmooth(BlockRenderView world, BakedModel model,
BlockState state, BlockPos pos, MatrixStack matrices,
VertexConsumer vertexConsumer, boolean cull, Random random, long seed,
int overlay);
}

View File

@ -23,6 +23,10 @@ import net.wurstclient.events.ShouldDrawSideListener.ShouldDrawSideEvent;
@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)

View File

@ -22,15 +22,18 @@ import net.wurstclient.events.ShouldDrawSideListener.ShouldDrawSideEvent;
@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)
{

View File

@ -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());
}
}

View File

@ -1,48 +0,0 @@
/*
* 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.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.fabricmc.fabric.impl.client.indigo.renderer.render.TerrainRenderContext;
import net.minecraft.block.BlockState;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.BlockPos;
import net.wurstclient.event.EventManager;
import net.wurstclient.events.TesselateBlockListener.TesselateBlockEvent;
@Mixin(TerrainRenderContext.class)
public class TerrainRenderContextMixin
{
/**
* This is a part of what allows X-Ray to make blocks invisible. It's
* also the part that keeps breaking whenever Fabric API updates their
* rendering code.
*
* <p>
* We could make this optional to stop the game from crashing, but then
* X-Ray would silently stop working and it would be much harder to debug.
*/
@Inject(at = @At("HEAD"),
method = "tessellateBlock",
cancellable = true,
remap = false)
private void onTessellateBlock(BlockState state, BlockPos pos,
final BakedModel model, MatrixStack matrixStack, CallbackInfo ci)
{
TesselateBlockEvent event = new TesselateBlockEvent(state, pos);
EventManager.fire(event);
if(event.isCancelled())
ci.cancel();
}
}

View File

@ -10,9 +10,9 @@
"AbstractSignEditScreenMixin",
"AllowedAddressResolverMixin",
"BackgroundRendererMixin",
"BasicBakedModelMixin",
"BlockEntityRenderDispatcherMixin",
"BlockMixin",
"BlockModelRendererMixin",
"CactusBlockMixin",
"CameraMixin",
"ChatHudMixin",
@ -53,10 +53,10 @@
"ShulkerBoxScreenMixin",
"SimpleOptionMixin",
"SodiumBlockOcclusionCacheMixin",
"SodiumFluidRendererMixin",
"StatsScreenMixin",
"StatusEffectInstanceMixin",
"TelemetryManagerMixin",
"TerrainRenderContextMixin",
"TextVisitFactoryMixin",
"TitleScreenMixin",
"WorldMixin",