../../../src/noise.cpp \
../../../src/objdef.cpp \
../../../src/object_properties.cpp \
+ ../../../src/particles.cpp \
../../../src/pathfinder.cpp \
../../../src/player.cpp \
../../../src/porting.cpp \
size = 1,
-- Scales the visual size of the particle texture.
+ -- If `node` is set, size can be set to 0 to spawn a randomly-sized
+ -- particle (just like actual node dig particles).
collisiondetection = false,
-- If true collides with `walkable` nodes and, depending on the
-- If true faces player using y axis only
texture = "image.png",
+ -- The texture of the particle
playername = "singleplayer",
-- Optional, if specified spawns particle only on the player's client
glow = 0
-- Optional, specify particle self-luminescence in darkness.
-- Values 0-14.
+
+ node = {name = "ignore", param2 = 0},
+ -- Optional, if specified the particle will have the same appearance as
+ -- node dig particles for the given node.
+ -- `texture` and `animation` will be ignored if this is set.
+
+ node_tile = 0,
+ -- Optional, only valid in combination with `node`
+ -- If set to a valid number 1-6, specifies the tile from which the
+ -- particle texture is picked.
+ -- Otherwise, the default behavior is used. (currently: any random tile)
}
maxsize = 1,
-- The particles' properties are random values between the min and max
-- values.
- -- pos, velocity, acceleration, expirationtime, size
+ -- applies to: pos, velocity, acceleration, expirationtime, size
+ -- If `node` is set, min and maxsize can be set to 0 to spawn
+ -- randomly-sized particles (just like actual node dig particles).
collisiondetection = false,
-- If true collide with `walkable` nodes and, depending on the
-- If true face player using y axis only
texture = "image.png",
+ -- The texture of the particle
playername = "singleplayer",
-- Optional, if specified spawns particles only on the player's client
glow = 0
-- Optional, specify particle self-luminescence in darkness.
-- Values 0-14.
+
+ node = {name = "ignore", param2 = 0},
+ -- Optional, if specified the particles will have the same appearance as
+ -- node dig particles for the given node.
+ -- `texture` and `animation` will be ignored if this is set.
+
+ node_tile = 0,
+ -- Optional, only valid in combination with `node`
+ -- If set to a valid number 1-6, specifies the tile from which the
+ -- particle texture is picked.
+ -- Otherwise, the default behavior is used. (currently: any random tile)
}
`HTTPRequest` definition
}
pp.expirationtime = random_f32(p.minexptime, p.maxexptime);
- pp.size = random_f32(p.minsize, p.maxsize);
-
p.copyCommon(pp);
+ video::ITexture *texture;
+ v2f texpos, texsize;
+ video::SColor color(0xFFFFFFFF);
+
+ if (p.node.getContent() != CONTENT_IGNORE) {
+ const ContentFeatures &f =
+ m_particlemanager->m_env->getGameDef()->ndef()->get(p.node);
+ if (!ParticleManager::getNodeParticleParams(p.node, f, pp, &texture,
+ texpos, texsize, &color, p.node_tile))
+ return;
+ } else {
+ texture = m_texture;
+ texpos = v2f(0.0f, 0.0f);
+ texsize = v2f(1.0f, 1.0f);
+ }
+
+ // Allow keeping default random size
+ if (p.maxsize > 0.0f)
+ pp.size = random_f32(p.minsize, p.maxsize);
+
m_particlemanager->addParticle(new Particle(
m_gamedef,
m_player,
env,
pp,
- m_texture,
- v2f(0.0, 0.0),
- v2f(1.0, 1.0)
+ texture,
+ texpos,
+ texsize,
+ color
));
}
break;
}
case CE_SPAWN_PARTICLE: {
- const ParticleParameters &p = *event->spawn_particle;
- video::ITexture *texture =
- client->tsrc()->getTextureForMesh(p.texture);
+ ParticleParameters &p = *event->spawn_particle;
- Particle *toadd = new Particle(client, player, m_env,
- p,
- texture,
- v2f(0.0, 0.0),
- v2f(1.0, 1.0));
+ video::ITexture *texture;
+ v2f texpos, texsize;
+ video::SColor color(0xFFFFFFFF);
+
+ f32 oldsize = p.size;
+
+ if (p.node.getContent() != CONTENT_IGNORE) {
+ const ContentFeatures &f = m_env->getGameDef()->ndef()->get(p.node);
+ if (!getNodeParticleParams(p.node, f, p, &texture, texpos,
+ texsize, &color, p.node_tile))
+ texture = nullptr;
+ } else {
+ texture = client->tsrc()->getTextureForMesh(p.texture);
+ texpos = v2f(0.0f, 0.0f);
+ texsize = v2f(1.0f, 1.0f);
+ }
+
+ // Allow keeping default random size
+ if (oldsize > 0.0f)
+ p.size = oldsize;
- addParticle(toadd);
+ if (texture) {
+ Particle *toadd = new Particle(client, player, m_env,
+ p, texture, texpos, texsize, color);
+
+ addParticle(toadd);
+ }
delete event->spawn_particle;
break;
}
bool ParticleManager::getNodeParticleParams(const MapNode &n,
- const ContentFeatures &f, ParticleParameters &p,
- video::ITexture **texture, v2f &texpos, v2f &texsize, video::SColor *color)
+ const ContentFeatures &f, ParticleParameters &p, video::ITexture **texture,
+ v2f &texpos, v2f &texsize, video::SColor *color, u8 tilenum)
{
// No particles for "airlike" nodes
if (f.drawtype == NDT_AIRLIKE)
return false;
// Texture
- u8 texid = rand() % 6;
+ u8 texid;
+ if (tilenum > 0 && tilenum <= 6)
+ texid = tilenum - 1;
+ else
+ texid = rand() % 6;
const TileLayer &tile = f.tiles[texid].layers[0];
p.animation.type = TAT_NONE;
video::ITexture *texture,
v2f texpos,
v2f texsize,
- video::SColor color = video::SColor(0xFFFFFFFF)
+ video::SColor color
);
~Particle() = default;
protected:
static bool getNodeParticleParams(const MapNode &n, const ContentFeatures &f,
ParticleParameters &p, video::ITexture **texture, v2f &texpos,
- v2f &texsize, video::SColor *color);
+ v2f &texsize, video::SColor *color, u8 tilenum = 0);
void addParticle(Particle* toadd);
p.glow = readU8(is);
p.object_collision = readU8(is);
+ // This is kinda awful
+ do {
+ u16 tmp_param0 = readU16(is);
+ if (is.eof())
+ break;
+ p.node.param0 = tmp_param0;
+ p.node.param2 = readU8(is);
+ p.node_tile = readU8(is);
+ } while (0);
+
auto event = new ClientEvent();
event->type = CE_ADD_PARTICLESPAWNER;
event->add_particlespawner.p = new ParticleSpawnerParameters(p);
animation.serialize(os, 6); /* NOT the protocol ver */
writeU8(os, glow);
writeU8(os, object_collision);
+ writeU16(os, node.param0);
+ writeU8(os, node.param2);
+ writeU8(os, node_tile);
}
void ParticleParameters::deSerialize(std::istream &is, u16 protocol_ver)
animation.deSerialize(is, 6); /* NOT the protocol ver */
glow = readU8(is);
object_collision = readU8(is);
+ // This is kinda awful
+ u16 tmp_param0 = readU16(is);
+ if (is.eof())
+ return;
+ node.param0 = tmp_param0;
+ node.param2 = readU8(is);
+ node_tile = readU8(is);
}
#include <string>
#include "irrlichttypes_bloated.h"
#include "tileanimation.h"
+#include "mapnode.h"
// This file defines the particle-related structures that both the server and
// client need. The ParticleManager and rendering is in client/particles.h
std::string texture;
struct TileAnimationParams animation;
u8 glow = 0;
+ MapNode node;
+ u8 node_tile = 0;
CommonParticleParams() {
animation.type = TAT_NONE;
+ node.setContent(CONTENT_IGNORE);
}
/* This helper is useful for copying params from
to.texture = texture;
to.animation = animation;
to.glow = glow;
+ to.node = node;
+ to.node_tile = node_tile;
}
};
p.texture = getstringfield_default(L, 1, "texture", p.texture);
p.glow = getintfield_default(L, 1, "glow", p.glow);
+ lua_getfield(L, 1, "node");
+ if (lua_istable(L, -1))
+ p.node = readnode(L, -1, getGameDef(L)->ndef());
+ lua_pop(L, 1);
+
+ p.node_tile = getintfield_default(L, 1, "node_tile", p.node_tile);
+
playername = getstringfield_default(L, 1, "playername", "");
}
p.texture = getstringfield_default(L, 1, "texture", p.texture);
playername = getstringfield_default(L, 1, "playername", "");
p.glow = getintfield_default(L, 1, "glow", p.glow);
+
+ lua_getfield(L, 1, "node");
+ if (lua_istable(L, -1))
+ p.node = readnode(L, -1, getGameDef(L)->ndef());
+ lua_pop(L, 1);
+
+ p.node_tile = getintfield_default(L, 1, "node_tile", p.node_tile);
}
u32 id = getServer(L)->addParticleSpawner(p, attached, playername);
p.texture = getstringfield_default(L, 1, "texture", p.texture);
p.glow = getintfield_default(L, 1, "glow", p.glow);
+ lua_getfield(L, 1, "node");
+ if (lua_istable(L, -1))
+ p.node = readnode(L, -1, getGameDef(L)->ndef());
+ lua_pop(L, 1);
+
+ p.node_tile = getintfield_default(L, 1, "node_tile", p.node_tile);
+
ClientEvent *event = new ClientEvent();
event->type = CE_SPAWN_PARTICLE;
event->spawn_particle = new ParticleParameters(p);
p.texture = getstringfield_default(L, 1, "texture", p.texture);
p.glow = getintfield_default(L, 1, "glow", p.glow);
+ lua_getfield(L, 1, "node");
+ if (lua_istable(L, -1))
+ p.node = readnode(L, -1, getGameDef(L)->ndef());
+ lua_pop(L, 1);
+
+ p.node_tile = getintfield_default(L, 1, "node_tile", p.node_tile);
+
u64 id = getClient(L)->getParticleManager()->generateSpawnerId();
auto event = new ClientEvent();
pkt.putRawString(os.str());
}
pkt << p.glow << p.object_collision;
+ pkt << p.node.param0 << p.node.param2 << p.node_tile;
Send(&pkt);
}