the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at master 255 lines 6.3 kB view raw
1#include "stdafx.h" 2#include "Particle.h" 3#include "Tesselator.h" 4#include "..\Minecraft.World\Random.h" 5#include "..\Minecraft.World\Mth.h" 6#include "..\Minecraft.World\JavaMath.h" 7#include "..\Minecraft.World\net.minecraft.world.h" 8 9/* 10 protected int tex; 11 protected float gravity; 12 */ 13 14double Particle::xOff = 0; 15double Particle::yOff = 0; 16double Particle::zOff = 0; 17 18void Particle::_init(Level *level, double x, double y, double z) 19{ 20 // 4J - added these initialisers 21 alpha = 1.0f; 22 tex = NULL; 23 gravity = 0.0f; 24 25 setSize(0.2f, 0.2f); 26 heightOffset = bbHeight / 2.0f; 27 setPos(x, y, z); 28 xo = xOld = x; 29 yo = yOld = y; 30 zo = zOld = z; 31 rCol = gCol = bCol = 1.0f; 32 33 uo = random->nextFloat() * 3; 34 vo = random->nextFloat() * 3; 35 36 size = (random->nextFloat() * 0.5f + 0.5f) * 2; 37 38 lifetime = (int) (4 / (random->nextFloat() * 0.9f + 0.1f)); 39 age = 0; 40 41 texX = 0; 42 texY = 0; 43} 44 45Particle::Particle(Level *level, double x, double y, double z) : Entity(level, false) 46{ 47 _init(level,x,y,z); 48} 49 50Particle::Particle(Level *level, double x, double y, double z, double xa, double ya, double za) : Entity(level, false) 51{ 52 _init(level,x,y,z); 53 54 xd = xa + (float) (Math::random() * 2 - 1) * 0.4f; 55 yd = ya + (float) (Math::random() * 2 - 1) * 0.4f; 56 zd = za + (float) (Math::random() * 2 - 1) * 0.4f; 57 float speed = (float) (Math::random() + Math::random() + 1) * 0.15f; 58 59 float dd = (float) (Mth::sqrt(xd * xd + yd * yd + zd * zd)); 60 xd = xd / dd * speed * 0.4f; 61 yd = yd / dd * speed * 0.4f + 0.1f; 62 zd = zd / dd * speed * 0.4f;} 63 64shared_ptr<Particle> Particle::setPower(float power) 65{ 66 xd *= power; 67 yd = (yd - 0.1f) * power + 0.1f; 68 zd *= power; 69 return dynamic_pointer_cast<Particle>( shared_from_this() ); 70} 71 72shared_ptr<Particle> Particle::scale(float scale) 73{ 74 setSize(0.2f * scale, 0.2f * scale); 75 size *= scale; 76 return dynamic_pointer_cast<Particle>( shared_from_this() ); 77} 78 79void Particle::setColor(float r, float g, float b) 80{ 81 this->rCol = r; 82 this->gCol = g; 83 this->bCol = b; 84} 85 86void Particle::setAlpha(float alpha) 87{ 88 // 4J - brought forward from Java 1.8 89 if (this->alpha == 1.0f && alpha < 1.0f) 90 { 91 Minecraft::GetInstance()->particleEngine->markTranslucent(dynamic_pointer_cast<Particle>(shared_from_this())); 92 } 93 else if (this->alpha < 1.0f && alpha == 1.0f) 94 { 95 Minecraft::GetInstance()->particleEngine->markOpaque(dynamic_pointer_cast<Particle>(shared_from_this())); 96 } 97 this->alpha = alpha; 98} 99 100float Particle::getRedCol() 101{ 102 return rCol; 103} 104 105float Particle::getGreenCol() 106{ 107 return gCol; 108} 109 110float Particle::getBlueCol() 111{ 112 return bCol; 113} 114 115float Particle::getAlpha() 116{ 117 return alpha; 118} 119 120bool Particle::makeStepSound() 121{ 122 return false; 123} 124 125void Particle::defineSynchedData() 126{ 127} 128 129void Particle::tick() 130{ 131 xo = x; 132 yo = y; 133 zo = z; 134 135 if (age++ >= lifetime) remove(); 136 137 yd -= 0.04 * gravity; 138 move(xd, yd, zd); 139 xd *= 0.98f; 140 yd *= 0.98f; 141 zd *= 0.98f; 142 143 if (onGround) 144 { 145 xd *= 0.7f; 146 zd *= 0.7f; 147 } 148 149} 150 151void Particle::render(Tesselator *t, float a, float xa, float ya, float za, float xa2, float za2) 152{ 153 float u0 = texX / 16.0f; 154 float u1 = u0 + 0.999f / 16.0f; 155 float v0 = texY / 16.0f; 156 float v1 = v0 + 0.999f / 16.0f; 157 float r = 0.1f * size; 158 159 if (tex != NULL) 160 { 161 u0 = tex->getU0(); 162 u1 = tex->getU1(); 163 v0 = tex->getV0(); 164 v1 = tex->getV1(); 165 } 166 167 float x = (float) (xo + (this->x - xo) * a - xOff); 168 float y = (float) (yo + (this->y - yo) * a - yOff); 169 float z = (float) (zo + (this->z - zo) * a - zOff); 170 171 float br = 1.0f; // 4J - change brought forward from 1.8.2 172 if( !SharedConstants::TEXTURE_LIGHTING ) 173 { 174 br = getBrightness(a); 175 } 176 177#ifdef __PSVITA__ 178 // AP - this will set up the 4 vertices in half the time. 179 t->tileParticleQuad((float)(x - xa * r - xa2 * r), (float)( y - ya * r), (float)( z - za * r - za2 * r), (float)( u1), (float)( v1), 180 (float)(x - xa * r + xa2 * r), (float)( y + ya * r), (float)( z - za * r + za2 * r), (float)( u1), (float)( v0), 181 (float)(x + xa * r + xa2 * r), (float)( y + ya * r), (float)( z + za * r + za2 * r), (float)( u0), (float)( v0), 182 (float)(x + xa * r - xa2 * r), (float)( y - ya * r), (float)( z + za * r - za2 * r), (float)( u0), (float)( v1), 183 rCol * br, gCol * br, bCol * br, alpha); 184#else 185 t->color(rCol * br, gCol * br, bCol * br, alpha); 186 187 t->vertexUV((float)(x - xa * r - xa2 * r), (float)( y - ya * r), (float)( z - za * r - za2 * r), (float)( u1), (float)( v1)); 188 t->vertexUV((float)(x - xa * r + xa2 * r), (float)( y + ya * r), (float)( z - za * r + za2 * r), (float)( u1), (float)( v0)); 189 t->vertexUV((float)(x + xa * r + xa2 * r), (float)( y + ya * r), (float)( z + za * r + za2 * r), (float)( u0), (float)( v0)); 190 t->vertexUV((float)(x + xa * r - xa2 * r), (float)( y - ya * r), (float)( z + za * r - za2 * r), (float)( u0), (float)( v1)); 191#endif 192} 193 194int Particle::getParticleTexture() 195{ 196 return ParticleEngine::MISC_TEXTURE; 197} 198 199void Particle::addAdditonalSaveData(CompoundTag *entityTag) 200{ 201} 202 203void Particle::readAdditionalSaveData(CompoundTag *tag) 204{ 205} 206 207void Particle::setTex(Textures *textures, Icon *icon) 208{ 209 if (getParticleTexture() == ParticleEngine::TERRAIN_TEXTURE) 210 { 211 tex = icon; 212 } 213 else if (getParticleTexture() == ParticleEngine::ITEM_TEXTURE) 214 { 215 tex = icon; 216 } 217 else 218 { 219#ifndef _CONTENT_PACKAGE 220 printf("Invalid call to Particle.setTex, use coordinate methods\n"); 221 __debugbreak(); 222#endif 223 //throw new RuntimeException("Invalid call to Particle.setTex, use coordinate methods"); 224 } 225} 226 227void Particle::setMiscTex(int slotIndex) 228{ 229 if (getParticleTexture() != ParticleEngine::MISC_TEXTURE && getParticleTexture() != ParticleEngine::DRAGON_BREATH_TEXTURE) 230 { 231#ifndef _CONTENT_PACKAGE 232 printf("Invalid call to Particle.setMixTex\n"); 233 __debugbreak(); 234 //throw new RuntimeException("Invalid call to Particle.setMiscTex"); 235#endif 236 } 237 texX = slotIndex % 16; 238 texY = slotIndex / 16; 239} 240 241void Particle::setNextMiscAnimTex() 242{ 243 texX++; 244} 245 246bool Particle::isAttackable() 247{ 248 return false; 249} 250 251//@Override 252wstring Particle::toString() 253{ 254 return L"A particle"; //getClass()->getSimpleName() + ", Pos (" + x + "," + y + "," + z + "), RGBA (" + rCol + "," + gCol + "," + bCol + "," + alpha + "), Age " + age; 255}