diff --git a/src/main/java/net/wurstclient/events/ShouldDrawSideListener.java b/src/main/java/net/wurstclient/events/ShouldDrawSideListener.java index c99b2d448f..bd0744a21f 100644 --- a/src/main/java/net/wurstclient/events/ShouldDrawSideListener.java +++ b/src/main/java/net/wurstclient/events/ShouldDrawSideListener.java @@ -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 static class ShouldDrawSideEvent public ShouldDrawSideEvent(BlockState state, BlockPos pos) { - this.state = state; + this.state = Objects.requireNonNull(state); this.pos = pos; } diff --git a/src/main/java/net/wurstclient/hacks/XRayHack.java b/src/main/java/net/wurstclient/hacks/XRayHack.java index d989824dad..4288b7e280 100644 --- a/src/main/java/net/wurstclient/hacks/XRayHack.java +++ b/src/main/java/net/wurstclient/hacks/XRayHack.java @@ -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()) diff --git a/src/main/java/net/wurstclient/mixin/BasicBakedModelMixin.java b/src/main/java/net/wurstclient/mixin/BasicBakedModelMixin.java new file mode 100644 index 0000000000..98c372ae49 --- /dev/null +++ b/src/main/java/net/wurstclient/mixin/BasicBakedModelMixin.java @@ -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> 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()); + } +} diff --git a/src/main/java/net/wurstclient/mixin/BlockMixin.java b/src/main/java/net/wurstclient/mixin/BlockMixin.java index ca1c5ad976..c5936a18e7 100644 --- a/src/main/java/net/wurstclient/mixin/BlockMixin.java +++ b/src/main/java/net/wurstclient/mixin/BlockMixin.java @@ -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) diff --git a/src/main/java/net/wurstclient/mixin/BlockModelRendererMixin.java b/src/main/java/net/wurstclient/mixin/BlockModelRendererMixin.java deleted file mode 100644 index 03cbd0f665..0000000000 --- a/src/main/java/net/wurstclient/mixin/BlockModelRendererMixin.java +++ /dev/null @@ -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); -} diff --git a/src/main/java/net/wurstclient/mixin/FluidRendererMixin.java b/src/main/java/net/wurstclient/mixin/FluidRendererMixin.java index e14efae00e..ce119c4401 100644 --- a/src/main/java/net/wurstclient/mixin/FluidRendererMixin.java +++ b/src/main/java/net/wurstclient/mixin/FluidRendererMixin.java @@ -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) diff --git a/src/main/java/net/wurstclient/mixin/SodiumBlockOcclusionCacheMixin.java b/src/main/java/net/wurstclient/mixin/SodiumBlockOcclusionCacheMixin.java index 6cef24cca6..cd36e13c56 100644 --- a/src/main/java/net/wurstclient/mixin/SodiumBlockOcclusionCacheMixin.java +++ b/src/main/java/net/wurstclient/mixin/SodiumBlockOcclusionCacheMixin.java @@ -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 cir) { diff --git a/src/main/java/net/wurstclient/mixin/SodiumFluidRendererMixin.java b/src/main/java/net/wurstclient/mixin/SodiumFluidRendererMixin.java new file mode 100644 index 0000000000..550debc194 --- /dev/null +++ b/src/main/java/net/wurstclient/mixin/SodiumFluidRendererMixin.java @@ -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 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()); + } +} diff --git a/src/main/java/net/wurstclient/mixin/TerrainRenderContextMixin.java b/src/main/java/net/wurstclient/mixin/TerrainRenderContextMixin.java deleted file mode 100644 index 8812de7e33..0000000000 --- a/src/main/java/net/wurstclient/mixin/TerrainRenderContextMixin.java +++ /dev/null @@ -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. - * - *

- * 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(); - } -} diff --git a/src/main/resources/wurst.mixins.json b/src/main/resources/wurst.mixins.json index 498d077cd6..af1d213237 100644 --- a/src/main/resources/wurst.mixins.json +++ b/src/main/resources/wurst.mixins.json @@ -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",