package net.minecraft.client.player; import com.mojang.authlib.GameProfile; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.PlayerInfo; import net.minecraft.client.resources.DefaultPlayerSkin; import net.minecraft.client.resources.PlayerSkin; import net.minecraft.util.Mth; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Items; import net.minecraft.world.level.GameType; import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.Nullable; @Environment(EnvType.CLIENT) public abstract class AbstractClientPlayer extends Player { @Nullable private PlayerInfo playerInfo; protected Vec3 deltaMovementOnPreviousTick = Vec3.ZERO; public float elytraRotX; public float elytraRotY; public float elytraRotZ; public final ClientLevel clientLevel; public float walkDistO; public float walkDist; public AbstractClientPlayer(ClientLevel clientLevel, GameProfile gameProfile) { super(clientLevel, clientLevel.getSharedSpawnPos(), clientLevel.getSharedSpawnAngle(), gameProfile); this.clientLevel = clientLevel; } @Nullable @Override public GameType gameMode() { PlayerInfo playerInfo = this.getPlayerInfo(); return playerInfo != null ? playerInfo.getGameMode() : null; } @Nullable protected PlayerInfo getPlayerInfo() { if (this.playerInfo == null) { this.playerInfo = Minecraft.getInstance().getConnection().getPlayerInfo(this.getUUID()); } return this.playerInfo; } @Override public void tick() { this.walkDistO = this.walkDist; this.deltaMovementOnPreviousTick = this.getDeltaMovement(); super.tick(); } public Vec3 getDeltaMovementLerped(float patialTick) { return this.deltaMovementOnPreviousTick.lerp(this.getDeltaMovement(), patialTick); } public PlayerSkin getSkin() { PlayerInfo playerInfo = this.getPlayerInfo(); return playerInfo == null ? DefaultPlayerSkin.get(this.getUUID()) : playerInfo.getSkin(); } public float getFieldOfViewModifier(boolean isFirstPerson, float fovEffectScale) { float f = 1.0F; if (this.getAbilities().flying) { f *= 1.1F; } float g = this.getAbilities().getWalkingSpeed(); if (g != 0.0F) { float h = (float)this.getAttributeValue(Attributes.MOVEMENT_SPEED) / g; f *= (h + 1.0F) / 2.0F; } if (this.isUsingItem()) { if (this.getUseItem().is(Items.BOW)) { float h = Math.min(this.getTicksUsingItem() / 20.0F, 1.0F); f *= 1.0F - Mth.square(h) * 0.15F; } else if (isFirstPerson && this.isScoping()) { return 0.1F; } } return Mth.lerp(fovEffectScale, 1.0F, f); } }