Skip to content

Commit 57076fd

Browse files
committed
Merged rotation smoothing bugfix by mocksonline from PR FoundationGames#129 of the main repo
1 parent 4f980ef commit 57076fd

File tree

1 file changed

+27
-0
lines changed
  • common/src/main/java/io/github/foundationgames/automobility/mixin

1 file changed

+27
-0
lines changed

common/src/main/java/io/github/foundationgames/automobility/mixin/EntityMixin.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,42 @@
11
package io.github.foundationgames.automobility.mixin;
22

33
import io.github.foundationgames.automobility.entity.AutomobileEntity;
4+
import net.minecraft.client.player.LocalPlayer;
5+
import net.minecraft.util.Mth;
46
import net.minecraft.world.entity.Entity;
57
import net.minecraft.world.entity.player.Player;
68
import org.spongepowered.asm.mixin.Mixin;
9+
import org.spongepowered.asm.mixin.Shadow;
10+
import org.spongepowered.asm.mixin.Unique;
711
import org.spongepowered.asm.mixin.injection.At;
812
import org.spongepowered.asm.mixin.injection.Inject;
913
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1014

1115
@Mixin(Entity.class)
1216
public class EntityMixin {
17+
@Shadow
18+
private float yRot;
19+
@Shadow
20+
public float yRotO;
21+
@Unique
22+
private float automobility$lastYRot = 0f;
23+
24+
// Rotation smoothing bug fix taken from https://github.com/FoundationGames/Automobility/pull/129
25+
@Inject(method = "setYRot", at = @At("HEAD"), cancellable = true)
26+
public void automobility$smoothYRotOnAutomobile(float yRot, CallbackInfo ci) {
27+
Entity self = (Entity)(Object)this;
28+
if (self instanceof LocalPlayer player && player.isLocalPlayer() && self.getVehicle() instanceof AutomobileEntity) {
29+
float smoothedYRot = Mth.rotLerp(1.0f, this.automobility$lastYRot, yRot);
30+
this.automobility$lastYRot = smoothedYRot;
31+
32+
ci.cancel();
33+
this.yRotO = this.yRot;
34+
this.yRot = smoothedYRot;
35+
} else {
36+
this.automobility$lastYRot = yRot;
37+
}
38+
}
39+
1340
@Inject(method = "stopRiding", at = @At("HEAD"))
1441
private void automobility$clientFinalSyncBeforeDismountAutomobile(CallbackInfo ci) {
1542
var self = (Entity) (Object) this;

0 commit comments

Comments
 (0)