Render .java

net.minecraft.client.renderer.entity.Render (class): members: getFontRendererFromRenderManager, doRenderShadowAndFire, bindEntityTexture, renderOffsetAABB.

net.minecraft.client.renderer.entityclass386 linesclientextends Entity>17.9 KB

API Surface (12)

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 renderName(T entity, double x, double y, double z)
boolean canRenderName(T entity)
void renderOffsetLivingLabel(T entityIn, double x, double y, double z, String str, float p_177069_9_, double p_177069_10_)
boolean bindEntityTexture(T entity)
void bindTexture(ResourceLocation location)
void renderOffsetAABB(AxisAlignedBB boundingBox, double x, double y, double z)
void doRenderShadowAndFire(Entity entityIn, double x, double y, double z, float yaw, float partialTicks)
FontRenderer getFontRendererFromRenderManager()
void renderLivingLabel(T entityIn, String str, double x, double y, double z, int maxDistance)
RenderManager getRenderManager()

Fields & Constants (4)

shadowTextures
renderManager
shadowSize
shadowOpaque

String literals (4)

"textures/misc/shadow.png"
"minecraft:blocks/fire_layer_0"
"minecraft:blocks/fire_layer_1"
"deadmau5"

Full Source

Render.java386 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.client.renderer.entity;
2
3
import net.minecraft.block.Block;
4
import net.minecraft.client.Minecraft;
5
import net.minecraft.client.gui.FontRenderer;
6
import net.minecraft.client.renderer.GlStateManager;
7
import net.minecraft.client.renderer.Tessellator;
8
import net.minecraft.client.renderer.WorldRenderer;
9
import net.minecraft.client.renderer.culling.ICamera;
10
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
11
import net.minecraft.client.renderer.texture.TextureMap;
12
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
13
import net.minecraft.entity.Entity;
14
import net.minecraft.entity.EntityLiving;
15
import net.minecraft.entity.player.EntityPlayer;
16
import net.minecraft.util.AxisAlignedBB;
17
import net.minecraft.util.BlockPos;
18
import net.minecraft.util.MathHelper;
19
import net.minecraft.util.ResourceLocation;
20
import net.minecraft.world.World;
21
import org.lwjgl.opengl.GL11;
22
23
public abstract class Render<T extends Entity>
24
{
25
    private static final ResourceLocation shadowTextures = new ResourceLocation("textures/misc/shadow.png");
26
    protected final RenderManager renderManager;
27
    protected float shadowSize;
28
29
    /**
30
     * Determines the darkness of the object's shadow. Higher value makes a darker shadow.
31
     */
32
    protected float shadowOpaque = 1.0F;
33
34
    protected Render(RenderManager renderManager)
35
    {
36
        this.renderManager = renderManager;
37
    }
38
39
    public boolean shouldRender(T livingEntity, ICamera camera, double camX, double camY, double camZ)
40
    {
41
        AxisAlignedBB axisalignedbb = livingEntity.getEntityBoundingBox();
42
43
        if (axisalignedbb.hasNaN() || axisalignedbb.getAverageEdgeLength() == 0.0D)
44
        {
45
            axisalignedbb = new AxisAlignedBB(livingEntity.posX - 2.0D, livingEntity.posY - 2.0D, livingEntity.posZ - 2.0D, livingEntity.posX + 2.0D, livingEntity.posY + 2.0D, livingEntity.posZ + 2.0D);
46
        }
47
48
        return livingEntity.isInRangeToRender3d(camX, camY, camZ) && (livingEntity.ignoreFrustumCheck || camera.isBoundingBoxInFrustum(axisalignedbb));
49
    }
50
51
    /**
52
     * Renders the desired {@code T} type Entity.
53
     */
54
    public void doRender(T entity, double x, double y, double z, float entityYaw, float partialTicks)
55
    {
56
        this.renderName(entity, x, y, z);
57
    }
58
59
    protected void renderName(T entity, double x, double y, double z)
60
    {
61
        if (this.canRenderName(entity))
62
        {
63
            this.renderLivingLabel(entity, entity.getDisplayName().getFormattedText(), x, y, z, 64);
64
        }
65
    }
66
67
    protected boolean canRenderName(T entity)
68
    {
69
        return entity.getAlwaysRenderNameTagForRender() && entity.hasCustomName();
70
    }
71
72
    protected void renderOffsetLivingLabel(T entityIn, double x, double y, double z, String str, float p_177069_9_, double p_177069_10_)
73
    {
74
        this.renderLivingLabel(entityIn, str, x, y, z, 64);
75
    }
76
77
    /**
78
     * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
79
     */
80
    protected abstract ResourceLocation getEntityTexture(T entity);
81
82
    protected boolean bindEntityTexture(T entity)
83
    {
84
        ResourceLocation resourcelocation = this.getEntityTexture(entity);
85
86
        if (resourcelocation == null)
87
        {
88
            return false;
89
        }
90
        else
91
        {
92
            this.bindTexture(resourcelocation);
93
            return true;
94
        }
95
    }
96
97
    public void bindTexture(ResourceLocation location)
98
    {
99
        this.renderManager.renderEngine.bindTexture(location);
100
    }
101
102
    /**
103
     * Renders fire on top of the entity. Args: entity, x, y, z, partialTickTime
104
     */
105
    private void renderEntityOnFire(Entity entity, double x, double y, double z, float partialTicks)
106
    {
107
        GlStateManager.disableLighting();
108
        TextureMap texturemap = Minecraft.getMinecraft().getTextureMapBlocks();
109
        TextureAtlasSprite textureatlassprite = texturemap.getAtlasSprite("minecraft:blocks/fire_layer_0");
110
        TextureAtlasSprite textureatlassprite1 = texturemap.getAtlasSprite("minecraft:blocks/fire_layer_1");
111
        GlStateManager.pushMatrix();
112
        GlStateManager.translate((float)x, (float)y, (float)z);
113
        float f = entity.width * 1.4F;
114
        GlStateManager.scale(f, f, f);
115
        Tessellator tessellator = Tessellator.getInstance();
116
        WorldRenderer worldrenderer = tessellator.getWorldRenderer();
117
        float f1 = 0.5F;
118
        float f2 = 0.0F;
119
        float f3 = entity.height / f;
120
        float f4 = (float)(entity.posY - entity.getEntityBoundingBox().minY);
121
        GlStateManager.rotate(-this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
122
        GlStateManager.translate(0.0F, 0.0F, -0.3F + (float)((int)f3) * 0.02F);
123
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
124
        float f5 = 0.0F;
125
        int i = 0;
126
        worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX);
127
128
        while (f3 > 0.0F)
129
        {
130
            TextureAtlasSprite textureatlassprite2 = i % 2 == 0 ? textureatlassprite : textureatlassprite1;
131
            this.bindTexture(TextureMap.locationBlocksTexture);
132
            float f6 = textureatlassprite2.getMinU();
133
            float f7 = textureatlassprite2.getMinV();
134
            float f8 = textureatlassprite2.getMaxU();
135
            float f9 = textureatlassprite2.getMaxV();
136
137
            if (i / 2 % 2 == 0)
138
            {
139
                float f10 = f8;
140
                f8 = f6;
141
                f6 = f10;
142
            }
143
144
            worldrenderer.pos((double)(f1 - f2), (double)(0.0F - f4), (double)f5).tex((double)f8, (double)f9).endVertex();
145
            worldrenderer.pos((double)(-f1 - f2), (double)(0.0F - f4), (double)f5).tex((double)f6, (double)f9).endVertex();
146
            worldrenderer.pos((double)(-f1 - f2), (double)(1.4F - f4), (double)f5).tex((double)f6, (double)f7).endVertex();
147
            worldrenderer.pos((double)(f1 - f2), (double)(1.4F - f4), (double)f5).tex((double)f8, (double)f7).endVertex();
148
            f3 -= 0.45F;
149
            f4 -= 0.45F;
150
            f1 *= 0.9F;
151
            f5 += 0.03F;
152
            ++i;
153
        }
154
155
        tessellator.draw();
156
        GlStateManager.popMatrix();
157
        GlStateManager.enableLighting();
158
    }
159
160
    /**
161
     * Renders the entity shadows at the position, shadow alpha and partialTickTime. Args: entity, x, y, z, shadowAlpha,
162
     * partialTickTime
163
     */
164
    private void renderShadow(Entity entityIn, double x, double y, double z, float shadowAlpha, float partialTicks)
165
    {
166
        GlStateManager.enableBlend();
167
        GlStateManager.blendFunc(770, 771);
168
        this.renderManager.renderEngine.bindTexture(shadowTextures);
169
        World world = this.getWorldFromRenderManager();
170
        GlStateManager.depthMask(false);
171
        float f = this.shadowSize;
172
173
        if (entityIn instanceof EntityLiving)
174
        {
175
            EntityLiving entityliving = (EntityLiving)entityIn;
176
            f *= entityliving.getRenderSizeModifier();
177
178
            if (entityliving.isChild())
179
            {
180
                f *= 0.5F;
181
            }
182
        }
183
184
        double d5 = entityIn.lastTickPosX + (entityIn.posX - entityIn.lastTickPosX) * (double)partialTicks;
185
        double d0 = entityIn.lastTickPosY + (entityIn.posY - entityIn.lastTickPosY) * (double)partialTicks;
186
        double d1 = entityIn.lastTickPosZ + (entityIn.posZ - entityIn.lastTickPosZ) * (double)partialTicks;
187
        int i = MathHelper.floor_double(d5 - (double)f);
188
        int j = MathHelper.floor_double(d5 + (double)f);
189
        int k = MathHelper.floor_double(d0 - (double)f);
190
        int l = MathHelper.floor_double(d0);
191
        int i1 = MathHelper.floor_double(d1 - (double)f);
192
        int j1 = MathHelper.floor_double(d1 + (double)f);
193
        double d2 = x - d5;
194
        double d3 = y - d0;
195
        double d4 = z - d1;
196
        Tessellator tessellator = Tessellator.getInstance();
197
        WorldRenderer worldrenderer = tessellator.getWorldRenderer();
198
        worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
199
200
        for (BlockPos blockpos : BlockPos.getAllInBoxMutable(new BlockPos(i, k, i1), new BlockPos(j, l, j1)))
201
        {
202
            Block block = world.getBlockState(blockpos.down()).getBlock();
203
204
            if (block.getRenderType() != -1 && world.getLightFromNeighbors(blockpos) > 3)
205
            {
206
                this.renderShadowBlock(block, x, y, z, blockpos, shadowAlpha, f, d2, d3, d4);
207
            }
208
        }
209
210
        tessellator.draw();
211
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
212
        GlStateManager.disableBlend();
213
        GlStateManager.depthMask(true);
214
    }
215
216
    /**
217
     * Returns the render manager's world object
218
     */
219
    private World getWorldFromRenderManager()
220
    {
221
        return this.renderManager.worldObj;
222
    }
223
224
    private void renderShadowBlock(Block blockIn, double p_180549_2_, double p_180549_4_, double p_180549_6_, BlockPos pos, float p_180549_9_, float p_180549_10_, double p_180549_11_, double p_180549_13_, double p_180549_15_)
225
    {
226
        if (blockIn.isFullCube())
227
        {
228
            Tessellator tessellator = Tessellator.getInstance();
229
            WorldRenderer worldrenderer = tessellator.getWorldRenderer();
230
            double d0 = ((double)p_180549_9_ - (p_180549_4_ - ((double)pos.getY() + p_180549_13_)) / 2.0D) * 0.5D * (double)this.getWorldFromRenderManager().getLightBrightness(pos);
231
232
            if (d0 >= 0.0D)
233
            {
234
                if (d0 > 1.0D)
235
                {
236
                    d0 = 1.0D;
237
                }
238
239
                double d1 = (double)pos.getX() + blockIn.getBlockBoundsMinX() + p_180549_11_;
240
                double d2 = (double)pos.getX() + blockIn.getBlockBoundsMaxX() + p_180549_11_;
241
                double d3 = (double)pos.getY() + blockIn.getBlockBoundsMinY() + p_180549_13_ + 0.015625D;
242
                double d4 = (double)pos.getZ() + blockIn.getBlockBoundsMinZ() + p_180549_15_;
243
                double d5 = (double)pos.getZ() + blockIn.getBlockBoundsMaxZ() + p_180549_15_;
244
                float f = (float)((p_180549_2_ - d1) / 2.0D / (double)p_180549_10_ + 0.5D);
245
                float f1 = (float)((p_180549_2_ - d2) / 2.0D / (double)p_180549_10_ + 0.5D);
246
                float f2 = (float)((p_180549_6_ - d4) / 2.0D / (double)p_180549_10_ + 0.5D);
247
                float f3 = (float)((p_180549_6_ - d5) / 2.0D / (double)p_180549_10_ + 0.5D);
248
                worldrenderer.pos(d1, d3, d4).tex((double)f, (double)f2).color(1.0F, 1.0F, 1.0F, (float)d0).endVertex();
249
                worldrenderer.pos(d1, d3, d5).tex((double)f, (double)f3).color(1.0F, 1.0F, 1.0F, (float)d0).endVertex();
250
                worldrenderer.pos(d2, d3, d5).tex((double)f1, (double)f3).color(1.0F, 1.0F, 1.0F, (float)d0).endVertex();
251
                worldrenderer.pos(d2, d3, d4).tex((double)f1, (double)f2).color(1.0F, 1.0F, 1.0F, (float)d0).endVertex();
252
            }
253
        }
254
    }
255
256
    /**
257
     * Renders a white box with the bounds of the AABB translated by the offset. Args: aabb, x, y, z
258
     */
259
    public static void renderOffsetAABB(AxisAlignedBB boundingBox, double x, double y, double z)
260
    {
261
        GlStateManager.disableTexture2D();
262
        Tessellator tessellator = Tessellator.getInstance();
263
        WorldRenderer worldrenderer = tessellator.getWorldRenderer();
264
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
265
        worldrenderer.setTranslation(x, y, z);
266
        worldrenderer.begin(7, DefaultVertexFormats.POSITION_NORMAL);
267
        worldrenderer.pos(boundingBox.minX, boundingBox.maxY, boundingBox.minZ).normal(0.0F, 0.0F, -1.0F).endVertex();
268
        worldrenderer.pos(boundingBox.maxX, boundingBox.maxY, boundingBox.minZ).normal(0.0F, 0.0F, -1.0F).endVertex();
269
        worldrenderer.pos(boundingBox.maxX, boundingBox.minY, boundingBox.minZ).normal(0.0F, 0.0F, -1.0F).endVertex();
270
        worldrenderer.pos(boundingBox.minX, boundingBox.minY, boundingBox.minZ).normal(0.0F, 0.0F, -1.0F).endVertex();
271
        worldrenderer.pos(boundingBox.minX, boundingBox.minY, boundingBox.maxZ).normal(0.0F, 0.0F, 1.0F).endVertex();
272
        worldrenderer.pos(boundingBox.maxX, boundingBox.minY, boundingBox.maxZ).normal(0.0F, 0.0F, 1.0F).endVertex();
273
        worldrenderer.pos(boundingBox.maxX, boundingBox.maxY, boundingBox.maxZ).normal(0.0F, 0.0F, 1.0F).endVertex();
274
        worldrenderer.pos(boundingBox.minX, boundingBox.maxY, boundingBox.maxZ).normal(0.0F, 0.0F, 1.0F).endVertex();
275
        worldrenderer.pos(boundingBox.minX, boundingBox.minY, boundingBox.minZ).normal(0.0F, -1.0F, 0.0F).endVertex();
276
        worldrenderer.pos(boundingBox.maxX, boundingBox.minY, boundingBox.minZ).normal(0.0F, -1.0F, 0.0F).endVertex();
277
        worldrenderer.pos(boundingBox.maxX, boundingBox.minY, boundingBox.maxZ).normal(0.0F, -1.0F, 0.0F).endVertex();
278
        worldrenderer.pos(boundingBox.minX, boundingBox.minY, boundingBox.maxZ).normal(0.0F, -1.0F, 0.0F).endVertex();
279
        worldrenderer.pos(boundingBox.minX, boundingBox.maxY, boundingBox.maxZ).normal(0.0F, 1.0F, 0.0F).endVertex();
280
        worldrenderer.pos(boundingBox.maxX, boundingBox.maxY, boundingBox.maxZ).normal(0.0F, 1.0F, 0.0F).endVertex();
281
        worldrenderer.pos(boundingBox.maxX, boundingBox.maxY, boundingBox.minZ).normal(0.0F, 1.0F, 0.0F).endVertex();
282
        worldrenderer.pos(boundingBox.minX, boundingBox.maxY, boundingBox.minZ).normal(0.0F, 1.0F, 0.0F).endVertex();
283
        worldrenderer.pos(boundingBox.minX, boundingBox.minY, boundingBox.maxZ).normal(-1.0F, 0.0F, 0.0F).endVertex();
284
        worldrenderer.pos(boundingBox.minX, boundingBox.maxY, boundingBox.maxZ).normal(-1.0F, 0.0F, 0.0F).endVertex();
285
        worldrenderer.pos(boundingBox.minX, boundingBox.maxY, boundingBox.minZ).normal(-1.0F, 0.0F, 0.0F).endVertex();
286
        worldrenderer.pos(boundingBox.minX, boundingBox.minY, boundingBox.minZ).normal(-1.0F, 0.0F, 0.0F).endVertex();
287
        worldrenderer.pos(boundingBox.maxX, boundingBox.minY, boundingBox.minZ).normal(1.0F, 0.0F, 0.0F).endVertex();
288
        worldrenderer.pos(boundingBox.maxX, boundingBox.maxY, boundingBox.minZ).normal(1.0F, 0.0F, 0.0F).endVertex();
289
        worldrenderer.pos(boundingBox.maxX, boundingBox.maxY, boundingBox.maxZ).normal(1.0F, 0.0F, 0.0F).endVertex();
290
        worldrenderer.pos(boundingBox.maxX, boundingBox.minY, boundingBox.maxZ).normal(1.0F, 0.0F, 0.0F).endVertex();
291
        tessellator.draw();
292
        worldrenderer.setTranslation(0.0D, 0.0D, 0.0D);
293
        GlStateManager.enableTexture2D();
294
    }
295
296
    /**
297
     * Renders the entity's shadow and fire (if its on fire). Args: entity, x, y, z, yaw, partialTickTime
298
     */
299
    public void doRenderShadowAndFire(Entity entityIn, double x, double y, double z, float yaw, float partialTicks)
300
    {
301
        if (this.renderManager.options != null)
302
        {
303
            if (this.renderManager.options.entityShadows && this.shadowSize > 0.0F && !entityIn.isInvisible() && this.renderManager.isRenderShadow())
304
            {
305
                double d0 = this.renderManager.getDistanceToCamera(entityIn.posX, entityIn.posY, entityIn.posZ);
306
                float f = (float)((1.0D - d0 / 256.0D) * (double)this.shadowOpaque);
307
308
                if (f > 0.0F)
309
                {
310
                    this.renderShadow(entityIn, x, y, z, f, partialTicks);
311
                }
312
            }
313
314
            if (entityIn.canRenderOnFire() && (!(entityIn instanceof EntityPlayer) || !((EntityPlayer)entityIn).isSpectator()))
315
            {
316
                this.renderEntityOnFire(entityIn, x, y, z, partialTicks);
317
            }
318
        }
319
    }
320
321
    /**
322
     * Returns the font renderer from the set render manager
323
     */
324
    public FontRenderer getFontRendererFromRenderManager()
325
    {
326
        return this.renderManager.getFontRenderer();
327
    }
328
329
    /**
330
     * Renders an entity's name above its head
331
     */
332
    protected void renderLivingLabel(T entityIn, String str, double x, double y, double z, int maxDistance)
333
    {
334
        double d0 = entityIn.getDistanceSqToEntity(this.renderManager.livingPlayer);
335
336
        if (d0 <= (double)(maxDistance * maxDistance))
337
        {
338
            FontRenderer fontrenderer = this.getFontRendererFromRenderManager();
339
            float f = 1.6F;
340
            float f1 = 0.016666668F * f;
341
            GlStateManager.pushMatrix();
342
            GlStateManager.translate((float)x + 0.0F, (float)y + entityIn.height + 0.5F, (float)z);
343
            GL11.glNormal3f(0.0F, 1.0F, 0.0F);
344
            GlStateManager.rotate(-this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
345
            GlStateManager.rotate(this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
346
            GlStateManager.scale(-f1, -f1, f1);
347
            GlStateManager.disableLighting();
348
            GlStateManager.depthMask(false);
349
            GlStateManager.disableDepth();
350
            GlStateManager.enableBlend();
351
            GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
352
            Tessellator tessellator = Tessellator.getInstance();
353
            WorldRenderer worldrenderer = tessellator.getWorldRenderer();
354
            int i = 0;
355
356
            if (str.equals("deadmau5"))
357
            {
358
                i = -10;
359
            }
360
361
            int j = fontrenderer.getStringWidth(str) / 2;
362
            GlStateManager.disableTexture2D();
363
            worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
364
            worldrenderer.pos((double)(-j - 1), (double)(-1 + i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
365
            worldrenderer.pos((double)(-j - 1), (double)(8 + i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
366
            worldrenderer.pos((double)(j + 1), (double)(8 + i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
367
            worldrenderer.pos((double)(j + 1), (double)(-1 + i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
368
            tessellator.draw();
369
            GlStateManager.enableTexture2D();
370
            fontrenderer.drawString(str, -fontrenderer.getStringWidth(str) / 2, i, 553648127);
371
            GlStateManager.enableDepth();
372
            GlStateManager.depthMask(true);
373
            fontrenderer.drawString(str, -fontrenderer.getStringWidth(str) / 2, i, -1);
374
            GlStateManager.enableLighting();
375
            GlStateManager.disableBlend();
376
            GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
377
            GlStateManager.popMatrix();
378
        }
379
    }
380
381
    public RenderManager getRenderManager()
382
    {
383
        return this.renderManager;
384
    }
385
}
386

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