RenderLiving .java

net.minecraft.client.renderer.entity.RenderLiving (class): members: renderLeash, setLightmap, canRenderName, shouldRender, doRender. imports: ICamera.

net.minecraft.client.renderer.entityclass158 linesclientextends EntityLiving>6.8 KB

API Surface (5)

boolean canRenderName(T entity)
boolean shouldRender(T livingEntity, ICamera camera, double camX, double camY, double camZ)
void doRender(T entity, double x, double y, double z, float entityYaw, float partialTicks)
void setLightmap(T entityLivingIn, float partialTicks)
void renderLeash(T entityLivingIn, double x, double y, double z, float entityYaw, float partialTicks)

Full Source

RenderLiving.java158 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.client.renderer.entity;
2
3
import net.minecraft.client.model.ModelBase;
4
import net.minecraft.client.renderer.GlStateManager;
5
import net.minecraft.client.renderer.OpenGlHelper;
6
import net.minecraft.client.renderer.Tessellator;
7
import net.minecraft.client.renderer.WorldRenderer;
8
import net.minecraft.client.renderer.culling.ICamera;
9
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
10
import net.minecraft.entity.Entity;
11
import net.minecraft.entity.EntityHanging;
12
import net.minecraft.entity.EntityLiving;
13
14
public abstract class RenderLiving<T extends EntityLiving> extends RendererLivingEntity<T>
15
{
16
    public RenderLiving(RenderManager rendermanagerIn, ModelBase modelbaseIn, float shadowsizeIn)
17
    {
18
        super(rendermanagerIn, modelbaseIn, shadowsizeIn);
19
    }
20
21
    protected boolean canRenderName(T entity)
22
    {
23
        return super.canRenderName(entity) && (entity.getAlwaysRenderNameTagForRender() || entity.hasCustomName() && entity == this.renderManager.pointedEntity);
24
    }
25
26
    public boolean shouldRender(T livingEntity, ICamera camera, double camX, double camY, double camZ)
27
    {
28
        if (super.shouldRender(livingEntity, camera, camX, camY, camZ))
29
        {
30
            return true;
31
        }
32
        else if (livingEntity.getLeashed() && livingEntity.getLeashedToEntity() != null)
33
        {
34
            Entity entity = livingEntity.getLeashedToEntity();
35
            return camera.isBoundingBoxInFrustum(entity.getEntityBoundingBox());
36
        }
37
        else
38
        {
39
            return false;
40
        }
41
    }
42
43
    /**
44
     * Renders the desired {@code T} type Entity.
45
     */
46
    public void doRender(T entity, double x, double y, double z, float entityYaw, float partialTicks)
47
    {
48
        super.doRender(entity, x, y, z, entityYaw, partialTicks);
49
        this.renderLeash(entity, x, y, z, entityYaw, partialTicks);
50
    }
51
52
    public void setLightmap(T entityLivingIn, float partialTicks)
53
    {
54
        int i = entityLivingIn.getBrightnessForRender(partialTicks);
55
        int j = i % 65536;
56
        int k = i / 65536;
57
        OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)j / 1.0F, (float)k / 1.0F);
58
    }
59
60
    /**
61
     * Gets the value between start and end according to pct
62
     */
63
    private double interpolateValue(double start, double end, double pct)
64
    {
65
        return start + (end - start) * pct;
66
    }
67
68
    protected void renderLeash(T entityLivingIn, double x, double y, double z, float entityYaw, float partialTicks)
69
    {
70
        Entity entity = entityLivingIn.getLeashedToEntity();
71
72
        if (entity != null)
73
        {
74
            y = y - (1.6D - (double)entityLivingIn.height) * 0.5D;
75
            Tessellator tessellator = Tessellator.getInstance();
76
            WorldRenderer worldrenderer = tessellator.getWorldRenderer();
77
            double d0 = this.interpolateValue((double)entity.prevRotationYaw, (double)entity.rotationYaw, (double)(partialTicks * 0.5F)) * 0.01745329238474369D;
78
            double d1 = this.interpolateValue((double)entity.prevRotationPitch, (double)entity.rotationPitch, (double)(partialTicks * 0.5F)) * 0.01745329238474369D;
79
            double d2 = Math.cos(d0);
80
            double d3 = Math.sin(d0);
81
            double d4 = Math.sin(d1);
82
83
            if (entity instanceof EntityHanging)
84
            {
85
                d2 = 0.0D;
86
                d3 = 0.0D;
87
                d4 = -1.0D;
88
            }
89
90
            double d5 = Math.cos(d1);
91
            double d6 = this.interpolateValue(entity.prevPosX, entity.posX, (double)partialTicks) - d2 * 0.7D - d3 * 0.5D * d5;
92
            double d7 = this.interpolateValue(entity.prevPosY + (double)entity.getEyeHeight() * 0.7D, entity.posY + (double)entity.getEyeHeight() * 0.7D, (double)partialTicks) - d4 * 0.5D - 0.25D;
93
            double d8 = this.interpolateValue(entity.prevPosZ, entity.posZ, (double)partialTicks) - d3 * 0.7D + d2 * 0.5D * d5;
94
            double d9 = this.interpolateValue((double)entityLivingIn.prevRenderYawOffset, (double)entityLivingIn.renderYawOffset, (double)partialTicks) * 0.01745329238474369D + (Math.PI / 2D);
95
            d2 = Math.cos(d9) * (double)entityLivingIn.width * 0.4D;
96
            d3 = Math.sin(d9) * (double)entityLivingIn.width * 0.4D;
97
            double d10 = this.interpolateValue(entityLivingIn.prevPosX, entityLivingIn.posX, (double)partialTicks) + d2;
98
            double d11 = this.interpolateValue(entityLivingIn.prevPosY, entityLivingIn.posY, (double)partialTicks);
99
            double d12 = this.interpolateValue(entityLivingIn.prevPosZ, entityLivingIn.posZ, (double)partialTicks) + d3;
100
            x = x + d2;
101
            z = z + d3;
102
            double d13 = (double)((float)(d6 - d10));
103
            double d14 = (double)((float)(d7 - d11));
104
            double d15 = (double)((float)(d8 - d12));
105
            GlStateManager.disableTexture2D();
106
            GlStateManager.disableLighting();
107
            GlStateManager.disableCull();
108
            int i = 24;
109
            double d16 = 0.025D;
110
            worldrenderer.begin(5, DefaultVertexFormats.POSITION_COLOR);
111
112
            for (int j = 0; j <= 24; ++j)
113
            {
114
                float f = 0.5F;
115
                float f1 = 0.4F;
116
                float f2 = 0.3F;
117
118
                if (j % 2 == 0)
119
                {
120
                    f *= 0.7F;
121
                    f1 *= 0.7F;
122
                    f2 *= 0.7F;
123
                }
124
125
                float f3 = (float)j / 24.0F;
126
                worldrenderer.pos(x + d13 * (double)f3 + 0.0D, y + d14 * (double)(f3 * f3 + f3) * 0.5D + (double)((24.0F - (float)j) / 18.0F + 0.125F), z + d15 * (double)f3).color(f, f1, f2, 1.0F).endVertex();
127
                worldrenderer.pos(x + d13 * (double)f3 + 0.025D, y + d14 * (double)(f3 * f3 + f3) * 0.5D + (double)((24.0F - (float)j) / 18.0F + 0.125F) + 0.025D, z + d15 * (double)f3).color(f, f1, f2, 1.0F).endVertex();
128
            }
129
130
            tessellator.draw();
131
            worldrenderer.begin(5, DefaultVertexFormats.POSITION_COLOR);
132
133
            for (int k = 0; k <= 24; ++k)
134
            {
135
                float f4 = 0.5F;
136
                float f5 = 0.4F;
137
                float f6 = 0.3F;
138
139
                if (k % 2 == 0)
140
                {
141
                    f4 *= 0.7F;
142
                    f5 *= 0.7F;
143
                    f6 *= 0.7F;
144
                }
145
146
                float f7 = (float)k / 24.0F;
147
                worldrenderer.pos(x + d13 * (double)f7 + 0.0D, y + d14 * (double)(f7 * f7 + f7) * 0.5D + (double)((24.0F - (float)k) / 18.0F + 0.125F) + 0.025D, z + d15 * (double)f7).color(f4, f5, f6, 1.0F).endVertex();
148
                worldrenderer.pos(x + d13 * (double)f7 + 0.025D, y + d14 * (double)(f7 * f7 + f7) * 0.5D + (double)((24.0F - (float)k) / 18.0F + 0.125F), z + d15 * (double)f7 + 0.025D).color(f4, f5, f6, 1.0F).endVertex();
149
            }
150
151
            tessellator.draw();
152
            GlStateManager.enableLighting();
153
            GlStateManager.enableTexture2D();
154
            GlStateManager.enableCull();
155
        }
156
    }
157
}
158

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