the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 269 lines 8.7 kB view raw
1#include "stdafx.h" 2#include "DragonModel.h" 3#include "..\Minecraft.World\net.minecraft.world.entity.boss.enderdragon.h" 4#include "Tesselator.h" 5#include "Lighting.h" 6#include "EnderDragonRenderer.h" 7#include "BossMobGuiInfo.h" 8 9ResourceLocation EnderDragonRenderer::DRAGON_EXPLODING_LOCATION = ResourceLocation(TN_MOB_ENDERDRAGON_SHUFFLE); 10ResourceLocation EnderDragonRenderer::CRYSTAL_BEAM_LOCATION = ResourceLocation(TN_MOB_ENDERDRAGON_BEAM); 11ResourceLocation EnderDragonRenderer::DRAGON_EYES_LOCATION = ResourceLocation(TN_MOB_ENDERDRAGON_ENDEREYES); 12ResourceLocation EnderDragonRenderer::DRAGON_LOCATION = ResourceLocation(TN_MOB_ENDERDRAGON); 13 14EnderDragonRenderer::EnderDragonRenderer() : MobRenderer(new DragonModel(0), 0.5f) 15{ 16 dragonModel = (DragonModel *) model; 17 setArmor(model); // TODO: Make second constructor that assigns this. 18} 19 20void EnderDragonRenderer::setupRotations(shared_ptr<LivingEntity> _mob, float bob, float bodyRot, float a) 21{ 22 // 4J - dynamic cast required because we aren't using templates/generics in our version 23 shared_ptr<EnderDragon> mob = dynamic_pointer_cast<EnderDragon>(_mob); 24 25 // 4J - reorganised a bit so we can free allocations 26 double lpComponents[3]; 27 doubleArray lp = doubleArray(lpComponents, 3); 28 mob->getLatencyPos(lp, 7, a); 29 float yr = lp[0]; 30 //mob->getLatencyPos(lp, 5, a); 31 //float rot2 = lp[1]; 32 //mob->getLatencyPos(lp, 10,a); 33 //rot2 -= lp[1]; 34 float rot2 = mob->getTilt(a); 35 36 glRotatef(-yr, 0, 1, 0); 37 38 glRotatef(rot2, 1, 0, 0); 39 //glRotatef(rot2 * 10, 1, 0, 0); 40 41 glTranslatef(0, 0, 1); 42 if (mob->deathTime > 0) 43 { 44 float fall = (mob->deathTime + a - 1) / 20.0f * 1.6f; 45 fall = sqrt(fall); 46 if (fall > 1) fall = 1; 47 glRotatef(fall * getFlipDegrees(mob), 0, 0, 1); 48 } 49} 50 51void EnderDragonRenderer::renderModel(shared_ptr<LivingEntity> _mob, float wp, float ws, float bob, float headRotMinusBodyRot, float headRotx, float scale) 52{ 53 // 4J - dynamic cast required because we aren't using templates/generics in our version 54 shared_ptr<EnderDragon> mob = dynamic_pointer_cast<EnderDragon>(_mob); 55 56 if (mob->dragonDeathTime > 0) 57 { 58 float tt = (mob->dragonDeathTime / 200.0f); 59 glDepthFunc(GL_LEQUAL); 60 glEnable(GL_ALPHA_TEST); 61 glAlphaFunc(GL_GREATER, tt); 62 bindTexture(&DRAGON_EXPLODING_LOCATION); // 4J was "/mob/enderdragon/shuffle.png" 63 model->render(mob, wp, ws, bob, headRotMinusBodyRot, headRotx, scale, true); 64 glAlphaFunc(GL_GREATER, 0.1f); 65 66 glDepthFunc(GL_EQUAL); 67 } 68 69 70 bindTexture(mob); 71 model->render(mob, wp, ws, bob, headRotMinusBodyRot, headRotx, scale, true); 72 73 if (mob->hurtTime > 0) 74 { 75 glDepthFunc(GL_EQUAL); 76 glDisable(GL_TEXTURE_2D); 77 glEnable(GL_BLEND); 78 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 79 glColor4f(1, 0, 0, 0.5f); 80#ifdef __PSVITA__ 81 // AP - not sure that the usecompiled flag is supposed to be false. This makes it really slow on vita. Making it true still seems to look the same 82 model->render(mob, wp, ws, bob, headRotMinusBodyRot, headRotx, scale, true); 83#else 84 model->render(mob, wp, ws, bob, headRotMinusBodyRot, headRotx, scale, false); 85#endif 86 glEnable(GL_TEXTURE_2D); 87 glDisable(GL_BLEND); 88 glDepthFunc(GL_LEQUAL); 89 } 90} 91 92void EnderDragonRenderer::render(shared_ptr<Entity> _mob, double x, double y, double z, float rot, float a) 93{ 94 // 4J - dynamic cast required because we aren't using templates/generics in our version 95 shared_ptr<EnderDragon> mob = dynamic_pointer_cast<EnderDragon>(_mob); 96 BossMobGuiInfo::setBossHealth(mob, false); 97 MobRenderer::render(mob, x, y, z, rot, a); 98 if (mob->nearestCrystal != NULL) 99 { 100 float tt = mob->nearestCrystal->time + a; 101 float hh = sin(tt * 0.2f) / 2 + 0.5f; 102 hh = (hh * hh + hh) * 0.2f; 103 104 float xd = (float) (mob->nearestCrystal->x - mob->x - (mob->xo - mob->x) * (1 - a)); 105 float yd = (float) (hh + mob->nearestCrystal->y - 1 - mob->y - (mob->yo - mob->y) * (1 - a)); 106 float zd = (float) (mob->nearestCrystal->z - mob->z - (mob->zo - mob->z) * (1 - a)); 107 108 float sdd = sqrt(xd * xd + zd * zd); 109 float dd = sqrt(xd * xd + yd * yd + zd * zd); 110 111 // this fixes a problem when the dragon is hit and the beam goes black because the diffuse colour isn't being reset in MobRenderer::render 112 glColor4f(1, 1, 1, 1); 113 114 glPushMatrix(); 115 glTranslatef((float) x, (float) y + 2, (float) z); 116 glRotatef((float) (-atan2(zd, xd)) * 180.0f / PI - 90.0f, 0, 1, 0); 117 glRotatef((float) (-atan2(sdd, yd)) * 180.0f / PI - 90.0f, 1, 0, 0); 118 119 // 4J-PB - Rotating the healing beam too 120 static float fRot=0.0f; 121 glRotatef(fRot, 0, 0, 1); 122 fRot+=0.5f; // 4J - rate of rotation changed from 5.0 to 0.5 for photosensitivity reasons 123 if(fRot>=360.0f) 124 { 125 fRot=0.0f; 126 } 127 128 Tesselator *t = Tesselator::getInstance(); 129 Lighting::turnOff(); 130 glDisable(GL_CULL_FACE); 131 132 glEnable(GL_BLEND); 133 glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA); 134 135 bindTexture(&CRYSTAL_BEAM_LOCATION); // 4J was "/mob/enderdragon/beam.png" 136 137 glShadeModel(GL_SMOOTH); 138 139 float v0 = 0 - (mob->tickCount + a) * 0.005f; // 4J - rate of movement changed from 0.01 to 0.005 for photosensitivity reasons 140 float v1 = sqrt(xd * xd + yd * yd + zd * zd) / 32.0f - (mob->tickCount + a) * 0.005f; 141 142 t->begin(GL_TRIANGLE_STRIP); 143 144 int steps = 8; 145 for (int i = 0; i <= steps; i++) 146 { 147 double d=i % steps * PI * 2 / steps; 148 float s = sin(i % steps * PI * 2 / steps) * 0.75f; 149 float c = cos(i % steps * PI * 2 / steps) * 0.75f; 150 float u = i % steps * 1.0f / steps; 151 //t->color(0x000000); 152 t->vertexUV(s * 0.2f, c * 0.2f, 0, u, v1); 153 //t->color(0xffffff); 154 t->vertexUV(s, c, dd, u, v0); 155 } 156 157 t->end(); 158 glEnable(GL_CULL_FACE); 159 glShadeModel(GL_FLAT); 160 glDisable(GL_BLEND); 161 162 glPopMatrix(); 163 Lighting::turnOn(); 164 } 165} 166 167ResourceLocation *EnderDragonRenderer::getTextureLocation(shared_ptr<Entity> mob) 168{ 169 return &DRAGON_LOCATION; 170} 171 172void EnderDragonRenderer::additionalRendering(shared_ptr<LivingEntity> _mob, float a) 173{ 174 // 4J - dynamic cast required because we aren't using templates/generics in our version 175 shared_ptr<EnderDragon> mob = dynamic_pointer_cast<EnderDragon>(_mob); 176 MobRenderer::additionalRendering(mob, a); 177 Tesselator *t = Tesselator::getInstance(); 178 179 if (mob->dragonDeathTime > 0) 180 { 181 Lighting::turnOff(); 182 float tt = ((mob->dragonDeathTime + a) / 200.0f); 183 float overDrive = 0; 184 if (tt > 0.8f) 185 { 186 overDrive = (tt - 0.8f) / 0.2f; 187 } 188 189 Random random(432); 190 glDisable(GL_TEXTURE_2D); 191 glShadeModel(GL_SMOOTH); 192 glEnable(GL_BLEND); 193 glBlendFunc(GL_SRC_ALPHA, GL_ONE); 194 glDisable(GL_ALPHA_TEST); 195 glEnable(GL_CULL_FACE); 196 glDepthMask(false); 197 glPushMatrix(); 198 glTranslatef(0, -1, -2); 199 for (int i = 0; i < (tt + tt * tt) / 2 * 60; i++) 200 { 201 glRotatef(random.nextFloat() * 360, 1, 0, 0); 202 glRotatef(random.nextFloat() * 360, 0, 1, 0); 203 glRotatef(random.nextFloat() * 360, 0, 0, 1); 204 glRotatef(random.nextFloat() * 360, 1, 0, 0); 205 glRotatef(random.nextFloat() * 360, 0, 1, 0); 206 glRotatef(random.nextFloat() * 360 + tt * 90, 0, 0, 1); 207 t->begin(GL_TRIANGLE_FAN); 208 float dist = random.nextFloat() * 20 + 5 + overDrive * 10; 209 float w = random.nextFloat() * 2 + 1 + overDrive * 2; 210 t->color(0xffffff, (int) (255 * (1 - overDrive))); 211 t->vertex(0, 0, 0); 212 t->color(0xff00ff, 0); 213 t->vertex(-0.866 * w, dist, -0.5f * w); 214 t->vertex(+0.866 * w, dist, -0.5f * w); 215 t->vertex(0, dist, 1 * w); 216 t->vertex(-0.866 * w, dist, -0.5f * w); 217 t->end(); 218 } 219 glPopMatrix(); 220 glDepthMask(true); 221 glDisable(GL_CULL_FACE); 222 glDisable(GL_BLEND); 223 glShadeModel(GL_FLAT); 224 glColor4f(1, 1, 1, 1); 225 glEnable(GL_TEXTURE_2D); 226 glEnable(GL_ALPHA_TEST); 227 Lighting::turnOn(); 228 } 229 230} 231 232int EnderDragonRenderer::prepareArmor(shared_ptr<LivingEntity> _mob, int layer, float a) 233{ 234 // 4J - dynamic cast required because we aren't using templates/generics in our version 235 shared_ptr<EnderDragon> mob = dynamic_pointer_cast<EnderDragon>(_mob); 236 237 if (layer == 1) 238 { 239 glDepthFunc(GL_LEQUAL); 240 } 241 if (layer != 0) return -1; 242 243 bindTexture(&DRAGON_EYES_LOCATION); // 4J was "/mob/enderdragon/ender_eyes.png" 244 float br = 1; 245 glEnable(GL_BLEND); 246 // 4J Stu - We probably don't need to do this on 360 either (as we force it back on the renderer) 247 // However we do want it off for other platforms that don't force it on in the render lib CBuff handling 248 // Several texture packs have fully transparent bits that break if this is off 249#ifdef _XBOX 250 glDisable(GL_ALPHA_TEST); 251#endif 252 glBlendFunc(GL_ONE, GL_ONE); 253 glDisable(GL_LIGHTING); 254 glDepthFunc(GL_EQUAL); 255 256 if (SharedConstants::TEXTURE_LIGHTING) 257 { 258 int col = 0xf0f0; 259 int u = col % 65536; 260 int v = col / 65536; 261 262 glMultiTexCoord2f(GL_TEXTURE1, u / 1.0f, v / 1.0f); 263 glColor4f(1, 1, 1, 1); 264 } 265 266 glEnable(GL_LIGHTING); 267 glColor4f(1, 1, 1, br); 268 return 1; 269}