| 1 | package net.minecraft.client.renderer.entity.layers;
|
| 2 |
|
| 3 | import com.mojang.authlib.GameProfile;
|
| 4 | import java.util.UUID;
|
| 5 | import net.minecraft.client.Minecraft;
|
| 6 | import net.minecraft.client.model.ModelRenderer;
|
| 7 | import net.minecraft.client.renderer.GlStateManager;
|
| 8 | import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
|
| 9 | import net.minecraft.client.renderer.tileentity.TileEntitySkullRenderer;
|
| 10 | import net.minecraft.entity.EntityLivingBase;
|
| 11 | import net.minecraft.entity.monster.EntityZombie;
|
| 12 | import net.minecraft.entity.passive.EntityVillager;
|
| 13 | import net.minecraft.init.Items;
|
| 14 | import net.minecraft.item.Item;
|
| 15 | import net.minecraft.item.ItemBlock;
|
| 16 | import net.minecraft.item.ItemStack;
|
| 17 | import net.minecraft.nbt.NBTTagCompound;
|
| 18 | import net.minecraft.nbt.NBTUtil;
|
| 19 | import net.minecraft.tileentity.TileEntitySkull;
|
| 20 | import net.minecraft.util.EnumFacing;
|
| 21 | import net.minecraft.util.StringUtils;
|
| 22 |
|
| 23 | public class LayerCustomHead implements LayerRenderer<EntityLivingBase>
|
| 24 | {
|
| 25 | private final ModelRenderer field_177209_a;
|
| 26 |
|
| 27 | public LayerCustomHead(ModelRenderer p_i46120_1_)
|
| 28 | {
|
| 29 | this.field_177209_a = p_i46120_1_;
|
| 30 | }
|
| 31 |
|
| 32 | public void doRenderLayer(EntityLivingBase entitylivingbaseIn, float p_177141_2_, float p_177141_3_, float partialTicks, float p_177141_5_, float p_177141_6_, float p_177141_7_, float scale)
|
| 33 | {
|
| 34 | ItemStack itemstack = entitylivingbaseIn.getCurrentArmor(3);
|
| 35 |
|
| 36 | if (itemstack != null && itemstack.getItem() != null)
|
| 37 | {
|
| 38 | Item item = itemstack.getItem();
|
| 39 | Minecraft minecraft = Minecraft.getMinecraft();
|
| 40 | GlStateManager.pushMatrix();
|
| 41 |
|
| 42 | if (entitylivingbaseIn.isSneaking())
|
| 43 | {
|
| 44 | GlStateManager.translate(0.0F, 0.2F, 0.0F);
|
| 45 | }
|
| 46 |
|
| 47 | boolean flag = entitylivingbaseIn instanceof EntityVillager || entitylivingbaseIn instanceof EntityZombie && ((EntityZombie)entitylivingbaseIn).isVillager();
|
| 48 |
|
| 49 | if (!flag && entitylivingbaseIn.isChild())
|
| 50 | {
|
| 51 | float f = 2.0F;
|
| 52 | float f1 = 1.4F;
|
| 53 | GlStateManager.scale(f1 / f, f1 / f, f1 / f);
|
| 54 | GlStateManager.translate(0.0F, 16.0F * scale, 0.0F);
|
| 55 | }
|
| 56 |
|
| 57 | this.field_177209_a.postRender(0.0625F);
|
| 58 | GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
| 59 |
|
| 60 | if (item instanceof ItemBlock)
|
| 61 | {
|
| 62 | float f2 = 0.625F;
|
| 63 | GlStateManager.translate(0.0F, -0.25F, 0.0F);
|
| 64 | GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F);
|
| 65 | GlStateManager.scale(f2, -f2, -f2);
|
| 66 |
|
| 67 | if (flag)
|
| 68 | {
|
| 69 | GlStateManager.translate(0.0F, 0.1875F, 0.0F);
|
| 70 | }
|
| 71 |
|
| 72 | minecraft.getItemRenderer().renderItem(entitylivingbaseIn, itemstack, ItemCameraTransforms.TransformType.HEAD);
|
| 73 | }
|
| 74 | else if (item == Items.skull)
|
| 75 | {
|
| 76 | float f3 = 1.1875F;
|
| 77 | GlStateManager.scale(f3, -f3, -f3);
|
| 78 |
|
| 79 | if (flag)
|
| 80 | {
|
| 81 | GlStateManager.translate(0.0F, 0.0625F, 0.0F);
|
| 82 | }
|
| 83 |
|
| 84 | GameProfile gameprofile = null;
|
| 85 |
|
| 86 | if (itemstack.hasTagCompound())
|
| 87 | {
|
| 88 | NBTTagCompound nbttagcompound = itemstack.getTagCompound();
|
| 89 |
|
| 90 | if (nbttagcompound.hasKey("SkullOwner", 10))
|
| 91 | {
|
| 92 | gameprofile = NBTUtil.readGameProfileFromNBT(nbttagcompound.getCompoundTag("SkullOwner"));
|
| 93 | }
|
| 94 | else if (nbttagcompound.hasKey("SkullOwner", 8))
|
| 95 | {
|
| 96 | String s = nbttagcompound.getString("SkullOwner");
|
| 97 |
|
| 98 | if (!StringUtils.isNullOrEmpty(s))
|
| 99 | {
|
| 100 | gameprofile = TileEntitySkull.updateGameprofile(new GameProfile((UUID)null, s));
|
| 101 | nbttagcompound.setTag("SkullOwner", NBTUtil.writeGameProfile(new NBTTagCompound(), gameprofile));
|
| 102 | }
|
| 103 | }
|
| 104 | }
|
| 105 |
|
| 106 | TileEntitySkullRenderer.instance.renderSkull(-0.5F, 0.0F, -0.5F, EnumFacing.UP, 180.0F, itemstack.getMetadata(), gameprofile, -1);
|
| 107 | }
|
| 108 |
|
| 109 | GlStateManager.popMatrix();
|
| 110 | }
|
| 111 | }
|
| 112 |
|
| 113 | public boolean shouldCombineTextures()
|
| 114 | {
|
| 115 | return true;
|
| 116 | }
|
| 117 | }
|
| 118 |
|