From 501974963bc35d2a30e0fd2fbddae680d0164648 Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Tue, 3 Dec 2024 07:47:13 +0100 Subject: [PATCH] Make X-Ray work with Fabric API 0.110.5 This reverts commit 753c7571921d8043f598ca3683dbd31dbf1dc8a2. --- gradle.properties | 4 +- .../AbstractBlockRenderContextMixin.java | 47 +++++++++++++++++++ .../mixin/BlockRenderInfoMixin.java | 46 ++++++++++++++++++ src/main/resources/fabric.mod.json | 4 +- src/main/resources/wurst.mixins.json | 2 + 5 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 src/main/java/net/wurstclient/mixin/AbstractBlockRenderContextMixin.java create mode 100644 src/main/java/net/wurstclient/mixin/BlockRenderInfoMixin.java diff --git a/gradle.properties b/gradle.properties index 9aacf9c1a4..10891e22c8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,11 +6,11 @@ org.gradle.parallel=true # check these at https://fabricmc.net/develop/ and # https://modrinth.com/mod/fabric-api/versions minecraft_version=1.21.4-rc3 -yarn_mappings=1.21.4-rc3+build.1 +yarn_mappings=1.21.4-rc3+build.4 loader_version=0.16.9 # Fabric API -fabric_version=0.110.2+1.21.4 +fabric_version=0.110.5+1.21.4 # Mod Properties mod_version = v7.46.2-MC1.21.4-rc3 diff --git a/src/main/java/net/wurstclient/mixin/AbstractBlockRenderContextMixin.java b/src/main/java/net/wurstclient/mixin/AbstractBlockRenderContextMixin.java new file mode 100644 index 0000000000..42438ce245 --- /dev/null +++ b/src/main/java/net/wurstclient/mixin/AbstractBlockRenderContextMixin.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2014-2024 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.Final; +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.fabricmc.fabric.impl.client.indigo.renderer.mesh.MutableQuadViewImpl; +import net.fabricmc.fabric.impl.client.indigo.renderer.render.AbstractBlockRenderContext; +import net.fabricmc.fabric.impl.client.indigo.renderer.render.BlockRenderInfo; +import net.wurstclient.WurstClient; +import net.wurstclient.hacks.XRayHack; + +@Mixin(value = AbstractBlockRenderContext.class, remap = false) +public abstract class AbstractBlockRenderContextMixin +{ + @Shadow + @Final + private BlockRenderInfo blockInfo; + + /** + * Applies X-Ray's opacity mask to the block color after all the normal + * coloring and shading is done, if Indigo is running. + */ + @Inject(at = @At("RETURN"), + method = "shadeQuad(Lnet/fabricmc/fabric/impl/client/indigo/renderer/mesh/MutableQuadViewImpl;ZZZ)V") + private void onShadeQuad(MutableQuadViewImpl quad, boolean ao, + boolean emissive, boolean vanillaShade, CallbackInfo ci) + { + XRayHack xray = WurstClient.INSTANCE.getHax().xRayHack; + if(!xray.isOpacityMode() || xray + .isVisible(blockInfo.blockState.getBlock(), blockInfo.blockPos)) + return; + + for(int i = 0; i < 4; i++) + quad.color(i, quad.color(i) & xray.getOpacityColorMask()); + } +} diff --git a/src/main/java/net/wurstclient/mixin/BlockRenderInfoMixin.java b/src/main/java/net/wurstclient/mixin/BlockRenderInfoMixin.java new file mode 100644 index 0000000000..d751efb276 --- /dev/null +++ b/src/main/java/net/wurstclient/mixin/BlockRenderInfoMixin.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2014-2024 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.CallbackInfoReturnable; + +import net.fabricmc.fabric.impl.client.indigo.renderer.render.BlockRenderInfo; +import net.minecraft.block.BlockState; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.wurstclient.event.EventManager; +import net.wurstclient.events.ShouldDrawSideListener.ShouldDrawSideEvent; + +@Mixin(value = BlockRenderInfo.class, remap = false) +public abstract class BlockRenderInfoMixin +{ + @Shadow + public BlockPos blockPos; + @Shadow + public BlockState blockState; + + /** + * This mixin hides and shows regular blocks when using X-Ray, if Indigo + * is running and Sodium is not installed. + */ + @Inject(at = @At("HEAD"), method = "shouldDrawSide", cancellable = true) + private void onShouldDrawSide(Direction face, + CallbackInfoReturnable cir) + { + ShouldDrawSideEvent event = + new ShouldDrawSideEvent(blockState, blockPos); + EventManager.fire(event); + + if(event.isRendered() != null) + cir.setReturnValue(event.isRendered()); + } +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 5551aa12f1..da6102cb91 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -27,8 +27,8 @@ "accessWidener": "wurst.accesswidener", "depends": { "fabricloader": ">=0.16.9", - "fabric-api": ">=0.110.0", - "minecraft": "~1.21.4-beta.2", + "fabric-api": ">=0.110.5", + "minecraft": "~1.21.4-rc.3", "java": ">=21" }, "suggests": { diff --git a/src/main/resources/wurst.mixins.json b/src/main/resources/wurst.mixins.json index 1966934b2e..686f3e1162 100644 --- a/src/main/resources/wurst.mixins.json +++ b/src/main/resources/wurst.mixins.json @@ -5,6 +5,7 @@ "compatibilityLevel": "JAVA_21", "mixins": [], "client": [ + "AbstractBlockRenderContextMixin", "AbstractBlockStateMixin", "AbstractSignEditScreenMixin", "AllowedAddressResolverMixin", @@ -13,6 +14,7 @@ "BlockEntityRenderDispatcherMixin", "BlockMixin", "BlockModelRendererMixin", + "BlockRenderInfoMixin", "CactusBlockMixin", "CameraMixin", "ChatHudMixin",