LayerArmorBase .java

net.minecraft.client.renderer.entity.layers.LayerArmorBase (class): members: ENCHANTED_ITEM_GLINT_RES, ARMOR_TEXTURE_RES_MAP, skipRenderGlint, modelArmor.

net.minecraft.client.renderer.entity.layersclass159 linesclientextends ModelBase>7.0 KB

Implements

API Surface (4)

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)
boolean shouldCombineTextures()
ItemStack getCurrentArmor(EntityLivingBase entitylivingbaseIn, int armorSlot)
T getArmorModel(int armorSlot)

Fields & Constants (10)

ENCHANTED_ITEM_GLINT_RES
ARMOR_TEXTURE_RES_MAP
modelLeggings
modelArmor
renderer
alpha
colorR
colorG
colorB
skipRenderGlint

String literals (2)

"textures/misc/enchanted_item_glint.png"
"overlay"

Full Source

LayerArmorBase.java159 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.client.renderer.entity.layers;
2
3
import com.google.common.collect.Maps;
4
import java.util.Map;
5
import net.minecraft.client.model.ModelBase;
6
import net.minecraft.client.renderer.GlStateManager;
7
import net.minecraft.client.renderer.entity.RendererLivingEntity;
8
import net.minecraft.entity.EntityLivingBase;
9
import net.minecraft.item.ItemArmor;
10
import net.minecraft.item.ItemStack;
11
import net.minecraft.util.ResourceLocation;
12
13
public abstract class LayerArmorBase<T extends ModelBase> implements LayerRenderer<EntityLivingBase>
14
{
15
    protected static final ResourceLocation ENCHANTED_ITEM_GLINT_RES = new ResourceLocation("textures/misc/enchanted_item_glint.png");
16
    protected T modelLeggings;
17
    protected T modelArmor;
18
    private final RendererLivingEntity<?> renderer;
19
    private float alpha = 1.0F;
20
    private float colorR = 1.0F;
21
    private float colorG = 1.0F;
22
    private float colorB = 1.0F;
23
    private boolean skipRenderGlint;
24
    private static final Map<String, ResourceLocation> ARMOR_TEXTURE_RES_MAP = Maps.<String, ResourceLocation>newHashMap();
25
26
    public LayerArmorBase(RendererLivingEntity<?> rendererIn)
27
    {
28
        this.renderer = rendererIn;
29
        this.initArmor();
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
        this.renderLayer(entitylivingbaseIn, p_177141_2_, p_177141_3_, partialTicks, p_177141_5_, p_177141_6_, p_177141_7_, scale, 4);
35
        this.renderLayer(entitylivingbaseIn, p_177141_2_, p_177141_3_, partialTicks, p_177141_5_, p_177141_6_, p_177141_7_, scale, 3);
36
        this.renderLayer(entitylivingbaseIn, p_177141_2_, p_177141_3_, partialTicks, p_177141_5_, p_177141_6_, p_177141_7_, scale, 2);
37
        this.renderLayer(entitylivingbaseIn, p_177141_2_, p_177141_3_, partialTicks, p_177141_5_, p_177141_6_, p_177141_7_, scale, 1);
38
    }
39
40
    public boolean shouldCombineTextures()
41
    {
42
        return false;
43
    }
44
45
    private void renderLayer(EntityLivingBase entitylivingbaseIn, float p_177182_2_, float p_177182_3_, float partialTicks, float p_177182_5_, float p_177182_6_, float p_177182_7_, float scale, int armorSlot)
46
    {
47
        ItemStack itemstack = this.getCurrentArmor(entitylivingbaseIn, armorSlot);
48
49
        if (itemstack != null && itemstack.getItem() instanceof ItemArmor)
50
        {
51
            ItemArmor itemarmor = (ItemArmor)itemstack.getItem();
52
            T t = this.getArmorModel(armorSlot);
53
            t.setModelAttributes(this.renderer.getMainModel());
54
            t.setLivingAnimations(entitylivingbaseIn, p_177182_2_, p_177182_3_, partialTicks);
55
            this.setModelPartVisible(t, armorSlot);
56
            boolean flag = this.isSlotForLeggings(armorSlot);
57
            this.renderer.bindTexture(this.getArmorResource(itemarmor, flag));
58
59
            switch (itemarmor.getArmorMaterial())
60
            {
61
                case LEATHER:
62
                    int i = itemarmor.getColor(itemstack);
63
                    float f = (float)(i >> 16 & 255) / 255.0F;
64
                    float f1 = (float)(i >> 8 & 255) / 255.0F;
65
                    float f2 = (float)(i & 255) / 255.0F;
66
                    GlStateManager.color(this.colorR * f, this.colorG * f1, this.colorB * f2, this.alpha);
67
                    t.render(entitylivingbaseIn, p_177182_2_, p_177182_3_, p_177182_5_, p_177182_6_, p_177182_7_, scale);
68
                    this.renderer.bindTexture(this.getArmorResource(itemarmor, flag, "overlay"));
69
70
                case CHAIN:
71
                case IRON:
72
                case GOLD:
73
                case DIAMOND:
74
                    GlStateManager.color(this.colorR, this.colorG, this.colorB, this.alpha);
75
                    t.render(entitylivingbaseIn, p_177182_2_, p_177182_3_, p_177182_5_, p_177182_6_, p_177182_7_, scale);
76
77
                default:
78
                    if (!this.skipRenderGlint && itemstack.isItemEnchanted())
79
                    {
80
                        this.renderGlint(entitylivingbaseIn, t, p_177182_2_, p_177182_3_, partialTicks, p_177182_5_, p_177182_6_, p_177182_7_, scale);
81
                    }
82
            }
83
        }
84
    }
85
86
    public ItemStack getCurrentArmor(EntityLivingBase entitylivingbaseIn, int armorSlot)
87
    {
88
        return entitylivingbaseIn.getCurrentArmor(armorSlot - 1);
89
    }
90
91
    public T getArmorModel(int armorSlot)
92
    {
93
        return (T)(this.isSlotForLeggings(armorSlot) ? this.modelLeggings : this.modelArmor);
94
    }
95
96
    private boolean isSlotForLeggings(int armorSlot)
97
    {
98
        return armorSlot == 2;
99
    }
100
101
    private void renderGlint(EntityLivingBase entitylivingbaseIn, T modelbaseIn, float p_177183_3_, float p_177183_4_, float partialTicks, float p_177183_6_, float p_177183_7_, float p_177183_8_, float scale)
102
    {
103
        float f = (float)entitylivingbaseIn.ticksExisted + partialTicks;
104
        this.renderer.bindTexture(ENCHANTED_ITEM_GLINT_RES);
105
        GlStateManager.enableBlend();
106
        GlStateManager.depthFunc(514);
107
        GlStateManager.depthMask(false);
108
        float f1 = 0.5F;
109
        GlStateManager.color(f1, f1, f1, 1.0F);
110
111
        for (int i = 0; i < 2; ++i)
112
        {
113
            GlStateManager.disableLighting();
114
            GlStateManager.blendFunc(768, 1);
115
            float f2 = 0.76F;
116
            GlStateManager.color(0.5F * f2, 0.25F * f2, 0.8F * f2, 1.0F);
117
            GlStateManager.matrixMode(5890);
118
            GlStateManager.loadIdentity();
119
            float f3 = 0.33333334F;
120
            GlStateManager.scale(f3, f3, f3);
121
            GlStateManager.rotate(30.0F - (float)i * 60.0F, 0.0F, 0.0F, 1.0F);
122
            GlStateManager.translate(0.0F, f * (0.001F + (float)i * 0.003F) * 20.0F, 0.0F);
123
            GlStateManager.matrixMode(5888);
124
            modelbaseIn.render(entitylivingbaseIn, p_177183_3_, p_177183_4_, p_177183_6_, p_177183_7_, p_177183_8_, scale);
125
        }
126
127
        GlStateManager.matrixMode(5890);
128
        GlStateManager.loadIdentity();
129
        GlStateManager.matrixMode(5888);
130
        GlStateManager.enableLighting();
131
        GlStateManager.depthMask(true);
132
        GlStateManager.depthFunc(515);
133
        GlStateManager.disableBlend();
134
    }
135
136
    private ResourceLocation getArmorResource(ItemArmor p_177181_1_, boolean p_177181_2_)
137
    {
138
        return this.getArmorResource(p_177181_1_, p_177181_2_, (String)null);
139
    }
140
141
    private ResourceLocation getArmorResource(ItemArmor p_177178_1_, boolean p_177178_2_, String p_177178_3_)
142
    {
143
        String s = String.format("textures/models/armor/%s_layer_%d%s.png", new Object[] {p_177178_1_.getArmorMaterial().getName(), Integer.valueOf(p_177178_2_ ? 2 : 1), p_177178_3_ == null ? "" : String.format("_%s", new Object[]{p_177178_3_})});
144
        ResourceLocation resourcelocation = (ResourceLocation)ARMOR_TEXTURE_RES_MAP.get(s);
145
146
        if (resourcelocation == null)
147
        {
148
            resourcelocation = new ResourceLocation(s);
149
            ARMOR_TEXTURE_RES_MAP.put(s, resourcelocation);
150
        }
151
152
        return resourcelocation;
153
    }
154
155
    protected abstract void initArmor();
156
157
    protected abstract void setModelPartVisible(T model, int armorSlot);
158
}
159

Deobfuscated MCP 1.8.9 source of LayerArmorBase from Marcelektro/MavenMCP-1.8.9 (net/minecraft/client/renderer/entity/layers/LayerArmorBase.java), stored verbatim.