Skip to content

Commit

Permalink
care more about whether the player is a client player than whether th…
Browse files Browse the repository at this point in the history
…ey are the client's main player
  • Loading branch information
der-fruhling committed May 17, 2024
1 parent a41a2cc commit 551504d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.simibubi.create.content.trains.entity.CarriageContraptionEntity;
import dev.architectury.event.events.common.TickEvent;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import org.slf4j.Logger;
Expand All @@ -26,7 +26,7 @@ public CreateTrainPerspectiveMod() {

public void onEntityMount(boolean isMounting, Entity entityMounting, Entity entityBeingMounted) {
if(
entityMounting instanceof LocalPlayer player &&
entityMounting instanceof AbstractClientPlayer player &&
entityBeingMounted instanceof CarriageContraptionEntity contraption
) {
var persp = (Perspective) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player);
Expand Down Expand Up @@ -67,11 +67,7 @@ public void tickStandingPlayer(final CarriageContraptionEntity contraption, fina
}
}

private void tickState(LocalPlayer player) {
var persp = (Perspective) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player);
var state = persp.getRotationState();
if(state == null) return;

private void tickState(Player player, Perspective persp, RotationState state) {
var carriage = state.getCarriageEntity();
if(carriage == null) return;
persp.setLean(carriage.pitch);
Expand All @@ -89,13 +85,14 @@ private void tickState(LocalPlayer player) {
}

public void onTickPlayer(final Player player) {
if(player instanceof LocalPlayer localPlayer) {
var persp = (Perspective) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player);
if(!(player instanceof AbstractClientPlayer)) return;
if(Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player) instanceof Perspective persp
&& persp.getRotationState() != null) {
var state = persp.getRotationState();
if(state == null) return;
assert state != null;

if(state.shouldTickState()) {
tickState(localPlayer);
tickState(player, persp, state);
} else {
persp.diminish();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import net.fabricmc.api.Environment;
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import org.joml.Quaternionf;
Expand Down Expand Up @@ -57,7 +57,7 @@ public void modifyRotationsPrimary(Camera instance,
float x,
@Local(argsOnly = true, ordinal = 0) boolean isThirdPerson,
@Local(argsOnly = true) float f) {
if(entity instanceof LocalPlayer player && !isThirdPerson) {
if(entity instanceof AbstractClientPlayer player && !isThirdPerson) {
var persp = (Perspective) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player);
ctp$zRot = persp.getLean(f) * Mth.cos((persp.getYaw(f) - y) * Mth.DEG_TO_RAD);
ctp$extraYRot = MixinUtil.getExtraYRot(persp, x, y, f);
Expand Down

0 comments on commit 551504d

Please sign in to comment.