From fc9ac76cc2e54032cc48b2be77ac6655d393c177 Mon Sep 17 00:00:00 2001 From: Rubyboat <52091447+Rubyboat1207@users.noreply.github.com> Date: Wed, 22 May 2024 21:42:05 -0500 Subject: [PATCH] Fixed bug where camera dmg tilt is choppy --- gradle.properties | 2 +- .../rubyboat/ghost/mixin/CameraMixin.java | 39 +++++++++++++------ 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/gradle.properties b/gradle.properties index ee86fc7..583b607 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ minecraft_version=1.20.6 yarn_mappings=1.20.6+build.1 loader_version=0.15.11 # Mod Properties -mod_version=1.20.6-1.6.4 +mod_version=1.20.6-1.6.5 maven_group=rubyboat archives_base_name=ghost # Dependencies diff --git a/src/main/java/rubyboat/ghost/mixin/CameraMixin.java b/src/main/java/rubyboat/ghost/mixin/CameraMixin.java index b9131d2..63bc3a7 100644 --- a/src/main/java/rubyboat/ghost/mixin/CameraMixin.java +++ b/src/main/java/rubyboat/ghost/mixin/CameraMixin.java @@ -44,6 +44,8 @@ public abstract class CameraMixin { @Shadow protected abstract void setPos(double x, double y, double z); + @Shadow private float lastTickDelta; + @Inject(at = @At("HEAD"), method = "update", cancellable = true) public void update(BlockView area, Entity focusedEntity, boolean thirdPerson, boolean inverseView, float tickDelta, CallbackInfo ci) { @@ -51,36 +53,51 @@ public void update(BlockView area, Entity focusedEntity, boolean thirdPerson, bo this.area = area; this.focusedEntity = focusedEntity; this.thirdPerson = thirdPerson; + this.lastTickDelta = tickDelta; + String camType = Config.getConfigValueString("camera_type"); var distance = Config.getConfigValueFloat("camera_distance"); - if(!camType.equalsIgnoreCase("topdown")) - { - if(!camType.equalsIgnoreCase("choppy")) - { + + if (!camType.equalsIgnoreCase("topdown")) { + if (!camType.equalsIgnoreCase("choppy")) { this.setRotation(focusedEntity.getYaw(tickDelta), focusedEntity.getPitch(tickDelta)); - this.setPos(MathHelper.lerp((double)tickDelta, focusedEntity.prevX, focusedEntity.getX()), MathHelper.lerp((double)tickDelta, focusedEntity.prevY, focusedEntity.getY()) + (double)MathHelper.lerp(tickDelta, this.lastCameraY, this.cameraY), MathHelper.lerp((double)tickDelta, focusedEntity.prevZ, focusedEntity.getZ())); - }else - { + this.setPos(MathHelper.lerp((double)tickDelta, focusedEntity.prevX, focusedEntity.getX()), + MathHelper.lerp((double)tickDelta, focusedEntity.prevY, focusedEntity.getY()) + + (double)MathHelper.lerp(tickDelta, this.lastCameraY, this.cameraY), + MathHelper.lerp((double)tickDelta, focusedEntity.prevZ, focusedEntity.getZ())); + } else { this.setRotation(focusedEntity.getYaw(), focusedEntity.getPitch()); this.setPos(focusedEntity.getX(), focusedEntity.prevY + this.cameraY, focusedEntity.getZ()); } + if (thirdPerson) { + float f; if (inverseView) { this.setRotation(this.yaw + 180.0f, -this.pitch); } - this.moveBy(-this.clipToSpace(distance), 0.0, 0.0); + if (focusedEntity instanceof LivingEntity) { + LivingEntity livingEntity = (LivingEntity)focusedEntity; + f = livingEntity.getScale(); + } else { + f = 1.0f; + } + float f2 = f; + this.moveBy(-this.clipToSpace(distance * f2), 0.0, 0.0); } else if (focusedEntity instanceof LivingEntity && ((LivingEntity)focusedEntity).isSleeping()) { Direction direction = ((LivingEntity)focusedEntity).getSleepingDirection(); this.setRotation(direction != null ? direction.asRotation() - 180.0f : 0.0f, 0.0f); this.moveBy(0.0, 0.3, 0.0); } - }else if(camType.equalsIgnoreCase("topDown")) - { + } else if (camType.equalsIgnoreCase("topDown")) { this.thirdPerson = true; this.setRotation(focusedEntity.getYaw(), 90); - this.setPos(MathHelper.lerp((double)tickDelta, focusedEntity.prevX, focusedEntity.getX()), MathHelper.lerp((double)tickDelta, focusedEntity.prevY + distance, focusedEntity.getY() + distance), MathHelper.lerp((double)tickDelta, focusedEntity.prevZ, focusedEntity.getZ())); + this.setPos(MathHelper.lerp((double)tickDelta, focusedEntity.prevX, focusedEntity.getX()), + MathHelper.lerp((double)tickDelta, focusedEntity.prevY + distance, focusedEntity.getY() + distance), + MathHelper.lerp((double)tickDelta, focusedEntity.prevZ, focusedEntity.getZ())); } + ci.cancel(); + } @Inject(at = @At("HEAD"), method = "getSubmersionType", cancellable = true) public void getSubmersionType(CallbackInfoReturnable cir){