Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.minecraft.client.entity;
- import com.mojang.authlib.GameProfile;
- import com.mojang.authlib.minecraft.MinecraftProfileTexture;
- import java.awt.Graphics;
- import java.awt.image.BufferedImage;
- import java.awt.image.ImageObserver;
- import java.io.File;
- import java.util.HashMap;
- import net.minecraft.client.Minecraft;
- import net.minecraft.client.network.NetworkPlayerInfo;
- import net.minecraft.client.renderer.IImageBuffer;
- import net.minecraft.client.renderer.ImageBufferDownload;
- import net.minecraft.client.renderer.ThreadDownloadImageData;
- import net.minecraft.client.renderer.texture.ITextureObject;
- import net.minecraft.client.renderer.texture.TextureManager;
- import net.minecraft.client.resources.DefaultPlayerSkin;
- import net.minecraft.entity.SharedMonsterAttributes;
- import net.minecraft.entity.ai.attributes.IAttributeInstance;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.init.Items;
- import net.minecraft.util.ResourceLocation;
- import net.minecraft.util.StringUtils;
- import net.minecraft.world.World;
- import net.minecraft.world.WorldSettings;
- public abstract class AbstractClientPlayer extends EntityPlayer
- {
- //TODO: Custom Capes
- private ThreadDownloadImageData field_110315_c;
- private NetworkPlayerInfo playerInfo;
- public float field_184835_a;
- public float field_184836_b;
- public float field_184837_c;
- public AbstractClientPlayer(World worldIn, GameProfile playerProfile)
- {
- super(worldIn, playerProfile);
- String username = playerProfile.getName();
- this.downloadCape(username);
- }
- /**
- * Returns true if the player is in spectator mode.
- */
- public boolean isSpectator()
- {
- NetworkPlayerInfo networkplayerinfo = Minecraft.getMinecraft().getNetHandler().getPlayerInfo(this.getGameProfile().getId());
- return networkplayerinfo != null && networkplayerinfo.getGameType() == WorldSettings.GameType.SPECTATOR;
- }
- public boolean isCreative()
- {
- NetworkPlayerInfo networkplayerinfo = Minecraft.getMinecraft().getNetHandler().getPlayerInfo(this.getGameProfile().getId());
- return networkplayerinfo != null && networkplayerinfo.getGameType() == WorldSettings.GameType.CREATIVE;
- }
- /**
- * Checks if this instance of AbstractClientPlayer has any associated player data.
- */
- public boolean hasPlayerInfo()
- {
- return this.getPlayerInfo() != null;
- }
- protected NetworkPlayerInfo getPlayerInfo()
- {
- if (this.playerInfo == null)
- {
- this.playerInfo = Minecraft.getMinecraft().getNetHandler().getPlayerInfo(this.getUniqueID());
- }
- return this.playerInfo;
- }
- /**
- * Returns true if the player has an associated skin.
- */
- public boolean hasSkin()
- {
- NetworkPlayerInfo networkplayerinfo = this.getPlayerInfo();
- return networkplayerinfo != null && networkplayerinfo.hasLocationSkin();
- }
- /**
- * Returns true if the player instance has an associated skin.
- */
- public ResourceLocation getLocationSkin()
- {
- NetworkPlayerInfo networkplayerinfo = this.getPlayerInfo();
- return networkplayerinfo == null ? DefaultPlayerSkin.getDefaultSkin(this.getUniqueID()) : networkplayerinfo.getLocationSkin();
- }
- public ResourceLocation getLocationCape() {
- if (this.ofLocationCape != null) {
- return this.ofLocationCape;
- } else {
- NetworkPlayerInfo var1 = this.getPlayerInfo();
- return var1 == null ? null : var1.getLocationCape();
- }
- }
- public boolean func_184833_s()
- {
- return this.getPlayerInfo() != null;
- }
- /**
- * Gets the special Elytra texture for the player.
- */
- public ResourceLocation getLocationElytra()
- {
- NetworkPlayerInfo networkplayerinfo = this.getPlayerInfo();
- return networkplayerinfo == null ? null : networkplayerinfo.getLocationElytra();
- }
- public static ThreadDownloadImageData getDownloadImageSkin(ResourceLocation resourceLocationIn, String username)
- {
- TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
- ITextureObject itextureobject = texturemanager.getTexture(resourceLocationIn);
- if (itextureobject == null)
- {
- 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());
- texturemanager.loadTexture(resourceLocationIn, itextureobject);
- }
- return (ThreadDownloadImageData)itextureobject;
- }
- /**
- * Returns true if the username has an associated skin.
- */
- public static ResourceLocation getLocationSkin(String username)
- {
- return new ResourceLocation("skins/" + StringUtils.stripControlCodes(username));
- }
- public String getSkinType()
- {
- NetworkPlayerInfo networkplayerinfo = this.getPlayerInfo();
- return networkplayerinfo == null ? DefaultPlayerSkin.getSkinType(this.getUniqueID()) : networkplayerinfo.getSkinType();
- }
- public float getFovModifier()
- {
- float f = 1.0F;
- if (this.capabilities.isFlying)
- {
- f *= 1.1F;
- }
- IAttributeInstance iattributeinstance = this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED);
- f = (float)((double)f * ((iattributeinstance.getAttributeValue() / (double)this.capabilities.getWalkSpeed() + 1.0D) / 2.0D));
- if (this.capabilities.getWalkSpeed() == 0.0F || Float.isNaN(f) || Float.isInfinite(f))
- {
- f = 1.0F;
- }
- if (this.func_184587_cr() && this.func_184607_cu() != null && this.func_184607_cu().getItem() == Items.bow)
- {
- int i = this.func_184612_cw();
- float f1 = (float)i / 20.0F;
- if (f1 > 1.0F)
- {
- f1 = 1.0F;
- }
- else
- {
- f1 = f1 * f1;
- }
- f *= 1.0F - f1 * 0.15F;
- }
- return f;
- }
- private ResourceLocation ofLocationCape = null;
- //TODO: Cape System [FROM OPTIFINE]
- private void downloadCape(String username) {
- if (username != null && !username.isEmpty()) {
- username = StringUtils.stripControlCodes(username);
- String ofCapeUrl = "CAPE URL HERE";
- MinecraftProfileTexture mpt = new MinecraftProfileTexture(ofCapeUrl, new HashMap());
- final ResourceLocation rl = new ResourceLocation("skins/" + mpt.getHash());
- IImageBuffer iib = new IImageBuffer() {
- ImageBufferDownload ibd = new ImageBufferDownload();
- public BufferedImage parseUserSkin(BufferedImage var1) {
- return AbstractClientPlayer.this.parseCape(var1);
- }
- public void skinAvailable() {
- AbstractClientPlayer.this.ofLocationCape = rl;
- }
- };
- ThreadDownloadImageData textureCape = new ThreadDownloadImageData((File) null, mpt.getUrl(), (ResourceLocation) null, iib);
- Minecraft.getMinecraft().getTextureManager().loadTexture(rl, textureCape);
- }
- }
- private BufferedImage parseCape(BufferedImage img) {
- int imageWidth = 64;
- int imageHeight = 32;
- int srcWidth = img.getWidth();
- for (int srcHeight = img.getHeight(); imageWidth < srcWidth || imageHeight < srcHeight; imageHeight *= 2) {
- imageWidth *= 2;
- }
- BufferedImage imgNew = new BufferedImage(imageWidth, imageHeight, 2);
- Graphics g = imgNew.getGraphics();
- g.drawImage(img, 0, 0, (ImageObserver) null);
- g.dispose();
- return imgNew;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement