mirror of
https://github.com/neoStudiosLCE/neoLegacy.git
synced 2026-06-08 21:03:00 +00:00
fix particles being sent from the server
This commit is contained in:
parent
baa6745f45
commit
61f363e803
|
|
@ -4323,22 +4323,19 @@ void ClientConnection::handleSetPlayerTeamPacket(shared_ptr<SetPlayerTeamPacket>
|
|||
|
||||
void ClientConnection::handleParticleEvent(shared_ptr<LevelParticlesPacket> packet)
|
||||
{
|
||||
const ParticleType* type = packet->getType();
|
||||
if (type == nullptr) return;
|
||||
ePARTICLE_TYPE particleId = (ePARTICLE_TYPE)Integer::parseInt(packet->getName());
|
||||
|
||||
ePARTICLE_TYPE particleId = (ePARTICLE_TYPE)type->getId();
|
||||
for (int i = 0; i < packet->getCount(); i++)
|
||||
{
|
||||
double xVarience = random->nextGaussian() * packet->getXDist();
|
||||
double yVarience = random->nextGaussian() * packet->getYDist();
|
||||
double zVarience = random->nextGaussian() * packet->getZDist();
|
||||
double xa = random->nextGaussian() * packet->getMaxSpeed();
|
||||
double ya = random->nextGaussian() * packet->getMaxSpeed();
|
||||
double za = random->nextGaussian() * packet->getMaxSpeed();
|
||||
|
||||
for (int i = 0; i < packet->getCount(); i++)
|
||||
{
|
||||
double xVarience = random->nextGaussian() * packet->getXDist();
|
||||
double yVarience = random->nextGaussian() * packet->getYDist();
|
||||
double zVarience = random->nextGaussian() * packet->getZDist();
|
||||
double xa = random->nextGaussian() * packet->getMaxSpeed();
|
||||
double ya = random->nextGaussian() * packet->getMaxSpeed();
|
||||
double za = random->nextGaussian() * packet->getMaxSpeed();
|
||||
|
||||
level->addParticle(particleId, packet->getX() + xVarience, packet->getY() + yVarience, packet->getZ() + zVarience, xa, ya, za);
|
||||
}
|
||||
level->addParticle(particleId, packet->getX() + xVarience, packet->getY() + yVarience, packet->getZ() + zVarience, xa, ya, za);
|
||||
}
|
||||
}
|
||||
|
||||
void ClientConnection::handleUpdateAttributes(shared_ptr<UpdateAttributesPacket> packet)
|
||||
|
|
|
|||
|
|
@ -1683,14 +1683,15 @@ void ServerLevel::flagEntitiesToBeRemoved(unsigned int *flags, bool *removedFoun
|
|||
}
|
||||
void ServerLevel::sendParticles(const ParticleType* type, bool longDistance, double x, double y, double z, int count, double dx, double dy, double dz, double speed, arrayWithLength<int> data)
|
||||
{
|
||||
wchar_t buf[32];
|
||||
swprintf_s(buf, L"%d", type->getId());
|
||||
|
||||
auto packet = make_shared<LevelParticlesPacket>(
|
||||
type,
|
||||
longDistance,
|
||||
buf,
|
||||
(float)x, (float)y, (float)z,
|
||||
(float)dx, (float)dy, (float)dz,
|
||||
(float)speed,
|
||||
count,
|
||||
data
|
||||
count
|
||||
);
|
||||
|
||||
for (auto const& p : players)
|
||||
|
|
|
|||
|
|
@ -1281,10 +1281,9 @@ void __cdecl NativeSpawnParticle(int entityId, int particleId, float x, float y,
|
|||
{
|
||||
auto player = FindPlayer(entityId);
|
||||
if (!player || !player->connection) return;
|
||||
const ParticleType* type = ParticleType::byId(particleId);
|
||||
if (!type) type = ParticleType::getDefault();
|
||||
arrayWithLength<int> noParams = { nullptr, 0 };
|
||||
player->connection->send(std::make_shared<LevelParticlesPacket>(type, false, x, y, z, offsetX, offsetY, offsetZ, speed, count, noParams));
|
||||
wchar_t buf[32];
|
||||
swprintf_s(buf, L"%d", particleId);
|
||||
player->connection->send(std::make_shared<LevelParticlesPacket>(std::wstring(buf), x, y, z, offsetX, offsetY, offsetZ, speed, count));
|
||||
}
|
||||
|
||||
int __cdecl NativeSetPassenger(int entityId, int passengerEntityId)
|
||||
|
|
|
|||
|
|
@ -1,127 +1,110 @@
|
|||
|
||||
#include "stdafx.h"
|
||||
#include "stdafx.h"
|
||||
#include "PacketListener.h"
|
||||
#include "LevelParticlesPacket.h"
|
||||
#include "../Minecraft.Client/ParticleType.h"
|
||||
|
||||
LevelParticlesPacket::LevelParticlesPacket()
|
||||
{
|
||||
|
||||
this->overrideLimiter = false;
|
||||
this->type = nullptr;
|
||||
this->count = 0;
|
||||
this->y = 0.0f;
|
||||
this->paramCount = 0;
|
||||
this->x = 0.0f;
|
||||
this->yDist = 0.0f;
|
||||
this->zDist = 0.0f;
|
||||
this->z = 0.0f;
|
||||
this->maxSpeed = 0.0f;
|
||||
this->xDist = 0.0f;
|
||||
this->params = nullptr;
|
||||
this->name = L"";
|
||||
this->x = 0.0f;
|
||||
this->y = 0.0f;
|
||||
this->z = 0.0f;
|
||||
this->xDist = 0.0f;
|
||||
this->yDist = 0.0f;
|
||||
this->zDist = 0.0f;
|
||||
this->maxSpeed = 0.0f;
|
||||
this->count = 0;
|
||||
}
|
||||
|
||||
LevelParticlesPacket::LevelParticlesPacket(const ParticleType* type, bool overrideLimiter,
|
||||
float x, float y, float z,
|
||||
float xDist, float yDist, float zDist,
|
||||
float maxSpeed, int count,
|
||||
arrayWithLength<int> data)
|
||||
LevelParticlesPacket::LevelParticlesPacket(const wstring& name, float x, float y, float z, float xDist, float yDist, float zDist, float maxSpeed, int count)
|
||||
{
|
||||
this->type = type;
|
||||
this->overrideLimiter = overrideLimiter;
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->z = z;
|
||||
this->xDist = xDist;
|
||||
this->yDist = yDist;
|
||||
this->zDist = zDist;
|
||||
this->maxSpeed = maxSpeed;
|
||||
this->count = count;
|
||||
this->paramCount = data.length;
|
||||
|
||||
if (data.data && data.length > 0)
|
||||
{
|
||||
this->params = new int[data.length];
|
||||
memcpy(this->params, data.data, data.length * sizeof(int));
|
||||
}
|
||||
else
|
||||
{
|
||||
this->params = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
LevelParticlesPacket::~LevelParticlesPacket()
|
||||
{
|
||||
|
||||
if (params)
|
||||
{
|
||||
delete[] params;
|
||||
params = nullptr;
|
||||
}
|
||||
this->name = name;
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->z = z;
|
||||
this->xDist = xDist;
|
||||
this->yDist = yDist;
|
||||
this->zDist = zDist;
|
||||
this->maxSpeed = maxSpeed;
|
||||
this->count = count;
|
||||
}
|
||||
|
||||
void LevelParticlesPacket::read(DataInputStream* dis)
|
||||
{
|
||||
int particleId = dis->readInt();
|
||||
const ParticleType* resolved = ParticleType::byId(particleId);
|
||||
if (!resolved)
|
||||
resolved = ParticleType::getDefault();
|
||||
this->type = resolved;
|
||||
|
||||
this->overrideLimiter = dis->readBoolean();
|
||||
|
||||
this->x = dis->readFloat();
|
||||
this->y = dis->readFloat();
|
||||
this->z = dis->readFloat();
|
||||
this->xDist = dis->readFloat();
|
||||
this->yDist = dis->readFloat();
|
||||
this->zDist = dis->readFloat();
|
||||
this->maxSpeed = dis->readFloat();
|
||||
this->count = dis->readInt();
|
||||
|
||||
int paramCount = this->type ? this->type->getParamCount() : 0;
|
||||
this->paramCount = paramCount;
|
||||
|
||||
if (paramCount > 0)
|
||||
{
|
||||
this->params = new int[paramCount]();
|
||||
for (int i = 0; i < paramCount; i++)
|
||||
{
|
||||
this->params[i] = dis->readInt();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this->params = nullptr;
|
||||
}
|
||||
name = readUtf(dis, 64);
|
||||
x = dis->readFloat();
|
||||
y = dis->readFloat();
|
||||
z = dis->readFloat();
|
||||
xDist = dis->readFloat();
|
||||
yDist = dis->readFloat();
|
||||
zDist = dis->readFloat();
|
||||
maxSpeed = dis->readFloat();
|
||||
count = dis->readInt();
|
||||
}
|
||||
|
||||
void LevelParticlesPacket::write(DataOutputStream* dos)
|
||||
{
|
||||
dos->writeInt(this->type ? this->type->getId() : 0);
|
||||
dos->writeBoolean(this->overrideLimiter);
|
||||
dos->writeFloat(this->x);
|
||||
dos->writeFloat(this->y);
|
||||
dos->writeFloat(this->z);
|
||||
dos->writeFloat(this->xDist);
|
||||
dos->writeFloat(this->yDist);
|
||||
dos->writeFloat(this->zDist);
|
||||
dos->writeFloat(this->maxSpeed);
|
||||
dos->writeInt(this->count);
|
||||
writeUtf(name, dos);
|
||||
dos->writeFloat(x);
|
||||
dos->writeFloat(y);
|
||||
dos->writeFloat(z);
|
||||
dos->writeFloat(xDist);
|
||||
dos->writeFloat(yDist);
|
||||
dos->writeFloat(zDist);
|
||||
dos->writeFloat(maxSpeed);
|
||||
dos->writeInt(count);
|
||||
}
|
||||
|
||||
int toWrite = this->type ? this->type->getParamCount() : 0;
|
||||
for (int i = 0; i < toWrite; i++)
|
||||
{
|
||||
dos->writeInt(this->params[i]);
|
||||
}
|
||||
wstring LevelParticlesPacket::getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
double LevelParticlesPacket::getX()
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
double LevelParticlesPacket::getY()
|
||||
{
|
||||
return y;
|
||||
}
|
||||
|
||||
double LevelParticlesPacket::getZ()
|
||||
{
|
||||
return z;
|
||||
}
|
||||
|
||||
float LevelParticlesPacket::getXDist()
|
||||
{
|
||||
return xDist;
|
||||
}
|
||||
|
||||
float LevelParticlesPacket::getYDist()
|
||||
{
|
||||
return yDist;
|
||||
}
|
||||
|
||||
float LevelParticlesPacket::getZDist()
|
||||
{
|
||||
return zDist;
|
||||
}
|
||||
|
||||
float LevelParticlesPacket::getMaxSpeed()
|
||||
{
|
||||
return maxSpeed;
|
||||
}
|
||||
|
||||
int LevelParticlesPacket::getCount()
|
||||
{
|
||||
return count;
|
||||
}
|
||||
|
||||
void LevelParticlesPacket::handle(PacketListener* listener)
|
||||
{
|
||||
listener->handleParticleEvent(shared_from_this());
|
||||
listener->handleParticleEvent(shared_from_this());
|
||||
}
|
||||
|
||||
int LevelParticlesPacket::getEstimatedSize()
|
||||
{
|
||||
return 0x40;
|
||||
return 4 * 2 + 7 * 8;
|
||||
}
|
||||
|
|
@ -1,53 +1,39 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "Packet.h"
|
||||
#include "../Minecraft.Client/ParticleType.h"
|
||||
|
||||
class LevelParticlesPacket : public Packet, public enable_shared_from_this<LevelParticlesPacket>
|
||||
{
|
||||
private:
|
||||
|
||||
const ParticleType* type;
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float xDist;
|
||||
float yDist;
|
||||
float zDist;
|
||||
float maxSpeed;
|
||||
int count;
|
||||
bool overrideLimiter;
|
||||
int* params;
|
||||
int paramCount;
|
||||
wstring name;
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float xDist;
|
||||
float yDist;
|
||||
float zDist;
|
||||
float maxSpeed;
|
||||
int count;
|
||||
|
||||
public:
|
||||
LevelParticlesPacket();
|
||||
LevelParticlesPacket(const ParticleType* type, bool overrideLimiter,
|
||||
float x, float y, float z,
|
||||
float xDist, float yDist, float zDist,
|
||||
float maxSpeed, int count,
|
||||
arrayWithLength<int> data);
|
||||
~LevelParticlesPacket();
|
||||
LevelParticlesPacket();
|
||||
LevelParticlesPacket(const wstring& name, float x, float y, float z, float xDist, float yDist, float zDist, float maxSpeed, int count);
|
||||
|
||||
void read(DataInputStream* dis) override;
|
||||
void write(DataOutputStream* dos) override;
|
||||
void read(DataInputStream* dis);
|
||||
void write(DataOutputStream* dos);
|
||||
wstring getName();
|
||||
double getX();
|
||||
double getY();
|
||||
double getZ();
|
||||
float getXDist();
|
||||
float getYDist();
|
||||
float getZDist();
|
||||
float getMaxSpeed();
|
||||
int getCount();
|
||||
void handle(PacketListener* listener);
|
||||
int getEstimatedSize();
|
||||
|
||||
const ParticleType* getType() { return type; }
|
||||
double getX() { return x; }
|
||||
double getY() { return y; }
|
||||
double getZ() { return z; }
|
||||
double getXDist() { return xDist; }
|
||||
double getYDist() { return yDist; }
|
||||
double getZDist() { return zDist; }
|
||||
double getMaxSpeed() { return maxSpeed; }
|
||||
int getCount() { return count; }
|
||||
bool isOverrideLimiter() { return overrideLimiter; }
|
||||
int* getParams() { return params; }
|
||||
int getParamCount() { return paramCount; }
|
||||
|
||||
void handle(PacketListener* listener) override;
|
||||
int getEstimatedSize() override;
|
||||
|
||||
static shared_ptr<Packet> create() { return std::make_shared<LevelParticlesPacket>(); }
|
||||
virtual int getId() override { return 63; }
|
||||
public:
|
||||
static shared_ptr<Packet> create() { return std::make_shared<LevelParticlesPacket>(); }
|
||||
virtual int getId() { return 63; }
|
||||
};
|
||||
Loading…
Reference in a new issue