| 1 | package net.minecraft.client.renderer.entity;
|
| 2 |
|
| 3 | import net.minecraft.block.state.IBlockState;
|
| 4 | import net.minecraft.client.Minecraft;
|
| 5 | import net.minecraft.client.model.ModelBase;
|
| 6 | import net.minecraft.client.model.ModelMinecart;
|
| 7 | import net.minecraft.client.renderer.GlStateManager;
|
| 8 | import net.minecraft.client.renderer.texture.TextureMap;
|
| 9 | import net.minecraft.entity.item.EntityMinecart;
|
| 10 | import net.minecraft.util.MathHelper;
|
| 11 | import net.minecraft.util.ResourceLocation;
|
| 12 | import net.minecraft.util.Vec3;
|
| 13 |
|
| 14 | public class RenderMinecart<T extends EntityMinecart> extends Render<T>
|
| 15 | {
|
| 16 | private static final ResourceLocation minecartTextures = new ResourceLocation("textures/entity/minecart.png");
|
| 17 |
|
| 18 | /** instance of ModelMinecart for rendering */
|
| 19 | protected ModelBase modelMinecart = new ModelMinecart();
|
| 20 |
|
| 21 | public RenderMinecart(RenderManager renderManagerIn)
|
| 22 | {
|
| 23 | super(renderManagerIn);
|
| 24 | this.shadowSize = 0.5F;
|
| 25 | }
|
| 26 |
|
| 27 | /**
|
| 28 | * Renders the desired {@code T} type Entity.
|
| 29 | */
|
| 30 | public void doRender(T entity, double x, double y, double z, float entityYaw, float partialTicks)
|
| 31 | {
|
| 32 | GlStateManager.pushMatrix();
|
| 33 | this.bindEntityTexture(entity);
|
| 34 | long i = (long)entity.getEntityId() * 493286711L;
|
| 35 | i = i * i * 4392167121L + i * 98761L;
|
| 36 | float f = (((float)(i >> 16 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F;
|
| 37 | float f1 = (((float)(i >> 20 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F;
|
| 38 | float f2 = (((float)(i >> 24 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F;
|
| 39 | GlStateManager.translate(f, f1, f2);
|
| 40 | double d0 = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * (double)partialTicks;
|
| 41 | double d1 = entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * (double)partialTicks;
|
| 42 | double d2 = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * (double)partialTicks;
|
| 43 | double d3 = 0.30000001192092896D;
|
| 44 | Vec3 vec3 = entity.func_70489_a(d0, d1, d2);
|
| 45 | float f3 = entity.prevRotationPitch + (entity.rotationPitch - entity.prevRotationPitch) * partialTicks;
|
| 46 |
|
| 47 | if (vec3 != null)
|
| 48 | {
|
| 49 | Vec3 vec31 = entity.func_70495_a(d0, d1, d2, d3);
|
| 50 | Vec3 vec32 = entity.func_70495_a(d0, d1, d2, -d3);
|
| 51 |
|
| 52 | if (vec31 == null)
|
| 53 | {
|
| 54 | vec31 = vec3;
|
| 55 | }
|
| 56 |
|
| 57 | if (vec32 == null)
|
| 58 | {
|
| 59 | vec32 = vec3;
|
| 60 | }
|
| 61 |
|
| 62 | x += vec3.xCoord - d0;
|
| 63 | y += (vec31.yCoord + vec32.yCoord) / 2.0D - d1;
|
| 64 | z += vec3.zCoord - d2;
|
| 65 | Vec3 vec33 = vec32.addVector(-vec31.xCoord, -vec31.yCoord, -vec31.zCoord);
|
| 66 |
|
| 67 | if (vec33.lengthVector() != 0.0D)
|
| 68 | {
|
| 69 | vec33 = vec33.normalize();
|
| 70 | entityYaw = (float)(Math.atan2(vec33.zCoord, vec33.xCoord) * 180.0D / Math.PI);
|
| 71 | f3 = (float)(Math.atan(vec33.yCoord) * 73.0D);
|
| 72 | }
|
| 73 | }
|
| 74 |
|
| 75 | GlStateManager.translate((float)x, (float)y + 0.375F, (float)z);
|
| 76 | GlStateManager.rotate(180.0F - entityYaw, 0.0F, 1.0F, 0.0F);
|
| 77 | GlStateManager.rotate(-f3, 0.0F, 0.0F, 1.0F);
|
| 78 | float f5 = (float)entity.getRollingAmplitude() - partialTicks;
|
| 79 | float f6 = entity.getDamage() - partialTicks;
|
| 80 |
|
| 81 | if (f6 < 0.0F)
|
| 82 | {
|
| 83 | f6 = 0.0F;
|
| 84 | }
|
| 85 |
|
| 86 | if (f5 > 0.0F)
|
| 87 | {
|
| 88 | GlStateManager.rotate(MathHelper.sin(f5) * f5 * f6 / 10.0F * (float)entity.getRollingDirection(), 1.0F, 0.0F, 0.0F);
|
| 89 | }
|
| 90 |
|
| 91 | int j = entity.getDisplayTileOffset();
|
| 92 | IBlockState iblockstate = entity.getDisplayTile();
|
| 93 |
|
| 94 | if (iblockstate.getBlock().getRenderType() != -1)
|
| 95 | {
|
| 96 | GlStateManager.pushMatrix();
|
| 97 | this.bindTexture(TextureMap.locationBlocksTexture);
|
| 98 | float f4 = 0.75F;
|
| 99 | GlStateManager.scale(f4, f4, f4);
|
| 100 | GlStateManager.translate(-0.5F, (float)(j - 8) / 16.0F, 0.5F);
|
| 101 | this.func_180560_a(entity, partialTicks, iblockstate);
|
| 102 | GlStateManager.popMatrix();
|
| 103 | GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
| 104 | this.bindEntityTexture(entity);
|
| 105 | }
|
| 106 |
|
| 107 | GlStateManager.scale(-1.0F, -1.0F, 1.0F);
|
| 108 | this.modelMinecart.render(entity, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
|
| 109 | GlStateManager.popMatrix();
|
| 110 | super.doRender(entity, x, y, z, entityYaw, partialTicks);
|
| 111 | }
|
| 112 |
|
| 113 | /**
|
| 114 | * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
|
| 115 | */
|
| 116 | protected ResourceLocation getEntityTexture(T entity)
|
| 117 | {
|
| 118 | return minecartTextures;
|
| 119 | }
|
| 120 |
|
| 121 | protected void func_180560_a(T minecart, float partialTicks, IBlockState state)
|
| 122 | {
|
| 123 | GlStateManager.pushMatrix();
|
| 124 | Minecraft.getMinecraft().getBlockRendererDispatcher().renderBlockBrightness(state, minecart.getBrightness(partialTicks));
|
| 125 | GlStateManager.popMatrix();
|
| 126 | }
|
| 127 | }
|
| 128 |
|