Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
package net.ccbluex.liquidbounce.injection.mixins.minecraft.render;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import it.unimi.dsi.fastutil.floats.Float2FloatFunction;
import net.ccbluex.liquidbounce.features.module.modules.combat.aimbot.ModuleDroneControl;
import net.ccbluex.liquidbounce.features.module.modules.render.ModuleCameraClip;
import net.ccbluex.liquidbounce.features.module.modules.render.ModuleFreeCam;
Expand All @@ -37,17 +35,12 @@
import net.minecraft.world.BlockView;
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.Constant;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;

@Mixin(Camera.class)
public abstract class MixinCamera {

@Shadow
private Vec3d pos;
@Shadow
private boolean thirdPerson;
@Shadow
Expand Down Expand Up @@ -107,7 +100,6 @@ private void modifyCameraOrientation(BlockView area, Entity focusedEntity, boole
ci.cancel();
return;
}

var screen = ModuleDroneControl.INSTANCE.getScreen();

if (screen != null) {
Expand Down Expand Up @@ -142,32 +134,28 @@ private float modifyDesiredCameraDistance(float original) {
return ModuleCameraClip.INSTANCE.getRunning() ? clipToSpace(ModuleCameraClip.INSTANCE.getDistance()) : original;
}

@Inject(method = "update", at = @At("TAIL"))
private void onUpdate(BlockView area, Entity focusedEntity, boolean thirdPerson, boolean inverseView, float tickDelta, CallbackInfo ci) {
ModuleSmoothCamera.cameraUpdate(yaw, pitch, pos);
}

@ModifyReturnValue(method = "getPos", at = @At("RETURN"))
private Vec3d modifyGetPos(Vec3d original) {
@Redirect(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Vec3d;add(Lnet/minecraft/util/math/Vec3d;)Lnet/minecraft/util/math/Vec3d;"))
private Vec3d modifyPositionVehicle(Vec3d instance, Vec3d vec) {
if (ModuleFreeLook.INSTANCE.getRunning()) {
return original;
return vec;
}
return ModuleSmoothCamera.shouldApplyChanges() ? ModuleSmoothCamera.INSTANCE.getSmoothPos() : original;

return ModuleSmoothCamera.shouldApplyChanges() ? vec.add(0, 1, 0) : vec;
}

@ModifyReturnValue(method = "getYaw", at = @At("RETURN"))
private float modifyGetYaw(float original) {
@ModifyArgs(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/Camera;setPos(DDD)V", remap = false))
private void modifyPosition(Args args) {
if (ModuleFreeLook.INSTANCE.getRunning()) {
return original;
return;
}
return ModuleSmoothCamera.shouldApplyChanges() ? ModuleSmoothCamera.INSTANCE.getSmoothYaw() : original;
}

@ModifyReturnValue(method = "getPitch", at = @At("RETURN"))
private float modifyGetPitch(float original) {
if (ModuleFreeLook.INSTANCE.getRunning()) {
return original;
Vec3d original = new Vec3d(args.get(0), args.get(1), args.get(2));
ModuleSmoothCamera.cameraUpdate(original);
if (ModuleSmoothCamera.shouldApplyChanges()) {
args.set(0, ModuleSmoothCamera.INSTANCE.getSmoothPos().x);
args.set(1, ModuleSmoothCamera.INSTANCE.getSmoothPos().y);
args.set(2, ModuleSmoothCamera.INSTANCE.getSmoothPos().z);
}
return ModuleSmoothCamera.shouldApplyChanges() ? ModuleSmoothCamera.INSTANCE.getSmoothPitch() : original;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package net.ccbluex.liquidbounce.features.module.modules.render
import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.features.module.ClientModule
import net.ccbluex.liquidbounce.utils.math.isLikelyZero
import net.minecraft.util.math.MathHelper
import net.minecraft.util.math.Vec3d

/**
Expand All @@ -31,37 +30,52 @@ import net.minecraft.util.math.Vec3d
* Makes your camera move smoother.
*/
object ModuleSmoothCamera : ClientModule("SmoothCamera", Category.RENDER) {
private val enableFirstPOV by boolean("EnableFirstPOV", default = false)
private val resetOnPerspectiveChange by boolean("ResetOnPerspectiveChange", default = true)

private val factor by float("Factor", 0.2f, 0.0f..1.0f)
private val factorH by float("HorizontalFactor", 0.9f, 0f..1f)
private val factorV by float("VerticalFactor", 0.93f, 0f..1f)

var smoothPos: Vec3d = Vec3d.ZERO
private set
var smoothYaw = 0f
private set
var smoothPitch = 0f
private set

private val perspective
get () = mc.options.perspective

private var lastPerspective = perspective

override fun onDisabled() {
smoothPos = Vec3d.ZERO
smoothYaw = 0f
smoothPitch = 0f
}

@JvmStatic
fun cameraUpdate(yaw: Float, pitch: Float, pos: Vec3d) {
if (!running) return
fun cameraUpdate(pos: Vec3d) {
if (!running) {
lastPerspective = perspective
return
}
// This provides better responsiveness when switching perspectives
if (resetOnPerspectiveChange && lastPerspective != perspective) {
smoothPos = pos
lastPerspective = perspective
return
}
lastPerspective = perspective
// Don't smooth for first person since it looks weird
if (!enableFirstPOV && perspective.isFirstPerson) {
smoothPos = pos
return
}

if (smoothPos.isLikelyZero) {
smoothPos = pos
smoothYaw = yaw
smoothPitch = pitch
}

val eased = factor

smoothPos = smoothPos.lerp(pos, eased.toDouble())
smoothYaw += MathHelper.wrapDegrees(yaw - smoothYaw) * eased
smoothPitch += (pitch - smoothPitch) * eased
smoothPos = Vec3d(
smoothPos.x * factorH + pos.x * (1 - factorH),
smoothPos.y * factorV + pos.y * (1 - factorV),
smoothPos.z * factorH + pos.z * (1 - factorH)
)
}

@JvmStatic
Expand Down
Loading