- 1,015
- 9
- 102
Всем примет, седня решил сделать спавн частиц около игрока. Всё вроде бы правильно сделал, но почему-то частицы спавнятся не на той позиции, что я указываю, но зато к ней летят, т.е. сходятся в одной точке из определенной стороны. Выглядит это примерно так:
Вот код пакета, где происходит спавн частиц:
Вот так пакет отправляется:
Как сделать так, что бы они спавнились со всех сторон игрока и улетали от него?
Код:
public class PacketSpawnParticle extends AbstractPacket<PacketSpawnParticle> {
protected int type;
protected float x;
protected float y;
protected float z;
protected float xSpeed;
protected float ySpeed;
protected float zSpeed;
protected int count;
protected float randomXPos;
protected float randomXMotion;
protected float randomYPos;
protected float randomYMotion;
protected float randomZPos;
protected float randomZMotion;
public PacketSpawnParticle(){}
public PacketSpawnParticle(int type, float x, float y, float z, float xSpeed, float ySpeed, float zSpeed, int count){
this(type, x, y, z, xSpeed, ySpeed, zSpeed, count, 0, 0);
}
public PacketSpawnParticle(int type, float x, float y, float z, float xSpeed, float ySpeed, float zSpeed, int count, float randomPos, float randomMotion){
this(type, x, y, z, xSpeed, ySpeed, zSpeed, count, randomPos, randomPos, randomPos, randomMotion, randomMotion, randomMotion);
}
public PacketSpawnParticle(int type, float x, float y, float z, float xSpeed, float ySpeed, float zSpeed, int count, float randomXPos, float randomXMotion, float randomYPos, float randomYMotion, float randomZPos, float randomZMotion) {
this.type = type;
this.x = x;
this.y = y;
this.z = z;
this.xSpeed = xSpeed;
this.ySpeed = ySpeed;
this.zSpeed = zSpeed;
this.count = count;
this.randomXPos = randomXPos;
this.randomXMotion = randomXMotion;
this.randomYPos = randomYPos;
this.randomYMotion = randomYMotion;
this.randomZPos = randomZPos;
this.randomZMotion = randomZMotion;
}
@Override
public void toBytes(final ByteBuf buf) {
buf.writeInt(type);
buf.writeInt(count);
buf.writeFloat(x);
buf.writeFloat(y);
buf.writeFloat(z);
buf.writeFloat(xSpeed);
buf.writeFloat(ySpeed);
buf.writeFloat(zSpeed);
buf.writeFloat(randomXPos);
buf.writeFloat(randomYPos);
buf.writeFloat(randomZPos);
buf.writeFloat(randomXMotion);
buf.writeFloat(randomYMotion);
buf.writeFloat(randomZMotion);
}
@Override
public void fromBytes(final ByteBuf buf) {
type = buf.readInt();
count = buf.readInt();
x = buf.readFloat();
y = buf.readFloat();
z = buf.readFloat();
xSpeed = buf.readFloat();
ySpeed = buf.readFloat();
zSpeed = buf.readFloat();
randomXPos = buf.readFloat();
randomYPos = buf.readFloat();
randomZPos = buf.readFloat();
randomXMotion = buf.readFloat();
randomYMotion = buf.readFloat();
randomZMotion = buf.readFloat();
}
@Override
public void handleClientSide(PacketSpawnParticle message, EntityPlayer player) {
for (int i = 0; i < message.count; i++) {
float xRandPos = (ModUtils.random.nextInt(2) == 0 ? -1 : 1) * ModUtils.random.nextFloat() * message.randomXPos;
float yRandPos = (ModUtils.random.nextInt(2) == 0 ? -1 : 1) * ModUtils.random.nextFloat() * message.randomYPos;
float zRandPos = (ModUtils.random.nextInt(2) == 0 ? -1 : 1) * ModUtils.random.nextFloat() * message.randomZPos;
float xRandMotion = (ModUtils.random.nextInt(2) == 0 ? -1 : 1) * ModUtils.random.nextFloat() * message.randomXMotion;
float yRandMotion = (ModUtils.random.nextInt(2) == 0 ? -1 : 1) * ModUtils.random.nextFloat() * message.randomYMotion;
float zRandMotion = (ModUtils.random.nextInt(2) == 0 ? -1 : 1) * ModUtils.random.nextFloat() * message.randomZMotion;
player.world.spawnParticle(
EnumParticleTypes.getParticleFromId(message.type),
message.x + xRandPos,
message.y + yRandPos,
message.z + zRandPos,
message.xSpeed + xRandMotion,
message.ySpeed + yRandMotion,
message.zSpeed + zRandMotion
);
}
}
@Override
public void handleServerSide(PacketSpawnParticle message, EntityPlayer player) {
}
}
Код:
Vec3d particlePos = args.player.getPositionEyes(Minecraft.getMinecraft().getRenderPartialTicks());
NetworkHandler.sendToAll(new PacketSpawnParticle(EnumParticleTypes.PORTAL.getParticleID(), (float)particlePos.xCoord, (float)particlePos.yCoord, (float)particlePos.zCoord, 0.5f, 0.5f, 0.5f, 100, 0.2f,2f));
Как сделать так, что бы они спавнились со всех сторон игрока и улетали от него?