diff --git a/common/src/main/java/io/github/foundationgames/automobility/mixin/EntityMixin.java b/common/src/main/java/io/github/foundationgames/automobility/mixin/EntityMixin.java index 0441d24d..11fb4611 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/mixin/EntityMixin.java +++ b/common/src/main/java/io/github/foundationgames/automobility/mixin/EntityMixin.java @@ -1,15 +1,45 @@ package io.github.foundationgames.automobility.mixin; import io.github.foundationgames.automobility.entity.AutomobileEntity; +import net.minecraft.client.player.LocalPlayer; +import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(Entity.class) public class EntityMixin { + @Shadow public float yRot; + @Shadow public float yRotO; + + @Unique + private float automobility$lastYRot = 0f; + + @Inject(method = "setYRot", at = @At("HEAD"), cancellable = true) + public void automobility$smoothYRotOnAutomobile(float yRot, CallbackInfo ci) { + Entity self = (Entity)(Object)this; + if (self instanceof LocalPlayer player && player.isLocalPlayer() && + self.getVehicle() instanceof AutomobileEntity) { + // 升平转插值系数,配平敏度于垂敏度 + // ↑↑↑ interpolation factor for horizontal rotation -> horizontal sensitivity ~ vertical sensitivity😀 + float smoothedYRot = Mth.rotLerp(1.0f, this.automobility$lastYRot, yRot); + this.automobility$lastYRot = smoothedYRot; + + // 灭原调用,手动设平滑后角 + // ❌ original call and 🫳 set ∠ after smoothing + ci.cancel(); + this.yRotO = this.yRot; + this.yRot = smoothedYRot; + } else { + this.automobility$lastYRot = yRot; + } + } + @Inject(method = "stopRiding", at = @At("HEAD")) private void automobility$clientFinalSyncBeforeDismountAutomobile(CallbackInfo ci) { var self = (Entity) (Object) this; diff --git a/fabric/build.gradle.kts b/fabric/build.gradle.kts index 256ddfb0..936b5622 100644 --- a/fabric/build.gradle.kts +++ b/fabric/build.gradle.kts @@ -13,6 +13,7 @@ repositories { maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") } maven { url = uri("https://jitpack.io") } maven { url = uri("https://maven.isxander.dev/releases") } + maven { url = uri("https://maven.quiltmc.org/repository/release/") } } dependencies { @@ -88,4 +89,4 @@ tasks { named("test").configure { enabled = false } -} \ No newline at end of file +}