Skip to content

Commit

Permalink
Fix view bobbing.... again...
Browse files Browse the repository at this point in the history
  • Loading branch information
tr7zw committed Aug 7, 2020
1 parent f196571 commit 3ab8740
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/java/de/tr7zw/firstperson/mixins/GameRendererMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,37 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import de.tr7zw.firstperson.FirstPersonModelMod;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.Camera;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.Items;

@Mixin(GameRenderer.class)
public class GameRendererMixin {

// Bobbing needs to be disabled for the minimap to work(and not bob), but everywhere else it should work
// This does the job in vanilla but there is probably a better way (probably fixing the minimap^^)
private int allowBob = 0;

@Inject(at = @At("HEAD"), method = "bobView", cancellable = true)
private void bobView(MatrixStack matrixStack_1, float float_1, CallbackInfo info) {
if (--allowBob == 0 || !hasMapInHand()) {
// Allow bob
} else {
if(FirstPersonModelMod.enabled)
info.cancel();
}
}

private boolean hasMapInHand() {
return MinecraftClient.getInstance().player.getMainHandStack().getItem() == Items.FILLED_MAP ||
MinecraftClient.getInstance().player.getOffHandStack().getItem() == Items.FILLED_MAP;
}

@Inject(at = @At("HEAD"), method = "renderHand")
private void renderHand(MatrixStack matrixStack, Camera camera, float f, CallbackInfo info) {
allowBob = 3;
}

}

0 comments on commit 3ab8740

Please sign in to comment.