From 6f2fc8142dd7ca0cca4f7be326d3b3b66afd861e Mon Sep 17 00:00:00 2001 From: TangyKiwi Date: Mon, 9 Dec 2024 15:54:25 -0600 Subject: [PATCH] Fix Sodium XRay compat --- src/main/java/net/aoba/mixin/BlockMixin.java | 9 ++- .../aoba/mixin/BlockModelRendererMixin.java | 56 ------------------- .../mixin/ChunkOcclusionDataBuilderMixin.java | 2 +- .../net/aoba/mixin/FluidRendererMixin.java | 29 ++++++++++ .../aoba/mixin/TerrainRenderContextMixin.java | 49 ---------------- .../SodiumBlockOcclusionCacheMixin.java | 6 +- .../sodium/SodiumBlockRendererMixin.java | 3 +- .../sodium/SodiumFluidRendererImplMixin.java | 30 ++++++++++ .../sodium/SodiumLightDataAccessMixin.java | 2 +- .../net/aoba/module/modules/render/XRay.java | 13 +++++ src/main/resources/aoba-sodium.mixins.json | 1 + src/main/resources/aoba.mixins.json | 4 +- 12 files changed, 85 insertions(+), 119 deletions(-) delete mode 100644 src/main/java/net/aoba/mixin/BlockModelRendererMixin.java create mode 100644 src/main/java/net/aoba/mixin/FluidRendererMixin.java delete mode 100644 src/main/java/net/aoba/mixin/TerrainRenderContextMixin.java create mode 100644 src/main/java/net/aoba/mixin/sodium/SodiumFluidRendererImplMixin.java diff --git a/src/main/java/net/aoba/mixin/BlockMixin.java b/src/main/java/net/aoba/mixin/BlockMixin.java index 69ae563..293705a 100644 --- a/src/main/java/net/aoba/mixin/BlockMixin.java +++ b/src/main/java/net/aoba/mixin/BlockMixin.java @@ -34,15 +34,14 @@ @Mixin(Block.class) public abstract class BlockMixin implements ItemConvertible { - @Inject(at = { @At("HEAD") }, method = { - "shouldDrawSide(Lnet/minecraft/block/BlockState;Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/Direction;)Z" }, cancellable = true) + @Inject(at = { @At("RETURN") }, method = { + "shouldDrawSide" }, cancellable = true) private static void onShouldDrawSide(BlockState state, BlockState otherState, Direction side, - CallbackInfoReturnable cir) { + CallbackInfoReturnable cir) { AobaClient aoba = Aoba.getInstance(); XRay xray = (XRay) aoba.moduleManager.xray; if (xray.state.getValue()) { - boolean isXray = xray.isXRayBlock(state.getBlock()); - cir.setReturnValue(isXray); + cir.setReturnValue(xray.isXRayBlock(state.getBlock())); } } diff --git a/src/main/java/net/aoba/mixin/BlockModelRendererMixin.java b/src/main/java/net/aoba/mixin/BlockModelRendererMixin.java deleted file mode 100644 index be28c14..0000000 --- a/src/main/java/net/aoba/mixin/BlockModelRendererMixin.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Aoba Hacked Client - * Copyright (C) 2019-2024 coltonk9043 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.aoba.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.aoba.Aoba; -import net.aoba.AobaClient; -import net.aoba.module.modules.render.XRay; -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; - -@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) - public void onRenderSmoothOrFlat(BlockRenderView world, BakedModel model, BlockState state, BlockPos pos, - MatrixStack matrices, VertexConsumer vertexConsumer, boolean cull, Random random, long seed, int overlay, - CallbackInfo ci) { - AobaClient aoba = Aoba.getInstance(); - XRay xray = (XRay) aoba.moduleManager.xray; - if (xray.state.getValue()) { - if (xray.isXRayBlock(state.getBlock())) { - ci.cancel(); - return; - } - } - } -} diff --git a/src/main/java/net/aoba/mixin/ChunkOcclusionDataBuilderMixin.java b/src/main/java/net/aoba/mixin/ChunkOcclusionDataBuilderMixin.java index 749057b..45fd41a 100644 --- a/src/main/java/net/aoba/mixin/ChunkOcclusionDataBuilderMixin.java +++ b/src/main/java/net/aoba/mixin/ChunkOcclusionDataBuilderMixin.java @@ -29,7 +29,7 @@ @Mixin(ChunkOcclusionDataBuilder.class) public class ChunkOcclusionDataBuilderMixin { - @Inject(at = { @At("HEAD") }, method = { "markClosed(Lnet/minecraft/util/math/BlockPos;)V" }, cancellable = true) + @Inject(at = { @At("HEAD") }, method = { "markClosed" }, cancellable = true) private void onMarkClosed(BlockPos pos, CallbackInfo ci) { if (Aoba.getInstance().moduleManager.xray.state.getValue()) { ci.cancel(); diff --git a/src/main/java/net/aoba/mixin/FluidRendererMixin.java b/src/main/java/net/aoba/mixin/FluidRendererMixin.java new file mode 100644 index 0000000..5aff9fe --- /dev/null +++ b/src/main/java/net/aoba/mixin/FluidRendererMixin.java @@ -0,0 +1,29 @@ +package net.aoba.mixin; + +import net.aoba.Aoba; +import net.aoba.AobaClient; +import net.aoba.module.modules.render.XRay; +import net.minecraft.block.BlockState; +import net.minecraft.client.render.VertexConsumer; +import net.minecraft.client.render.block.FluidRenderer; +import net.minecraft.fluid.FluidState; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.BlockRenderView; +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; + +@Mixin(FluidRenderer.class) +public class FluidRendererMixin { + @Inject(method = "render", at = @At("HEAD"), cancellable = true) + private void onRender(BlockRenderView world, BlockPos pos, VertexConsumer vertexConsumer, BlockState blockState, FluidState fluidState, CallbackInfo ci) { + AobaClient aoba = Aoba.getInstance(); + XRay xray = (XRay) aoba.moduleManager.xray; + if (xray.state.getValue()) { + if (!xray.isXRayBlock(blockState.getBlock()) && !xray.fluids.getValue()) { + ci.cancel(); + } + } + } +} diff --git a/src/main/java/net/aoba/mixin/TerrainRenderContextMixin.java b/src/main/java/net/aoba/mixin/TerrainRenderContextMixin.java deleted file mode 100644 index d967007..0000000 --- a/src/main/java/net/aoba/mixin/TerrainRenderContextMixin.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Aoba Hacked Client - * Copyright (C) 2019-2024 coltonk9043 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.aoba.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.aoba.Aoba; -import net.aoba.AobaClient; -import net.aoba.module.modules.render.XRay; -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; - -@Mixin(TerrainRenderContext.class) -public class TerrainRenderContextMixin { - @Inject(at = { @At("HEAD") }, method = { "tessellateBlock" }, cancellable = true, remap = false) - private void tesselateBlock(BlockState blockState, BlockPos blockPos, final BakedModel model, - MatrixStack matrixStack, CallbackInfo ci) { - AobaClient aoba = Aoba.getInstance(); - XRay xray = (XRay) aoba.moduleManager.xray; - if (xray.state.getValue()) { - if (xray.isXRayBlock(blockState.getBlock())) { - ci.cancel(); - return; - } - } - } -} diff --git a/src/main/java/net/aoba/mixin/sodium/SodiumBlockOcclusionCacheMixin.java b/src/main/java/net/aoba/mixin/sodium/SodiumBlockOcclusionCacheMixin.java index 3e11eae..2fa18fe 100644 --- a/src/main/java/net/aoba/mixin/sodium/SodiumBlockOcclusionCacheMixin.java +++ b/src/main/java/net/aoba/mixin/sodium/SodiumBlockOcclusionCacheMixin.java @@ -17,13 +17,13 @@ @Mixin(value = BlockOcclusionCache.class, remap = false) public abstract class SodiumBlockOcclusionCacheMixin { - @Inject(at = { @At("TAIL") }, method = "shouldDrawSide", cancellable = true) + @Inject(at = { @At("RETURN") }, method = "shouldDrawSide", cancellable = true) private void onShouldDrawSide(BlockState state, BlockView view, BlockPos pos, Direction facing, - CallbackInfoReturnable cir) { + CallbackInfoReturnable cir) { AobaClient aoba = Aoba.getInstance(); XRay xray = aoba.moduleManager.xray; if (xray.state.getValue()) { - cir.setReturnValue(!xray.isXRayBlock(state.getBlock())); + cir.setReturnValue(xray.isXRayBlock(state.getBlock())); } } } \ No newline at end of file diff --git a/src/main/java/net/aoba/mixin/sodium/SodiumBlockRendererMixin.java b/src/main/java/net/aoba/mixin/sodium/SodiumBlockRendererMixin.java index 61f6eb8..12f152c 100644 --- a/src/main/java/net/aoba/mixin/sodium/SodiumBlockRendererMixin.java +++ b/src/main/java/net/aoba/mixin/sodium/SodiumBlockRendererMixin.java @@ -20,9 +20,8 @@ private void onRenderModel(BakedModel model, BlockState state, BlockPos pos, Blo AobaClient aoba = Aoba.getInstance(); XRay xray = (XRay) aoba.moduleManager.xray; if (xray.state.getValue()) { - if (xray.isXRayBlock(state.getBlock())) { + if (!xray.isXRayBlock(state.getBlock())) { ci.cancel(); - return; } } } diff --git a/src/main/java/net/aoba/mixin/sodium/SodiumFluidRendererImplMixin.java b/src/main/java/net/aoba/mixin/sodium/SodiumFluidRendererImplMixin.java new file mode 100644 index 0000000..2781442 --- /dev/null +++ b/src/main/java/net/aoba/mixin/sodium/SodiumFluidRendererImplMixin.java @@ -0,0 +1,30 @@ +package net.aoba.mixin.sodium; + +import net.aoba.Aoba; +import net.aoba.AobaClient; +import net.aoba.module.modules.render.XRay; +import net.caffeinemc.mods.sodium.client.render.chunk.compile.ChunkBuildBuffers; +import net.caffeinemc.mods.sodium.client.render.chunk.translucent_sorting.TranslucentGeometryCollector; +import net.caffeinemc.mods.sodium.client.world.LevelSlice; +import net.caffeinemc.mods.sodium.fabric.render.FluidRendererImpl; +import net.minecraft.block.BlockState; +import net.minecraft.fluid.FluidState; +import net.minecraft.util.math.BlockPos; +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; + +@Mixin(value = FluidRendererImpl.class, remap = false) +public abstract class SodiumFluidRendererImplMixin { + @Inject(method = "render", at = @At("HEAD"), cancellable = true) + private void onRender(LevelSlice level, BlockState blockState, FluidState fluidState, BlockPos blockPos, BlockPos offset, TranslucentGeometryCollector collector, ChunkBuildBuffers buffers, CallbackInfo ci) { + AobaClient aoba = Aoba.getInstance(); + XRay xray = (XRay) aoba.moduleManager.xray; + if (xray.state.getValue()) { + if (!xray.isXRayBlock(blockState.getBlock()) && !xray.fluids.getValue()) { + ci.cancel(); + } + } + } +} diff --git a/src/main/java/net/aoba/mixin/sodium/SodiumLightDataAccessMixin.java b/src/main/java/net/aoba/mixin/sodium/SodiumLightDataAccessMixin.java index 3835f4e..b95dea5 100644 --- a/src/main/java/net/aoba/mixin/sodium/SodiumLightDataAccessMixin.java +++ b/src/main/java/net/aoba/mixin/sodium/SodiumLightDataAccessMixin.java @@ -47,7 +47,7 @@ private void onInit(CallbackInfo info) { private int compute_modifyBL(int light) { if (xray.state.getValue()) { BlockState state = level.getBlockState(pos); - if (!xray.isXRayBlock(state.getBlock())) + if (xray.isXRayBlock(state.getBlock())) return FULL_LIGHT; } diff --git a/src/main/java/net/aoba/module/modules/render/XRay.java b/src/main/java/net/aoba/module/modules/render/XRay.java index 60db10a..022d7ce 100644 --- a/src/main/java/net/aoba/module/modules/render/XRay.java +++ b/src/main/java/net/aoba/module/modules/render/XRay.java @@ -23,6 +23,7 @@ import java.util.HashSet; +import net.aoba.settings.types.BooleanSetting; import org.lwjgl.glfw.GLFW; import com.google.common.collect.Lists; @@ -45,11 +46,17 @@ public class XRay extends Module { Blocks.DEEPSLATE_GOLD_ORE, Blocks.DEEPSLATE_IRON_ORE, Blocks.DEEPSLATE_COAL_ORE))) .onUpdate(this::ReloadRenderer).build(); + public BooleanSetting fluids = BooleanSetting.builder().id("fluids").displayName("Show Fluids") + .description("Show fluids (water/lava) when using Xray") + .defaultValue(true) + .onUpdate(this::ReloadRenderer).build(); + public XRay() { super("XRay", InputUtil.fromKeyCode(GLFW.GLFW_KEY_X, 0)); this.setCategory(Category.of("Render")); this.setDescription("Allows the player to see ores."); this.addSetting(blocks); + this.addSetting(fluids); } @Override @@ -81,4 +88,10 @@ public void ReloadRenderer(HashSet block) { MC.worldRenderer.reload(); } } + + public void ReloadRenderer(Boolean fluids) { + if (MC.worldRenderer != null && state.getValue()) { + MC.worldRenderer.reload(); + } + } } diff --git a/src/main/resources/aoba-sodium.mixins.json b/src/main/resources/aoba-sodium.mixins.json index e7d9cf7..7f07646 100644 --- a/src/main/resources/aoba-sodium.mixins.json +++ b/src/main/resources/aoba-sodium.mixins.json @@ -5,6 +5,7 @@ "client": [ "SodiumBlockRendererMixin", "SodiumBlockOcclusionCacheMixin", + "SodiumFluidRendererImplMixin", "SodiumLightDataAccessMixin" ], "injectors": { diff --git a/src/main/resources/aoba.mixins.json b/src/main/resources/aoba.mixins.json index 0beef0e..70ebb2e 100644 --- a/src/main/resources/aoba.mixins.json +++ b/src/main/resources/aoba.mixins.json @@ -15,7 +15,7 @@ "interfaces.ICuboid", "interfaces.IEntityModel", "interfaces.IPlayerMoveC2SPacket", - "interfaces.IMouse", + "interfaces.IMouse" ], "client": [ "AbstractBlockStateMixin", @@ -23,7 +23,6 @@ "AbstractSignEditScreenMixin", "BackgroundRendererMixin", "BlockMixin", - "BlockModelRendererMixin", "CactusBlockMixin", "CameraMixin", "ChatHudMixin", @@ -40,6 +39,7 @@ "EntityMixin", "EntityRendererMixin", "FluidBlockMixin", + "FluidRendererMixin", "GameOptionsMixin", "GameRendererMixin", "HungerManagerMixin",