| 1 | package net.minecraft.client.entity;
|
| 2 |
|
| 3 | import com.mojang.authlib.GameProfile;
|
| 4 | import java.io.File;
|
| 5 | import net.minecraft.client.Minecraft;
|
| 6 | import net.minecraft.client.network.NetworkPlayerInfo;
|
| 7 | import net.minecraft.client.renderer.ImageBufferDownload;
|
| 8 | import net.minecraft.client.renderer.ThreadDownloadImageData;
|
| 9 | import net.minecraft.client.renderer.texture.ITextureObject;
|
| 10 | import net.minecraft.client.renderer.texture.TextureManager;
|
| 11 | import net.minecraft.client.resources.DefaultPlayerSkin;
|
| 12 | import net.minecraft.entity.SharedMonsterAttributes;
|
| 13 | import net.minecraft.entity.ai.attributes.IAttributeInstance;
|
| 14 | import net.minecraft.entity.player.EntityPlayer;
|
| 15 | import net.minecraft.init.Items;
|
| 16 | import net.minecraft.util.ResourceLocation;
|
| 17 | import net.minecraft.util.StringUtils;
|
| 18 | import net.minecraft.world.World;
|
| 19 | import net.minecraft.world.WorldSettings;
|
| 20 |
|
| 21 | public abstract class AbstractClientPlayer extends EntityPlayer
|
| 22 | {
|
| 23 | private NetworkPlayerInfo playerInfo;
|
| 24 |
|
| 25 | public AbstractClientPlayer(World worldIn, GameProfile playerProfile)
|
| 26 | {
|
| 27 | super(worldIn, playerProfile);
|
| 28 | }
|
| 29 |
|
| 30 | /**
|
| 31 | * Returns true if the player is in spectator mode.
|
| 32 | */
|
| 33 | public boolean isSpectator()
|
| 34 | {
|
| 35 | NetworkPlayerInfo networkplayerinfo = Minecraft.getMinecraft().getNetHandler().getPlayerInfo(this.getGameProfile().getId());
|
| 36 | return networkplayerinfo != null && networkplayerinfo.getGameType() == WorldSettings.GameType.SPECTATOR;
|
| 37 | }
|
| 38 |
|
| 39 | /**
|
| 40 | * Checks if this instance of AbstractClientPlayer has any associated player data.
|
| 41 | */
|
| 42 | public boolean hasPlayerInfo()
|
| 43 | {
|
| 44 | return this.getPlayerInfo() != null;
|
| 45 | }
|
| 46 |
|
| 47 | protected NetworkPlayerInfo getPlayerInfo()
|
| 48 | {
|
| 49 | if (this.playerInfo == null)
|
| 50 | {
|
| 51 | this.playerInfo = Minecraft.getMinecraft().getNetHandler().getPlayerInfo(this.getUniqueID());
|
| 52 | }
|
| 53 |
|
| 54 | return this.playerInfo;
|
| 55 | }
|
| 56 |
|
| 57 | /**
|
| 58 | * Returns true if the player has an associated skin.
|
| 59 | */
|
| 60 | public boolean hasSkin()
|
| 61 | {
|
| 62 | NetworkPlayerInfo networkplayerinfo = this.getPlayerInfo();
|
| 63 | return networkplayerinfo != null && networkplayerinfo.hasLocationSkin();
|
| 64 | }
|
| 65 |
|
| 66 | /**
|
| 67 | * Returns true if the player instance has an associated skin.
|
| 68 | */
|
| 69 | public ResourceLocation getLocationSkin()
|
| 70 | {
|
| 71 | NetworkPlayerInfo networkplayerinfo = this.getPlayerInfo();
|
| 72 | return networkplayerinfo == null ? DefaultPlayerSkin.getDefaultSkin(this.getUniqueID()) : networkplayerinfo.getLocationSkin();
|
| 73 | }
|
| 74 |
|
| 75 | public ResourceLocation getLocationCape()
|
| 76 | {
|
| 77 | NetworkPlayerInfo networkplayerinfo = this.getPlayerInfo();
|
| 78 | return networkplayerinfo == null ? null : networkplayerinfo.getLocationCape();
|
| 79 | }
|
| 80 |
|
| 81 | public static ThreadDownloadImageData getDownloadImageSkin(ResourceLocation resourceLocationIn, String username)
|
| 82 | {
|
| 83 | TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
|
| 84 | ITextureObject itextureobject = texturemanager.getTexture(resourceLocationIn);
|
| 85 |
|
| 86 | if (itextureobject == null)
|
| 87 | {
|
| 88 | itextureobject = new ThreadDownloadImageData((File)null, String.format("http://skins.minecraft.net/MinecraftSkins/%s.png", new Object[] {StringUtils.stripControlCodes(username)}), DefaultPlayerSkin.getDefaultSkin(getOfflineUUID(username)), new ImageBufferDownload());
|
| 89 | texturemanager.loadTexture(resourceLocationIn, itextureobject);
|
| 90 | }
|
| 91 |
|
| 92 | return (ThreadDownloadImageData)itextureobject;
|
| 93 | }
|
| 94 |
|
| 95 | /**
|
| 96 | * Returns true if the username has an associated skin.
|
| 97 | */
|
| 98 | public static ResourceLocation getLocationSkin(String username)
|
| 99 | {
|
| 100 | return new ResourceLocation("skins/" + StringUtils.stripControlCodes(username));
|
| 101 | }
|
| 102 |
|
| 103 | public String getSkinType()
|
| 104 | {
|
| 105 | NetworkPlayerInfo networkplayerinfo = this.getPlayerInfo();
|
| 106 | return networkplayerinfo == null ? DefaultPlayerSkin.getSkinType(this.getUniqueID()) : networkplayerinfo.getSkinType();
|
| 107 | }
|
| 108 |
|
| 109 | public float getFovModifier()
|
| 110 | {
|
| 111 | float f = 1.0F;
|
| 112 |
|
| 113 | if (this.capabilities.isFlying)
|
| 114 | {
|
| 115 | f *= 1.1F;
|
| 116 | }
|
| 117 |
|
| 118 | IAttributeInstance iattributeinstance = this.getEntityAttribute(SharedMonsterAttributes.movementSpeed);
|
| 119 | f = (float)((double)f * ((iattributeinstance.getAttributeValue() / (double)this.capabilities.getWalkSpeed() + 1.0D) / 2.0D));
|
| 120 |
|
| 121 | if (this.capabilities.getWalkSpeed() == 0.0F || Float.isNaN(f) || Float.isInfinite(f))
|
| 122 | {
|
| 123 | f = 1.0F;
|
| 124 | }
|
| 125 |
|
| 126 | if (this.isUsingItem() && this.getItemInUse().getItem() == Items.bow)
|
| 127 | {
|
| 128 | int i = this.getItemInUseDuration();
|
| 129 | float f1 = (float)i / 20.0F;
|
| 130 |
|
| 131 | if (f1 > 1.0F)
|
| 132 | {
|
| 133 | f1 = 1.0F;
|
| 134 | }
|
| 135 | else
|
| 136 | {
|
| 137 | f1 = f1 * f1;
|
| 138 | }
|
| 139 |
|
| 140 | f *= 1.0F - f1 * 0.15F;
|
| 141 | }
|
| 142 |
|
| 143 | return f;
|
| 144 | }
|
| 145 | }
|
| 146 |
|