|
1 | 1 | package io.github.foundationgames.automobility.mixin; |
2 | 2 |
|
3 | 3 | import io.github.foundationgames.automobility.entity.AutomobileEntity; |
| 4 | +import net.minecraft.client.player.LocalPlayer; |
| 5 | +import net.minecraft.util.Mth; |
4 | 6 | import net.minecraft.world.entity.Entity; |
5 | 7 | import net.minecraft.world.entity.player.Player; |
6 | 8 | import org.spongepowered.asm.mixin.Mixin; |
| 9 | +import org.spongepowered.asm.mixin.Shadow; |
| 10 | +import org.spongepowered.asm.mixin.Unique; |
7 | 11 | import org.spongepowered.asm.mixin.injection.At; |
8 | 12 | import org.spongepowered.asm.mixin.injection.Inject; |
9 | 13 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
10 | 14 |
|
11 | 15 | @Mixin(Entity.class) |
12 | 16 | 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 | + |
13 | 40 | @Inject(method = "stopRiding", at = @At("HEAD")) |
14 | 41 | private void automobility$clientFinalSyncBeforeDismountAutomobile(CallbackInfo ci) { |
15 | 42 | var self = (Entity) (Object) this; |
|
0 commit comments