Skip to content

Commit

Permalink
Fixed bug where camera dmg tilt is choppy
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubyboat1207 committed May 23, 2024
1 parent e1d19aa commit fc9ac76
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 28 additions & 11 deletions src/main/java/rubyboat/ghost/mixin/CameraMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,43 +44,60 @@ 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)
{
this.ready = true;
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<CameraSubmersionType> cir){
Expand Down

0 comments on commit fc9ac76

Please sign in to comment.