the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at master 127 lines 5.2 kB view raw
1#include "stdafx.h" 2#include "MobRenderer.h" 3#include "LivingEntityRenderer.h" 4#include "MultiPlayerLocalPlayer.h" 5#include "..\Minecraft.World\net.minecraft.world.entity.h" 6#include "..\Minecraft.World\net.minecraft.world.entity.player.h" 7#include "..\Minecraft.World\net.minecraft.world.entity.projectile.h" 8#include "..\Minecraft.World\StringHelpers.h" 9#include "..\Minecraft.World\Mth.h" 10#include "entityRenderDispatcher.h" 11 12MobRenderer::MobRenderer(Model *model, float shadow) : LivingEntityRenderer(model, shadow) 13{ 14} 15 16void MobRenderer::render(shared_ptr<Entity> _mob, double x, double y, double z, float rot, float a) 17{ 18 shared_ptr<Mob> mob = dynamic_pointer_cast<Mob>(_mob); 19 20 LivingEntityRenderer::render(mob, x, y, z, rot, a); 21 renderLeash(mob, x, y, z, rot, a); 22} 23 24bool MobRenderer::shouldShowName(shared_ptr<LivingEntity> mob) 25{ 26 return LivingEntityRenderer::shouldShowName(mob) && (mob->shouldShowName() || dynamic_pointer_cast<Mob>(mob)->hasCustomName() && mob == entityRenderDispatcher->crosshairPickMob); 27} 28 29void MobRenderer::renderLeash(shared_ptr<Mob> entity, double x, double y, double z, float rot, float a) 30{ 31 shared_ptr<Entity> roper = entity->getLeashHolder(); 32 // roper = entityRenderDispatcher.cameraEntity; 33 if (roper != NULL) 34 { 35 glColor4f(1.0f, 1.0f, 1.0f, 1.0f); 36 37 y -= (1.6 - entity->bbHeight) * .5; 38 Tesselator *tessellator = Tesselator::getInstance(); 39 double roperYRot = lerp(roper->yRotO, roper->yRot, a * .5f) * Mth::RAD_TO_GRAD; 40 double roperXRot = lerp(roper->xRotO, roper->xRot, a * .5f) * Mth::RAD_TO_GRAD; 41 double rotOffCos = cos(roperYRot); 42 double rotOffSin = sin(roperYRot); 43 double yOff = sin(roperXRot); 44 if (roper->instanceof(eTYPE_HANGING_ENTITY)) 45 { 46 rotOffCos = 0; 47 rotOffSin = 0; 48 yOff = -1; 49 } 50 double swingOff = cos(roperXRot); 51 double endX = lerp(roper->xo, roper->x, a) - (rotOffCos * 0.7) - (rotOffSin * 0.5 * swingOff); 52 double endY = lerp(roper->yo + roper->getHeadHeight() * .7, roper->y + roper->getHeadHeight() * .7, a) - (yOff * 0.5) - .25; 53 double endZ = lerp(roper->zo, roper->z, a) - (rotOffSin * 0.7) + (rotOffCos * 0.5 * swingOff); 54 55 double entityYRot = lerp(entity->yBodyRotO, entity->yBodyRot, a) * Mth::RAD_TO_GRAD + PI * .5; 56 rotOffCos = cos(entityYRot) * entity->bbWidth * .4; 57 rotOffSin = sin(entityYRot) * entity->bbWidth * .4; 58 double startX = lerp(entity->xo, entity->x, a) + rotOffCos; 59 double startY = lerp(entity->yo, entity->y, a); 60 double startZ = lerp(entity->zo, entity->z, a) + rotOffSin; 61 x += rotOffCos; 62 z += rotOffSin; 63 64 double dx = (float) (endX - startX); 65 double dy = (float) (endY - startY); 66 double dz = (float) (endZ - startZ); 67 68 glDisable(GL_TEXTURE_2D); 69 glDisable(GL_LIGHTING); 70 glDisable(GL_CULL_FACE); 71 72 unsigned int lightCol = Minecraft::GetInstance()->getColourTable()->getColor( eMinecraftColour_Leash_Light_Colour ); 73 float rLightCol = ( (lightCol>>16)&0xFF )/255.0f; 74 float gLightCol = ( (lightCol>>8)&0xFF )/255.0; 75 float bLightCol = ( lightCol&0xFF )/255.0; 76 77 unsigned int darkCol = Minecraft::GetInstance()->getColourTable()->getColor( eMinecraftColour_Leash_Dark_Colour ); 78 float rDarkCol = ( (darkCol>>16)&0xFF )/255.0f; 79 float gDarkCol = ( (darkCol>>8)&0xFF )/255.0; 80 float bDarkCol = ( darkCol&0xFF )/255.0; 81 82 int steps = 24; 83 double width = .025; 84 tessellator->begin(GL_TRIANGLE_STRIP); 85 for (int k = 0; k <= steps; k++) 86 { 87 if (k % 2 == 0) 88 { 89 tessellator->color(rLightCol, gLightCol, bLightCol, 1.0F); 90 } 91 else 92 { 93 tessellator->color(rDarkCol, gDarkCol, bDarkCol, 1.0F); 94 } 95 float aa = (float) k / (float) steps; 96 tessellator->vertex(x + (dx * aa) + 0, y + (dy * ((aa * aa) + aa) * 0.5) + ((((float) steps - (float) k) / (steps * 0.75F)) + 0.125F), z + (dz * aa)); 97 tessellator->vertex(x + (dx * aa) + width, y + (dy * ((aa * aa) + aa) * 0.5) + ((((float) steps - (float) k) / (steps * 0.75F)) + 0.125F) + width, z + (dz * aa)); 98 } 99 tessellator->end(); 100 101 tessellator->begin(GL_TRIANGLE_STRIP); 102 for (int k = 0; k <= steps; k++) 103 { 104 if (k % 2 == 0) 105 { 106 tessellator->color(rLightCol, gLightCol, bLightCol, 1.0F); 107 } 108 else 109 { 110 tessellator->color(rDarkCol, gDarkCol, bDarkCol, 1.0F); 111 } 112 float aa = (float) k / (float) steps; 113 tessellator->vertex(x + (dx * aa) + 0, y + (dy * ((aa * aa) + aa) * 0.5) + ((((float) steps - (float) k) / (steps * 0.75F)) + 0.125F) + width, z + (dz * aa)); 114 tessellator->vertex(x + (dx * aa) + width, y + (dy * ((aa * aa) + aa) * 0.5) + ((((float) steps - (float) k) / (steps * 0.75F)) + 0.125F), z + (dz * aa) + width); 115 } 116 tessellator->end(); 117 118 glEnable(GL_LIGHTING); 119 glEnable(GL_TEXTURE_2D); 120 glEnable(GL_CULL_FACE); 121 } 122} 123 124double MobRenderer::lerp(double prev, double next, double a) 125{ 126 return prev + (next - prev) * a; 127}