Advertisement
Guest User

AbstractClientPlayer [CUSTOM CAPE 1.9]

a guest
Mar 11th, 2016
5,354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.96 KB | None | 0 0
  1. package net.minecraft.client.entity;
  2.  
  3. import com.mojang.authlib.GameProfile;
  4. import com.mojang.authlib.minecraft.MinecraftProfileTexture;
  5.  
  6. import java.awt.Graphics;
  7. import java.awt.image.BufferedImage;
  8. import java.awt.image.ImageObserver;
  9. import java.io.File;
  10. import java.util.HashMap;
  11.  
  12. import net.minecraft.client.Minecraft;
  13. import net.minecraft.client.network.NetworkPlayerInfo;
  14. import net.minecraft.client.renderer.IImageBuffer;
  15. import net.minecraft.client.renderer.ImageBufferDownload;
  16. import net.minecraft.client.renderer.ThreadDownloadImageData;
  17. import net.minecraft.client.renderer.texture.ITextureObject;
  18. import net.minecraft.client.renderer.texture.TextureManager;
  19. import net.minecraft.client.resources.DefaultPlayerSkin;
  20. import net.minecraft.entity.SharedMonsterAttributes;
  21. import net.minecraft.entity.ai.attributes.IAttributeInstance;
  22. import net.minecraft.entity.player.EntityPlayer;
  23. import net.minecraft.init.Items;
  24. import net.minecraft.util.ResourceLocation;
  25. import net.minecraft.util.StringUtils;
  26. import net.minecraft.world.World;
  27. import net.minecraft.world.WorldSettings;
  28.  
  29. public abstract class AbstractClientPlayer extends EntityPlayer
  30. {
  31.     //TODO: Custom Capes
  32.     private ThreadDownloadImageData field_110315_c;
  33.     private NetworkPlayerInfo playerInfo;
  34.     public float field_184835_a;
  35.     public float field_184836_b;
  36.     public float field_184837_c;
  37.  
  38.     public AbstractClientPlayer(World worldIn, GameProfile playerProfile)
  39.     {
  40.         super(worldIn, playerProfile);
  41.         String username = playerProfile.getName();
  42.         this.downloadCape(username);
  43.     }
  44.  
  45.     /**
  46.      * Returns true if the player is in spectator mode.
  47.      */
  48.     public boolean isSpectator()
  49.     {
  50.         NetworkPlayerInfo networkplayerinfo = Minecraft.getMinecraft().getNetHandler().getPlayerInfo(this.getGameProfile().getId());
  51.         return networkplayerinfo != null && networkplayerinfo.getGameType() == WorldSettings.GameType.SPECTATOR;
  52.     }
  53.  
  54.     public boolean isCreative()
  55.     {
  56.         NetworkPlayerInfo networkplayerinfo = Minecraft.getMinecraft().getNetHandler().getPlayerInfo(this.getGameProfile().getId());
  57.         return networkplayerinfo != null && networkplayerinfo.getGameType() == WorldSettings.GameType.CREATIVE;
  58.     }
  59.  
  60.     /**
  61.      * Checks if this instance of AbstractClientPlayer has any associated player data.
  62.      */
  63.     public boolean hasPlayerInfo()
  64.     {
  65.         return this.getPlayerInfo() != null;
  66.     }
  67.  
  68.     protected NetworkPlayerInfo getPlayerInfo()
  69.     {
  70.         if (this.playerInfo == null)
  71.         {
  72.             this.playerInfo = Minecraft.getMinecraft().getNetHandler().getPlayerInfo(this.getUniqueID());
  73.         }
  74.  
  75.         return this.playerInfo;
  76.     }
  77.  
  78.     /**
  79.      * Returns true if the player has an associated skin.
  80.      */
  81.     public boolean hasSkin()
  82.     {
  83.         NetworkPlayerInfo networkplayerinfo = this.getPlayerInfo();
  84.         return networkplayerinfo != null && networkplayerinfo.hasLocationSkin();
  85.     }
  86.  
  87.     /**
  88.      * Returns true if the player instance has an associated skin.
  89.      */
  90.     public ResourceLocation getLocationSkin()
  91.     {
  92.         NetworkPlayerInfo networkplayerinfo = this.getPlayerInfo();
  93.         return networkplayerinfo == null ? DefaultPlayerSkin.getDefaultSkin(this.getUniqueID()) : networkplayerinfo.getLocationSkin();
  94.     }
  95.  
  96.     public ResourceLocation getLocationCape() {
  97.        if (this.ofLocationCape != null) {
  98.             return this.ofLocationCape;
  99.         } else {
  100.             NetworkPlayerInfo var1 = this.getPlayerInfo();
  101.             return var1 == null ? null : var1.getLocationCape();
  102.         }
  103.     }
  104.    
  105.     public boolean func_184833_s()
  106.     {
  107.         return this.getPlayerInfo() != null;
  108.     }
  109.  
  110.     /**
  111.      * Gets the special Elytra texture for the player.
  112.      */
  113.     public ResourceLocation getLocationElytra()
  114.     {
  115.         NetworkPlayerInfo networkplayerinfo = this.getPlayerInfo();
  116.         return networkplayerinfo == null ? null : networkplayerinfo.getLocationElytra();
  117.     }
  118.  
  119.     public static ThreadDownloadImageData getDownloadImageSkin(ResourceLocation resourceLocationIn, String username)
  120.     {
  121.         TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
  122.         ITextureObject itextureobject = texturemanager.getTexture(resourceLocationIn);
  123.  
  124.         if (itextureobject == null)
  125.         {
  126.             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());
  127.             texturemanager.loadTexture(resourceLocationIn, itextureobject);
  128.         }
  129.  
  130.         return (ThreadDownloadImageData)itextureobject;
  131.     }
  132.  
  133.     /**
  134.      * Returns true if the username has an associated skin.
  135.      */
  136.     public static ResourceLocation getLocationSkin(String username)
  137.     {
  138.         return new ResourceLocation("skins/" + StringUtils.stripControlCodes(username));
  139.     }
  140.  
  141.     public String getSkinType()
  142.     {
  143.         NetworkPlayerInfo networkplayerinfo = this.getPlayerInfo();
  144.         return networkplayerinfo == null ? DefaultPlayerSkin.getSkinType(this.getUniqueID()) : networkplayerinfo.getSkinType();
  145.     }
  146.  
  147.     public float getFovModifier()
  148.     {
  149.         float f = 1.0F;
  150.  
  151.         if (this.capabilities.isFlying)
  152.         {
  153.             f *= 1.1F;
  154.         }
  155.  
  156.         IAttributeInstance iattributeinstance = this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED);
  157.         f = (float)((double)f * ((iattributeinstance.getAttributeValue() / (double)this.capabilities.getWalkSpeed() + 1.0D) / 2.0D));
  158.  
  159.         if (this.capabilities.getWalkSpeed() == 0.0F || Float.isNaN(f) || Float.isInfinite(f))
  160.         {
  161.             f = 1.0F;
  162.         }
  163.  
  164.         if (this.func_184587_cr() && this.func_184607_cu() != null && this.func_184607_cu().getItem() == Items.bow)
  165.         {
  166.             int i = this.func_184612_cw();
  167.             float f1 = (float)i / 20.0F;
  168.  
  169.             if (f1 > 1.0F)
  170.             {
  171.                 f1 = 1.0F;
  172.             }
  173.             else
  174.             {
  175.                 f1 = f1 * f1;
  176.             }
  177.  
  178.             f *= 1.0F - f1 * 0.15F;
  179.         }
  180.  
  181.         return f;
  182.     }
  183.    
  184.     private ResourceLocation ofLocationCape = null;
  185.    
  186.     //TODO: Cape System [FROM OPTIFINE]
  187.     private void downloadCape(String username) {
  188.         if (username != null && !username.isEmpty()) {
  189.             username = StringUtils.stripControlCodes(username);
  190.             String ofCapeUrl = "CAPE URL HERE";
  191.             MinecraftProfileTexture mpt = new MinecraftProfileTexture(ofCapeUrl, new HashMap());
  192.             final ResourceLocation rl = new ResourceLocation("skins/" + mpt.getHash());
  193.             IImageBuffer iib = new IImageBuffer() {
  194.                 ImageBufferDownload ibd = new ImageBufferDownload();
  195.  
  196.                 public BufferedImage parseUserSkin(BufferedImage var1) {
  197.                     return AbstractClientPlayer.this.parseCape(var1);
  198.                 }
  199.  
  200.                 public void skinAvailable() {
  201.                     AbstractClientPlayer.this.ofLocationCape = rl;
  202.                 }
  203.             };
  204.             ThreadDownloadImageData textureCape = new ThreadDownloadImageData((File) null, mpt.getUrl(), (ResourceLocation) null, iib);
  205.             Minecraft.getMinecraft().getTextureManager().loadTexture(rl, textureCape);
  206.         }
  207.     }
  208.    
  209.     private BufferedImage parseCape(BufferedImage img) {
  210.         int imageWidth = 64;
  211.         int imageHeight = 32;
  212.         int srcWidth = img.getWidth();
  213.  
  214.         for (int srcHeight = img.getHeight(); imageWidth < srcWidth || imageHeight < srcHeight; imageHeight *= 2) {
  215.             imageWidth *= 2;
  216.         }
  217.  
  218.         BufferedImage imgNew = new BufferedImage(imageWidth, imageHeight, 2);
  219.         Graphics g = imgNew.getGraphics();
  220.         g.drawImage(img, 0, 0, (ImageObserver) null);
  221.         g.dispose();
  222.         return imgNew;
  223.     }
  224.    
  225. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement