| 1 | package net.minecraft.client.renderer.tileentity;
|
| 2 |
|
| 3 | import com.mojang.authlib.GameProfile;
|
| 4 | import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
| 5 | import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
|
| 6 | import java.util.Map;
|
| 7 | import java.util.UUID;
|
| 8 | import net.minecraft.client.Minecraft;
|
| 9 | import net.minecraft.client.model.ModelBase;
|
| 10 | import net.minecraft.client.model.ModelHumanoidHead;
|
| 11 | import net.minecraft.client.model.ModelSkeletonHead;
|
| 12 | import net.minecraft.client.renderer.GlStateManager;
|
| 13 | import net.minecraft.client.resources.DefaultPlayerSkin;
|
| 14 | import net.minecraft.entity.Entity;
|
| 15 | import net.minecraft.entity.player.EntityPlayer;
|
| 16 | import net.minecraft.tileentity.TileEntitySkull;
|
| 17 | import net.minecraft.util.EnumFacing;
|
| 18 | import net.minecraft.util.ResourceLocation;
|
| 19 |
|
| 20 | public class TileEntitySkullRenderer extends TileEntitySpecialRenderer<TileEntitySkull>
|
| 21 | {
|
| 22 | private static final ResourceLocation SKELETON_TEXTURES = new ResourceLocation("textures/entity/skeleton/skeleton.png");
|
| 23 | private static final ResourceLocation WITHER_SKELETON_TEXTURES = new ResourceLocation("textures/entity/skeleton/wither_skeleton.png");
|
| 24 | private static final ResourceLocation ZOMBIE_TEXTURES = new ResourceLocation("textures/entity/zombie/zombie.png");
|
| 25 | private static final ResourceLocation CREEPER_TEXTURES = new ResourceLocation("textures/entity/creeper/creeper.png");
|
| 26 | public static TileEntitySkullRenderer instance;
|
| 27 | private final ModelSkeletonHead skeletonHead = new ModelSkeletonHead(0, 0, 64, 32);
|
| 28 | private final ModelSkeletonHead humanoidHead = new ModelHumanoidHead();
|
| 29 |
|
| 30 | public void renderTileEntityAt(TileEntitySkull te, double x, double y, double z, float partialTicks, int destroyStage)
|
| 31 | {
|
| 32 | EnumFacing enumfacing = EnumFacing.getFront(te.getBlockMetadata() & 7);
|
| 33 | this.renderSkull((float)x, (float)y, (float)z, enumfacing, (float)(te.getSkullRotation() * 360) / 16.0F, te.getSkullType(), te.getPlayerProfile(), destroyStage);
|
| 34 | }
|
| 35 |
|
| 36 | public void setRendererDispatcher(TileEntityRendererDispatcher rendererDispatcherIn)
|
| 37 | {
|
| 38 | super.setRendererDispatcher(rendererDispatcherIn);
|
| 39 | instance = this;
|
| 40 | }
|
| 41 |
|
| 42 | public void renderSkull(float p_180543_1_, float p_180543_2_, float p_180543_3_, EnumFacing p_180543_4_, float p_180543_5_, int p_180543_6_, GameProfile p_180543_7_, int p_180543_8_)
|
| 43 | {
|
| 44 | ModelBase modelbase = this.skeletonHead;
|
| 45 |
|
| 46 | if (p_180543_8_ >= 0)
|
| 47 | {
|
| 48 | this.bindTexture(DESTROY_STAGES[p_180543_8_]);
|
| 49 | GlStateManager.matrixMode(5890);
|
| 50 | GlStateManager.pushMatrix();
|
| 51 | GlStateManager.scale(4.0F, 2.0F, 1.0F);
|
| 52 | GlStateManager.translate(0.0625F, 0.0625F, 0.0625F);
|
| 53 | GlStateManager.matrixMode(5888);
|
| 54 | }
|
| 55 | else
|
| 56 | {
|
| 57 | switch (p_180543_6_)
|
| 58 | {
|
| 59 | case 0:
|
| 60 | default:
|
| 61 | this.bindTexture(SKELETON_TEXTURES);
|
| 62 | break;
|
| 63 |
|
| 64 | case 1:
|
| 65 | this.bindTexture(WITHER_SKELETON_TEXTURES);
|
| 66 | break;
|
| 67 |
|
| 68 | case 2:
|
| 69 | this.bindTexture(ZOMBIE_TEXTURES);
|
| 70 | modelbase = this.humanoidHead;
|
| 71 | break;
|
| 72 |
|
| 73 | case 3:
|
| 74 | modelbase = this.humanoidHead;
|
| 75 | ResourceLocation resourcelocation = DefaultPlayerSkin.getDefaultSkinLegacy();
|
| 76 |
|
| 77 | if (p_180543_7_ != null)
|
| 78 | {
|
| 79 | Minecraft minecraft = Minecraft.getMinecraft();
|
| 80 | Map<Type, MinecraftProfileTexture> map = minecraft.getSkinManager().loadSkinFromCache(p_180543_7_);
|
| 81 |
|
| 82 | if (map.containsKey(Type.SKIN))
|
| 83 | {
|
| 84 | resourcelocation = minecraft.getSkinManager().loadSkin((MinecraftProfileTexture)map.get(Type.SKIN), Type.SKIN);
|
| 85 | }
|
| 86 | else
|
| 87 | {
|
| 88 | UUID uuid = EntityPlayer.getUUID(p_180543_7_);
|
| 89 | resourcelocation = DefaultPlayerSkin.getDefaultSkin(uuid);
|
| 90 | }
|
| 91 | }
|
| 92 |
|
| 93 | this.bindTexture(resourcelocation);
|
| 94 | break;
|
| 95 |
|
| 96 | case 4:
|
| 97 | this.bindTexture(CREEPER_TEXTURES);
|
| 98 | }
|
| 99 | }
|
| 100 |
|
| 101 | GlStateManager.pushMatrix();
|
| 102 | GlStateManager.disableCull();
|
| 103 |
|
| 104 | if (p_180543_4_ != EnumFacing.UP)
|
| 105 | {
|
| 106 | switch (p_180543_4_)
|
| 107 | {
|
| 108 | case NORTH:
|
| 109 | GlStateManager.translate(p_180543_1_ + 0.5F, p_180543_2_ + 0.25F, p_180543_3_ + 0.74F);
|
| 110 | break;
|
| 111 |
|
| 112 | case SOUTH:
|
| 113 | GlStateManager.translate(p_180543_1_ + 0.5F, p_180543_2_ + 0.25F, p_180543_3_ + 0.26F);
|
| 114 | p_180543_5_ = 180.0F;
|
| 115 | break;
|
| 116 |
|
| 117 | case WEST:
|
| 118 | GlStateManager.translate(p_180543_1_ + 0.74F, p_180543_2_ + 0.25F, p_180543_3_ + 0.5F);
|
| 119 | p_180543_5_ = 270.0F;
|
| 120 | break;
|
| 121 |
|
| 122 | case EAST:
|
| 123 | default:
|
| 124 | GlStateManager.translate(p_180543_1_ + 0.26F, p_180543_2_ + 0.25F, p_180543_3_ + 0.5F);
|
| 125 | p_180543_5_ = 90.0F;
|
| 126 | }
|
| 127 | }
|
| 128 | else
|
| 129 | {
|
| 130 | GlStateManager.translate(p_180543_1_ + 0.5F, p_180543_2_, p_180543_3_ + 0.5F);
|
| 131 | }
|
| 132 |
|
| 133 | float f = 0.0625F;
|
| 134 | GlStateManager.enableRescaleNormal();
|
| 135 | GlStateManager.scale(-1.0F, -1.0F, 1.0F);
|
| 136 | GlStateManager.enableAlpha();
|
| 137 | modelbase.render((Entity)null, 0.0F, 0.0F, 0.0F, p_180543_5_, 0.0F, f);
|
| 138 | GlStateManager.popMatrix();
|
| 139 |
|
| 140 | if (p_180543_8_ >= 0)
|
| 141 | {
|
| 142 | GlStateManager.matrixMode(5890);
|
| 143 | GlStateManager.popMatrix();
|
| 144 | GlStateManager.matrixMode(5888);
|
| 145 | }
|
| 146 | }
|
| 147 | }
|
| 148 |
|