+
+ if (event->type == CE_SPAWN_PARTICLE) {
+ video::ITexture *texture =
+ gamedef->tsrc()->getTextureForMesh(*(event->spawn_particle.texture));
+
+ Particle* toadd = new Particle(gamedef, smgr, player, m_env,
+ *event->spawn_particle.pos,
+ *event->spawn_particle.vel,
+ *event->spawn_particle.acc,
+ event->spawn_particle.expirationtime,
+ event->spawn_particle.size,
+ event->spawn_particle.collisiondetection,
+ event->spawn_particle.vertical,
+ texture,
+ v2f(0.0, 0.0),
+ v2f(1.0, 1.0));
+
+ addParticle(toadd);
+
+ delete event->spawn_particle.pos;
+ delete event->spawn_particle.vel;
+ delete event->spawn_particle.acc;
+
+ return;
+ }
+}
+
+void ParticleManager::addDiggingParticles(IGameDef* gamedef, scene::ISceneManager* smgr,
+ LocalPlayer *player, v3s16 pos, const TileSpec tiles[])
+{
+ for (u16 j = 0; j < 32; j++) // set the amount of particles here
+ {
+ addNodeParticle(gamedef, smgr, player, pos, tiles);
+ }
+}
+
+void ParticleManager::addPunchingParticles(IGameDef* gamedef, scene::ISceneManager* smgr,
+ LocalPlayer *player, v3s16 pos, const TileSpec tiles[])
+{
+ addNodeParticle(gamedef, smgr, player, pos, tiles);
+}
+
+void ParticleManager::addNodeParticle(IGameDef* gamedef, scene::ISceneManager* smgr,
+ LocalPlayer *player, v3s16 pos, const TileSpec tiles[])
+{
+ // Texture
+ u8 texid = myrand_range(0, 5);
+ video::ITexture *texture = tiles[texid].texture;
+
+ // Only use first frame of animated texture
+ f32 ymax = 1;
+ if(tiles[texid].material_flags & MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES)
+ ymax /= tiles[texid].animation_frame_count;
+
+ float size = rand() % 64 / 512.;
+ float visual_size = BS * size;
+ v2f texsize(size * 2, ymax * size * 2);
+ v2f texpos;
+ texpos.X = ((rand() % 64) / 64. - texsize.X);
+ texpos.Y = ymax * ((rand() % 64) / 64. - texsize.Y);
+
+ // Physics
+ v3f velocity((rand() % 100 / 50. - 1) / 1.5,
+ rand() % 100 / 35.,
+ (rand() % 100 / 50. - 1) / 1.5);
+
+ v3f acceleration(0,-9,0);
+ v3f particlepos = v3f(
+ (f32) pos.X + rand() %100 /200. - 0.25,
+ (f32) pos.Y + rand() %100 /200. - 0.25,
+ (f32) pos.Z + rand() %100 /200. - 0.25
+ );
+
+ Particle* toadd = new Particle(
+ gamedef,
+ smgr,
+ player,
+ m_env,
+ particlepos,
+ velocity,
+ acceleration,
+ rand() % 100 / 100., // expiration time
+ visual_size,
+ true,
+ false,
+ texture,
+ texpos,
+ texsize);
+
+ addParticle(toadd);
+}
+
+void ParticleManager::addParticle(Particle* toadd)
+{
+ MutexAutoLock lock(m_particle_list_lock);
+ m_particles.push_back(toadd);