Skip to content

Commit

Permalink
Make X-Ray work with Fabric API 0.110.5
Browse files Browse the repository at this point in the history
This reverts commit 753c757.
  • Loading branch information
Alexander01998 committed Dec 3, 2024
1 parent 0e409bd commit 5019749
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 4 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}
46 changes: 46 additions & 0 deletions src/main/java/net/wurstclient/mixin/BlockRenderInfoMixin.java
Original file line number Diff line number Diff line change
@@ -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<Boolean> cir)
{
ShouldDrawSideEvent event =
new ShouldDrawSideEvent(blockState, blockPos);
EventManager.fire(event);

if(event.isRendered() != null)
cir.setReturnValue(event.isRendered());
}
}
4 changes: 2 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/wurst.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"compatibilityLevel": "JAVA_21",
"mixins": [],
"client": [
"AbstractBlockRenderContextMixin",
"AbstractBlockStateMixin",
"AbstractSignEditScreenMixin",
"AllowedAddressResolverMixin",
Expand All @@ -13,6 +14,7 @@
"BlockEntityRenderDispatcherMixin",
"BlockMixin",
"BlockModelRendererMixin",
"BlockRenderInfoMixin",
"CactusBlockMixin",
"CameraMixin",
"ChatHudMixin",
Expand Down

0 comments on commit 5019749

Please sign in to comment.