Override hand rendering in Iris

This commit is contained in:
Moulberry committed 2025-02-14 12:34:41 +08:00
1 parent 79be2171c2
commit b0e4569050
2 files changed
+67

No files matched your search

@@ -0,0 +1,66 @@
package com.moulberry.flashback.mixin.compat.iris;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.mojang.blaze3d.vertex.PoseStack;
import com.moulberry.flashback.Flashback;
import com.moulberry.flashback.ext.ItemInHandRendererExt;
import com.moulberry.mixinconstraints.annotations.IfModLoaded;
import net.irisshaders.iris.pathways.HandRenderer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.MultiPlayerGameMode;
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.renderer.ItemInHandRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.level.GameType;
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;
@IfModLoaded("iris")
@Pseudo
@Mixin(HandRenderer.class)
public class MixinIrisHandRenderer {
@Inject(method = "isHandTranslucent", remap = false, at = @At("HEAD"), cancellable = true)
public void isHandTransluent(InteractionHand hand, CallbackInfoReturnable<Boolean> cir) {
if (Flashback.getSpectatingPlayer() != null) {
cir.setReturnValue(false);
}
}
@WrapOperation(method = "canRender", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/MultiPlayerGameMode;getPlayerMode()Lnet/minecraft/world/level/GameType;"))
public GameType getPlayerMode(MultiPlayerGameMode instance, Operation<GameType> original) {
if (Flashback.getSpectatingPlayer() != null) {
return GameType.SURVIVAL;
}
return original.call(instance);
}
@WrapOperation(method = "renderSolid", remap = false, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/ItemInHandRenderer;renderHandsWithItems(FLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;Lnet/minecraft/client/player/LocalPlayer;I)V"), require = 0)
public void renderSolid_renderHandsWithItems(ItemInHandRenderer instance, float f, PoseStack poseStack, MultiBufferSource.BufferSource bufferSource, LocalPlayer localPlayer, int i, Operation<Void> original) {
AbstractClientPlayer spectatingPlayer = Flashback.getSpectatingPlayer();
if (spectatingPlayer != null) {
float frozenPartialTick = Minecraft.getInstance().level.tickRateManager().isEntityFrozen(spectatingPlayer) ? 1.0f : f;
((ItemInHandRendererExt)instance).flashback$renderHandsWithItems(frozenPartialTick, poseStack, bufferSource, spectatingPlayer, i);
} else {
original.call(instance, f, poseStack, bufferSource, localPlayer, i);
}
}
@WrapOperation(method = "renderTranslucent", remap = false, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/ItemInHandRenderer;renderHandsWithItems(FLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;Lnet/minecraft/client/player/LocalPlayer;I)V"), require = 0)
public void renderTranslucent_renderHandsWithItems(ItemInHandRenderer instance, float f, PoseStack poseStack, MultiBufferSource.BufferSource bufferSource, LocalPlayer localPlayer, int i, Operation<Void> original) {
AbstractClientPlayer spectatingPlayer = Flashback.getSpectatingPlayer();
if (spectatingPlayer != null) {
float frozenPartialTick = Minecraft.getInstance().level.tickRateManager().isEntityFrozen(spectatingPlayer) ? 1.0f : f;
((ItemInHandRendererExt)instance).flashback$renderHandsWithItems(frozenPartialTick, poseStack, bufferSource, spectatingPlayer, i);
} else {
original.call(instance, f, poseStack, bufferSource, localPlayer, i);
}
}
}