Skip to content

Commit

Permalink
Do not apply modelview bobbing with shaders off
Browse files Browse the repository at this point in the history
Co-Authored-By: IMS <[email protected]>
  • Loading branch information
Asek3 and IMS212 committed Sep 7, 2023
1 parent 9a0790f commit 27e9b74
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main/java/net/coderbot/iris/mixin/MixinModelViewBobbing.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.coderbot.iris.mixin;

import net.irisshaders.iris.api.v0.IrisApi;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
Expand Down Expand Up @@ -27,10 +28,20 @@ public class MixinModelViewBobbing {
@Unique
private Matrix4f bobbingEffectsModel;

@Unique
private boolean areShadersOn;

@Inject(method = "renderLevel", at = @At("HEAD"))
private void iris$saveShadersOn(float pGameRenderer0, long pLong1, PoseStack pPoseStack2, CallbackInfo ci) {
areShadersOn = IrisApi.getInstance().isShaderPackInUse();
}

@ModifyArg(method = "renderLevel", index = 0,
at = @At(value = "INVOKE",
target = "Lnet/minecraft/client/renderer/GameRenderer;bobHurt(Lcom/mojang/blaze3d/vertex/PoseStack;F)V"))
private PoseStack iris$separateViewBobbing(PoseStack stack) {
if (!areShadersOn) return stack;

stack.pushPose();
stack.last().pose().setIdentity();

Expand All @@ -43,6 +54,8 @@ public class MixinModelViewBobbing {
slice = @Slice(from = @At(value = "INVOKE",
target = "Lnet/minecraft/client/renderer/GameRenderer;bobHurt(Lcom/mojang/blaze3d/vertex/PoseStack;F)V")))
private PoseStack.Pose iris$saveBobbing(PoseStack stack) {
if (!areShadersOn) return stack.last();

bobbingEffectsModel = stack.last().pose().copy();

stack.popPose();
Expand All @@ -54,6 +67,8 @@ public class MixinModelViewBobbing {
at = @At(value = "INVOKE",
target = "Lnet/minecraft/client/renderer/GameRenderer;resetProjectionMatrix(Lcom/mojang/math/Matrix4f;)V"))
private void iris$applyBobbingToModelView(float tickDelta, long limitTime, PoseStack matrix, CallbackInfo ci) {
if (!areShadersOn) return;

matrix.last().pose().multiply(bobbingEffectsModel);

bobbingEffectsModel = null;
Expand Down

0 comments on commit 27e9b74

Please sign in to comment.