diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/LocalPlayerMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/LocalPlayerMixin.java index 2e4d625..3573919 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/LocalPlayerMixin.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/LocalPlayerMixin.java @@ -1,29 +1,23 @@ package net.derfruhling.minecraft.create.trainperspective.mixin; -import com.mojang.authlib.GameProfile; -import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.client.player.AbstractClientPlayer; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import net.derfruhling.minecraft.create.trainperspective.Perspective; +import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; // If anything else tries to @Overwrite getViewYRot, use their changes. -@Mixin(value = LocalPlayer.class, priority = 200) -public class LocalPlayerMixin extends AbstractClientPlayer { - private LocalPlayerMixin(ClientLevel clientLevel, GameProfile gameProfile) { - super(clientLevel, gameProfile); - } +@Mixin(value = LocalPlayer.class) +public class LocalPlayerMixin { + @Shadow @Final protected Minecraft minecraft; - /** - * @author der_frühling - * @reason Mojang, for some reason, is not using the value of getViewYRot unless - * the player is a passenger. - * This breaks yaw while standing on a train. - * This is an {@link Overwrite @Overwrite} method because of the small - * size of the target method and the simple fix it needs to apply. - */ - @Overwrite - public float getViewYRot(float f) { - return super.getViewYRot(f); + @WrapOperation(method = "getViewYRot", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;isPassenger()Z")) + public boolean isPassenger(LocalPlayer instance, Operation original) { + var perspective = (Perspective) minecraft.getEntityRenderDispatcher().getRenderer(instance); + return original.call(instance) || perspective.isEnabled(); } }