| 1 | package net.minecraft.client.player;
|
| 2 |
|
| 3 | import com.mojang.authlib.GameProfile;
|
| 4 | import net.fabricmc.api.EnvType;
|
| 5 | import net.fabricmc.api.Environment;
|
| 6 | import net.minecraft.client.Minecraft;
|
| 7 | import net.minecraft.client.entity.ClientAvatarEntity;
|
| 8 | import net.minecraft.client.entity.ClientAvatarState;
|
| 9 | import net.minecraft.client.multiplayer.ClientLevel;
|
| 10 | import net.minecraft.client.multiplayer.PlayerInfo;
|
| 11 | import net.minecraft.client.resources.DefaultPlayerSkin;
|
| 12 | import net.minecraft.util.Mth;
|
| 13 | import net.minecraft.world.entity.ai.attributes.Attributes;
|
| 14 | import net.minecraft.world.entity.animal.parrot.Parrot.Variant;
|
| 15 | import net.minecraft.world.entity.player.Player;
|
| 16 | import net.minecraft.world.entity.player.PlayerSkin;
|
| 17 | import net.minecraft.world.item.Items;
|
| 18 | import net.minecraft.world.level.GameType;
|
| 19 | import org.jspecify.annotations.Nullable;
|
| 20 |
|
| 21 | @Environment(EnvType.CLIENT)
|
| 22 | public abstract class AbstractClientPlayer extends Player implements ClientAvatarEntity {
|
| 23 | private @Nullable PlayerInfo playerInfo;
|
| 24 | private final boolean showExtraEars;
|
| 25 | private final ClientAvatarState clientAvatarState = new ClientAvatarState();
|
| 26 |
|
| 27 | public AbstractClientPlayer(final ClientLevel level, final GameProfile gameProfile) {
|
| 28 | super(level, gameProfile);
|
| 29 | this.showExtraEars = "deadmau5".equals(this.getGameProfile().name());
|
| 30 | }
|
| 31 |
|
| 32 | @Override
|
| 33 | public @Nullable GameType gameMode() {
|
| 34 | PlayerInfo info = this.getPlayerInfo();
|
| 35 | return info != null ? info.getGameMode() : null;
|
| 36 | }
|
| 37 |
|
| 38 | protected @Nullable PlayerInfo getPlayerInfo() {
|
| 39 | if (this.playerInfo == null) {
|
| 40 | this.playerInfo = Minecraft.getInstance().getConnection().getPlayerInfo(this.getUUID());
|
| 41 | }
|
| 42 |
|
| 43 | return this.playerInfo;
|
| 44 | }
|
| 45 |
|
| 46 | @Override
|
| 47 | public void tick() {
|
| 48 | this.clientAvatarState.tick(this.position(), this.getDeltaMovement());
|
| 49 | super.tick();
|
| 50 | }
|
| 51 |
|
| 52 | protected void addWalkedDistance(final float distance) {
|
| 53 | this.clientAvatarState.addWalkDistance(distance);
|
| 54 | }
|
| 55 |
|
| 56 | @Override
|
| 57 | public ClientAvatarState avatarState() {
|
| 58 | return this.clientAvatarState;
|
| 59 | }
|
| 60 |
|
| 61 | @Override
|
| 62 | public PlayerSkin getSkin() {
|
| 63 | PlayerInfo info = this.getPlayerInfo();
|
| 64 | return info == null ? DefaultPlayerSkin.get(this.getUUID()) : info.getSkin();
|
| 65 | }
|
| 66 |
|
| 67 | @Override
|
| 68 | public @Nullable Variant getParrotVariantOnShoulder(final boolean left) {
|
| 69 | return (left ? this.getShoulderParrotLeft() : this.getShoulderParrotRight()).orElse(null);
|
| 70 | }
|
| 71 |
|
| 72 | @Override
|
| 73 | public void rideTick() {
|
| 74 | super.rideTick();
|
| 75 | this.avatarState().resetBob();
|
| 76 | }
|
| 77 |
|
| 78 | @Override
|
| 79 | public void aiStep() {
|
| 80 | this.updateBob();
|
| 81 | super.aiStep();
|
| 82 | }
|
| 83 |
|
| 84 | protected void updateBob() {
|
| 85 | float tBob;
|
| 86 | if (this.onGround() && !this.isDeadOrDying() && !this.isSwimming()) {
|
| 87 | tBob = Math.min(0.1F, (float)this.getDeltaMovement().horizontalDistance());
|
| 88 | } else {
|
| 89 | tBob = 0.0F;
|
| 90 | }
|
| 91 |
|
| 92 | this.avatarState().updateBob(tBob);
|
| 93 | }
|
| 94 |
|
| 95 | public float getFieldOfViewModifier(final boolean firstPerson, final float effectScale) {
|
| 96 | float modifier = 1.0F;
|
| 97 | if (this.getAbilities().flying) {
|
| 98 | modifier *= 1.1F;
|
| 99 | }
|
| 100 |
|
| 101 | float walkingSpeed = this.getAbilities().getWalkingSpeed();
|
| 102 | if (walkingSpeed != 0.0F) {
|
| 103 | float speedFactor = (float)this.getAttributeValue(Attributes.MOVEMENT_SPEED) / walkingSpeed;
|
| 104 | modifier *= (speedFactor + 1.0F) / 2.0F;
|
| 105 | }
|
| 106 |
|
| 107 | if (this.isUsingItem()) {
|
| 108 | if (this.getUseItem().is(Items.BOW)) {
|
| 109 | float scale = Math.min(this.getTicksUsingItem() / 20.0F, 1.0F);
|
| 110 | modifier *= 1.0F - Mth.square(scale) * 0.15F;
|
| 111 | } else if (firstPerson && this.isScoping()) {
|
| 112 | return 0.1F;
|
| 113 | }
|
| 114 | }
|
| 115 |
|
| 116 | return Mth.lerp(effectScale, 1.0F, modifier);
|
| 117 | }
|
| 118 |
|
| 119 | @Override
|
| 120 | public boolean showExtraEars() {
|
| 121 | return this.showExtraEars;
|
| 122 | }
|
| 123 | }
|
| 124 |
|